Skip to content

fix: preserve caller context for queued Swarm work - #146490

Merged
steipete merged 3 commits into
mainfrom
codex/swarm-scheduler-context
Sep 13, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/swarm-scheduler-context

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

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.

@clawsweeper

clawsweeper Bot commented Sep 12, 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: M maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 21:28
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 8:23 PM ET / September 13, 2026, 00:23 UTC (Revision 6).

ClawSweeper review

What this changes

The 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
Reviewed head: 3bd8cd55d04cdd9a3bbe937959030a8fe7f7f8ca

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful final-effect coverage and no actionable correctness finding.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The reported production-boundary runs exercise the real scheduler, Gateway authorization, placement claims, and durable session deletion: current owners succeed, replacements survive, and stopped queued children never launch. The inspected harness mocks model execution outside those effects; historical umbrella media is not treated as proof of this repair.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The reported production-boundary runs exercise the real scheduler, Gateway authorization, placement claims, and durable session deletion: current owners succeed, replacements survive, and stopped queued children never launch. The inspected harness mocks model execution outside those effects; historical umbrella media is not treated as proof of this repair.
Evidence reviewed 8 items Introduced scheduler repair: Activation binds start, failure, and removal callbacks to their original asynchronous context; each invocation receives a fresh work scope that is joined before settlement.
Authority reaches the write boundary: The changed dispatch guard invokes receiptAuthority. The worker owner validates run liveness and the current placement claim; Gateway dispatch composes this guard into session mutation authorization, which deletion rechecks after its lifecycle drain and before committing.
Allowed and revoked authority coverage: The inspected production-boundary harness uses real Gateway dispatch, placement claims, and session storage. Cases assert successful current-owner deletion and unchanged durable state after session replacement, Gateway replacement, worker reassignment, or reassignment during the deletion wait. Separate cases cover active, normally completed, and stopped parents. The captured PR body reports passing boundary runs and pre-fix counterexamples; this review did not execute tests.
Findings None None.
Security None None.

How this fits together

Swarm 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +725. Total +744 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 34 15 +19
Tests 3 763 38 +725
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 797 53 +744

Review metrics

Metric Value Why it matters
Production versus test growth production +19 net lines; tests +725 net lines Production growth is justified by callback lifetime ownership and the live worker guard; most growth exercises context and durable-effect counterexamples.

Technical review

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

Labels

Label justifications:

  • P2: This is a bounded repair to queued Swarm caller identity and cleanup correctness.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The reported production-boundary runs exercise the real scheduler, Gateway authorization, placement claims, and durable session deletion: current owners succeed, replacements survive, and stopped queued children never launch. The inspected harness mocks model execution outside those effects; historical umbrella media is not treated as proof of this repair.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported production-boundary runs exercise the real scheduler, Gateway authorization, placement claims, and durable session deletion: current owners succeed, replacements survive, and stopped queued children never launch. The inspected harness mocks model execution outside those effects; historical umbrella media is not treated as proof of this repair.

Evidence

What I checked:

  • Introduced scheduler repair: Activation binds start, failure, and removal callbacks to their original asynchronous context; each invocation receives a fresh work scope that is joined before settlement. (src/agents/subagents/swarm/swarm-scheduler.ts:43, 3bd8cd55d04c)
  • Authority reaches the write boundary: The changed dispatch guard invokes receiptAuthority. The worker owner validates run liveness and the current placement claim; Gateway dispatch composes this guard into session mutation authorization, which deletion rechecks after its lifecycle drain and before committing. (src/agents/subagents/spawn/subagent-spawn-gateway.ts:95, 3bd8cd55d04c)
  • Allowed and revoked authority coverage: The inspected production-boundary harness uses real Gateway dispatch, placement claims, and session storage. Cases assert successful current-owner deletion and unchanged durable state after session replacement, Gateway replacement, worker reassignment, or reassignment during the deletion wait. Separate cases cover active, normally completed, and stopped parents. The captured PR body reports passing boundary runs and pre-fix counterexamples; this review did not execute tests. (src/agents/subagents/spawn/subagent-spawn.production-boundary.test.ts:591, 3bd8cd55d04c)
  • Existing behavior and implementation boundary: The documented contract distinguishes Stop from normal parent completion: Stop prevents selected queued children from starting, while accepted children remain independent after normal completion. Swarm's core tools are explicitly harness-independent, so this patch does not depend on the Codex implementation. Public docs: docs/tools/swarm.md. (docs/tools/swarm.md:410, 3bd8cd55d04c)
  • Current main still needs the repair: Comparison with fetched main shows that callback binding and the worker pre-commit guard remain absent there. No merged fixing PR is established. The release-source inspection could not retrieve its unavailable blob, so no shipped-version claim is made. (src/agents/subagents/swarm/swarm-scheduler.ts, 1db6e89d4ead)
  • Previous conflict warning resolved: Raw test-merge parents are the pinned base followed by the exact reviewed head. Its comparison with that base contains the intended repair. The earlier reviewed object was unavailable locally; no unchanged-code or late-finding attribution relies on it. (69bda19181bf)

Likely related people:

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

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-12T21:36:48.621Z sha 244e5ca :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-12T21:53:37.942Z sha 244e5ca :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-12T22:52:17.483Z sha 35d44cd :: needs changes before merge. :: none
  • reviewed 2026-09-12T23:47:44.515Z sha b822f6c4476add35fed071e66b42f8fb620a21f3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T23:58:35.300Z sha 582a314bbcb0c2e7e6adc31a47188bfba21a27bf :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/swarm-scheduler-context branch from 244e5ca to 35d44cd Compare September 12, 2026 22:45
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 12, 2026
@steipete
steipete force-pushed the codex/swarm-scheduler-context branch from 35d44cd to b822f6c Compare September 12, 2026 23:40
@steipete
steipete requested a review from a team as a code owner September 12, 2026 23:40
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui scripts Repository scripts size: L and removed size: M labels Sep 12, 2026
@steipete
steipete force-pushed the codex/swarm-scheduler-context branch from b822f6c to 582a314 Compare September 12, 2026 23:52
@openclaw-barnacle openclaw-barnacle Bot removed app: web-ui App: web-ui scripts Repository scripts labels Sep 12, 2026
@steipete
steipete force-pushed the codex/swarm-scheduler-context branch from 582a314 to 3bd8cd5 Compare September 13, 2026 00:17
@steipete
steipete merged commit 92ae2c1 into main Sep 13, 2026
180 checks passed
@steipete
steipete deleted the codex/swarm-scheduler-context branch September 13, 2026 01:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
* fix: preserve caller context for queued Swarm work

* fix: fence queued worker cleanup before session writes

* test(gateway): isolate profile lifetime fixture setup
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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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