Skip to content

fix(agents): preserve successor sessions during spawn rollback - #137183

Merged
steipete merged 2 commits into
mainfrom
codex/session-child-cleanup-fence
Sep 3, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/session-child-cleanup-fence

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #136952 and its late cleanup-race review.

What changed

Visible-session startup failures previously discarded the creation identity and rolled back by session key. A reset keeps the session ID while rotating its lifecycle revision; replacement can also reuse the key. Detached cleanup could therefore stop and delete a newer session.

Fresh identities now receive their lifecycle revision in the existing session patch/creation owner. Existing session revisions, including their absence, are preserved. Visible spawn retains the creation receipt and reuses the shared subagent cleanup helper, which requires both session ID and lifecycle revision. All three failure exits use one guarded sessions.delete; its existing lifecycle drain stops owned work before deletion. The separate abort-then-delete paths are removed.

Cleanup reports whether the original child was removed, a newer session was preserved, or cleanup remains unconfirmed. Missing receipt identity never falls back to a key-only operation. Caller permissions remain unchanged; an operator who lacks deletion permission gets an explicit unconfirmed result and the child key for inspection.

No configuration, protocol, SQLite schema, migration, or stored representation is added. The revision is an existing lifecycle field already written by reset and hidden-subagent creation.

Validation

  • Real Gateway/SQLite red proof: replacement was deleted; a same-ID reset successor was aborted and deleted; unchanged cleanup passed.
  • Fixed Gateway/SQLite cases cover unchanged and active-original cleanup, new-ID replacement preservation, and same-ID/new-revision reset preservation, including a live abort controller. All 14 tests in that authority fixture pass.
  • 137 spawn-tool tests, 4 hidden-subagent cleanup tests, and 104 session-patch tests pass. Production types, the affected Gateway/agent test type graphs, scoped typed lint, and assertion safety pass.
  • Full supported build passed (4m 5.9s). Live built Gateway RPC verified fresh revision creation, successful original-child deletion, new-ID replacement rejection, and same-ID/new-revision reset rejection. The built candidate's changed source blobs match commit 4cc1549e017cb7d379d0b14db97a8ad3fdab2ccf. Independent Codex review of the complete changed modules and owner/caller evidence found no actionable P0–P2 issue. Exact-head CI run 33735580502, attempt 2, its aggregate gate, and Workflow Sanity 33735580435 all passed on 2051145c8752d6c81238c96ffd24e2f231bb8b45. One shard never acquired a Blacksmith runner; after all 119 other jobs passed, the stalled run was stopped and only that job plus its dependent gate were retried through the existing hosted fallback. The shard passed in 2m18s and earlier passes were preserved.

The test fixture uses the worker's existing timeoutMs: null create/drain contract while preserving the outer test bound. Its active run releases its controller when cancellation is observed. CI exposed two stale update-command call-shape assertions and an unrelated explicit-model catalog preparation inside the rollback fixture. The assertions now require the explicit system actor and exact trusted routing shape. The rollback fixture creates the real session with its default selection while faulting the initial task boundary; measured first creation fell from 75.5 seconds to 20 milliseconds. All 14 real Gateway/SQLite cases and 31 update-command cases pass after this test-only correction. No production timeout, authority check, or lifecycle assertion was weakened.

Production: −23 lines. Tests/test support: +38 lines in the landed commit. Docs: +2 lines. Shared deletion policy replaces duplicate rollback code. The equivalent update-command assertion corrections landed on main through #137196 and #137199 while CI ran, so they are absent from this final merge diff.

Follow-up and landing scope

Land this focused visible-session repair; retain ACP lifecycle work under existing issue #127531 and coordinate with related cancellation PR #128001. ACP has a different manager/initialization owner, and this PR neither changes that contract nor claims to repair it.

Current ACP failed-spawn cleanup still closes through a manager, removes bindings, and deletes by key. The existing issue's original concurrent same-key-spawn example was challenged because both spawn callers mint UUID keys. A reset/rebind of an already committed child during awaited work is a distinct scenario to establish in that ACP investigation; no new live ACP race reproduction is claimed here. This tracking resolves the scope decision requested by the latest ClawSweeper review without duplicating the existing issue or broadening the verified visible-session change.

Retain the created session ID and lifecycle revision for failed visible spawns.
Initialize the revision alongside a new session identity and preserve existing
rows. Reuse guarded subagent cleanup and remove abort-then-delete rollback.
Report removed, changed, or unconfirmed cleanup without widening permission.

Follow-up to #136952. Production delta: -23 lines.

Validation: real Gateway/SQLite replacement and reset regressions, active-child
cleanup, 259 focused tests, production and affected test types, scoped typed
lint, independent Codex review, full build, and live Gateway creation/deletion
fences. No schema, migration, configuration, or protocol changes.
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 3, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 4:59 AM ET / 08:59 UTC.

ClawSweeper review

What this changes

The PR preserves a visible spawn's creation identity through failure cleanup so only the original session generation can be stopped and deleted.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

No blocking defect was found in the introduced visible-session cleanup path. Current main still has the key-only rollback this PR repairs; because this is a maintainer-owned protected item, a maintainer should confirm whether the separate ACP cleanup gap remains a follow-up rather than expanding this focused repair.

Priority: P1
Reviewed head: 2051145c8752d6c81238c96ffd24e2f231bb8b45
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative lifecycle repair with meaningful owner-boundary coverage; the remaining question is ACP scope, not an introduced defect.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied PR body nevertheless describes real Gateway/SQLite and built-Gateway after-fix coverage of the changed deletion owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied PR body nevertheless describes real Gateway/SQLite and built-Gateway after-fix coverage of the changed deletion owner.
Evidence reviewed 6 items Introduced caller path: The visible-spawn failure exits retain the create receipt and pass both session ID and lifecycle revision to the shared cleanup helper; a missing receipt becomes an explicit unconfirmed cleanup result.
Lifecycle owner fence: The Gateway deletion owner validates expected session ID and lifecycle revision before draining work, then revalidates the originally loaded row before cancellation and commit.
Boundary coverage: The new in-process Gateway and SQLite fixture covers unchanged and active original children plus same-key replacement and reset successors; it asserts that only the original is removed.
Findings None None.
Security None None.

How this fits together

Visible session spawns create persistent dashboard sessions through the Gateway. If startup or run registration fails, this path cleans up the created child while the Gateway lifecycle owner protects a concurrently reset or replaced successor.

flowchart LR
  A[Visible session spawn] --> B[Gateway creates child]
  B --> C[Creation identity receipt]
  C --> D[Startup or registration failure]
  D --> E[Guarded Gateway cleanup]
  E --> F[Original child removed]
  E --> G[Successor preserved]
Loading

Decision needed

Question Recommendation
Should the visible-session fence land as a focused repair while ACP's distinct failed-spawn cleanup is tracked separately? Land focused visible repair: Keep this PR limited to visible sessions and create or retain a separately owned ACP repair that carries the committed creation identity.

Why: ACP has different manager and initialization ownership, but its existing cleanup still deletes by key after awaits; only a maintainer should choose whether that pre-existing scope must join this PR.

Before merge

  • Resolve merge risk (P1) - ACP failed-spawn cleanup remains a separate pre-existing key-only sequence after awaited manager and binding cleanup, so a maintainer should explicitly decide whether it stays as follow-up scope.
  • Complete next step (P2) - Confirm whether ACP's pre-existing key-only failed-spawn cleanup remains a separately tracked repair before merging this focused visible-session fix.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source -23, Tests +40, Docs +2. Total +19 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 34 57 -23
Tests 4 209 169 +40
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 245 226 +19

Review metrics

Metric Value Why it matters
Production versus test delta production −23, tests/test support +40, docs +2 The repair consolidates duplicate rollback paths while adding boundary coverage for replacement and reset successors.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep this focused visible-session repair and track ACP with a separate creation-receipt fence, unless the maintainer chooses to expand the work into one coherent cross-ACP repair.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep this focused visible-session repair and track ACP with a separate creation-receipt fence, unless the maintainer chooses to expand the work into one coherent cross-ACP repair.

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

Yes, source-reproducible: current main's visible failure path rolls back by key, and the added real Gateway/SQLite fixture injects replacement and reset before cleanup. This read-only review did not rerun the fixture.

Is this the best way to solve the issue?

Yes for visible spawns: preserving the creation receipt and delegating to the existing owner-validated deletion flow is preferable to key-only abort/delete logic. ACP needs its own receipt-preserving repair rather than a visible-path workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A failed visible spawn could otherwise stop or delete a newer user session sharing the same key.
  • 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. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied PR body nevertheless describes real Gateway/SQLite and built-Gateway after-fix coverage of the changed deletion owner.

Evidence

What I checked:

Likely related people:

  • steipete: 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 (1 earlier review cycle)
  • reviewed 2026-09-03T08:32:49.793Z sha 4cc1549 :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Scope decision for this requested landing: land the focused visible-session repair and retain ACP manager/lifecycle work under existing issue #127531, coordinated with related cancellation PR #128001. The PR body now records those references.

This addresses the three scope/maintainer-decision items in the latest review, which reported no defect in the introduced path. The visible-session repair has its own reproduced failure, guarded creation/deletion owner, and local/live proof. ACP has a separate manager initialization and cleanup contract, so it remains a separately tracked owner repair.

I also checked the existing issue's review: its original concurrent same-key-spawn example was challenged because callers mint UUID keys. A reset/rebind of an already committed child during awaited work is a distinct scenario for that investigation; this PR does not claim a new live ACP reproduction or change the supported ACP key contract.

@steipete
steipete merged commit 587455b into main Sep 3, 2026
337 of 341 checks passed
@steipete
steipete deleted the codex/session-child-cleanup-fence branch September 3, 2026 09:22
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
…law#137183)

* fix(agents): fence visible child cleanup to creation identity

Retain the created session ID and lifecycle revision for failed visible spawns.
Initialize the revision alongside a new session identity and preserve existing
rows. Reuse guarded subagent cleanup and remove abort-then-delete rollback.
Report removed, changed, or unconfirmed cleanup without widening permission.

Follow-up to openclaw#136952. Production delta: -23 lines.

Validation: real Gateway/SQLite replacement and reset regressions, active-child
cleanup, 259 focused tests, production and affected test types, scoped typed
lint, independent Codex review, full build, and live Gateway creation/deletion
fences. No schema, migration, configuration, or protocol changes.

* test(gateway): align authority assertions and scope rollback fixture
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 maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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