Skip to content

fix: require current subagent control to cancel descendant tasks - #149082

Merged
steipete merged 13 commits into
mainfrom
codex/subagent-cancel-ownership-20260914
Sep 17, 2026
Merged

steipete merged 13 commits into
mainfrom
codex/subagent-cancel-ownership-20260914

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A former controller could cancel descendant work through retained task links, and stale ACP task IDs could stop newer executions that reused a run ID. A native stop accepted by the Gateway could also be reported as declined if caller authority changed while the run unwound.

User Impact

New cancellation effects require current control and stay bound to the selected execution. Accepted native stops retain their cleanup claim through delayed settlement. Historical listing and completion-recipient waiting remain available.

A canonical ACP task's recorded owner retains control over its exact execution after a navigation-parent change. Core cancellation refuses older ACP task records without execution-instance metadata and directs the caller to the current task or ACP session controls.

Why This Change Was Made

The cancellation path follows current controller ancestry and carries the selected task, backing instance, and authority checks through asynchronous runtime handoffs. Gateway controllers record actual stop acceptance so later caller revocation cannot turn an accepted stop into a false refusal; untouched targets still require current authority. The drain path preserves the original cleanup claim until terminal observation settles it.

Distinct ACP executions receive distinct task and flow records. Lifecycle callbacks use an optional task ID to narrow existing run/runtime/session selection to the canonical task and matching managed projections; omission preserves run-scoped behavior. Run-ID lookup selects the current execution while exact task-ID reads preserve history. No terminal task is reopened, and no schema, retention, configuration, or dependency change is required.

Evidence

The branch includes main through 90b421a, including the existing worktree-fixture repair. The original 50 cancellation paths and every added/removed line are preserved; shared-file changes were checked for compatible ownership and error handling.

CI on f3f7af6 passed UI performance and all selected jobs except one initial native-hook relay publication assertion. Two adjacent renewal tests now await the existing relay readiness promise before checking the same stored locator, keeping the held-renewal, unregister, expiry, and cleanup assertions unchanged. The complete 21-case lifecycle file, targeted lint, and independent P0–P2 review pass. CI then caught that the public handle type does not expose readiness; both fixtures now use the existing owned registration entry point, which forwards the same runtime parameters. Both matching CI compiler stripes, all 21 lifecycle cases, core lint, formatting, and independent P0–P2 review passed on that correction. This is a test synchronization repair; production cancellation behavior is unchanged. Full CI35182437542 passed on final head1fda8e18f41b90dbf1cbabdd075039c4e87751d9.

The production implementation passed its complete changed-file gate and full build. CI exposed outdated test fixtures: direct registry imports, missing ACP execution-instance metadata, and pauses around the old combined drain wrapper. The fixtures now use the existing facades, explicit instance identity, and an observer that pauses after the real drain without extending its deadline. The first fixture refresh passed all 73 selected tests and its complete changed-file gate. The final two-file correction reproduces all seven original failures and passes all 19 focused cases, including exact execution-instance assertions. A final cleanup moves seven repeated terminal-result envelopes into the existing typed test support, preserves every scenario and assertion, and passes the current count-based size guard. Its 21 focused cases, independent P0–P2 review, and complete changed-file check passed on Blacksmith Testbox (exit 0). The preceding fixture check also passed. Both one-shot leases stopped successfully; their Actions jobs may display cancellation during provider-owned cleanup.

The complete-candidate review's actionable legacy ACP finding was reproduced and fixed, and independent review of that repair and extraction delta found no P0–P2 issues. Other reported ownership cases were checked against the existing recorded-owner contract and eight real-manager compatibility cases.

The final ACP/task suite passed 46 cases. Both legacy same-run-ID regressions—new work already running and new work accepted but still queued—fail on the preceding candidate and pass with the repair using identical fixtures. Gateway fixture extraction preserved all 349 registrations and all 13 moved case bodies, with 16 selected cases passing before and after. Earlier integrated proofs covered production-boundary spawning, follow-up/resume/adoption, exact cancellation, delayed terminal settlement, held admission, and worker placement.

Earlier real-process probes established the original ownership defects and verified the then-current fixes. Revoked requests left descendant heartbeats running; allowed requests issued SIGTERM and settled cancellation. Those probes precede the final lifecycle changes and remain historical component evidence. The original native witness proved false refusal after an accepted stop, not lost final settlement; a separate held-admission regression proves cleanup-claim preservation through drain timeout.

Final manager/Gateway proofs use isolated state and synthetic adapters. They do not establish final-candidate provider inference, ACP bridge transport, or real channel authentication. The build's hard checks passed with an existing advisory startup-CSS warning.

@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 docs Improvements or additions to documentation agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete
steipete marked this pull request as ready for review September 15, 2026 12:35
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 17, 2026, 1:08 AM ET / 05:08 UTC (Revision 16).

ClawSweeper review

What this changes

The PR requires current control when cancelling descendant tasks, separates ACP executions that reuse request IDs, and preserves cleanup ownership after an accepted stop.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains a useful, unmerged cancellation repair that current main does not provide. No discrete introduced bug was established; backend authority proof and retained-state recovery evidence remain incomplete.

Priority: P2
Reviewed head: 1fda8e18f41b90dbf1cbabdd075039c4e87751d9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation and regression coverage are substantial, but unresolved authority and retained-state proof limit merge confidence.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: actual Gateway queued-stop coverage supports acceptance and delayed cleanup, but ACP final-effect evidence uses a synthetic backend. Historical process probes predate the lifecycle repair; current backend rejection before stop I/O and exact-instance cancellation with an unaffected same-ID successor remain unproven. Provider inference and channel authentication are unnecessary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: actual Gateway queued-stop coverage supports acceptance and delayed cleanup, but ACP final-effect evidence uses a synthetic backend. Historical process probes predate the lifecycle repair; current backend rejection before stop I/O and exact-instance cancellation with an unaffected same-ID successor remain unproven. Provider inference and channel authentication are unnecessary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Current main still needs the repair: Current main selects cancellation targets through retained task-tree links and calls cancellation without the branch’s current-controller context. The existing ownership predicate remains the appropriate owner for native control checks.
Latest-release comparison: The v2026.9.4 source also selects cancellation targets from retained task relationships without the proposed current-controller checks. Local retrieval of its missing blob failed, so the release source was read through GitHub’s contents API.
Authority and execution binding: The introduced cancellation context captures task identity, checks current caller ancestry, and expires when the operation finishes. Runtime owners consume that context before new stop effects; accepted ACP cancellation retains separate cleanup custody.
Findings None None.
Security None None.

How this fits together

OpenClaw’s task registry connects background work to its controlling session and execution. Cancellation passes through the subagents tool to Gateway or ACP runtime owners, which stop the selected work and record its outcome.

flowchart TD
  A[Session cancellation request] --> B[Current controller check]
  B --> C[Selected task and execution]
  C --> D[Gateway or ACP runtime]
  D --> E{Stop accepted}
  E -->|Yes| F[Retain exact cleanup ownership]
  E -->|No| G[Report refusal]
  F --> H[Record terminal outcome]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: actual Gateway queued-stop coverage supports acceptance and delayed cleanup, but ACP final-effect evidence uses a synthetic backend. Historical process probes predate the lifecycle repair; current backend rejection before stop I/O and exact-instance cancellation with an unaffected same-ID successor remain unproven. Provider inference and channel authentication are unnecessary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Final-candidate ACP evidence does not yet show revoked ancestry rejected before backend stop I/O, or an authorized stop leaving a queued same-request-ID successor unaffected through delayed backend cancellation.
  • Resolve merge risk (P1) - Existing retained ACP records without execution metadata become uncancellable through task cancellation; the documented current-task/session-control recovery path has not been demonstrated after reopening persisted pre-change state.
  • Complete next step (P2) - Attach final-candidate ACP backend authority evidence and persisted legacy-task recovery evidence before merge.
Agent review details

Security

None.

PR surface

Source +501, Tests +2199, Docs +11. Total +2711 across 51 files.

View PR surface stats
Area Files Added Removed Net
Source 24 651 150 +501
Tests 25 3002 803 +2199
Docs 2 13 2 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 51 3666 955 +2711

Review metrics

Metric Value Why it matters
Production versus regression coverage production +501; tests and test support +2199 Production growth has a stated purpose: carrying cancellation authority and execution identity across existing owners.
Lifecycle selector extension 1 optional taskId selector across start, progress, and terminal updates The PR documents omission preserving run-scoped behavior and tests scoped SDK forwarding.

Merge-risk options

Maintainer options:

  1. Complete backend and recovery evidence (recommended)
    Demonstrate forbidden and allowed cancellation through the actual ACP backend, plus recovery after reopening retained task records.
  2. Hold the branch pending evidence
    Keep this useful repair open until the remaining authority and upgrade cases are observable.

Technical review

Best possible solution:

Keep cancellation with the existing task and runtime owners, requiring current authority for new stops while preserving exact-execution cleanup and a proven recovery path for retained ACP records.

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

Yes, from source: current main uses retained task links to authorize cancellation without rechecking current controller ancestry. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes at the owner level: the patch reuses controller checks, binds execution identity, and separates stop acceptance from cleanup; merge readiness still depends on backend and retained-state evidence.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded cancellation correctness repair without evidence of an urgent widespread outage.
  • merge-risk: 🚨 security-boundary: The patch changes authority carried across asynchronous cancellation handoffs, with actual ACP final-effect coverage still incomplete.
  • merge-risk: 🚨 compatibility: Retained ACP task records lacking execution metadata lose task-level cancellation and require a demonstrated recovery path.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: actual Gateway queued-stop coverage supports acceptance and delayed cleanup, but ACP final-effect evidence uses a synthetic backend. Historical process probes predate the lifecycle repair; current backend rejection before stop I/O and exact-instance cancellation with an unaffected same-ID successor remain unproven. Provider inference and channel authentication are unnecessary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main still needs the repair: Current main selects cancellation targets through retained task-tree links and calls cancellation without the branch’s current-controller context. The existing ownership predicate remains the appropriate owner for native control checks. (src/agents/tools/subagents-tool.ts:330, 9c32bda3c01e)
  • Latest-release comparison: The v2026.9.4 source also selects cancellation targets from retained task relationships without the proposed current-controller checks. Local retrieval of its missing blob failed, so the release source was read through GitHub’s contents API. (src/agents/tools/subagents-tool.ts:79, 3a9d69db306c)
  • Authority and execution binding: The introduced cancellation context captures task identity, checks current caller ancestry, and expires when the operation finishes. Runtime owners consume that context before new stop effects; accepted ACP cancellation retains separate cleanup custody. (src/tasks/task-cancellation-context.ts:35, 1fda8e18f41b)
  • Gateway proof has meaningful bounded coverage: The production-boundary fixture exercises the actual Gateway abort controller, before/after-interruption authority changes, and cleanup-claim retention through a blocked drain. Its assertions explicitly identify queued work with providerStarted=false, so this supports queued-stop behavior rather than provider-process termination. (src/agents/subagents/spawn/subagent-spawn.cancellation.test-support.ts:254, 1fda8e18f41b)
  • ACP final-effect coverage gap: The real-manager fixture installs a synthetic legacy runTurn backend whose cancel method records a session key and waits on a promise. It covers ancestry and same-ID execution selection, but does not exercise actual backend cancellation I/O or the preferred startTurn transport path. (src/agents/tools/subagents-tool.acp-cancellation.test.ts:142, 1fda8e18f41b)
  • Retained-state compatibility boundary: Core cancellation now refuses ACP records without execution-instance backing and directs callers to the current task or ACP session controls. The manager scenarios construct legacy rows in an in-memory task registry; they do not establish reopening pre-change persisted task state and completing that recovery path. (src/tasks/task-registry-cancel.ts:251, 1fda8e18f41b)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Gabrielnkl: 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.

  • Provide final-effect evidence that revoked ancestry cannot issue a backend stop and authorized cancellation affects only the selected execution while a same-ID successor continues.
  • Demonstrate reopening retained ACP task state and recovering through the documented current-task or session-control path.
  • Add redacted terminal output, logs, or diagnostic media to the PR body, removing private identifiers and credentials; updating the body should trigger re-review, otherwise ask a maintainer to comment @clawsweeper re-review.

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 (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-16T14:59:33.757Z sha 35d01b8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T15:46:24.848Z sha b8c0512 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T17:05:32.477Z sha fa75cf3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T23:28:52.882Z sha 778515e :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T00:27:40.012Z sha 940dfde :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T03:39:56.784Z sha f3f7af6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T04:27:10.545Z sha bd913e8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T04:41:52.043Z sha 1fda8e1 :: needs real behavior proof before merge. :: none

Preserve the reviewed current-controller cancellation scope and include the synthetic model catalog fixture correction for production-boundary validation.
Merge d4580e1 to include the managed
handoff fixture lint repair and consolidation from #149423 and #149427.

Preserve all four reviewed task edit payloads, including the synthetic
model-catalog fixture, and the unchanged authority and producer owners.

Validation: all 32 focused cases, formatting, and targeted lint passed,
including the previously failing managed handoff fixture.
Merge 83f9484 while preserving the
reviewed current-controller cancellation code, tests, and documentation.
The identical model-catalog fixture is already present on main.

Validation: all 32 focused scope and production-boundary cases passed,
along with the selected local changed-file gates. The cancellation,
run-generation, and process-stop owners remain unchanged.
@steipete
steipete marked this pull request as draft September 16, 2026 10:18
@steipete
steipete marked this pull request as ready for review September 16, 2026 14:50
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 16, 2026
@steipete
steipete requested a review from a team as a code owner September 16, 2026 16:56
@steipete
steipete merged commit a3376d5 into main Sep 17, 2026
219 of 220 checks passed
@steipete
steipete deleted the codex/subagent-cancel-ownership-20260914 branch September 17, 2026 05:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…nclaw#149082)

* fix: require current subagent control to cancel descendant tasks

* test: use task facades in cancellation fixtures

* test: align cancellation fixtures with execution ownership

* test: give ACP cancellation fixtures execution backing

* test: share terminal subagent cancellation fixtures

* test: await native hook relay publication readiness

* test: use owned relay handles for readiness checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant