Skip to content

fix(subagents): honor recorded owners for raw session keys in listings - #166550

Merged
steipete merged 1 commit into
mainfrom
deslop/d06-agents-subagents-tools-20261007
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
deslop/d06-agents-subagents-tools-20261007

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes /subagents list and the subagents list action failing when a watched child uses a raw session key such as global, including children owned by a different configured agent.

User Impact

Watched raw-key children can be listed with their own saved model and usage metadata. Two agents using the same raw key retain separate metadata. No configuration, protocol, or stored-data migration is required.

Why This Change Was Made

The metadata reader in src/agents/subagents/registry/subagent-list.ts:89 derived the owner only from childSessionKey, ignoring the recorded childAgentId. Raw keys contain no agent prefix, so templated/default stores failed owner resolution; literal stores could also reach the missing-agent error. The result map also used the raw key alone.

Use the existing child-owner resolver for each batch and associate returned metadata with the run ID. The list builder and its internal benchmark consumer use that same key.

Evidence

Both regressions in src/agents/subagents/registry/subagent-list.test.ts failed before the fix and passed afterward:

  • reads fresh active and recent metadata from each visible child's store now includes distinct main/global and research/global rows; the original code threw SessionStoreAgentIdRequiredError.
  • reads a raw child's metadata from its recorded owner in a custom store covers a literal SQLite path; the original code threw Cannot resolve subagent session metadata without an agent id.

Validation on rebased head b6e5cc9a32466a3872e0624715c6affcb01dc7e3:

  • node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-list.test.ts --maxWorkers=1: 16 passed, 113.08 seconds wall time locally. Hosted CI ran all 16 tests in a 20.76-second Vitest shard; the owning checks-node-changed-1 job took 262 seconds.
  • Dedicated Linux validation ran node scripts/check-changed.mjs, then node scripts/run-vitest.mjs src/agents/subagents src/agents/tools test/scripts/lint-suppressions.test.ts: 5,311 tests passed across 338 files, with two existing opt-in benchmark skips. The eight Vitest shards took 961.30 seconds. The changed-file checks passed, including all 27 selected test-type graphs and all three unused-export scans.
  • Runtime value cycles: 0. Madge cycles: 0. Targeted lint and lint-suppression tests passed.
  • Independent P2 review was clean; git range-diff confirms the rebase was patch-identical.

An additional macOS full-directory run hit the unchanged five-second polling deadline in subagent-registry.persistence.test.ts ("settles orphaned restored runs through canonical completion"). The same case passed on Linux in 1.34 seconds. The complete persistence test file passed all 13 tests on clean main 49c18152c8bf5b9b73f5823aa425343b617fa689 in 406.91 seconds wall time. This did not reproduce or explain the original macOS polling failure; it remains recorded, not claimed fixed or classified as main-red. Exact-head hosted CI remains the merge gate.

Watched raw session keys such as global already carry childAgentId.
Resolve list reads through the existing child-owner helper, batch by agent,
and associate display metadata with run IDs so agents sharing a raw key
cannot overwrite each other's metadata.

Cover templated and literal stores, duplicate raw keys, and existing
active/recent metadata refresh. Both raw-key regressions failed before
the fix; 35 focused tests pass after it. The opt-in allocation benchmark
retains its assertion with the new private map key.

Core production types and all 27 selected test-type graphs pass, along
with focused lint, lint-suppression tests, both cycle checks, and P2
independent review. check-changed stopped when the production and
full-tree unused-export scans hit the unchanged 600-second timeout;
the script unused-export scan passed. No full subsystem or hosted CI
run is claimed by this branch-only handoff.
@clawsweeper

clawsweeper Bot commented Oct 7, 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 agents Agent runtime and tooling size: S labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

Subagent listings read saved metadata from each child’s recorded agent owner and keep metadata separate for runs sharing a raw session key.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still has the raw-key listing defect. The focused repair has no actionable correctness findings, and the previous review’s empty finding list remains supported.

Priority: P2
Reviewed head: b6e5cc9a32466a3872e0624715c6affcb01dc7e3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful regression coverage and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. Reported real-store regressions exercise the metadata reader and list builder, but do not claim a live command demonstration. No persisted-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. Reported real-store regressions exercise the metadata reader and list builder, but do not claim a live command demonstration. No persisted-data contract changes require migration proof.
Evidence reviewed 7 items Pinned introduced change: The merge-base-to-head delta replaces key-derived ownership with the existing child-owner resolver and keys returned metadata by run ID. The verified test-merge comparison contains the same production change.
Still necessary on current main: Fetched main still parses the child key to select its owner and stores metadata under the child key alone; raw keys therefore retain the reported failure mechanism. No merged fixing PR was supplied or established.
Existing ownership contract and history: The existing resolver uses recorded childAgentId with the established session-owner fallback. Git history and the GitHub commit endpoint connect this helper to steipete’s prior merged raw-key cancellation work, #162540.
Findings None None.
Security None None.

How this fits together

Subagent listings combine visible run records with saved session model and usage metadata. The resulting rows feed the subagents tool and the /subagents list command.

flowchart TD
  A[Visible child runs] --> B[Resolve recorded agent owner]
  C[Session store configuration] --> B
  B --> D[Read metadata in workers]
  D --> E[Associate metadata with run IDs]
  E --> F[Build active and recent rows]
  F --> G[Tool and command output]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +36. Total +37 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 22 21 +1
Tests 2 41 5 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 63 26 +37

Review metrics

None.

Technical review

Best possible solution:

Keep session metadata enrichment on the existing child-owner resolver and worker reader, with run IDs separating display results.

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

Yes, source establishes a focused path: list a visible child with key global and recorded childAgentId using a templated or literal store. Current main ignores that owner; execution was not performed during this review.

Is this the best way to solve the issue?

Yes. Reusing the established child-owner resolver and changing the private result-map key repairs both owner resolution and cross-agent metadata collisions without adding a competing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6a6f7ba3e37b.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded listing failure for watched children using raw session keys.
  • 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 supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. Reported real-store regressions exercise the metadata reader and list builder, but do not claim a live command demonstration. No persisted-data contract changes require migration proof.

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 (1 earlier review cycle)
  • reviewed 2026-10-07T09:53:02.745Z sha b6e5cc9 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review October 7, 2026 09:55
@steipete
steipete merged commit 8f43600 into main Oct 7, 2026
209 of 212 checks passed
@steipete
steipete deleted the deslop/d06-agents-subagents-tools-20261007 branch October 7, 2026 10:19
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
openclaw#166550)

Watched raw session keys such as global already carry childAgentId.
Resolve list reads through the existing child-owner helper, batch by agent,
and associate display metadata with run IDs so agents sharing a raw key
cannot overwrite each other's metadata.

Cover templated and literal stores, duplicate raw keys, and existing
active/recent metadata refresh. Both raw-key regressions failed before
and pass after the fix. The private benchmark lookup uses the run ID.

Validation: 16 focused tests; 5,311 full subsystem and lint-suppression
tests on Linux; changed checks including production and test types and
unused-export scans; zero runtime or Madge cycles; clean independent
review; green hosted CI on b6e5cc9.
An additional macOS persistence polling failure remains unexplained;
the unchanged case passed on Linux and in the clean-main file replay.
zeroaltitude added a commit to zeroaltitude/openclaw that referenced this pull request Oct 13, 2026
…view feedback)

The shared-working-directory advisory looked its metadata up by
`run.childSessionKey` while `readSubagentListSessionEntries` stores that
selection under `run.runId`. For every ordinary child those two strings
differ, so the lookup returned `undefined`, every child was skipped, and
`sharedCwdGroupTotal` stayed 0 even with two live children in one explicit
directory. The whole feature was dead at the reviewed head.

Root cause is a silent main-merge drop, not an authoring mistake. At the
branch's last author commit (5a6f6b2) the branch owned
`loadSubagentSessionEntries`, which keyed entries by session key, and both
consumers read by session key — consistent. Upstream openclaw#166550 then replaced
that reader with `readSubagentListSessionEntries`, keyed by run id so two
agents sharing one raw session key keep separate metadata, and updated the
row builder it could see. `buildSharedCwdIndex` is this branch's own code,
so the merge left its session-key lookup in place and produced no conflict
marker: the two edits never textually overlapped.

Fix the consumer, not the producer — the run-ID keying is the contract
openclaw#166550 exists to provide. The JSDoc now states that key contract where the
lookup happens, since nothing else in the file did.

Verified end to end rather than at the named line: the reader batches by
resolved owner store and stores per run; `buildSharedCwdIndex` iterates
`runView.latest` filtered by `isRetainedUnendedSubagentRun`, and every such
run is in `view.active`, which is exactly what the reader requested, so each
considered run always has an entry. `projection: "list"` strips only the
three session-entry snapshot fields, never `spawnedCwd`. The row builder at
the same call site already used `run.runId`. `subagent-active-context.ts`
passes an empty selection deliberately, so the prompt block carries no
advisory by design.

Added a regression test for the case the key contract exists for: two agents
sharing the raw child session key `global`, each with its own resolved store
— silent on distinct directories, grouped on a shared one. Added proof
scenario 9, which asserts the reader's key set directly and then feeds that
exact selection to the builder, so a producer/consumer key disagreement
cannot pass again.

Removed the low-value test
`src/agents/tools/subagents-tool.test.ts: "surfaces the shared-cwd advisory
in structured list output"` at the reviewer's request. It supplied the whole
advisory through a mocked list builder and asserted the same data back, so it
passed while real grouping was broken; its only non-trivial assertion covered
upstream's pre-existing row `line` stripping. With it and its mock scaffolding
gone, that file is byte-identical to origin/main.

Measured, reverting only this finding's own source file:
- src/agents/subagents/registry/subagent-list.test.ts: 8 failed / 20 passed
  -> 29 passed. The new raw-session-key test alone moves 8 failures to 9 on
  the old key, so it pins the contract independently.
- scripts/proof-135480-subagent-shared-cwd-advisory.ts: EXIT 1, 11 failed /
  4 passed -> EXIT 0, 17 passed.

Beads: openclaw-cy3n

Also fixes a red gate lane the PR body had written off as environmental.
`check:line-cap-ratchet` does run on this host under git 2.55 and rejected
`src/agents/subagents/spawn/acp-spawn.test.ts` at 1303 -> 1353 counted lines
against a 1000-line cap: this branch's two ACP explicit-cwd cases. They moved
into `acp-spawn-policy.test-support.ts`, which already owns what root an ACP
spawn receives and what the session writer records for it and already holds
both mocks, so no new parameter is threaded and `acp-spawn.test.ts` is now
byte-identical to origin/main. No coverage was trimmed and no cap suppressed.
Because `check:changed` bails at its first failed lane, that red had kept every
later lane unexercised.

A second lane the ratchet red had hidden: `lint core` reported 19
`typescript(no-floating-promises)` errors, every one an unawaited
`addSubagentRunForTests(...)` in this branch's own shared-cwd tests. They are
now awaited. That is not only a lint fix — the helper performs a durable
registry write, so each call was a real race between the fixture and the list
build it was meant to set up. Type-aware rules need the gate's own
`config/tsconfig/oxlint.core.json`; a bare `pnpm oxlint <files>` does not run
them and reported these files clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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