Skip to content

fix(agents): keep collector launches in submission order - #159272

Closed
steipete wants to merge 1 commit into
mainfrom
deslop/l94-collector-fifo
Closed

steipete wants to merge 1 commit into
mainfrom
deslop/l94-collector-fifo

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent collector spawns can launch out of submission order when the later request's asynchronous requester-session lookup finishes first.

User Impact

Collector launches retain the documented FIFO order under the group's concurrency limit. Failed or cancelled requester lookups release their reserved position so later collectors can proceed. Ordinary child cancellation, requester identity, and private completion behavior are preserved.

Why This Change Was Made

The requester-worker change in #159135 placed an await ahead of the existing collector FIFO reservation. The scripts sweep in #159199 exposed the race through the Gateway queued-collector suite on its CI merge tree.

Collectors now reserve their position before their first await and capture the requester after the executor holds that reservation. The existing executor cleanup withdraws and releases the reservation on lookup failure or cancellation. Ordinary spawns keep their previous capture and admission order. Both paths use one requester-read helper, retain worker-backed SQLite access and authority checks, and preserve the established error result for already-cancelled calls. There is no additional queue, configuration, schema, or protocol.

Evidence

Independent Codex review of the complete candidate is scoped-clean through P2. Validation ran on Blacksmith Testbox run 36276852584, lease tbx_01m3fxtnhhmxefc0rman8xk4fb, with Node 24.19.0 and pnpm 12.4.2. The lease is stopped. It verifies all changed source hashes after synchronization against base 547bb312f4098cd0f28f71cc45a7e351e944b1ff.

  • Deterministic regression gates the first requester lookup until the second spawn is accepted, then checks actual dispatch order. With original production code, the second collector launches first and the assertion fails. The corrected owner passes.
  • The full requester-incarnation file passes all 12 tests, covering FIFO, failed and cancelled lookup cleanup, already-cancelled no-effect behavior, ordinary cancellation, dirty-sibling validation, and native/visible/ACP requester identity. Measured command: pnpm test src/agents/subagents/spawn/subagent-spawn.requester-incarnation.test.ts --maxWorkers=1, 28.347s wall (includes worker preparation).
  • Authority/preparation, scheduler, Gateway queued-collector and fs-safe/import-boundary siblings pass (118.466s). The original 18-file CI group passes with the repair (144.025s).
  • Twenty repetitions of the four deterministic cases pass: 80 test executions, 20.156–26.073s per command, 458.855s total. A subsequent mechanical grouping of two existing context captures satisfies the unchanged 700-line cap; the complete requester suite and fresh independent review pass afterward.
  • node scripts/check-changed.mjs --base 547bb312f4098cd0f28f71cc45a7e351e944b1ff --timed passes in 468.380s, including all 25 core-test type graphs, lint, dead exports, cycles, and storage/security guards. pnpm build passes in 406.349s. The final wrapper returns exitCode: 0 / runStatus: succeeded.

The original CI failure was in session-utils.queued-collector.test-support.ts:222 on merge tree b014d5fc4348a0ccc7b4c5d9b0694ab93c82fc00. A replay of the exact 18-file group on that unmodified tree passed, demonstrating why a passing retry is not a fix. The new controlled lookup inversion supplies the original-red/candidate-green proof without sleeps, retries, weaker assertions, or serialized spawn submissions.

The entry-point composition is necessary: the scheduler’s existing FIFO unit coverage passes while the original requester lookup can reorder calls before they reach it. These tests use explicit promise gates and the existing isolated state fixture, with no model or network calls.

Superseded by main: 5cf18de3d103a6bea797cbfe52fa8f51dce8c596 independently landed the FIFO repair while this PR was completing CI. The landed owner retains the exact reservation hold through requester acquisition and transfers it into execution, with requester-incarnation and failed-read coverage. Fresh Blacksmith Testbox verification of the landed src/gateway/session-utils.queued-collector.test.ts passes all 35 cases in 62.905s on the main-containing scripts candidate ecd179ea0355eabe424743c38497acb13d7bbcab. Closing this duplicate unmerged so there is one canonical implementation. The earlier independent proof and successful CI remain recorded above.

Reserve collector FIFO before asynchronous requester lookup, retaining worker-backed reads and existing reservation cleanup. Preserve ordinary requester identity, cancellation, and error behavior. Add controlled lookup-order, failure, and cancellation regressions.
@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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Sep 27, 2026
@steipete
steipete marked this pull request as ready for review September 27, 2026 00:14
@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: blocked before merge. Reviewed September 26, 2026, 8:52 PM ET / September 27, 2026, 00:52 UTC (Revision 2).

ClawSweeper review

What this changes

The branch moves collector requester-session lookup after FIFO reservation and adds ordering, lookup-failure, and cancellation regression tests.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Current main fixes the collector ordering race, but this PR still contains distinct early-cancellation behavior worth considering. The branch conflicts with main and would record a replacement requester session if the spawn-effects callback rotates the completion owner. It needs a narrow maintainer disposition, not an automatic closure or merge.

Priority: P2
Reviewed head: 355fe6c9b5b28f0f732254291e55e563e4ef3a84
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The controlled regression evidence is useful, but the branch now conflicts with a main repair and has a requester-incarnation defect.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied repository state identifies a member-authored PR, so contributor real-setup proof is not required. The PR describes controlled spawn-path regressions and Testbox validation; those tests support the FIFO claim but do not resolve the newly identified requester-incarnation ordering defect. No stored-data format changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a member-authored PR, so contributor real-setup proof is not required. The PR describes controlled spawn-path regressions and Testbox validation; those tests support the FIFO claim but do not resolve the newly identified requester-incarnation ordering defect. No stored-data format changes.
Evidence reviewed 11 items Introduced branch behavior: The pinned PR delta moves collector requester lookup out of request resolution and into the executor after the reservation path.
Requester-incarnation regression: The branch calls the effects callback at line 299 before its new collector requester read in the executor; a callback-time session rotation therefore changes the recorded requester session ID.
Distinct cancellation guard: The PR converts a pre-reservation cancellation exception into the established spawn error result and tests an already-cancelled collector.
Findings 1 actionable finding [P2] Capture the requester before marking collector effects
Security None None.

How this fits together

OpenClaw's subagent spawn path accepts collector requests and passes them to a per-group scheduler. It captures the requesting session, reserves a queue position, and eventually records and launches a child run.

flowchart LR
A[Collector request] --> B[Validate requester]
B --> C[Reserve group position]
C --> D[Capture requester session]
D --> E[Prepare child run]
E --> F[Launch or release reservation]
Loading

Decision needed

Question Recommendation
Should the distinct early-cancellation behavior be carried onto the current main repair, with this alternate FIFO implementation retired? Narrow onto main: Retain main's FIFO and requester-incarnation ordering while carrying over the early-cancellation result and useful test.

Why: The central race is fixed on main, but this branch contains a narrow remaining behavior change and cannot merge cleanly as submitted.

Before merge

  • Capture the requester before marking collector effects (P2) - Late discovery on the unchanged reviewed head: request resolution invokes onSpawnEffectsStart before this newly delayed collector lookup. If that callback rotates the completion owner, the child records the replacement session ID; current main's Gateway regression asserts the original ID. Preserve the reservation order while capturing the requester before that callback.
  • Resolve merge risk (P1) - The branch currently conflicts with main's same-path repair, and its collector requester read can record a replacement session ID when the effects callback rotates the completion owner.
  • Complete next step (P2) - Resolve the conflict with current main and preserve the original requester session ID before the effects callback if this PR continues.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Capture the requester before marking collector effects — src/agents/subagents/spawn/subagent-spawn.ts:139-149
Agent review details

Security

None.

PR surface

Source +39, Tests +114. Total +153 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 74 35 +39
Tests 1 114 0 +114
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 188 35 +153

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Narrow onto main (recommended)
    Resolve the conflict by retaining main's requester capture order and bringing over only the cancellation behavior that remains distinct.
  2. Close the alternate patch
    Retire this conflicting branch if its remaining cancellation behavior is not needed.

Technical review

Best possible solution:

Keep main's scheduler-owned hold and capture-before-effects order; port the distinct already-cancelled collector error behavior and any nonduplicated cancellation coverage in a narrow update.

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

No current-main reproduction of the original FIFO race is expected: main reserves and holds before requester lookup and has a forced-order test. The branch's requester-identity regression and main's early-cancellation error gap are source-reproducible; this read-only review did not execute them.

Is this the best way to solve the issue?

No. Main's existing scheduler hold is the narrower FIFO owner; the useful cancellation behavior should be retained without moving requester capture past the effects callback.

Full review comments:

  • [P2] Capture the requester before marking collector effects — src/agents/subagents/spawn/subagent-spawn.ts:139-149
    Late discovery on the unchanged reviewed head: request resolution invokes onSpawnEffectsStart before this newly delayed collector lookup. If that callback rotates the completion owner, the child records the replacement session ID; current main's Gateway regression asserts the original ID. Preserve the reservation order while capturing the requester before that callback.
    Confidence: 0.94
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The introduced lookup order can store a replacement requester session ID in a collector record.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied repository state identifies a member-authored PR, so contributor real-setup proof is not required. The PR describes controlled spawn-path regressions and Testbox validation; those tests support the FIFO claim but do not resolve the newly identified requester-incarnation ordering defect. No stored-data format changes.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: The ordering failure is fixed on main, while a bounded cancellation contract and branch integration still need review.
  • merge-risk: 🚨 session-state: The introduced lookup order can store a replacement requester session ID in a collector record.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied repository state identifies a member-authored PR, so contributor real-setup proof is not required. The PR describes controlled spawn-path regressions and Testbox validation; those tests support the FIFO claim but do not resolve the newly identified requester-incarnation ordering defect. No stored-data format changes.

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)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the branch against current main while retaining capture-before-effects ordering.
  • Keep the already-cancelled collector regression only if it protects the remaining main behavior gap.

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-09-27T00:21:25.162Z sha 355fe6c :: needs maintainer review before merge. :: none

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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
@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 deslop/l94-collector-fifo branch October 22, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant