Skip to content

fix(cli): keep shell tools working after plugin refresh - #159000

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/stale-tool-hook-registry
Sep 26, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/stale-tool-hook-registry

Conversation

@VACInc

@VACInc VACInc commented Sep 26, 2026

Copy link
Copy Markdown
Member

Summary

High Level TLDR

Warm Claude CLI sessions can lose shell access after a plugin generation refresh. Bind native tool permission callbacks to the turn that created them so later turns do not run policy against the transport's retired plugin registry.

What Problem This Solves

Fixes native shell calls being denied with Tool call blocked because before_tool_call hook failed after a warm CLI transport outlives its original plugin generation.

User Impact

Follow-up turns keep using their admitted policy context. Current policy denials, approval requirements, cancellation, and expired-run rejection remain enforced. No configuration or migration is needed.

Why This Change Was Made

Root Cause

The Anthropic CLI transport is created once and reused across turns. Its asynchronous control-request reader retains the first turn's async context. It selects the new turn's requestToolPermission callback, but that unbound callback still executes in the reader's old context. Global hook selection prefers that retained generation and can invoke an already-retired plugin instance.

A live incident produced repeated PluginInstanceUnavailableError: Plugin <policy-plugin> was reloaded or disabled; use its current tools. failures before shell execution. A preceding secrets reload is a suspected trigger, not a separately proven retirement path. The regression reproduces the stale-transport boundary on upstream base 915a974868c1f856c9b3059efa1385a5625556cf using a real plugin instance and its retirement lifecycle.

AsyncLocalStorage.bind captures the admitted turn at callback creation. It restores that context on invocation without reviving retired instances or falling back to another Gateway's global registry.

Evidence

Verification

  • RED: with only the regression added, the first turn succeeds, then the next turn's allowed native shell call is denied after the old guard retires. The other 15 policy tests pass.
  • GREEN: 57 focused tests pass across native tool policy, CLI execution lifecycle, and native Bash approval rules. The new regression verifies both an allowed command and an explicit denial from the current guard.
  • Core production typecheck, affected agents-other test typecheck, scoped type-aware lint, assertion-safety and line-cap guards, formatting, and git diff --check pass.
  • check:changed stops on a pre-existing unbaselined max-lines suppression in extensions/openrouter/index.test.ts:1272, present unchanged in the base. No suppression or baseline was changed here.
  • Changed policy file: pnpm test src/agents/cli-runner/execute-plugin.policy.test.ts --maxWorkers=1 passed 16 tests in 12.20 s wall; the new test took 171 ms. Hosted CI timing is pending.
  • Callback-only microbenchmark on Linux/Node 24.19.0: five samples of 200,000 calls after 20,000 warmup calls measured 4-12 ns/call unbound versus 61-94 ns/call bound. This measures binding overhead only; end-to-end model/tool latency was not measured.

Real Behavior Proof

The test uses the real executePluginOwnedProcess permission callback, hook runner, plugin wrapper, and registry retirement. A retained async snapshot simulates the warm transport reader; the first turn establishes working policy, the old instance retires, and the next admitted generation supplies its own allow/deny policy. No shell subprocess or external model is needed for this boundary proof.

What Was Not Tested

No production deployment, Gateway restart, authenticated Claude round trip, or full build/suite. This is a host callback fix, not a plugin-loader or updater change. Manual diff review completed; no independent review agent was launched under the task's no-delegation policy.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 agents Agent runtime and tooling size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

The branch binds each CLI native-tool permission callback to its admitted turn and adds a regression test for plugin retirement between warm turns.

Merge readiness

✅ Ready for maintainer review

Current main still has the reported failure path, and this focused PR remains a viable fix. Source tracing found no discrete introduced defect or unresolved security concern.

Priority: P1
Reviewed head: 6166a5179d614d637189edce9c9079bd90fa8fb5

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The narrow repair and regression are credible, with behavioral confidence limited by the absence of a warm Claude transport trace.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The new test exercises the production host callback and real registry retirement through a simulated warm-reader context, observing current-policy allow and deny results. It does not capture an actual Claude subprocess or shell effect; the member-authored ordinary proof gate does not apply. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The new test exercises the production host callback and real registry retirement through a simulated warm-reader context, observing current-policy allow and deny results. It does not capture an actual Claude subprocess or shell effect; the member-authored ordinary proof gate does not apply. No stored-data contract changes.
Evidence reviewed 8 items Introduced host change: The PR binds the native-tool permission callback at creation, capturing the admitted turn's async context.
Retirement regression: The added owner-boundary test retires a wrapped old policy instance and checks both an allow and an explicit denial from the current policy. The PR body reports this case red before the fix and green afterward; this review did not execute it.
Transport and final-effect checks: The reusable transport selects the active turn, invokes its permission callback, and rechecks the turn after the decision. Its response closure checks again before the control response is written.
Findings None None.
Security None None.

How this fits together

The CLI runner passes a permission callback to a reusable Claude CLI transport. Native tool requests return through that callback for plugin policy, run-authority, and approval checks before the transport receives an allow or deny decision.

flowchart LR
A[Admitted CLI turn] --> C[Turn-bound permission callback]
B[Warm Claude transport] --> C
C --> D[Plugin policy hook]
D --> E[Run and approval checks]
E --> F{Allowed?}
F -- Yes --> G[Native tool]
F -- No --> H[Denial to transport]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +56. Total +60 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 6 +4
Tests 1 56 0 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 66 6 +60

Review metrics

Metric Value Why it matters
Regression test cost 171 ms new case; 12.20 s file wall, as reported in the PR The new lifecycle case has a bounded measured cost within the repository's per-file explanation threshold.

Technical review

Best possible solution:

Each warm CLI turn should use its own admitted plugin policy context, while canceled and superseded turns remain unable to authorize native tools.

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

Yes, at the source boundary: a warm transport can invoke a later turn's unbound callback inside its retained async context, where hook dispatch prefers the old generation. The PR reports a red-before, green-after regression; this review did not execute it.

Is this the best way to solve the issue?

Yes. Binding the callback where the host creates it restores the admitted turn's policy context without adding a competing registry or approval path; existing active-turn checks remain in place.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against be46e6966c2b.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A plugin refresh can deny native shell tools on a warm Claude CLI follow-up turn, breaking an active agent workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 new test exercises the production host callback and real registry retirement through a simulated warm-reader context, observing current-policy allow and deny results. It does not capture an actual Claude subprocess or shell effect; the member-authored ordinary proof gate does not apply. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • A warm Claude transport trace across plugin retirement showing a current-policy allow and denial would strengthen confidence.

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-26T16:13:47.487Z sha 6166a51 :: needs maintainer review before merge. :: none

@VACInc
VACInc marked this pull request as ready for review September 26, 2026 16:20
@VACInc
VACInc merged commit 06ab626 into openclaw:main Sep 26, 2026
268 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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