Skip to content

fix(gateway): avoid loopback connections for embedded config reads - #146226

Merged
steipete merged 1 commit into
mainfrom
codex/gateway-config-in-process
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/gateway-config-in-process

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where an agent running inside the Gateway opened another WebSocket connection to read that same Gateway's configuration. Repeated config reads paid connection and authentication overhead and could wait on the local transport under load.

Why This Change Was Made

Route config.get and config.schema.lookup through the existing in-process dispatcher when the caller has an admitted Gateway binding. Reuse its current-authority checks, least-privilege read scope, cancellation, deadline, and typed errors. Retired bindings reject locally.

Explicit URL/token overrides and standalone local agents retain the existing Gateway client. Configuration handlers, redaction, and the model-facing tool schema are unchanged.

User Impact

Embedded configuration reads avoid unnecessary sockets and handshakes while preserving explicit remote access and existing response behavior.

Evidence

  • The new registered-tool regression failed on the original path because neither config action reached the in-process router. It passes with the fix.
  • 65 focused tests passed, covering routing, explicit overrides, standalone/embedded contexts, read scope, expired caller authority, replaced Gateway, cancellation, deadline, and schema misses.
  • Synthetic comparison through the real tool and WebSocket client/server: 100 warm reads took 0.4498 seconds via loopback and 0.00330 seconds through direct dispatch. The socket arm opened 110 connections including ten warmups; the direct arm opened none. Both used identical fixed handler payloads. This measures routing overhead, not production handler latency.
  • Sampled worker RSS was 607.2 MB for the socket arm and 575.8 MB for direct dispatch. Whole test-run timings include differing transform-cache warmth and are not used as a speedup claim.
  • The complete changed-check gate (including core and test typechecks, lint, and architecture guards) and independent P0–P2 review passed. Full pnpm build passed on the same reviewed production tree. Exact-head CI supplies hosted proof.

The branch includes #146212’s shared typecheck-shard repair, with a patch-identical rebase. An earlier hosted run also failed an unchanged IPv6 portal fixture; no portal code is changed by this PR.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 17:04
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 1:27 PM ET / 17:27 UTC (Revision 2).

ClawSweeper review

What this changes

Routes admitted agents’ configuration reads through their hosting Gateway’s existing dispatcher, with routing tests and documentation, while preserving explicit connection overrides and standalone client access.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still uses the socket path, and this focused change remains useful. No actionable correctness or security defect was found; the protected maintainer label also excludes automated closure.

Priority: P2
Reviewed head: 468cd643c1b05658dfba797801df2e6f0bdb852e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with relevant routing coverage, bounded performance evidence, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this PR from ordinary contributor proof. Its reported real-tool/WebSocket comparison supports removal of routing overhead, while boundary tests supplement caller-lifetime coverage; no unresolved material authority violation was identified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this PR from ordinary contributor proof. Its reported real-tool/WebSocket comparison supports removal of routing overhead, while boundary tests supplement caller-lifetime coverage; no unresolved material authority violation was identified.
Evidence reviewed 9 items Introduced routing boundary: Both config actions use the existing in-process helper only with an admitted resolver and no explicit URL/token override; localEmbedded callers retain transport routing. The introduced delta contains no CI repair or new dependency contract.
Current main still needs the change: Fetched main calls callGatewayTool for config.get and config.schema.lookup. The related merged CI repair, #146212, concerns test-shard allocation and does not implement this behavior.
Existing caller and instance fences: The reused helper checks host-owned run authority, binds the admitted Gateway instance, forwards a dispatch guard, and rechecks authority before returning success or an error.
Findings None None.
Security None None.

How this fits together

The built-in Gateway tool lets agents inspect configuration and schema. It sends requests to shared Gateway handlers, which authorize reads and return configuration with sensitive values redacted.

flowchart TD
  A[Agent config read] --> B{Admitted Gateway without override?}
  B -->|Yes| C[In-process dispatcher]
  B -->|No| D[Gateway WebSocket client]
  C --> E[Shared authorization and config handlers]
  D --> E
  E --> F[Config or schema result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +182, Docs +5. Total +195 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 15 7 +8
Tests 1 182 0 +182
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 202 7 +195

Review metrics

None.

Technical review

Best possible solution:

Keep configuration reads on the existing admitted-Gateway dispatcher, preserving shared authorization, redaction, deadlines, and explicit remote access.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: an admitted agent invoking either config read on fetched main unconditionally enters the Gateway client path. Runtime execution was not performed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing dispatcher removes connection overhead without duplicating config handlers or changing stored settings, and retains the supported transport exceptions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 50877be9476d.

Labels

Label justifications:

  • P2: Removes avoidable connection overhead from embedded configuration reads without changing the public tool surface.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER association exempts this PR from ordinary contributor proof. Its reported real-tool/WebSocket comparison supports removal of routing overhead, while boundary tests supplement caller-lifetime coverage; no unresolved material authority violation was identified.

Evidence

What I checked:

  • Introduced routing boundary: Both config actions use the existing in-process helper only with an admitted resolver and no explicit URL/token override; localEmbedded callers retain transport routing. The introduced delta contains no CI repair or new dependency contract. (src/agents/tools/gateway-tool.ts:191, 468cd643c1b0)
  • Current main still needs the change: Fetched main calls callGatewayTool for config.get and config.schema.lookup. The related merged CI repair, ci: restore gateway typecheck shard headroom #146212, concerns test-shard allocation and does not implement this behavior. (src/agents/tools/gateway-tool.ts:195, 50877be9476d)
  • Existing caller and instance fences: The reused helper checks host-owned run authority, binds the admitted Gateway instance, forwards a dispatch guard, and rechecks authority before returning success or an error. (src/agents/tools/in-process-gateway.ts:90, 468cd643c1b0)
  • Final handler admission: After asynchronous authorization and handler preparation, the ordinary router invokes the caller/context guard immediately before the handler. Both config methods remain operator.read-scoped in src/gateway/methods/core-descriptors.ts. (src/gateway/server-methods.ts:552, 468cd643c1b0)
  • Configuration redaction remains shared: The config.get handler continues through readConfigGetResponse, which applies redactConfigSnapshot and the existing revision projector; the patch adds no alternate config reader. (src/gateway/config-get-response.ts:25, 468cd643c1b0)
  • Registered-tool regression coverage: The new tests exercise createGatewayTool and cover both reads, explicit overrides, standalone/localEmbedded callers, retired authority, replaced Gateway, schema errors, cancellation, and deadlines. These are mocked boundary tests, not independently observed live proof. (src/agents/tools/gateway-tool.routing.test.ts:25, 468cd643c1b0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-12T17:10:17.786Z sha 3430ad3b67f8f5290d1be11fc552d778d5b1b18b :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/gateway-config-in-process branch from 3430ad3 to 468cd64 Compare September 12, 2026 17:19
@steipete
steipete merged commit 4208ce6 into main Sep 12, 2026
187 checks passed
@steipete
steipete deleted the codex/gateway-config-in-process branch September 12, 2026 17:50
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant