Repository navigation
fix(subagents): keep raw-key child cancel from stopping another agent's work - #162540
Conversation
…'s work Cancelling a watched sessions_send child registered under a raw session key such as `global` re-derived its owner from config and cleared every agent's queue under that key. With two agents this aborted the default agent's run, marked it aborted, and dropped its queued follow-ups and lane commands; even with the owner resolved correctly, another agent's queued work was dropped. Registration now records the known owning agent as optional `childAgentId` for raw child keys (payload_json only; no DDL or schema-version bump). One owner resolver feeds direct cancel, kill-scope discovery, the durable-kill sweep, provisional reconciliation, and completion reads, and queue cleanup uses the agent-scoped clearSessionLifecycleQueues owner. The raw-key clearSessionQueues helper and its re-exports are deleted. Sweep session reads move off the main thread onto worker reads.
|
🦞👀 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 October 1, 2026, 6:26 AM ET / 10:26 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR records the owning agent for unqualified child sessions and scopes cancellation, queue cleanup, and recovery to that agent. Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the raw-key cancellation gap explicitly deferred by the related merged fixes. No introduced blocking defect was found, and the latest commit changes only registry test fixtures. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw's subagent registry tracks background child work created by agent tools. Cancellation uses those records to select the child's session store, stop its execution, and remove its queued work. flowchart TD
A[Watched session follow-up] --> B[Register child and owning agent]
C[Cancel request or recovery sweep] --> D[Check current run and session]
B --> D
D --> E[Resolve agent session store]
E --> F[Stop child and clear owned queues]
F --> G[Other agents retain their work]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +86, Tests +376, Docs +21. Total +483 across 50 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep child cancellation on the existing agent-scoped lifecycle owner, with the target agent captured when raw-key work is registered. Do we have a high-confidence way to reproduce the issue? Yes, the source exposes a clear two-agent reproduction: register a watched raw-key child and cancel it while another agent owns work under the same key. The PR supplies a focused failing-before regression; this read-only review did not execute it. Is this the best way to solve the issue? Yes, capturing the already-resolved target agent and reusing scoped lifecycle cleanup repairs the producer and consumers without adding a competing cleanup policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1128a4ae92af. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Configure the seeded fixture store and keep synthetic generation facts on the same session owner. Preserve real-store reads, identity and revision checks, and release invalidation; extract session mock wiring to keep the registry suite within its line-count budget.
|
The PR-caused registry failure is fixed at Exact-head CI run 36848368953 ended cancelled after job The failing file has identical blob Landing this exact reviewed head under Peter's explicitly authorized pre-existing-CI-failure exception. No rebase or CI rerun is being used to hide the inherited failure. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…'s work (openclaw#162540) * fix(subagents): keep raw-key child cancel from stopping another agent's work Cancelling a watched sessions_send child registered under a raw session key such as `global` re-derived its owner from config and cleared every agent's queue under that key. With two agents this aborted the default agent's run, marked it aborted, and dropped its queued follow-ups and lane commands; even with the owner resolved correctly, another agent's queued work was dropped. Registration now records the known owning agent as optional `childAgentId` for raw child keys (payload_json only; no DDL or schema-version bump). One owner resolver feeds direct cancel, kill-scope discovery, the durable-kill sweep, provisional reconciliation, and completion reads, and queue cleanup uses the agent-scoped clearSessionLifecycleQueues owner. The raw-key clearSessionQueues helper and its re-exports are deleted. Sweep session reads move off the main thread onto worker reads. * fix(subagents): align registry fixture with session owner reads Configure the seeded fixture store and keep synthetic generation facts on the same session owner. Preserve real-store reads, identity and revision checks, and release invalidation; extract session mock wiring to keep the registry suite within its line-count budget.
…ardown openclaw#162540 deleted the raw-key clearSessionQueues helper while openclaw#148025 landed a test that still imported it for teardown. Use the shared clearFollowupQueueForTest helper; the test enqueues no lane commands.
…ess cancellation test Upstream bb60413 (openclaw#162540) deleted the raw-key clearSessionQueues helper and moved tests to clearFollowupQueueForTest. This overlay test only uses the follow-up queue (no command lane), so the helper is equivalent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fq5EX9ESA3CG9cuZxVoKAK
When two agents both had live raw-key children with the same key (for example `global` for `main` and `research`), the in-memory registry still looked runs up by the raw key alone. Generation numbering, registration ownership, the watched sessions_send follow-up's completion child and steered adoption, and subagents-tool cancel could select the other agent's row: wrong generation, unregistered watched follow-ups, and cancels rejected as outside the controlled tree. Child-key lookups now take an optional owner and filter the existing raw-key buckets through one predicate, matchesSubagentChildSessionOwner, using the childAgentId recorded by #162540. Rows without a recorded owner (agent-qualified keys and legacy unbound raw rows) and callers without an owner keep raw-key matching. Kill, admin kill, kill scope and run currentness keep the requester-agent filter for legacy unbound raw rows. No schema, payload shape, or schema-version change: list reads project the existing payload_json childAgentId. Proof: real-entry sessions_send/subagents tests with two agents failed before (generation 2 vs 1, missing watched registration, forbidden cancel, legacy cancel selecting main's row) and pass after; full src/agents/subagents sweep plus sessions-send/subagents-tool/gateway caller suites on Testbox (166 files, 2,686 tests). Follow-ups (owner not available at the call site): gateway session-subagent-reactivation, session-subagent-resume, approval-session-audience, ACP spawn admission, raw-key list aggregation.
When two agents both had live raw-key children with the same key (for example `global` for `main` and `research`), the in-memory registry still looked runs up by the raw key alone. Generation numbering, registration ownership, the watched sessions_send follow-up's completion child and steered adoption, and subagents-tool cancel could select the other agent's row: wrong generation, unregistered watched follow-ups, and cancels rejected as outside the controlled tree. Child-key lookups now take an optional owner and filter the existing raw-key buckets through one predicate, matchesSubagentChildSessionOwner, using the childAgentId recorded by #162540. Rows without a recorded owner (agent-qualified keys and legacy unbound raw rows) and callers without an owner keep raw-key matching. Kill, admin kill, kill scope and run currentness keep the requester-agent filter for legacy unbound raw rows. No schema, payload shape, or schema-version change: list reads project the existing payload_json childAgentId. Proof: real-entry sessions_send/subagents tests with two agents failed before (generation 2 vs 1, missing watched registration, forbidden cancel, legacy cancel selecting main's row) and pass after; full src/agents/subagents sweep plus sessions-send/subagents-tool/gateway caller suites on Testbox (166 files, 2,686 tests). Follow-ups (owner not available at the call site): gateway session-subagent-reactivation, session-subagent-resume, approval-session-audience, ACP spawn admission, raw-key list aggregation.
…ach other's subagent runs (#163282) * fix(subagents): keep raw child-key lookups on the recorded owning agent When two agents both had live raw-key children with the same key (for example `global` for `main` and `research`), the in-memory registry still looked runs up by the raw key alone. Generation numbering, registration ownership, the watched sessions_send follow-up's completion child and steered adoption, and subagents-tool cancel could select the other agent's row: wrong generation, unregistered watched follow-ups, and cancels rejected as outside the controlled tree. Child-key lookups now take an optional owner and filter the existing raw-key buckets through one predicate, matchesSubagentChildSessionOwner, using the childAgentId recorded by #162540. Rows without a recorded owner (agent-qualified keys and legacy unbound raw rows) and callers without an owner keep raw-key matching. Kill, admin kill, kill scope and run currentness keep the requester-agent filter for legacy unbound raw rows. No schema, payload shape, or schema-version change: list reads project the existing payload_json childAgentId. Proof: real-entry sessions_send/subagents tests with two agents failed before (generation 2 vs 1, missing watched registration, forbidden cancel, legacy cancel selecting main's row) and pass after; full src/agents/subagents sweep plus sessions-send/subagents-tool/gateway caller suites on Testbox (166 files, 2,686 tests). Follow-ups (owner not available at the call site): gateway session-subagent-reactivation, session-subagent-resume, approval-session-audience, ACP spawn admission, raw-key list aggregation. * fix(subagents): keep required cfg on owned-run control helpers Upstream #162227 made cfg required on getLatestOwnedSubagentRun and isCurrentSubagentRun; the rebase had loosened it back to optional. Every caller passes it. * fix(subagents): keep owner matching out of the registry import graph Moving the shared owner predicate into leaf registry modules (memory, queries, generation, view, state) imported it from the module that also resolves owner store paths through agent-scope, and the requester-settle state helper started importing registry reads. Both edges joined the registry into one large import cycle that the Madge architecture check rejects. The pure predicate now lives in its own leaf module with only a session-key dependency, and the requester-settle run lookup returns to the wake owner that already reads the registry. A record-based getLatestSubagentRunForChild replaces positional undefined placeholders at restore, restart recovery, and kill reconciliation; the registered subagent timeout inheritance moves next to the Gateway subagent admission helpers. Both keep their files within the line cap. Parent-resume adoption now checks the latest run for the adopted record's own owner. * test(subagents): hold raw-owner registry commits through the current persistence seam
…ach other's subagent runs (openclaw#163282) * fix(subagents): keep raw child-key lookups on the recorded owning agent When two agents both had live raw-key children with the same key (for example `global` for `main` and `research`), the in-memory registry still looked runs up by the raw key alone. Generation numbering, registration ownership, the watched sessions_send follow-up's completion child and steered adoption, and subagents-tool cancel could select the other agent's row: wrong generation, unregistered watched follow-ups, and cancels rejected as outside the controlled tree. Child-key lookups now take an optional owner and filter the existing raw-key buckets through one predicate, matchesSubagentChildSessionOwner, using the childAgentId recorded by openclaw#162540. Rows without a recorded owner (agent-qualified keys and legacy unbound raw rows) and callers without an owner keep raw-key matching. Kill, admin kill, kill scope and run currentness keep the requester-agent filter for legacy unbound raw rows. No schema, payload shape, or schema-version change: list reads project the existing payload_json childAgentId. Proof: real-entry sessions_send/subagents tests with two agents failed before (generation 2 vs 1, missing watched registration, forbidden cancel, legacy cancel selecting main's row) and pass after; full src/agents/subagents sweep plus sessions-send/subagents-tool/gateway caller suites on Testbox (166 files, 2,686 tests). Follow-ups (owner not available at the call site): gateway session-subagent-reactivation, session-subagent-resume, approval-session-audience, ACP spawn admission, raw-key list aggregation. * fix(subagents): keep required cfg on owned-run control helpers Upstream openclaw#162227 made cfg required on getLatestOwnedSubagentRun and isCurrentSubagentRun; the rebase had loosened it back to optional. Every caller passes it. * fix(subagents): keep owner matching out of the registry import graph Moving the shared owner predicate into leaf registry modules (memory, queries, generation, view, state) imported it from the module that also resolves owner store paths through agent-scope, and the requester-settle state helper started importing registry reads. Both edges joined the registry into one large import cycle that the Madge architecture check rejects. The pure predicate now lives in its own leaf module with only a session-key dependency, and the requester-settle run lookup returns to the wake owner that already reads the registry. A record-based getLatestSubagentRunForChild replaces positional undefined placeholders at restore, restart recovery, and kill reconciliation; the registered subagent timeout inheritance moves next to the Gateway subagent admission helpers. Both keep their files within the line cap. Parent-resume adoption now checks the latest run for the adopted record's own owner. * test(subagents): hold raw-owner registry commits through the current persistence seam
Related: #161736, #162179
What Problem This Solves
Fixes: cancelling a subagent whose session has no agent prefix (such as
global) stops another agent's conversation and drops its queued messages and commands.User Impact
User impact: with multiple agents, cancelling one background child only stops that child. Another agent's active run, its abort marker, and its queued follow-ups and lane commands under the same raw session key now survive.
Why This Change Was Made
A watched
sessions_sendfollow-up registers a subagent run for a raw child key (reachable via session-id targeting,agent:research:mainunder global scope, or aresearchparent sending to literalglobal). Registration kept only the raw key, so cancel re-derived the owner from config (the default agent) and then called the raw-keyclearSessionQueues, which cleared every agent's queue under that key. Two defects followed:research/globalreadmain's store, abortedmain's active run, markedmainaborted, and droppedmain's queued work;maincorrectly resolved,research's queued work underglobalwas dropped.Registration now records the known owning agent as optional
childAgentIdfor raw child keys only (the follow-up passes its already-resolved target agent). One owner resolver feeds direct cancel, kill-scope descendant discovery, the durable-kill sweep, provisional kill reconciliation, and completion reads; the store is derived from that agent exactly as for agent-qualified keys, which are unchanged. Queue cleanup uses the agent-scopedclearSessionLifecycleQueuesowner, soclearSessionQueuesand its re-exports are deleted (these were its last production callers after #161736/#162179). The sweep's synchronous main-thread session reads moved onto worker reads, and kill-intent supersession compares recorded owners so raw-key rows owned by different agents no longer supersede each other.Storage decision (accepted by @steipete in the maintainer session).
childAgentIdlives only inside the existingsubagent_runs.payload_json: no DDL, no new column, no schema-version bump, no generated types. Legacy rows without it keep today's config resolution, but their queue cleanup is now limited to that one resolved agent; no backfill. Downgraded builds keep the key through rewrites becausenormalizeSubagentRunStatemutates the parsed record in place, and simply ignore it. Resolving the owner at cancel time instead was rejected: two agents can each persistglobal, so the key alone cannot identify the owner. The approved draft recorded{ agentId, storePath }; this narrows it to the agent only, because a recorded physical store path conflicts with the logical locator that lifecycle admission keys on and would change agent-qualified behavior. Documented indocs/reference/database-schemas/versioning.mdanddocs/tools/subagents/operations.md.Remaining risk (follow-up, not widened here): the in-memory registry still indexes runs by raw child key, so lookups such as
getLatestLiveSubagentRunByChildSessionKey("global")can still see another agent's live raw-key row.Evidence
src/agents/subagents/registry/subagent-control.raw-entry.test.tsdrives the realsessions_sendtool (watched follow-up toglobal) and the real subagentscanceltool for ownermainand ownerresearch. On the unmodified base it fails both cases (foreign follow-up and lane command cleared; research cancel aborted main and marked it aborted); on this branch both pass.global/unknownis blocked before registration; other legacy creation keys canonicalize to qualified keys; native/ACP spawns mint qualified keys; pluginagentRPC registration rejects raw keys.node scripts/check-changed.mjspassed (production tsgo and all 27 affected test graphs); every touched test file ran;git diff --checkclean.tbx_01m3v7w92fz6ypykep0vqqqe7v(run):agent-runner.runreplyagent.e2e.test.ts224/224 and the raw-entry regression passed. A local run of the e2e file missed one 5s admission deadline (keeps the replacement source when retired admission completes, admission completed after 14.4s) on a host at load average ~50; the same test passed on Testbox, so this is host load, not this change.tbx_01m3vb49jd125e8szc8x59r6ga(run 36839998663) passed 2,764 tests across 168 files (all non-live subagent files, sessions-send and queue tests, five explicit E2E files, raw-entry regression, and key-resolution checks; the opt-in benchmark was skipped). The repaired registry suite passed 116/116 in 6.92s Vitest / 20.55s wrapper wall withpnpm test <file> --maxWorkers=1;node scripts/check-changed.mjspassed, including all 27 test type graphs; Codex delta autoreview was scoped-clean at P0–P2.