Skip to content

fix(gateway): later CLI bridge calls fail after the listener's creator turn completes - #165428

Merged
steipete merged 3 commits into
mainfrom
rel/mcp-listener-authority-164944
Oct 5, 2026
Merged

steipete merged 3 commits into
mainfrom
rel/mcp-listener-authority-164944

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: later CLI bridge tool calls can fail with “operator tool invocation authority expired” after the invocation that first started the shared MCP listener completes.

User Impact

CLI-backed agents can keep using Gateway tools across later turns without restarting the Gateway. Each request still needs its own active grant and permissions. No configuration changes or migrations are required. This is a listener-lifetime fix, not a general native-agent continuation repair.

Why This Change Was Made

Start the process-owned listener outside its creator's temporary operator-tool authority using the existing authority owner's exit helper. Per-request grant, caller, cancellation, and dispatch checks stay intact.

Keep the focused real-HTTP lifetime regression. Remove the added storage integration test and its routing entry: dispatch scope ceilings, expired authority, grant revocation, and commit admission already have owner coverage. Simplify duplicate batch/single-response serialization while preserving serialization before headers are sent, and document the shared listener lifetime.

This additional context leak was found during the related request-scope work in #157144; this PR does not duplicate that work.

Evidence

Verified candidate: 20b41e5ff7aa36a8cf4a158f559242eaafe3dd0f. Execution environment: isolated, secretless Crabbox AWS lease cbx_62cebfdf14b9, Linux x64, Node 24.21.0, pnpm 12.5.1. The trusted main bootstrap checked the exact head and absence of an instance role; hydration and Tailscale were disabled. The lease is stopped.

  • pnpm tsgo:core && pnpm test src/gateway/mcp-http.async-scope.test.ts --maxWorkers=1: passed. Core typechecking completed successfully, followed by 3 passing tests.
  • Test cost: pnpm test src/gateway/mcp-http.async-scope.test.ts --maxWorkers=1 took 38.61s wall time, including about 2.66s in test bodies. Cold compiled-worker preparation took 21.23s; compilation and transforms dominate the command time. A real listener is necessary because listener creation is where the temporary authority is retained.
  • Negative control on the same lease and unchanged HEAD: replaced only src/gateway/mcp-http.ts with its merge-base version from b2b434acbc624ed0c212fa2941dc9ac1fa5f1731, then ran pnpm test src/gateway/mcp-http.async-scope.test.ts --maxWorkers=1 -t 'does not inherit an expired operator-tool invocation'. 1 failed, 2 skipped, as expected, in 31.54s wall time. The tool response contained operator tool invocation authority expired with isError: true instead of a successful result. Restored the candidate file afterward and confirmed clean source status.
  • Local oxfmt, focused oxlint, and git diff --check: passed. Independent Codex autoreview through P2: scoped-clean. The shared local dependency installation prevented local typechecking; the isolated remote typecheck above supplies that proof.
  • CI test seconds remain unavailable: the exact-head CI run skipped its jobs because the PR is a draft. The passing proof above is from isolated AWS execution, not GitHub CI.

The regression exercises the real HTTP listener and authority storage with synthetic tool resolution/execution. It does not claim full Gateway or model-backed CLI acceptance.

LOC versus origin/main: production +10/-10 (net 0); tests +20/-0; docs +1/-0.

Credit

Replaces #164944 by @nano-richtera (organization-owned fork does not accept maintainer pushes). Original fix and regression by @nano-richtera; maintainer cleanup by @steipete.

The two original contributor commits remain in this branch with their original authorship.

Co-authored-by: nano-richtera [email protected]

nano-richtera and others added 3 commits October 4, 2026 08:20
Keep the operator-authority detachment and real HTTP regression from the original contributor fix. Remove duplicate storage integration coverage, document the listener lifetime, and deduplicate response serialization without changing header or error ordering.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 size: XS labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 4:45 AM ET / 08:45 UTC (Revision 3).

ClawSweeper review

What this changes

The PR keeps the shared CLI tool bridge available after its creator’s invocation completes, adds an HTTP lifetime regression, simplifies response serialization, and documents the behavior.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix absent from current main and the latest release. The recorded exact-head validation resolves the previous review’s blocker; no actionable patch defect remains.

Priority: P1
Reviewed head: 20b41e5ff7aa36a8cf4a158f559242eaafe3dd0f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with meaningful boundary proof, a failing negative control, and completed exact-head validation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Exact-head isolated execution exercises the production HTTP listener with a real HTTP client after creator-authority expiry and observes successful recovery; the pre-fix control fails as expected. Original final-effect proof remains applicable to the preserved detachment and demonstrates denied restricted callers and commit-time revocation. Synthetic tool execution limits the focused lifetime run's claim; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Exact-head isolated execution exercises the production HTTP listener with a real HTTP client after creator-authority expiry and observes successful recovery; the pre-fix control fails as expected. Original final-effect proof remains applicable to the preserved detachment and demonstrates denied restricted callers and commit-time revocation. Synthetic tool execution limits the focused lifetime run's claim; no stored-data contract changes.
Evidence reviewed 10 items Introduced fix and serialization changes: The pinned introduced delta wraps listener startup in the existing authority owner's exit helper. Both serialization changes select the same response value and serialize it before sending headers.
Verified merge result: The raw test-merge records the pinned base followed by the exact PR head. Its production delta contains the same authority detachment and serialization simplifications, rather than removal of unrelated main work.
Still necessary on current main: Fetched main starts the process-owned listener outside plugin-generation and root-work scopes, but does not exit temporary operator-tool authority.
Findings None None.
Security None None.

How this fits together

CLI-backed agents call Gateway tools through a shared loopback HTTP bridge. The listener lasts for the Gateway process, while each tool request carries its own grant and authorization.

flowchart TD
  A[CLI agent turn] --> B[Per-turn context grant]
  B --> C[Shared HTTP bridge]
  D[Gateway process lifetime] --> C
  C --> E[Current grant and permission checks]
  E --> F[Gateway tool execution]
  F --> G[Tool result to CLI]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +20, Docs +1. Total +21 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 10 0
Tests 1 20 0 +20
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 31 10 +21

Review metrics

Metric Value Why it matters
Focused regression cost 38.61s command wall; 2.66s test bodies The recorded cost is dominated by preparation, while the real listener boundary is necessary to catch inherited authority.

Root-cause cluster

Relationship: canonical
Canonical: #165428
Summary: This is the credited replacement for the original listener-authority fix; request-scope inheritance remains adjacent work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep listener lifetime process-owned while every CLI request remains bound to its own current grant and final-effect authority.

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

Yes: start the listener inside temporary operator-tool authority, expire that invocation, then call a tool over HTTP. Source explains the failure, and the recorded isolated negative control reproduces it; this reviewer did not run current main.

Is this the best way to solve the issue?

Yes: exiting the existing temporary-authority owner at listener creation repairs the lifetime mismatch without adding another authority owner or changing per-request authorization.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The defect prevents later CLI-backed agent turns from using Gateway tools until the shared listener is restarted.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Exact-head isolated execution exercises the production HTTP listener with a real HTTP client after creator-authority expiry and observes successful recovery; the pre-fix control fails as expected. Original final-effect proof remains applicable to the preserved detachment and demonstrates denied restricted callers and commit-time revocation. Synthetic tool execution limits the focused lifetime run's claim; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Exact-head isolated execution exercises the production HTTP listener with a real HTTP client after creator-authority expiry and observes successful recovery; the pre-fix control fails as expected. Original final-effect proof remains applicable to the preserved detachment and demonstrates denied restricted callers and commit-time revocation. Synthetic tool execution limits the focused lifetime run's claim; no stored-data contract changes.

Evidence

What I checked:

  • Introduced fix and serialization changes: The pinned introduced delta wraps listener startup in the existing authority owner's exit helper. Both serialization changes select the same response value and serialize it before sending headers. (src/gateway/mcp-http.ts:573, 20b41e5ff7aa)
  • Verified merge result: The raw test-merge records the pinned base followed by the exact PR head. Its production delta contains the same authority detachment and serialization simplifications, rather than removal of unrelated main work. (src/gateway/mcp-http.ts:573, 11864db3af48)
  • Still necessary on current main: Fetched main starts the process-owned listener outside plugin-generation and root-work scopes, but does not exit temporary operator-tool authority. (src/gateway/mcp-http.ts, f8749864dc4c)
  • Latest release lacks the fix: The v2026.9.8 listener startup also lacks the operator-authority exit wrapper; this PR is not redundant with the supplied latest release. (src/gateway/mcp-http.ts, fc23bc864e45)
  • Request authority remains independently enforced: Grant resolution checks the exact runtime, active capture, admitted authority, abort state, and current stored row. The HTTP owner rechecks grant liveness after preparation and supplies its current-authority predicate to tool construction and execution. Detaching listener-creator authority does not detach the calling grant. (src/gateway/mcp-grant-store.ts:313, 20b41e5ff7aa)
  • Exact-head validation and negative control: The captured PR body records secretless isolated Linux execution at the exact reviewed head: core typechecking and three real-HTTP lifetime tests passed. Replacing only the production owner with its merge-base version made the focused regression fail with the reported expired-authority error. Command wall time was 38.61 seconds, with 2.66 seconds in test bodies. This satisfies the previous completed review's concrete validation request; the reviewer did not execute repository code. (src/gateway/mcp-http.async-scope.test.ts:95, 20b41e5ff7aa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Raw commit f2e5268 adds src/gateway/operator-tool-gateway-authority.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f2e526882c7e; files: src/gateway/operator-tool-gateway-authority.ts)

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 (2 earlier review cycles)
  • reviewed 2026-10-05T07:57:58.006Z sha 20b41e5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T08:16:39.728Z sha 20b41e5 :: needs changes before merge. :: none

@steipete
steipete marked this pull request as ready for review October 5, 2026 08:31
@steipete
steipete merged commit 488c0f0 into main Oct 5, 2026
210 of 212 checks passed
@steipete
steipete deleted the rel/mcp-listener-authority-164944 branch October 5, 2026 08:54
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…r turn completes (openclaw#165428)

* fix: later CLI bridge calls fail after listener creator completes

* test: prove later MCP grants retain authorized state effects

* refactor(gateway): focus MCP listener lifetime regression

Keep the operator-authority detachment and real HTTP regression from the original contributor fix. Remove duplicate storage integration coverage, document the listener lifetime, and deduplicate response serialization without changing header or error ordering.

---------

Co-authored-by: nano-richtera <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 6, 2026
…r turn completes (#165428)

* fix: later CLI bridge calls fail after listener creator completes

* test: prove later MCP grants retain authorized state effects

* refactor(gateway): focus MCP listener lifetime regression

Keep the operator-authority detachment and real HTTP regression from the original contributor fix. Remove duplicate storage integration coverage, document the listener lifetime, and deduplicate response serialization without changing header or error ordering.

---------

Co-authored-by: nano-richtera <[email protected]>
(cherry picked from commit 488c0f0)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Backport openclaw#165428 to the extended-stable loopback listener.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

2 participants