Skip to content

fix: later CLI bridge calls fail after listener creator completes - #164944

Closed
nano-richtera wants to merge 2 commits into
openclaw:mainfrom
SafeIdea-LLC:fix/mcp-listener-operator-authority-20261004
Closed

nano-richtera wants to merge 2 commits into
openclaw:mainfrom
SafeIdea-LLC:fix/mcp-listener-operator-authority-20261004

Conversation

@nano-richtera

@nano-richtera nano-richtera commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157144

What Problem This Solves

Fixes: later CLI bridge tool calls can fail with “operator tool invocation authority expired” when the process-wide MCP listener was started inside an earlier operator-tool invocation.

User Impact

User impact: a completed listener-creating invocation no longer invalidates unrelated later MCP requests. No configuration changes or migrations are required. This is a narrowly scoped CLI bridge lifecycle fix, not a general native-agent continuation repair.

Why This Change Was Made

The listener outlives the invocation that happens to start it. Detach that invocation’s temporary operator-tool authority when starting the shared listener, using the existing authority owner’s exit helper. Keep per-request grant, caller, cancellation, and dispatch authorization checks unchanged.

This additional context leak was found while validating Amrit Chana’s related request-scope work in #157144. This PR contains only the operator-tool-authority detachment and its regressions; it does not duplicate that PR’s caller/request-scope implementation.

Evidence

Production-effect proof added for review feedback

pnpm test src/gateway/mcp-http.dispatch-effect.test.ts --maxWorkers=1 now exercises real HTTP with an activated per-run MCP grant through production tool resolution, the theme tool, the themes.set handler, and a real SQLite preference commit. No resolver, tool execution, handler, or storage implementation is mocked.

  • Expire the listener creator's invocation signal, then admit a separate write-authorized caller: its own profile stores ui.themeMode=dark.
  • Admit a read-only caller: the request fails with missing scope and its preferences remain unchanged.
  • Revoke the allowed source at the actual SQLite worker commit-admission checkpoint: the attempted light update fails and persisted dark is unchanged. A narrow checkpoint spy injects revocation, then delegates to the real admission check; it does not replace the effect.
  • Reuse that revoked grant: HTTP 401, persisted preferences unchanged.

The identical test fails with the original mcp-http.ts from the pinned base (allowed request returns HTTP 500): 1 failed, 46.29s command wall. With this PR's production fix: 1 passed, 47.08s command wall, 14.053s test-body time. The test runs in the existing forked database-worker project because SQLite host admission cannot run in a Vitest worker thread; no authorization guard was bypassed.

Final combined run of the effect and async-scope files: 4 passed, 94.11s command wall (89.86s Vitest duration). This composition is needed to prove that authorization survives through actual final storage; helper-only or mocked-handler tests cannot establish that. Compilation/import and real storage-worker startup dominate wall time. No per-case sleeps or polling were added.

This is an isolated integration proof with an admitted test caller and a test Gateway context registering the production method, not a full Gateway or model-backed CLI acceptance test. It does not establish that native-worker continuation works.

Follow-up independent autoreview: scoped-clean at P0/P1. Codex exited without a report (reviewer_unavailable, exit 1); the permitted Claude fallback completed. Focused type-aware lint: 0 warnings, 0 errors. Formatting and git diff --check passed. The only post-review edit was the lint-required equivalent cleanup spelling, toReversed() instead of reverse() on the newly spliced array.

Original fix evidence (production source unchanged in the follow-up)

  • Fresh base: b2b434acbc624ed0c212fa2941dc9ac1fa5f1731.
  • Original fix head: 6a2a448ebcb7d55f6a5653566c84c395028b922d; follow-up proof head: b16dbcb7437b7932cffcb09f2b059b662aae3228.
  • Real loopback HTTP regression: start the listener inside an operator-tool authority, expire its signal, then send tools/call over HTTP. Tool resolution/execution is mocked; the HTTP listener and authority storage are real.
  • pnpm test src/gateway/mcp-http.async-scope.test.ts --maxWorkers=1: before 1 failed / 2 passed, after 3 passed. Command wall: 68.94s before / 56.62s after; after test-body time 2.67s. Most command time is worker compilation/import. The test needs the actual listener boundary because asynchronous listener creation is where authority is retained; a helper-only test would miss it.
  • pnpm test src/gateway/mcp-grant-store.test.ts --maxWorkers=1: 28 passed, 19.88s command wall.
  • pnpm test src/gateway/server-plugin-in-process-dispatch.authorization.test.ts --maxWorkers=1: 47 passed, 152.61s command wall; includes operator restrictions, expired authority, and request cancellation controls.
  • Independent autoreview: scoped-clean at P0/P1, no actionable findings. The preferred Codex reviewer was unavailable; the skill-permitted Claude fallback completed.
  • Focused two-file lint: no errors or warnings. Formatting and git diff --check: passed.
  • Execution environment: isolated container, Node 24.21.0, pnpm 12.5.1; no credentials/state mounted, external network disconnected during tests.
  • Remote contributor CI on the original head is action_required (maintainer approval pending), not an observed test failure; CI duration is unavailable. Full build/typecheck and an actual model-backed CLI session were not run for this standalone upstream patch.

@clawsweeper

clawsweeper Bot commented Oct 4, 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 gateway Gateway runtime size: XS labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 1:33 PM ET / 17:33 UTC (Revision 2).

ClawSweeper review

What this changes

The CLI tool bridge starts its shared HTTP listener outside its creator’s temporary tool authority and adds regressions showing later callers retain their own permissions.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix absent from current main and the latest release. The new production-boundary evidence resolves the previous authority-proof gap; no blocking patch defect was found.

Priority: P1
Reviewed head: b16dbcb7437b7932cffcb09f2b059b662aae3228

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful production-boundary proof and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. 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): The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. No stored-data contract changes.
Evidence reviewed 11 items Pinned introduced change: The merge-base-to-head patch adds the existing authority owner's exit helper around listener startup. Request authentication, grant checks, caller reconstruction, cancellation, and dispatch guards are unchanged. Production code is identical to the earlier reviewed head.
Fix still needed on main: Fetched main starts the process-owned listener outside plugin-generation and root-work admission scopes, but does not exit operator-tool authority. The dispatch owner checks the inherited invocation signal, explaining why a completed creator can invalidate subsequent requests.
Latest release check: The v2026.9.8 source also lacks operator-tool-authority detachment at listener startup. A REST source read established this after local access to the release blob failed; no release-fix claim is made.
Findings None None.
Security None None.

How this fits together

The CLI tool bridge accepts authenticated local HTTP tool requests from CLI-backed agent runs and dispatches them through Gateway tools. Its listener lasts for the process, while each request’s permissions and lifetime belong to its admitted run.

flowchart TD
  A[CLI agent run] --> B[Per-run grant]
  B --> C[Shared HTTP listener]
  D[Creator finishes] --> C
  C --> E[Check caller permissions and liveness]
  E --> F[Gateway tool dispatch]
  F --> G[Guarded storage commit]
  E --> H[Reject unauthorized request]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +205. Total +211 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 2 +6
Tests 3 205 0 +205
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 213 2 +211

Review metrics

Metric Value Why it matters
Production versus regression growth production net +6 lines; tests +204; test routing +1 The small lifecycle repair has substantial boundary coverage justified by recovery and final-effect authorization checks.
Production-effect proof cost 47.08 seconds command wall; 14.053 seconds test body The PR explains the real storage-worker cost and why helper-only coverage cannot establish commit-time rejection.

Technical review

Best possible solution:

Keep the listener process-owned while each tool call uses its own live admitted-run authority through dispatch and final storage.

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

Yes: current main retains invocation authority during listener creation, and dispatch checks its expired signal on later requests. The contributor records a failing production-boundary regression; this review did not execute it.

Is this the best way to solve the issue?

Yes: exiting the existing authority carrier at process-owned listener creation repairs the lifetime mismatch without replacing per-request authorization or adding configuration.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. No stored-data contract changes.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Expired listener-creator authority can break subsequent CLI-backed agent tool calls until the process 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): The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded isolated production-path harness exercises the changed HTTP listener with activated per-run grants, real tool resolution, themes.set, and SQLite writes: later allowed-caller recovery succeeds, read-only access is denied, commit-time revocation prevents mutation, and revoked-grant reuse returns 401. This satisfies the prior authority-chain requests without claiming full model-backed CLI acceptance. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head patch adds the existing authority owner's exit helper around listener startup. Request authentication, grant checks, caller reconstruction, cancellation, and dispatch guards are unchanged. Production code is identical to the earlier reviewed head. (src/gateway/mcp-http.ts:580, b16dbcb7437b)
  • Fix still needed on main: Fetched main starts the process-owned listener outside plugin-generation and root-work admission scopes, but does not exit operator-tool authority. The dispatch owner checks the inherited invocation signal, explaining why a completed creator can invalidate subsequent requests. (src/gateway/mcp-http.ts:577, 15f60faa8e09)
  • Latest release check: The v2026.9.8 source also lacks operator-tool-authority detachment at listener startup. A REST source read established this after local access to the release blob failed; no release-fix claim is made. (src/gateway/mcp-http.ts, fc23bc864e45)
  • Allowed and forbidden final effects: The added harness expires the listener creator, activates separate admitted-run grants, and sends real HTTP requests through production tool resolution, the theme tool, themes.set, and SQLite preferences. It asserts that a write caller stores dark, a read-only caller receives missing-scope denial without a write, revocation injected at real commit admission preserves dark, and subsequent reuse receives HTTP 401. The checkpoint spy delegates to the actual admission guard. (src/gateway/mcp-http.dispatch-effect.test.ts:131, b16dbcb7437b)
  • Final-storage authority owner: themes.set passes the requesting profile's live-authority assertion to the preference writer. The writer invokes that assertion at transaction and commit admission before granting the SQLite worker permission, so the injected revocation exercises the final-effect boundary rather than an unrelated mock denial. (src/state/user-preferences.ts:93, b16dbcb7437b)
  • Recorded execution and re-review continuity: The captured body reports the same production-effect harness failing against the original production source with HTTP 500, then passing after the fix: 46.29 seconds before, 47.08 seconds after, with 14.053 seconds in the passing test body. Combined effect and async-scope coverage reports four passing tests in a secretless isolated container. This addresses the prior requests for later-caller recovery and restricted/revoked final-effect rejection. These are contributor-recorded observations; this read-only review did not execute tests. (src/gateway/mcp-http.dispatch-effect.test.ts:34, b16dbcb7437b)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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-10-04T14:23:43.395Z sha 6a2a448 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 4, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thank you @nano-richtera, your fix landed. GitHub does not let maintainers push to organization-owned forks, so we carried your two commits (authorship preserved) plus a small cleanup in #165428, merged as 488c0f0. That PR keeps your listener-authority fix and focused regression, and credits you as co-author. Closing this one as superseded by #165428.

@steipete steipete closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: 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.

2 participants