Skip to content

fix(plugins): preserve tool identity during managed cancellation - #143305

Merged
steipete merged 1 commit into
mainfrom
codex/plugin-tool-cancellation-context
Sep 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/plugin-tool-cancellation-context

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Related: #140674

What Problem This Solves

A plugin tool's cancellation callback can run under the context that dispatched cancellation instead of the plugin that started the work. This can misidentify the caller of nested runtime operations, including when MCP relays cancellation while accepted work is still draining.

Why This Change Was Made

The existing MCP cancellation owner moves into a small shared work helper. Signal-bearing managed plugin calls capture their context after the existing registration-authority check. The direct result remains independent of actual descendant cleanup, and the original abort reason is preserved.

User Impact

Managed tool cancellation retains the executing plugin's identity through its existing work owner. Retired authority still refuses new invocation; raw and no-signal callers preserve their existing context behavior. No public API or registry resource manager is added.

Evidence

  • Native regressions reproduced foreign caller identity, parent-close identity and closed-parent admission failures. All six maintained cases pass alongside the initial 134 sibling tests.
  • The five-file changed gate and independent Codex review through P2 passed. The composed MCP/plugin tool run passed 132 tests; counts overlap. Ordinary build passed in 203.75 seconds.
  • A plain-Node compiled five-row probe exercised the actual emitted wrappers, work scope and LLM early-denial diagnostics in 1.44 seconds. It preserved original plugin/host/registry identity, abort reasons and early results, refused retired/new work, and made zero configuration, model or network requests. All 11,674 build artifacts stayed unchanged and the managed process group exited.
  • Rebased onto the landed MCP parent: all five files match the verified candidate byte-for-byte. This is compiled ownership/identity proof; full MCP wire drainage remains covered by the parent PR.

@clawsweeper

clawsweeper Bot commented Sep 9, 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 size: M maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 2:03 PM ET / 18:03 UTC (Revision 2).

ClawSweeper review

What this changes

Preserves plugin identity and abort reasons during managed tool cancellation, shares cancellation handling with MCP requests, and adds lifecycle regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still forwards cancellation without preserving the executing tool’s context. No actionable introduced defect was found, and the merged MCP parent explicitly leaves this behavior for a follow-up.

Priority: P2
Reviewed head: d9589f59f3ff1723f40b38cc7c9c415ca764ccdd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no actionable findings; runtime results remain attributed to the PR’s reported validation.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. Its body reports a compiled probe through the changed wrappers and work owner, including retired-work rejection and zero downstream requests; raw output was not independently inspected. The authority review found no unresolved introduced violation requiring additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. Its body reports a compiled probe through the changed wrappers and work owner, including retired-work rejection and zero downstream requests; raw output was not independently inspected. The authority review found no unresolved introduced violation requiring additional final-effect proof.
Evidence reviewed 9 items Current main still needs the fix: The fetched main revision invokes tool.execute with the original signal directly; its shared work-scope module has no runWithTrackedCancellation helper.
Latest release retains direct signal forwarding: GitHub's release endpoint identifies v2026.9.3 as latest, published September 8. Reading tools.ts at that tag confirms direct forwarding of the original signal without the proposed cancellation helper.
Cancellation and cleanup ownership: The introduced helper captures context inside the child work scope, forwards the original abort reason, registers parent ownership before invocation, and removes both listeners after descendant cleanup. Unmanaged calls retain their original signal.
Findings None None.
Security None None.

How this fits together

Plugin tools execute requests from agents and MCP clients under a plugin-specific runtime context. Managed work scopes retain their background work through cancellation and cleanup while allowing results to return early.

flowchart TD
  A[Agent or MCP request] --> B[Check live plugin registration]
  B --> C[Execute in plugin context]
  C --> D[Return tool result]
  C --> E[Track background work]
  F[Request cancellation or owner shutdown] --> G[Restore captured cancellation context]
  G --> E
  E --> H[Finish cleanup and remove listeners]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +26, Tests +150, Docs +9. Total +185 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 64 38 +26
Tests 1 150 0 +150
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 223 38 +185

Review metrics

None.

Technical review

Best possible solution:

Keep one cancellation owner that restores the executing plugin’s context, preserves early results, and retains cleanup without renewing execution authority.

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

Yes, from source: execute a managed plugin tool, retain a cancellation listener after its early result, then abort from another plugin’s context. Current main forwards the original signal without restoring the executing context; this review did not run the reproduction.

Is this the best way to solve the issue?

Yes. Moving the existing MCP cancellation owner into a shared helper and invoking it inside the checked plugin scope fixes the producer boundary without adding a public API or configuration path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a bounded plugin cancellation-context defect without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 repository-state MEMBER classification exempts this PR from the external-contributor proof gate. Its body reports a compiled probe through the changed wrappers and work owner, including retired-work rejection and zero downstream requests; raw output was not independently inspected. The authority review found no unresolved introduced violation requiring additional final-effect proof.

Evidence

What I checked:

  • Current main still needs the fix: The fetched main revision invokes tool.execute with the original signal directly; its shared work-scope module has no runWithTrackedCancellation helper. (src/plugins/tools.ts:118, fa914c52f128)
  • Latest release retains direct signal forwarding: GitHub's release endpoint identifies v2026.9.3 as latest, published September 8. Reading tools.ts at that tag confirms direct forwarding of the original signal without the proposed cancellation helper. (src/plugins/tools.ts:118, 1391f7cd2d40)
  • Cancellation and cleanup ownership: The introduced helper captures context inside the child work scope, forwards the original abort reason, registers parent ownership before invocation, and removes both listeners after descendant cleanup. Unmanaged calls retain their original signal. (src/shared/async-work-scope.ts:119, d9589f59f3ff)
  • Authority remains separate from retained context: The tool wrapper checks captured live registration authority before entering the new helper. Registry retirement and activation generations remain checked by the existing lifecycle owner; the patch does not mint replacement authority or bypass that check. (src/plugins/tools.ts:102, d9589f59f3ff)
  • Focused regression coverage: Five cancellation cases cover same-context, foreign-context, already-aborted, retired-registry, and parent-close dispatch. A separate case checks rejection before tool execution after the work owner closes. Assertions also cover early results, original reasons, cleanup completion, and listener removal. These tests were inspected, not executed. (src/plugins/tools.optional.test.ts:747, d9589f59f3ff)
  • Merged parent is complementary: fix(mcp): close plugin resources after accepted stdio work finishes #143031 is verified merged at d7c3869. Its supplied discussion explicitly separates generic per-tool abort identity from its serving-registry and SDK-host cleanup work. The aggregate refactor(plugins): release scoped resources after actual work #140674 describes itself as a draft reference that will not merge. (d7c38695127a)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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-09-09T17:56:27.930Z sha d9589f5 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 9, 2026 17:59
@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 9, 2026
@steipete
steipete merged commit 542f96b into main Sep 9, 2026
371 of 374 checks passed
@steipete
steipete deleted the codex/plugin-tool-cancellation-context branch September 9, 2026 19:20
@steipete

steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant