Skip to content

fix(subagents): agents sharing a raw session key like global select each other's subagent runs - #163282

Merged
steipete merged 4 commits into
mainfrom
steipete/subagent-child-owner-lookups
Oct 2, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/subagent-child-owner-lookups

Conversation

@steipete

@steipete steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Related: #162540

What Problem This Solves

Fixes: when two agents both have a live subagent run under the same raw session key (for example global for main and research), subagent lookups can select the other agent's run — wrong generation numbering, watched sessions_send follow-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_send follow-ups (session-id targeting, agent:research:main under global session scope, or a parent sending literal global) 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

  • Real entry points (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 (generation 2 instead of 1, missing watched registration, rejected send, forbidden cancel, legacy cancel selecting main's run); with the fix all 15 pass. Wall time --maxWorkers=1: raw-entry ~24s, raw-owner ~20s on a loaded host.
  • Full sweep on a Blacksmith Testbox: every test file under 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 missing OPENAI_API_KEY, identical on clean main.
  • pnpm tsgo, all 27 test typecheck graphs, lint, oxfmt, git diff --check pass. check-changed hits Knip's 600s full-tree timeout, identical on clean main.
  • Two independent Codex autoreviews: no P0/P1 findings.

@clawsweeper

clawsweeper Bot commented Oct 2, 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 2, 2026
@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 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 7:54 AM ET / 11:54 UTC (Revision 6).

ClawSweeper review

What this changes

The 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
Reviewed head: 1f9dbe1a8ab508c92e0de6159c0eada92bb1d551

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent ownership repair with meaningful regression coverage and no identified blocking patch defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate does not apply to this verified repository-admin author. Inspected production-tool regressions supplement the owner-selection repair, but use mocked Gateway dispatch and are not claimed as live proof; no unresolved introduced authority violation was identified. Stored payload and schema contracts remain unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this verified repository-admin author. Inspected production-tool regressions supplement the owner-selection repair, but use mocked Gateway dispatch and are not claimed as live proof; no unresolved introduced authority violation was identified. Stored payload and schema contracts remain unchanged.
Evidence reviewed 12 items Pinned introduction reviewed: Inspected the complete merge-base-to-head introduced diff. The stale test merge was not used to infer removal of current-main behavior.
Current main still needs the repair: Current main’s live registry lookup accepts a child key and optional predicate, but does not accept the recorded child agent owner; its child bucket remains key-only.
Merged predecessor identifies the remaining gap: #162540 merged on October 1 and explicitly documented in-memory raw-key lookup as remaining work. It supplied the existing childAgentId binding rather than solving this PR’s central problem.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +304, Tests +287, Docs +4. Total +595 across 50 files.

View PR surface stats
Area Files Added Removed Net
Source 45 504 200 +304
Tests 4 292 5 +287
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 50 800 205 +595

Review metrics

Metric Value Why it matters
Production versus test growth production +304 net LOC; tests +287 net LOC; docs +4 Production growth threads the existing owner through lifecycle decisions and shares matching in one leaf module.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Shared raw session keys can select another agent’s child, breaking watched completion, steering, and cancellation workflows.
  • 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 ordinary external-contributor proof gate does not apply to this verified repository-admin author. Inspected production-tool regressions supplement the owner-selection repair, but use mocked Gateway dispatch and are not claimed as live proof; no unresolved introduced authority violation was identified. Stored payload and schema contracts remain unchanged.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (5 earlier review cycles)
  • reviewed 2026-10-02T05:28:49.176Z sha d40339e :: needs changes before merge. :: none
  • reviewed 2026-10-02T06:22:56.342Z sha 0a3368c :: needs changes before merge. :: none
  • reviewed 2026-10-02T06:45:28.429Z sha 0a3368c :: blocked before merge. :: none
  • reviewed 2026-10-02T07:37:25.438Z sha 0a3368c :: blocked before merge. :: none
  • reviewed 2026-10-02T10:25:30.859Z sha c1c3a8a :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/subagent-child-owner-lookups branch from d40339e to 0a3368c Compare October 2, 2026 06:17
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to resolve GitHub's reported conflict with main; the reviewed head is now 0a3368c9db3d7355625de0ad70dcf3b1ed53f419.

The only textual conflict was the SQLite session-list projection. The resolution keeps upstream's compact-payload reader and includes the existing childAgentId field in its projection allowlist. The required-config control-helper commit is patch-identical. No schema or stored-payload change.

Post-rebase validation on Blacksmith Testbox passed all 11 requested test files / 192 tests: every subagent-control*.test.ts, the raw-owner lookup regression, and the SQLite store suite. Test wall time was 151.4 seconds; pnpm tsgo:core passed in 39.5 seconds. The remote checkout verified SHA-256 hashes for all 54 changed files plus the package and lock manifests before execution. Fresh independent Codex autoreview found no P0/P1 defects; git diff --check passed.

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.

@openclaw-barnacle openclaw-barnacle Bot closed this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this 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.
Upstream #162227 made cfg required on getLatestOwnedSubagentRun and isCurrentSubagentRun; the rebase had loosened it back to optional. Every caller passes it.
@steipete
steipete force-pushed the steipete/subagent-child-owner-lookups branch from 0a3368c to c1c3a8a Compare October 2, 2026 10:18
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

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=1

Both commands exited 1 with the same result:

FAIL src/agents/subagents/registry/subagent-control.concurrency.test.ts
  > admin cancellation interrupts every sibling before waiting for any sibling to drain
AssertionError: expected "vi.fn()" to be called 2 times, but got 0 times
  src/agents/subagents/registry/subagent-control.concurrency.test.ts:461:46
Test Files  1 failed (1)
Tests       1 failed | 12 passed (13)

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.
@steipete
steipete merged commit 6440653 into main Oct 2, 2026
141 of 142 checks passed
@steipete
steipete deleted the steipete/subagent-child-owner-lookups branch October 2, 2026 12:00
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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