Repository navigation
fix(subagents): agents sharing a raw session key like global select each other's subagent runs - #163282
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 October 2, 2026, 7:54 AM ET / 11:54 UTC (Revision 6). ClawSweeper reviewWhat this changesThe branch separates subagent lookup, generation numbering, completion, recovery, and cancellation by the recorded agent owner when agents share a session key such as global. Merge readiness✅ Ready for maintainer review This PR addresses a documented gap that remains on current main. No blocking introduced defect was found in the pinned diff. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s subagent registry tracks delegated work created by agent tools and Gateway requests. Its ownership decisions determine which child receives follow-ups, which completion reaches the parent, and which work cancellation stops. flowchart TD
A[Agent tools and Gateway requests] --> B[Session key and agent owner]
B --> C[Subagent registry]
C --> D[Select matching current run]
D --> E[Follow-up and completion]
D --> F[Cancellation and recovery]
E --> G[Parent conversation]
F --> H[Owned child session]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +304, Tests +287, Docs +4. Total +595 across 50 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing recorded child owner consistently while retaining legacy lookup behavior and current-authority checks. Do we have a high-confidence way to reproduce the issue? Yes, from source: create watched child runs for two agents under global, then follow up or cancel the earlier agent’s child. Current-main key-only lookup can select the other owner; focused regressions cover this path, but this review did not execute it. Is this the best way to solve the issue? Yes. Filtering the existing registry through one owner predicate repairs the selection boundary without introducing a competing registry, configuration option, or migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cae2f937ce97. 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 (5 earlier review cycles)
|
d40339e to
0a3368c
Compare
|
Rebased to resolve GitHub's reported conflict with The only textual conflict was the SQLite session-list projection. The resolution keeps upstream's compact-payload reader and includes the existing Post-rebase validation on Blacksmith Testbox passed all 11 requested test files / 192 tests: every Testbox environment: https://github.com/openclaw/openclaw/actions/runs/36971740970 . The delegated command exited 0; its lease was stopped after validation. The first lease expired while queued, and the replacement needed a frozen dependency install before tests could start. These were setup failures, not candidate test failures. |
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.
Upstream #162227 made cfg required on getLatestOwnedSubagentRun and isCurrentSubagentRun; the rebase had loosened it back to optional. Every caller passes it.
0a3368c to
c1c3a8a
Compare
|
The admin sibling-cancellation failure is pre-existing on the clean base, not introduced by this PR. I ran the unchanged test file in isolated clean-base and PR checkouts with frozen dependencies: # Clean base d7fd9a7dea11b529738562d6ae472788e5085620
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/Users/steipete/Projects/.child-owner-163282-proof/base-cache pnpm test src/agents/subagents/registry/subagent-control.concurrency.test.ts --maxWorkers=1
# PR head c1c3a8a8a7cba37d39e198edb076fb534a85ddcb
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/Users/steipete/Projects/.child-owner-163282-proof/pr-cache pnpm test src/agents/subagents/registry/subagent-control.concurrency.test.ts --maxWorkers=1Both commands exited 1 with the same result: Vitest reported 604.92 seconds on the clean base and 692.50 seconds on the PR head, including substantial cold compilation/import time. This was an assertion failure, not a runner timeout. The test file is byte-identical between the two revisions. No assertion, timeout, retry, or source change was made for this inherited failure. The candidate merged cleanly in Git's merge-tree check against main 4188361 before publication. The two-commit candidate is now pushed at c1c3a8a. Exact-head CI and independent review are pending; the local reproduction is not a claim of passing CI. This upstream regression is intentionally left outside this PR's child-owner lookup change. |
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.
|
Merged via squash.
|
…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: #162540
What Problem This Solves
Fixes: when two agents both have a live subagent run under the same raw session key (for example
globalformainandresearch), subagent lookups can select the other agent's run — wrong generation numbering, watchedsessions_sendfollow-ups that never register their completion, and cancels rejected as "Run outside the controlled session tree" or aimed at the wrong child.User Impact
Multi-agent setups that reach shared raw keys through watched
sessions_sendfollow-ups (session-id targeting,agent:research:mainunder global session scope, or a parent sending literalglobal) now keep each agent's child runs separate for numbering, completion, and cancellation. Agent-qualified session keys behave exactly as before. No config, schema, or migration change.Why This Change Was Made
#162540 started recording the owning agent (
childAgentId, payload only) for raw-key child runs and used it for cancel, the durable-kill sweep, and completion reads. The in-memory registry still found runs by the raw key alone. Child-key lookups now take an optional owner and filter through one shared predicate: rows that recorded an owner match only that owner; rows without one (agent-qualified keys and runs registered before #162540) and callers that do not know the owner keep raw-key matching. Kill, admin kill, kill scope, and run currentness keep their existing requester-agent filter for those older unbound rows, and the durable-kill sweep keeps #162540's raw-key supersession for them.Callers that do not have the child's owner available stay unchanged and are follow-ups: gateway session reactivation/resume, approval session audience, ACP spawn admission, and raw-key list aggregation.
Evidence
sessions_send+ subagents tools, two agents,subagent-control.raw-entry.test.ts) plus focused lookup coverage (subagent-registry-queries.raw-owner.test.ts). Against unfixed production code: 4/8 real-entry and 3/7 lookup tests fail (generation2instead of1, missing watched registration, rejected send, forbidden cancel, legacy cancel selectingmain's run); with the fix all 15 pass. Wall time--maxWorkers=1: raw-entry ~24s, raw-owner ~20s on a loaded host.src/agents/subagents/plus the sessions-send, subagents-tool, and touched gateway caller suites — 184 files / 3,241 tests passed. Seven live-provider files fail only on a missingOPENAI_API_KEY, identical on clean main.pnpm tsgo, all 27 test typecheck graphs, lint, oxfmt,git diff --checkpass.check-changedhits Knip's 600s full-tree timeout, identical on clean main.