Skip to content

fix: revoke CLI tool access when a run is canceled - #149154

Merged
shakkernerd merged 2 commits into
mainfrom
fix/cli-grant-cancellation
Sep 15, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
fix/cli-grant-cancellation

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A CLI backend can leave a Gateway tool request pending while its originating run is canceled. The HTTP request and outer run admission can remain open while the subprocess stops and accepted results drain. During that interval, the tool grant previously stayed valid: an already prepared, rooted file write could still overwrite a report after its source had been canceled.

User Impact

Canceling the caller or execution attempt now stops that CLI grant from authorizing further work, including writes already waiting on filesystem preparation. Timeouts and supervisor cancellation take effect before native termination finishes, including attempts queued behind another process. Successful runs continue to drain accepted tool results so completed work is recorded correctly.

Why This Change Was Made

The host-private grant now retains the original caller/source checks and the active attempt's liveness assertion alongside its existing admission and capture identity. The same current-authority check serves fresh requests, retained tools, and native-tool capture callbacks. Capture rotation and warm-process token transfer replace the attempt assertion, preserving the new turn's authority without reviving the previous turn.

CLI execution supplies that assertion at capture activation. The supervisor notifies its caller when cancellation starts, before waiting for startup or sending the termination signal. Plugin execution distinguishes cancellation from the cleanup abort used after normal completion, keeping accepted results valid during the existing drain.

The change uses the existing in-memory grant and cancellation owners. It adds no tool capabilities, provider policy, configuration, protocol, persistence, or plugin SDK changes.

Evidence

  • The rooted MCP HTTP fixture pauses filesystem preparation, cancels only the CLI source, and keeps the HTTP request and admission live. With only the regression test added, the unchanged baseline overwrites the file with stale write; the candidate preserves original report and returns an authority error.
  • The three queued-cancellation assertions fail on the unchanged baseline and pass with the repair, covering child and PTY startup plus cancellation of a fenced scope. The supervisor deadline case verifies that the capture is already inactive when native termination starts.
  • Remote Linux proof passed 688 focused tests across 20 files, covering CLI execution, timeout and live-session cancellation, grant transfer and rotation, retained tools, rooted writes, question authority, preparation, and result draining. A separate isolated HTTP/Gateway control preserves one accepted send result through normal native cleanup.
  • Formatting, targeted lint, assertion and size ratchets, core and affected test type graphs, and the remaining source, dependency, database, media, loader, and import-boundary guards passed. Independent review through P2 found no actionable findings, including the final test-fixture correction.
  • Final-head CI results and ClawSweeper review track the hosted delivery gates.

@shakkernerd
shakkernerd requested a review from a team as a code owner September 15, 2026 14:08
@clawsweeper

clawsweeper Bot commented Sep 15, 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 agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 15, 2026
@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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 10:58 AM ET / 14:58 UTC (Revision 3).

ClawSweeper review

What this changes

Makes CLI backend Gateway tool grants expire on cancellation or timeout while preserving accepted-result draining after successful execution.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main and v2026.9.4. Source inspection and the reported boundary proof support the approach; no blocking introduced defect was found.

Priority: P2
Reviewed head: 461b21b6ad4fc88e14569a442da0fabaa534ec63

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant final-effect evidence and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The reported isolated Linux run exercises the production CLI grant through real HTTP dispatch and filesystem writes: cancellation preserves the original file while the request remains live, replacement permits fresh authorized writes, and the reported normal-cleanup control retains an accepted send. Source inspection confirms those boundaries; execution was not repeated here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The reported isolated Linux run exercises the production CLI grant through real HTTP dispatch and filesystem writes: cancellation preserves the original file while the request remains live, replacement permits fresh authorized writes, and the reported normal-cleanup control retains an accepted send. Source inspection confirms those boundaries; execution was not repeated here.
Evidence reviewed 9 items Pinned introduction and current-main necessity: Reviewed the merge-base-to-head changes at the pinned head. Comparing the grant and supervisor owners with fetched main shows that main still lacks the source/attempt cancellation checks and early cancellation notification. The supplied stale test merge was not used to attribute base-branch changes to this PR.
Latest release still has the old grant check: The v2026.9.4 source checks grant-row identity and admitted authority, without the added source signal or capture assertion.
Authority reaches the final write guard: MCP dispatch passes the grant's current-authority closure into the admitted tool caller. The source-execution guard captures that closure, and writeWorkspaceFile supplies it as assertBeforeMutation after asynchronous filesystem preparation.
Findings None None.
Security None None.

How this fits together

CLI backends use a local MCP bridge to call OpenClaw’s Gateway tools. Host-owned grants connect those requests to the originating run and authorize tool effects, including filesystem writes.

flowchart TD
  A[CLI execution attempt] --> B[Host-owned tool grant]
  C[Cancellation or timeout] --> D[Attempt liveness check]
  B --> E[Gateway tool request]
  D --> E
  E --> F{Authority still current?}
  F -->|Yes| G[Authorized tool effect]
  F -->|No| H[Reject before effect]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +74, Tests +318. Total +392 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 9 107 33 +74
Tests 12 409 91 +318
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 516 124 +392

Review metrics

Metric Value Why it matters
Production versus test growth Net production +74 lines; tests and test support +318 lines Production growth connects existing authority owners, while most added code validates cancellation, transfer, and draining.

Technical review

Best possible solution:

Keep final tool effects bound to both caller and attempt liveness, using the existing grant owner while retaining successful-result accounting.

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

Yes: the real HTTP fixture pauses filesystem preparation and cancels only the CLI source while admission remains live. Current main's grant predicate explains the reported failure; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: extending the existing grant predicate and cancellation owners closes the authority gap without introducing another policy owner, configuration option, or persistent format.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The reported isolated Linux run exercises the production CLI grant through real HTTP dispatch and filesystem writes: cancellation preserves the original file while the request remains live, replacement permits fresh authorized writes, and the reported normal-cleanup control retains an accepted send. Source inspection confirms those boundaries; execution was not repeated here.

Label justifications:

  • P2: This repairs a bounded CLI cancellation race that can permit pending tool effects after the caller stops.
  • 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 (live_output): The reported isolated Linux run exercises the production CLI grant through real HTTP dispatch and filesystem writes: cancellation preserves the original file while the request remains live, replacement permits fresh authorized writes, and the reported normal-cleanup control retains an accepted send. Source inspection confirms those boundaries; execution was not repeated here.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported isolated Linux run exercises the production CLI grant through real HTTP dispatch and filesystem writes: cancellation preserves the original file while the request remains live, replacement permits fresh authorized writes, and the reported normal-cleanup control retains an accepted send. Source inspection confirms those boundaries; execution was not repeated here.

Evidence

What I checked:

  • Pinned introduction and current-main necessity: Reviewed the merge-base-to-head changes at the pinned head. Comparing the grant and supervisor owners with fetched main shows that main still lacks the source/attempt cancellation checks and early cancellation notification. The supplied stale test merge was not used to attribute base-branch changes to this PR. (src/gateway/mcp-grant-store.ts:287, 461b21b6ad4f)
  • Latest release still has the old grant check: The v2026.9.4 source checks grant-row identity and admitted authority, without the added source signal or capture assertion. (src/gateway/mcp-grant-store.ts:441, 3a9d69db306c)
  • Authority reaches the final write guard: MCP dispatch passes the grant's current-authority closure into the admitted tool caller. The source-execution guard captures that closure, and writeWorkspaceFile supplies it as assertBeforeMutation after asynchronous filesystem preparation. (src/agents/agent-tools.read.ts:1424, 461b21b6ad4f)
  • Allowed, canceled, and replacement write scenarios: The inspected fixture uses real HTTP fetch, the production loopback server, prepared CLI grants, and filesystem writes. It checks successful authorized writes, cancellation while preparation is paused with HTTP/admission still live, preservation of original file contents, rejection of retained authority, and successful fresh writes after capture replacement. Its lightweight stubs replace unrelated media/web/plugin tools, not the write path. (src/gateway/mcp-http/rooted-execution.test.ts:181, 461b21b6ad4f)
  • Captured execution evidence: The supplied PR body reports the baseline overwriting the paused write with 'stale write', while the candidate preserves 'original report' and returns an authority error. It also reports 688 focused tests on isolated Linux and an HTTP/Gateway control retaining an accepted send through normal cleanup. These are contributor-reported observations, not executions performed by this reviewer; the captured context identity is 5e7b99e93a68d64b87467842c0db14245a81be22f917ada6aca3ea65ac55b7c3. (461b21b6ad4f)
  • Cancellation and successful cleanup remain distinct: Plugin capture checks use attempt cancellation for interrupted runs and original run authority during normal cleanup. Supervisor cancellation notifies the caller before native termination, including queued starts. Capture deactivation still follows result draining. (src/agents/cli-runner/execute-plugin.ts:450, 461b21b6ad4f)

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 (2 earlier review cycles)
  • reviewed 2026-09-15T14:13:27.099Z sha 23b8a9e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T14:48:17.589Z sha 461b21b :: needs maintainer review before merge. :: none

@shakkernerd shakkernerd self-assigned this Sep 15, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 15, 2026
@shakkernerd
shakkernerd merged commit 684e301 into main Sep 15, 2026
196 checks passed
@shakkernerd
shakkernerd deleted the fix/cli-grant-cancellation branch September 15, 2026 15:53
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: canceled CLI runs can no longer use their Gateway tool grants while process cleanup is pending.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
Stop canceled CLI sources and execution attempts from retaining Gateway tool access through delayed process cleanup, while preserving accepted tool results during normal completion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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