Repository navigation
fix(cli): keep shell tools working after plugin refresh - #159000
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 12:26 PM ET / 16:26 UTC (Revision 2). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +4, Tests +56. Total +60 across 2 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…9000) Co-authored-by: VACInc <[email protected]>
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 failedafter 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
requestToolPermissioncallback, 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 base915a974868c1f856c9b3059efa1385a5625556cfusing a real plugin instance and its retirement lifecycle.AsyncLocalStorage.bindcaptures 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
agents-othertest typecheck, scoped type-aware lint, assertion-safety and line-cap guards, formatting, andgit diff --checkpass.check:changedstops on a pre-existing unbaselined max-lines suppression inextensions/openrouter/index.test.ts:1272, present unchanged in the base. No suppression or baseline was changed here.pnpm test src/agents/cli-runner/execute-plugin.policy.test.ts --maxWorkers=1passed 16 tests in 12.20 s wall; the new test took 171 ms. Hosted CI timing is pending.Real Behavior Proof
The test uses the real
executePluginOwnedProcesspermission 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.