Skip to content

fix(agents): keep collector spawn requests in submission order - #159274

Closed
steipete wants to merge 1 commit into
mainfrom
fix/live2-queued-collector-flake
Closed

steipete wants to merge 1 commit into
mainfrom
fix/live2-queued-collector-flake

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent collect subagent spawn requests in the same swarm group could launch out of submission order. The collector admits children FIFO, so the first-submitted request should reserve and launch first; instead, whichever request finished an earlier async step first won. This surfaced as an intermittent CI failure in src/gateway/session-utils.queued-collector.test.ts (shard agentic-gateway-server-isolated-hosted-19), hitting two unrelated PRs (#159173, #159185) on the same day with expected [ <run A> ] to deeply equal [ <run B> ].

Why This Change Was Made

resolveSubagentSpawnRequest (src/agents/subagents/spawn/subagent-spawn-request.ts) awaited the requester session lookup (capturing the requester window so a reset cannot redirect child results) before reserving the request's FIFO slot. Under load a later request's lookup could resolve first, so it reserved and launched first. The test was asserting a real ordering guarantee; the product violated it.

The group key ([requesterAgentId, requesterInternalKey, swarmGroupId]) is now derived synchronously, and for collector requests the whole resolution, requester capture through FIFO reservation, runs in a per-group KeyedAsyncQueue (the same helper ACP and meeting-bot already use in core). Submission order is therefore reservation order within a group. Non-collector requests bypass the queue, other groups stay concurrent, and child preparation and execution remain outside the critical section. The queue isolates rejections and drops a key once its tail settles.

User Impact

Collected (swarm) subagents launch in the order they were requested, and the recurring queued-collector CI failure goes away.

Evidence

  • Deterministic regression (reordered requester lookup) in session-utils.queued-collector.test.ts: fails on main (1 failed, 33 passed) with the observed run-id mismatch; passes with the fix.
  • On Blacksmith Testboxes via Crabbox: the file 30/30 runs (1,020 tests), 173 owner/sibling tests, and three replays of the original CI shard (396 tests each) passed; node scripts/check-changed.mjs passed.
  • Codex autoreview: scoped-clean ("patch is correct", 0.86); queue cleanup and rejection isolation verified against src/plugin-sdk/keyed-async-queue.ts.

Production LOC: +196 / −186 (net +10; whitespace-insensitive: +23 / −15 — the body moved into a closure). Tests: +18 / −1.

Serialize requester acquisition through FIFO reservation per collector group.
Keep requester capture before effects and authority checks before admission;
child preparation and execution remain outside the request queue.

Extend the existing queued session projection case with a requester lookup
that completes out of submission order. It fails against the original product
with the same launched-run mismatch reported in CI; retain the FIFO assertions.

Blacksmith Testbox proof: deterministic baseline 1 failed / 33 passed; fixed
file 30 clean runs / 1020 tests; seven owner and sibling files / 173 tests;
three original 15-file shard replays / 396 tests each; check-changed passed;
independent review clean through P2. Single-worker file command: 62.43s wall.

An earlier extra shard replay failed workspace temp-ancestor permission
admission. The exact offending ancestor was not captured before that lease
finished. The unchanged candidate passed three replays on a fresh lease with
the normal temp environment; no permission policy or fixture was weakened.
@clawsweeper

clawsweeper Bot commented Sep 27, 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.

@steipete
steipete marked this pull request as ready for review September 27, 2026 00:14
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels Sep 27, 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 Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 8:21 PM ET / September 27, 2026, 00:21 UTC.

ClawSweeper review

What this changes

Serializes collector spawn request resolution per Swarm group through FIFO reservation and adds a Gateway regression case with out-of-order requester reads.

Merge readiness

✅ Ready for maintainer review

Current main still permits concurrent requester reads to reverse the documented collector submission order. The proposed repair addresses that race, and the review found no blocking defect.

Priority: P2
Reviewed head: 5513d44652459bcc60159f52bb2115e5eb24f8fb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair has a baseline-failing regression and substantial reported repeat validation, with no blocking review finding.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The changed spawn owner is exercised through the production spawn entry point with an injected requester-read race and mocked Gateway dispatch; the PR reports a failed main baseline and passing fixed runs. The provided MEMBER association exempts this PR from external-contributor real-setup proof, and no stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The changed spawn owner is exercised through the production spawn entry point with an injected requester-read race and mocked Gateway dispatch; the PR reports a failed main baseline and passing fixed runs. The provided MEMBER association exempts this PR from external-contributor real-setup proof, and no stored-data contract changes.
Evidence reviewed 9 items Documented ordering contract: Swarm documentation says children above group capacity queue in submission order.
Current-main race: The requester session read is awaited before the later synchronous Swarm reservation, allowing a later read to finish first.
Introduced repair: The PR enqueues resolution by requester and Swarm group before the asynchronous read and reserves the scheduler slot within that queued operation.
Findings None None.
Security None None.

How this fits together

OpenClaw’s subagent spawn path receives collector requests from agent tools, reads the requester session, reserves a Swarm group slot, and then prepares and launches child runs.

flowchart LR
A[Collector requests] --> B[Swarm group identity]
B --> C[Per-group request queue]
C --> D[Requester session read]
D --> E[FIFO reservation]
E --> F[Child preparation and launch]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +17. Total +27 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 196 186 +10
Tests 1 18 1 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 214 187 +27

Review metrics

None.

Technical review

Best possible solution:

Keep the Swarm scheduler as the FIFO owner while ordering same-group requester reads before reservation and preserving authority checks before child effects.

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

Yes. Concurrent same-group collector spawns with the first requester read delayed expose the read-before-reservation race on current main; the PR reports a failing baseline, though this review did not execute it.

Is this the best way to solve the issue?

Yes. The repair orders only same-group request resolution through reservation, using the existing queue helper and leaving child preparation with the existing spawn and scheduler owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e68cfe26f13a.

Labels

Label changes:

  • add P2: The race breaks documented collector ordering but has a limited Swarm-group scope.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed spawn owner is exercised through the production spawn entry point with an injected requester-read race and mocked Gateway dispatch; the PR reports a failed main baseline and passing fixed runs. The provided MEMBER association exempts this PR from external-contributor real-setup proof, and no stored-data contract changes.

Label justifications:

  • P2: The race breaks documented collector ordering but has a limited Swarm-group scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed spawn owner is exercised through the production spawn entry point with an injected requester-read race and mocked Gateway dispatch; the PR reports a failed main baseline and passing fixed runs. The provided MEMBER association exempts this PR from external-contributor real-setup proof, and no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: 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.

@steipete

Copy link
Copy Markdown
Contributor Author

Heads-up: main now carries 5cf18de (fix(agents): reserve collector FIFO before requester preparation), pushed directly as a red-main repair for this same queued-collector ordering flake. It reserves the scheduler hold before requester reads and hands it to native spawn, and it adds forced out-of-order coverage in src/gateway/session-utils.queued-collector.test.ts.

#159272, #159273, and #159274 all target the same failure. Before landing, please merge main and confirm this PR still adds something beyond 5cf18de. If it doesn't, close it as superseded.

@steipete

Copy link
Copy Markdown
Contributor Author

Closing as superseded by 5cf18de (fix(agents): reserve collector FIFO before requester preparation), which is on main. It fixes this same queued-collector ordering flake: it reserves the scheduler hold before requester reads, transfers it to native spawn, and adds forced out-of-order coverage in src/gateway/session-utils.queued-collector.test.ts, proven with 20 pressured full-file runs plus three original-shard replays on a Linux Testbox. This branch now conflicts with that change and adds no separate contract, so there is nothing left to land here.

@steipete steipete closed this Sep 27, 2026
@RomneyDa
RomneyDa deleted the fix/live2-queued-collector-flake branch October 22, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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