Skip to content

fix(swarm): wait for owned cleanup when stopping children - #163558

Merged
steipete merged 10 commits into
mainfrom
codex/swarm-queue-ready-20261002
Oct 3, 2026
Merged

steipete merged 10 commits into
mainfrom
codex/swarm-queue-ready-20261002

Conversation

@steipete

@steipete steipete commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157347, #130741

Continuation of #157347 by @steipete.

What Problem This Solves

Fixes: stopping a Swarm could release a child's queue or lifecycle ownership while its preparation, terminal persistence, or runtime disposal was still pending.

User Impact

Stop retains the selected children through their owned cleanup and reports cleanup failures. Children belonging to different agents remain distinct even when they share a raw session key. Accepted cancellation survives the initiating caller's retirement.

A disposer can stop its own work without waiting for itself. If the execution binding retires before or during that call, the pending self-call requires the exact recorded retirement and current session authority. Unrecorded binding loss and replacement controllers still refuse.

An external Stop waits for selected cleanup to settle. A disposer that never settles leaves that request pending with ownership retained. This is the cleanup ownership repair; the real-OpenAI 500 ms responsiveness target remains unproven. FIFO ordering, integrity checks, and retention remain intact. No configuration or schema migration is required.

Why This Change Was Made

Keep preparation with its existing reservation and retain each exact execution through terminal persistence and disposal. Compose this with current main's acknowledged registration, failed-registration cleanup, attachment-removal policy, and silent-child completion behavior. Permission to abort remains separate from permission to delete. Main’s parent lineage capture remains inside the preparation hold; cancellation joins both ancestor and child publication readiness.

Self-cancellation joins its terminal writer while its outer execution remains responsible for final disposal. The retirement observation supplies cleanup facts without restoring execution authority.

Evidence

Reviewed, committed source: 73fd7487237b28a7a7f53ae9cfc9c4ee977d28d2, incorporating main a97e007542efcc5757e59fd2d7e0b467c1a7a262.

  • Current-main composition: all 33 selected cases passed across six files, covering cancellation concurrency, publication and discovery, refresh failures, parent lineage, and production spawn ownership.
  • Production and affected-test types pass. Scoped formatting, lint, conflict-marker and diff checks pass.
  • Fresh independent review of the full remaining change completed all ten passes with no findings through P2.
  • The preceding 0003036 head passed all 34 canonical checks, the normal build, and exact-head hosted CI run 37068334838. Main then introduced two real conflicts; this successor preserves aggregate readiness while adopting its parent-binding structure. The focused proof above covers that composition. Current-head CI run 37077363634 passed separately: 65 successful jobs, 22 skipped, no failures or cancellations. Its build-artifacts job was skipped; this is not a new normal-build result.
  • Retained cleanup regression proof covers both self-retirement orderings and refuses unrecorded binding loss. Combined live latency acceptance remains outstanding.

Earlier fixture corrections made child completion explicit, retained exact abort-controller ownership, and preserved scoped catalog-reader lifetime checks. No timeout, capacity limit, assertion, or baseline was weakened to obtain passing results.

Measured focused-test costs

Node 24.21.0, pnpm 12.5.1, one worker. The 33-case integration command took 353.540 s including preparation and cleanup; affected types took 104.826 s. The earlier 28-case cleanup command took 436.556 s; its wake-retirement case took 7.964 s, unrecorded-loss control 6.789 s, and retired-self case 9.476 s. These include test infrastructure and host contention; they are not product latency measurements. Current-head CI’s observed job window was 484 s; its slowest selected Node test job took 394 s. These are job-level costs, not per-case timings.

@clawsweeper

clawsweeper Bot commented Oct 2, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 2, 2026
@steipete
steipete marked this pull request as ready for review October 2, 2026 13:50
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 73fd7487237b28a7a7f53ae9cfc9c4ee977d28d2
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/chat-abort-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 7:45 PM ET / 23:45 UTC (Revision 7).

ClawSweeper review

What this changes

Swarm Stop waits for selected children's preparation, terminal persistence, and runtime disposal while preserving exact ownership and reporting cleanup failures.

Merge readiness

✅ Ready for maintainer review

This remains a useful maintainer-owned repair: current main does not retain the same execution cleanup ownership. No actionable introduced defect was found, and the documented indefinite-wait tradeoff has already been accepted in the maintainer-authored PR.

Priority: P1
Reviewed head: 73fd7487237b28a7a7f53ae9cfc9c4ee977d28d2

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The repair has coherent ownership boundaries, substantial targeted regression coverage, and clearly qualified validation with no actionable code finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-author exemption applies. Inspected production-boundary regressions cover exact Stop settlement and forbidden replacement/revocation cases; reported tests and CI are supplemental, and broader real-provider latency remains unproven. Existing session-field compatibility is supported by guarded writes and replacement-state coverage.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-author exemption applies. Inspected production-boundary regressions cover exact Stop settlement and forbidden replacement/revocation cases; reported tests and CI are supplemental, and broader real-provider latency remains unproven. Existing session-field compatibility is supported by guarded writes and replacement-state coverage.
Evidence reviewed 8 items Pinned introduction and clean checkout: Reviewed the introduced delta from a97e007 to 73fd748. The checkout remained clean. The supplied stale test merge was not used to infer removal of current-main behavior.
Current main still lacks execution-tail custody: Fetched main's cancellation lifecycle module tracks terminal persistence and registration removal, but lacks the proposed execution-settlement owner. Its subagent kill path also lacks the new wrapper that joins exact raw execution cleanup.
Exact cleanup and self-retirement checks: Cleanup is joined outside the exclusive lifecycle mutation. Self-disposal avoids awaiting itself; recorded retirement, current session authority, exact controller identity, and resolver identity fence the subsequent result.
Findings None None.
Security None None.

How this fits together

Swarm schedules child agent work through the Gateway and subagent registry. Stop selects authorized children, cancels their work, and publishes results after the selected cleanup owners settle.

flowchart TD
  A[Swarm Stop request] --> B[Select authorized children]
  B --> C[Retain exact execution ownership]
  C --> D[Cancel queued or running work]
  D --> E[Join persistence and disposal]
  E --> F[Publish result or cleanup failure]
  F --> G[Release retained ownership]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1002, Tests +2283, Docs +3. Total +3288 across 50 files.

View PR surface stats
Area Files Added Removed Net
Source 26 1328 326 +1002
Tests 23 2493 210 +2283
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 50 3826 538 +3288

Review metrics

Metric Value Why it matters
Production and regression growth production net +922 lines; tests/support net +2362 lines Production growth is justified in the PR body by retaining exact cleanup custody across preparation, retirement, and cancellation publication.

Technical review

Best possible solution:

Keep cancellation settlement with the existing scheduler, session, and execution owners, preserving truthful results without releasing unfinished cleanup.

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

Yes, from source: current main can retire logical registration without retaining the raw disposal tail that this branch joins. This review did not execute a failing runtime reproduction.

Is this the best way to solve the issue?

Yes. The patch extends the existing ownership boundaries, keeps cancellation separate from deletion authority, and avoids a competing cleanup manager.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 810018486a55.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Premature cancellation completion affects active Swarm child ownership and the reliability of Stop.
  • merge-risk: 🚨 availability: External Stop can remain pending indefinitely behind unfinished disposal; the maintainer-authored body explicitly accepts this ownership-preserving tradeoff.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool 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 maintainer-author exemption applies. Inspected production-boundary regressions cover exact Stop settlement and forbidden replacement/revocation cases; reported tests and CI are supplemental, and broader real-provider latency remains unproven. Existing session-field compatibility is supported by guarded writes and replacement-state coverage.

Evidence

What I checked:

  • Pinned introduction and clean checkout: Reviewed the introduced delta from a97e007 to 73fd748. The checkout remained clean. The supplied stale test merge was not used to infer removal of current-main behavior. (73fd7487237b)
  • Current main still lacks execution-tail custody: Fetched main's cancellation lifecycle module tracks terminal persistence and registration removal, but lacks the proposed execution-settlement owner. Its subagent kill path also lacks the new wrapper that joins exact raw execution cleanup. (src/gateway/chat-abort-lifecycle-internal.ts:1, 810018486a55)
  • Exact cleanup and self-retirement checks: Cleanup is joined outside the exclusive lifecycle mutation. Self-disposal avoids awaiting itself; recorded retirement, current session authority, exact controller identity, and resolver identity fence the subsequent result. (src/agents/subagents/registry/subagent-control-kill.ts:64, 73fd7487237b)
  • Authority inversion coverage: The accepted-stop suite exercises revoked publication, replacement controllers, both recorded self-retirement orderings, and unrecorded binding loss. It asserts that replacement controllers remain un-aborted and that failed ownership checks leave descendants running. (src/agents/subagents/registry/subagent-control.accepted-stop.test.ts:82, 73fd7487237b)
  • Existing-state compatibility: Queued cancellation uses existing session fields and only qualifies lastRunId after successful owned cleanup. Guards preserve a different existing run identity, active writers, and replacement session generations; handler-level tests preserve replacement terminal metadata and never fabricate startedAt or runtimeMs. (src/agents/subagents/registry/subagent-registry-helpers.ts:143, 73fd7487237b)
  • Accepted availability tradeoff: The captured maintainer-authored PR body explicitly accepts that external Stop waits for cleanup and remains pending if a disposer never settles, retaining ownership. It separately states that the broader real-provider 500 ms target remains unproven; this repair does not claim that acceptance result. The supplied security-guard comment verifies the author's repository admin role. (73fd7487237b)

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.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-02T13:57:18.437Z sha a62bbd8 :: blocked before merge. :: none
  • reviewed 2026-10-02T18:41:13.281Z sha 1ef65b8 :: blocked before merge. :: none
  • reviewed 2026-10-02T19:28:18.806Z sha 1ef65b8 :: blocked before merge. :: none
  • reviewed 2026-10-02T20:30:41.991Z sha 1ef65b8 :: blocked before merge. :: none
  • reviewed 2026-10-02T21:48:35.236Z sha 0003036 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T23:30:06.513Z sha 73fd748 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot closed this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Oct 2, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 2, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 2, 2026
Preserve recorded execution cleanup when Stop is called from a disposer before or after normal retirement. Keep session and controller authority current, reject unrecorded binding loss, and compose current attachment cleanup and silent-child completion behavior.
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 2, 2026
@steipete
steipete merged commit fdbf48d into main Oct 3, 2026
162 of 163 checks passed
@steipete
steipete deleted the codex/swarm-queue-ready-20261002 branch October 3, 2026 01:43
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 3, 2026
fdbf48d (#163558) changed subagent binding retirement to retain owned
execution cleanup. That path reads the Gateway chatAbortControllers map,
which production contexts always initialize, but the shared restart
fixture and its predecessor/replacement contexts omitted it.

Give each fixture Gateway its own empty controller map. Preserve the real
retirement path and every sweeper and parent-continuation assertion.

Before: sweeper 2/8 and parent recovery 1/14 failed at the missing map.
Validation: both files passed three complete local runs (66/66). Linux
Crabbox proof used the authorized AWS fallback after Testbox congestion:
all four fixture consumers passed (67/67), the full agents-support config
passed (5,326 tests), and check-changed plus boundary lint passed. P2
review found no actionable issues. No assertions or skips changed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
…63558)

* fix(swarm): wait for queued child cleanup on Stop

Continue openclaw#157347 with exact execution ownership through terminal persistence and runtime cleanup.

* test(swarm): bind cancellation fixtures to actual execution cleanup

* refactor(tests): keep cancellation fixtures in bounded support modules

* refactor(swarm): simplify spawn cleanup handoff
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
94d479b (openclaw#163558) changed subagent binding retirement to retain owned
execution cleanup. That path reads the Gateway chatAbortControllers map,
which production contexts always initialize, but the shared restart
fixture and its predecessor/replacement contexts omitted it.

Give each fixture Gateway its own empty controller map. Preserve the real
retirement path and every sweeper and parent-continuation assertion.

Before: sweeper 2/8 and parent recovery 1/14 failed at the missing map.
Validation: both files passed three complete local runs (66/66). Linux
Crabbox proof used the authorized AWS fallback after Testbox congestion:
all four fixture consumers passed (67/67), the full agents-support config
passed (5,326 tests), and check-changed plus boundary lint passed. P2
review found no actionable issues. No assertions or skips changed.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 6, 2026
- registry SQLite fixture helpers moved to subagent-registry-state.fixture.test-support
- registration scopes carry canAbortAcceptedRun (upstream openclaw#163558 family)
- kill publication preparation is { prepare, publishSnapshot } (upstream openclaw#163558)
- resumed-run set is keyed by run runtime key; startQueued/settleFailed/add/reset are async
- restore runSubagentAnnounceDispatch import dropped with upstream's removed cases
- widen registration promise annotations for the ownership-returning registerSubagentRun

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: XL 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