#22804: fix: prioritize loopback for internal gateway calls (issue #22706)
gateway
size: XS
Cluster:
Gateway Resilience and Configuration
Fixes #22706. Recreating PR 22784 from a clean branch to resolve bot closure.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Forces internal gateway calls to use loopback interface instead of remote URLs. When the gateway server starts, it sets `OPENCLAW_IS_GATEWAY_SERVER="true"`. The `buildGatewayConnectionDetails` function now checks this env var (or explicit `forceLocal` option) to prevent remote URL resolution, ensuring internal RPC calls from within the gateway process always connect to `127.0.0.1` regardless of remote gateway configuration.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-scoped and address a clear architectural issue where internal gateway calls could incorrectly attempt to use remote URLs. The implementation is clean, follows existing patterns, adds proper documentation, and includes the forceLocal parameter threading through the call stack correctly.
- No files require special attention
<sub>Last reviewed commit: 2914903</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22110: fix(tools): prefer loopback for internal tool-to-gateway RPC calls
by pierreeurope · 2026-02-20
84.8%
#19026: fix(gateway): use loopback for local CLI-to-gateway connections
by Phineas1500 · 2026-02-17
83.7%
#22056: fix(gateway): use loopback for self-connections regardless of bind ...
by usedhonda · 2026-02-20
82.3%
#19437: Gateway: respect custom bind host for local health/RPC target resol...
by frudas24 · 2026-02-17
81.0%
#21000: fix: resolve option collision between browser and cookies set commands
by MisterGuy420 · 2026-02-19
78.8%
#14564: fix(gateway): crashes on startup when tailscale meets non-loopback ...
by yinghaosang · 2026-02-12
78.6%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
78.3%
#14277: fix(CLI): Use wss for probeUrl, when gateway has tls enabled
by tha80 · 2026-02-11
77.4%
#4653: fix(gateway): improve crash resilience for mDNS and network errors
by AyedAlmudarra · 2026-01-30
77.1%
#9460: fix(gateway): clean up lock file on service stop
by zenchantlive · 2026-02-05
77.0%