Skip to content

fix(subagents): keep raw-key child cancel from stopping another agent's work - #162540

Merged
steipete merged 2 commits into
mainfrom
fix/subagent-kill-scoped-queue-cleanup
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/subagent-kill-scoped-queue-cleanup

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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_send follow-up registers a subagent run for a raw child key (reachable via session-id targeting, agent:research:main under global scope, or a research parent sending to literal global). Registration kept only the raw key, so cancel re-derived the owner from config (the default agent) and then called the raw-key clearSessionQueues, which cleared every agent's queue under that key. Two defects followed:

  • wrong owner: cancelling research/global read main's store, aborted main's active run, marked main aborted, and dropped main's queued work;
  • unscoped clear: even with main correctly resolved, research's queued work under global was dropped.

Registration now records the known owning agent as optional childAgentId for 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-scoped clearSessionLifecycleQueues owner, so clearSessionQueues and 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). childAgentId lives only inside the existing subagent_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 because normalizeSubagentRunState mutates the parsed record in place, and simply ignore it. Resolving the owner at cancel time instead was rejected: two agents can each persist global, 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 in docs/reference/database-schemas/versioning.md and docs/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

  • Regression src/agents/subagents/registry/subagent-control.raw-entry.test.ts drives the real sessions_send tool (watched follow-up to global) and the real subagents cancel tool for owner main and owner research. 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.
  • Route audit (investigation test, not kept): label targeting of global/unknown is blocked before registration; other legacy creation keys canonicalize to qualified keys; native/ACP spawns mint qualified keys; plugin agent RPC registration rejects raw keys.
  • node scripts/check-changed.mjs passed (production tsgo and all 27 affected test graphs); every touched test file ran; git diff --check clean.
  • Codex autoreview (P0–P2) on the full candidate: scoped-clean.
  • Blacksmith Testbox tbx_01m3v7w92fz6ypykep0vqqqe7v (run): agent-runner.runreplyagent.e2e.test.ts 224/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.
  • Test cost: the new regression file runs in ~2.3s of test time (Testbox shard); no new serial config, real timers, or Gateway boots.
  • CI repair: aligned the registry fixture store and generation reads with the shared child-session owner; Blacksmith Testbox 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 with pnpm test <file> --maxWorkers=1; node scripts/check-changed.mjs passed, including all 27 test type graphs; Codex delta autoreview was scoped-clean at P0–P2.

…'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.
@clawsweeper

clawsweeper Bot commented Oct 1, 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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 1, 2026
@steipete
steipete marked this pull request as ready for review October 1, 2026 08:24
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:26 AM ET / 10:26 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: 045469ef02bcd607475b7878988a5e934857e23d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful regression coverage, compatible payload handling, and no introduced blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The trusted repository author's ordinary external-contributor proof gate does not apply. The tool-boundary regression exercises selected-child cancellation and foreign-work preservation with mocked dispatch; reported Testbox runs are supplemental validation. Source inspection of the released and candidate codecs verifies compatibility of the additive payload field.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The trusted repository author's ordinary external-contributor proof gate does not apply. The tool-boundary regression exercises selected-child cancellation and foreign-work preservation with mocked dispatch; reported Testbox runs are supplemental validation. Source inspection of the released and candidate codecs verifies compatibility of the additive payload field.
Evidence reviewed 10 items Pinned introduction and review continuity: Reviewed the merge-base-to-head introduced changes. Compared the previously reviewed head with the current head: the latter adds session mock wiring and aligns the registry fixture store, without changing production behavior. The previous completed review retained no findings or rank-up moves.
Current main still needs this repair: At the fetched main revision, direct child cancellation still calls clearSessionQueues with the raw child key and session ID. Watched follow-up registration does not yet capture childAgentId.
Owner capture and replay: The resolved sessions_send target supplies childAgentId. Registration validates it, rejects disagreement with qualified keys, stores it only for raw keys, and preserves the original binding during replay.
Findings None None.
Security None None.

How this fits together

OpenClaw'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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +86, Tests +376, Docs +21. Total +483 across 50 files.

View PR surface stats
Area Files Added Removed Net
Source 16 158 72 +86
Tests 32 612 236 +376
Docs 2 21 0 +21
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 50 791 308 +483

Review metrics

Metric Value Why it matters
Production and test growth production +88 net; tests and test support +374 net Production growth carries the missing agent binding through cancellation and recovery while removing unscoped cleanup.
Persistent contract 1 optional payload field; 0 SQL schema changes Released serialization preserves the additional field, and legacy rows require no backfill.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The repair prevents cancelling one background child from aborting another agent's active work and dropping its queued messages and commands.
  • 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 trusted repository author's ordinary external-contributor proof gate does not apply. The tool-boundary regression exercises selected-child cancellation and foreign-work preservation with mocked dispatch; reported Testbox runs are supplemental validation. Source inspection of the released and candidate codecs verifies compatibility of the additive payload field.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base-to-head introduced changes. Compared the previously reviewed head with the current head: the latter adds session mock wiring and aligns the registry fixture store, without changing production behavior. The previous completed review retained no findings or rank-up moves. (045469ef02bc)
  • Current main still needs this repair: At the fetched main revision, direct child cancellation still calls clearSessionQueues with the raw child key and session ID. Watched follow-up registration does not yet capture childAgentId. (src/agents/subagents/registry/subagent-control-kill-runtime.ts:585, 1128a4ae92af)
  • Owner capture and replay: The resolved sessions_send target supplies childAgentId. Registration validates it, rejects disagreement with qualified keys, stores it only for raw keys, and preserves the original binding during replay. (src/agents/subagents/registry/subagent-registry-run-launch.ts:84, 045469ef02bc)
  • Final-effect ownership guards: Direct cancellation supplies the prepared agent identity to the existing scoped cleanup owner and rechecks caller, kill-claim, and session authority. Recovery prepares worker-backed session facts and checks the retained incarnation before abort and queue cleanup. Controller authorization remains independently enforced. (src/agents/subagents/registry/subagent-control-kill-runtime.ts:585, 045469ef02bc)
  • Boundary regression: The new regression drives sessions_send and subagents cancel for both main/global and research/global. It checks interruption of the selected child, preservation of the foreign abort marker and follow-up, rejection of the selected child's queued command, and execution of the foreign command. Gateway dispatch and completion are mocked; this is supplemental boundary coverage, not a live deployment trace. (src/agents/subagents/registry/subagent-control.raw-entry.test.ts:145, 045469ef02bc)
  • Released payload compatibility: Inspected the exact v2026.9.7 codec: it accepts additional root payload fields, normalizes the parsed record, and serializes the complete normalized record. The released normalizer mutates the record without removing unknown root fields. This supports retaining childAgentId across older-reader rewrites without DDL or a backfill. (src/agents/subagents/registry/subagent-registry.store.codec.ts:62, c074824a27c9)

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-10-01T08:30:54.338Z sha 1cc8000 :: needs maintainer review before merge. :: none

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.
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

The PR-caused registry failure is fixed at 045469ef02bcd607475b7878988a5e934857e23d. The repaired suite passed 116/116 on Testbox, and the full requested non-live subagent/sessions-send/queue coverage plus explicit E2E files passed 2,764 tests; changed checks and the fresh Codex delta review also passed.

Exact-head CI run 36848368953 ended cancelled after job 110324385582 failed five cases in src/gateway/server-agent-database-startup.test.ts:188: PRAGMA journal_mode=DELETE reports database is locked during fixture setup, before Gateway startup. The same failure is independently recorded on scheduled main CI, run 36843916577 / job 110309666774, at main head 57d4719841ce67bc4e80bca45173560882836b47.

The failing file has identical blob 4c78924ea5df9fa47e4afc4c05239b82635b6517 on that main head, current main, and this PR. The PR does not change its database setup or storage implementation. The failed PR checkout was merge 2f917c3f791392442f8d6193f1aecffe9572d027 (main 9ced5fc07daee9af43fa2a7542f7543bdd651648 plus the exact head above). security-fast passed. Three sibling jobs were cancelled after this failure; their remaining coverage is not claimed as passing.

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.

@steipete
steipete merged commit bb60413 into main Oct 1, 2026
128 of 135 checks passed
@steipete
steipete deleted the fix/subagent-kill-scoped-queue-cleanup branch October 1, 2026 10:53
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

steipete added a commit that referenced this pull request Oct 1, 2026
…ardown

#162540 deleted the raw-key clearSessionQueues helper while #148025 landed a test that still imported it for teardown. Use the shared clearFollowupQueueForTest helper; the test enqueues no lane commands.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…'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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 2, 2026
…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
steipete added a commit that referenced this pull request Oct 2, 2026
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.
steipete added a commit that referenced this pull request Oct 2, 2026
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.
steipete added a commit that referenced this pull request Oct 2, 2026
…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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
…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
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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