Repository navigation
fix(agents): preserve successor sessions during spawn rollback - #137183
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 3, 2026, 4:59 AM ET / 08:59 UTC. ClawSweeper reviewWhat this changesThe PR preserves a visible spawn's creation identity through failure cleanup so only the original session generation can be stopped and deleted. Regression provenancePossible 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 Review scores
Verification
How this fits togetherVisible 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]
Decision needed
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
Agent review detailsSecurityNone. PR surfaceSource -23, Tests +40, Docs +2. Total +19 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
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. |
|
Merged via squash.
|
…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
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
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 on2051145c8752d6c81238c96ffd24e2f231bb8b45. 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: nullcreate/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.