Skip to content

fix(agents): preserve collector order during requester lookup - #159273

Closed
steipete wants to merge 1 commit into
mainfrom
codex/collector-fifo-order-20260926
Closed

steipete wants to merge 1 commit into
mainfrom
codex/collector-fifo-order-20260926

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After #159135 moved requester lookup to a worker, a collector could await that lookup before reserving its FIFO position. A later request in the same group could finish lookup first and launch ahead of the earlier request. This also caused the queued-collector operator-rename test to fail in CI.

User Impact

Collectors retain invocation order while requester lookup remains off the Gateway thread. Other groups can still make progress. Requester identity and current authority are checked before child admission; failed or cancelled preparation releases its position.

Why This Change Was Made

The existing scheduler now owns the reservation before the first lookup await. The request retains that exact hold, transfers it to spawn on success, and withdraws and joins it on failure. It never reacquires ownership from a reused run ID. Ordinary child admission and the existing lookup-before-validation behavior remain intact.

The host effect marker still precedes reservation. Regression cases use the real effect-boundary owner to ensure an attempted reservation is not reported as never started. No new queue, synchronous SQL path, schema, retention policy, protocol, or dependency is introduced.

Evidence

Fresh independent review through P2 passed. Deterministic tests gate the first real lookup while a second collector and another group prepare, then check launch order, captured requester identity, cancellation, lookup/schema errors, and replacement-reservation fencing. Existing group-cap fixtures now provide stable, valid execution snapshots; their assertions are unchanged.

Controlled proof reproduced the original FIFO failure and passed 181 tests across ten complete owner and sibling files with no skips. The attempt then failed the line-count ratchet before later static checks. The unchanged preference fixture table has since moved into the existing test helper, with fresh independent review; its complete 84-case consumer file and remaining selected checks are being verified. The negative and unaffected sibling evidence are retained with their source bindings. Exact-head CI is required before landing. No deployed latency improvement is claimed.

@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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. 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:23 PM ET / September 27, 2026, 00:23 UTC (Revision 2).

ClawSweeper review

What this changes

The branch reserves a Swarm collector’s queue position before asynchronous requester lookup, transfers that reservation into child spawning, and adds ordering, cancellation, and reservation ownership tests.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep this PR open. Current main still has the requester lookup before the FIFO reservation, so the ordering repair remains useful. The current head also retains the prior review’s blocker: malformed collector input can hold a group’s queue while its requester lookup is pending.

Priority: P2
Reviewed head: 7f57fcf835320cd4e9c6b797a0b4ffccd9ced905

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair has targeted regression coverage, but one demonstrated queue stall and pending boundary and test-cost evidence keep it below merge-ready quality.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Repository State classifies the author as MEMBER, so the external-contributor real-setup gate does not apply. The changed spawn owner is exercised by an injected requester-lookup delay through the Gateway test fixture, but the PR body still says its original/fixed boundary result is in progress. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State classifies the author as MEMBER, so the external-contributor real-setup gate does not apply. The changed spawn owner is exercised by an injected requester-lookup delay through the Gateway test fixture, but the PR body still says its original/fixed boundary result is in progress. No stored-data contract changes.
Evidence reviewed 10 items Introduced reservation order: The branch reserves and holds a collector slot before awaiting requester lookup.
Validation follows the hold: The output schema is rejected only after the worker lookup returns, while the reservation remains held.
Regression scenario in the patch: The new invalid-schema case holds the first lookup and asserts that a valid second collector is accepted but has not launched until the invalid first request is released.
Findings 1 actionable finding [P2] Validate malformed collectors before reserving FIFO order
Security None None.

How this fits together

Swarm accepts collector spawn requests from an agent and schedules each group’s children in invocation order. Requester lookup and admission precede child launch; the launched child later supplies a collector result.

flowchart LR
 A[Collector spawn request] --> B[Group queue reservation]
 B --> C[Requester lookup worker]
 C --> D[Input and child admission]
 D --> E[Queued child launch]
 E --> F[Collector result]
Loading

Before merge

  • Validate malformed collectors before reserving FIFO order (P2) - The new reservation runs before outputSchema validation. In the added invalid-schema case, a valid follower remains unlaunched until the malformed first request’s gated lookup finishes; a slow lookup can therefore stall the group for input that could be rejected immediately. This remains the prior review’s finding on the same head.
  • Resolve merge risk (P1) - A malformed collector can hold its group’s FIFO head during a slow requester lookup and delay valid children in that group.
  • Resolve merge risk (P1) - The PR body does not yet record the completed original/fixed boundary result or measured cost of the changed test files required by repository guidance.
  • Complete next step (P2) - Reject deterministic malformed collector input before taking the FIFO reservation, prove a valid follower proceeds, and record the original/fixed boundary result plus changed-test costs.

Findings

  • [P2] Validate malformed collectors before reserving FIFO order — src/agents/subagents/spawn/subagent-spawn-request.ts:153-155
Agent review details

Security

None.

PR surface

Source +25, Tests +206. Total +231 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 207 182 +25
Tests 2 211 5 +206
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 418 187 +231

Review metrics

Metric Value Why it matters
Production and test growth production +25 lines, tests +206 lines The production growth carries reservation ownership and cleanup; the expanded Gateway test needs measured CI cost before merge.

Merge-risk options

Maintainer options:

  1. Validate before reserving (recommended)
    Move deterministic collector input checks ahead of the queue hold and prove an invalid first request cannot delay a valid follower.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Move deterministic collector input validation ahead of FIFO reservation while retaining post-lookup mutable admission checks. Add a regression where an invalid first collector is rejected without holding a valid follower, and record the original/fixed boundary result and measured changed-test cost.

Technical review

Best possible solution:

Keep early FIFO reservation for valid collectors, reject deterministic input errors before reserving, retain mutable admission checks after lookup, and demonstrate that a valid follower proceeds after malformed input is rejected.

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

Yes, from source: hold the first collector’s requester lookup, then submit another collector in the same group; current main reserves only after lookup, while the branch’s invalid-schema case exposes a separate queue stall. This read-only review did not execute the test.

Is this the best way to solve the issue?

No, not yet. Reserving before lookup addresses the FIFO race, but deterministic malformed-input rejection must happen before the reservation.

Full review comments:

  • [P2] Validate malformed collectors before reserving FIFO order — src/agents/subagents/spawn/subagent-spawn-request.ts:153-155
    The new reservation runs before outputSchema validation. In the added invalid-schema case, a valid follower remains unlaunched until the malformed first request’s gated lookup finishes; a slow lookup can therefore stall the group for input that could be rejected immediately. This remains the prior review’s finding on the same head.
    Confidence: 0.96

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 5fd7c3d95e03.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR addresses a real collector ordering regression, with impact confined to affected Swarm groups.
  • merge-risk: 🚨 availability: The introduced early hold lets invalid collector input delay valid queued children during requester lookup.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Repository State classifies the author as MEMBER, so the external-contributor real-setup gate does not apply. The changed spawn owner is exercised by an injected requester-lookup delay through the Gateway test fixture, but the PR body still says its original/fixed boundary result is in progress. No stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/session-utils.queued-collector.test.ts --maxWorkers=1.
  • [P1] node scripts/run-vitest.mjs src/agents/subagents/spawn/subagent-spawn.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Reject malformed collector input before reservation and cover a valid follower proceeding without waiting for that rejection.
  • Record the original/fixed boundary result and measured cost of the changed tests.

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:15:45.748Z sha 7f57fcf :: blocked before merge. :: [P2] Validate malformed collectors before reserving FIFO order

@steipete
steipete marked this pull request as ready for review September 27, 2026 00:18
@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
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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