Repository navigation
fix: preserve caller context for queued Swarm work - #146490
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 8:23 PM ET / September 13, 2026, 00:23 UTC (Revision 6). ClawSweeper reviewWhat this changesThe PR preserves the original caller context for queued Swarm callbacks, joins their asynchronous work, and rechecks worker authority before session cleanup writes. Merge readiness✅ Ready for maintainer review This remains a useful, focused repair that current main does not contain. No blocking defect was found, and the verified test merge supersedes the previous conflict warning. Priority: P2 Review scores
Verification
How this fits togetherSwarm queues accepted child-agent work until capacity becomes available. Its scheduler invokes launch and cleanup callbacks through the Gateway, which checks authority before admitting agents or changing session state. flowchart TD
A[Parent accepts child work] --> B[FIFO Swarm queue]
B --> C[Capacity released or work cancelled]
C --> D[Original caller context and fresh work scope]
D --> E[Gateway authority checks]
E --> F[Launch child or clean up session]
F --> G[Join callback work before settlement]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +19, Tests +725. Total +744 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep caller context attached to accepted work while the existing Gateway and worker owners enforce live authority at each final mutation. Do we have a high-confidence way to reproduce the issue? Yes, from source: release capacity under a different caller after queue activation, or reassign a worker while deletion awaits its lifecycle drain. The boundary harness covers both triggers; this read-only review did not execute them. Is this the best way to solve the issue? Yes. The patch repairs context ownership at scheduler activation and composes worker liveness into the existing mutation guard without adding a competing authority store or public configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1db6e89d4ead. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
244e5ca to
35d44cd
Compare
35d44cd to
b822f6c
Compare
b822f6c to
582a314
Compare
582a314 to
3bd8cd5
Compare
|
Merged via squash.
|
* fix: preserve caller context for queued Swarm work * fix: fence queued worker cleanup before session writes * test(gateway): isolate profile lifetime fixture setup
Related: #130741
What Problem This Solves
Fixes queued Swarm launches and cleanup inheriting another caller’s context when a sibling frees capacity or a later request cancels the work.
User Impact
Queued children and their cleanup retain the original caller identity and trace, including when the initiating request has already finished.
Why This Change Was Made
The scheduler captures callbacks at activation and gives each invocation its own work scope. This preserves the caller identity without restoring a retired request’s work scope, and joins the callback’s cooperating work before settlement. FIFO ordering, cancellation holds, and existing cleanup outcomes remain intact.
Worker cleanup checks the current worker identity and carries that authority into the session mutation commit guard, so reassignment during a deletion wait cannot remove the replacement’s durable state. Child parent-lineage checks apply to child launches. The Gateway profile lifetime fixture also isolates unrelated session setup while retaining the real router, authorization, profile synchronization, and independent handler join.
Evidence
Validation includes 24 scheduler tests, 30 Gateway boundary and sibling cases, and 80 lifetime and authorization cases. Counterexamples reproduced the wrong caller context, stale cleanup deleting durable state, and premature dispatcher completion. Canonical checks passed for the production repair; the final fixture change passed scoped types and lint. Independent reviews are clean. Exact-head CI remains required before landing.
The isolated cold profile case improved from 71.3 seconds to 0.83 seconds locally, with no timeout changes. The earlier Linux CI timeout was not reproduced or attributed; the local grouped run also retained a separate workspace quiescence failure. These results do not establish the overall Swarm 500 ms responsiveness target or cloud-worker collector support.