Repository navigation
fix: keep cloud sessions stopped and surface cleanup failures - #135583
Conversation
Keep admission and readiness closed after terminal ownership or transport closure. Preserve accepted workspace recovery fences until provider teardown succeeds, including drain epoch changes. Share recovery and journal ownership checks, simplify turn-launch validation, and let reclaim own UI cancellation.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 10:19 PM ET / September 2, 2026, 02:19 UTC. ClawSweeper reviewWhat this changesThis PR makes cloud-worker Stop retain failed provider cleanup for retry and prevents terminal workers from becoming ready through late WebSocket traffic. Regression provenancePossible regression — probable (reviewed change; reproduction). No predecessor PR is attributed. Merge readinessKeep open for maintainer review: the introduced lifecycle changes have no concrete correctness finding, but the PR is maintainer-labeled and its stated authenticated Codex remote-exec cancellation proof remains pending. Priority: P1 Review scores
Verification
How this fits togetherCloud sessions run work on remote workers while the Gateway retains the session, workspace, and placement record. Reclaim, pending-result recovery, and worker connection admission decide whether a remote worker is released or remains visibly retryable. flowchart LR
UI[Control UI Stop] --> Reclaim[Gateway reclaim]
Reclaim --> Placement[Placement lifecycle]
Placement --> Cleanup[Provider cleanup]
Cleanup --> Confirm{Release confirmed?}
Confirm -->|yes| Local[Local or reclaimed session]
Confirm -->|no| Retry[Visible retryable failure]
Worker[Worker WebSocket] --> Admission[Connection admission]
Admission --> Placement
Decision needed
Why: The patch changes both worker-turn and remote-exec lifecycle paths; source tests are strong, but the PR expressly leaves the latter runtime proof incomplete. Before merge
Agent review detailsSecurityNone. PR surfaceSource -160, Tests +138, Docs 0. Total -22 across 20 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve the owner-level cleanup and admission refactor, then record exact-head Codex remote-exec cancellation evidence or have the responsible maintainer explicitly accept that bounded proof gap. Do we have a high-confidence way to reproduce the issue? Yes, source provides focused failure-injection and real WebSocket boundary tests for the reported lifecycle conditions, though this review did not execute them and the Codex live scenario remains pending. Is this the best way to solve the issue? Yes, provisionally: moving cleanup confirmation, journal ownership, and readiness closure to their respective owners removes duplicate policy; the remaining question is proof coverage rather than a better code path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against dfa8b7df9e6f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
Merged via squash.
|
…aw#135583) Keep admission and readiness closed after terminal ownership or transport closure. Preserve accepted workspace recovery fences until provider teardown succeeds, including drain epoch changes. Share recovery and journal ownership checks, simplify turn-launch validation, and let reclaim own UI cancellation.
What Problem This Solves
Fixes an issue where users stopping or recovering cloud sessions could see a reclaimed session while provider deletion was still failing. A late WebSocket hello could also report a stopped, fenced, or already-closing worker as ready.
Why This Change Was Made
Keep each lifecycle decision with its authoritative owner: the connection controls admission and readiness; environment teardown owns the provider cleanup acknowledgement; the placement store resolves journal ownership. Startup and runtime recovery now share those checks, accepted workspace results retain their recovery fence until cleanup succeeds, and the UI uses one canonical reclaim request instead of issuing a second abort.
The refactor removes duplicate recovery, journal-ownership, capability-fallback, and launcher checks. Production code shrinks by 160 lines; regression coverage adds 138 test/support lines, for 22 fewer lines overall. There are no configuration keys, protocol changes, database/schema migrations, dependency changes, or changelog edits.
User Impact
Stopped workers stay stopped. Failed cleanup remains visible and retryable instead of reporting success while a paid worker is still retained. Accepted workspace changes remain protected through cleanup retries and restart recovery. The cloud-session and worker docs now describe these outcomes consistently.
Evidence
3766b9f99975188731a1c2ac7d8d6ea294a01dd5: 46 files / 723 tests passed (56 worker tests, 558 Gateway tests, 109 UI tests), with an unchanged-source check afterward. This covers dispatch/reclaim, recovery, accepted results, journal ownership, placement barriers, startup maintenance, both launcher modes, cancellation, media, computer operations, and UI recovery.node scripts/check-changed.mjsand complete normal-production Node 24 builds passed, including runtime postbuild, SDK exports, UI asset/performance guards, and startup metadata. The isolated exact-head Linux Testbox build completed in 1m28s; its filtered node inventory has 9,332 files with zero missing imports. Both canonical bootstrap modes passed in about ten seconds each, including archive hash/size verification and complete owned-file cleanup. Pinned Chromium launched, verified a synthetic page, and closed.3766b9f99975188731a1c2ac7d8d6ea294a01dd5.Real startup cleanup failure
This is the exact PR build and a synthetic project. The recording shows Stop returning a visible cleanup-pending error instead of claiming the cloud worker is gone. It is failure/retention evidence, not a completed cleanup result.
cloud-startup-stop-pending-cleanup.mp4
Same-session recovery after cleanup
After the broker confirmed no remaining provider resource, an ordinary UI Stop retry returned the original session to local without replacing its allocation identity or changing its workspace. This genuine after-capture intentionally shows no model credential: cleanup recovery did not need one.
Review scope and follow-ups
The reviewed path runs from Control UI startup through sessions dispatch/reclaim, worker admission, turn claims and launcher callbacks, environment teardown, journal ownership, and accepted-result recovery. OpenClaw worker-turn and Codex remote-exec paths are both included. Codex contracts were inspected directly: environment registration/status and environment transport ownership. The inspected files match that official commit byte-for-byte, and GitHub's commit API independently resolves the revision. This change does not alter the Codex protocol.
The automated stored-data warning does not reflect a schema change: tables, columns, representations, schema versions, and migrations are unchanged. This repairs existing cleanup and pending-result ownership; both restart and retained-reference paths have regression proof. Provider-deletion failures were injected at the real state/Git owner boundary. The live pending-cleanup failure occurred naturally during cancelled broker provisioning; AWS deletion was not deliberately made to fail. The ClawSweeper rank-up requests, including its 2026-09-02 02:19 UTC request for authenticated Codex evidence, are covered by the exact-head runtime flows and real UI Stop/failure/retained-state/successful-retry evidence above. No live-proof waiver is being used.
Source provenance: the admission/readiness holes appear in #105865, premature no-result reclamation in #106332, and the staged-result exact-epoch cleanup guard in #110952. #111244 carried the guard forward and added the accepted-but-missing-reference variant. These attributions were checked against raw commit parents; historical builds, first observed incidents, and earliest stable-release exposure were not established.
A separate source-only audit of recent main changes through
00baa02687d7d4cdc707746f6dbd0979f47b0f34found no concrete integration conflict: newer Codex native-configuration ownership explicitly supports isolated cloud-node clients and leaves placement/provider cleanup separate. Later hook-context, worker-label, sandbox, observer, client-projection, and plugin-loader changes retain their inspected owner boundaries. The latest review's unavailable-main limitation is also resolved locally:dfa8b7df9e6f58dd7baab29ee7e2e238c74580a8is available and is an ancestor of fetchedaec22ecc73019282592e503948a68716ef10da51; that commit only changes CI planning/docs/tests. The test totals and CI above remain proof of the exact PR head, not an executed combined tree.The separate completed-result/restart finalization work in #132027 remains outside this change; it needs its own accepted persistence design. A possible model-overridden child-session routing issue still needs a concrete reproduction and is not claimed as fixed here.
Follow-up: the reclaim barrier reports “has active work” for an already-local session even when it has no active turn. This was observed on a redundant safety RPC after failed bootstrap recovery; the normal UI does not offer Stop for local sessions. The rejection is correct, but its diagnostic wording needs a separate cleanup.
Follow-up — Codex node-channel cancellation versus native background-terminal cleanup acknowledgement ordering. During the live Codex cancellation, the node channel closed and the separate background-terminal termination request exceeded its fresh five-second cleanup deadline. The runtime surfaced that failure before worker reclaim completed successfully. The cancellation owners in
extensions/codex/src/app-server/attempt-client-cleanup.tsandrun-attempt-active-turn.tsare not changed by this PR; the competing lifetimes also exist on its base. Node-side process-tree cleanup is attempted separately, but the shell's state between turn cancellation and worker reclaim was not observed. This is a real unresolved acknowledgement gap, not a cosmetic warning or a proven surviving process. It needs focused ownership/proof work; no timeout increase or error suppression is included here.