Repository navigation
fix(gateway): reclaim cloud workers before session recovery - #128597
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 24, 2026, 3:36 AM ET / 07:36 UTC. ClawSweeper reviewWhat this changesThe PR makes Gateway session recovery reclaim and verify an active cloud worker before atomically archiving the source session and creating its successor. Merge readiness⛔ Blocked by patch quality or review findings - 7 items remain Keep open and block merge: the branch correctly adds reclaim-before-archive ordering, but a revoked runtime authority can still complete cloud-worker reconciliation and teardown before the recovery code notices the revocation. Priority: P1 Review scores
Verification
How this fits togetherGateway recovery converts a restart-tombstoned session into a successor session. It must settle the attached cloud-worker placement first so remote execution, workspace synchronization, and SQLite session state retain one authoritative lifecycle owner. flowchart LR
A[Restart tombstone] --> B[Gateway recovery]
B --> C[Read source session]
C --> D[Reclaim cloud worker]
D --> E[Revalidate authority and ownership]
E --> F[Atomic SQLite recovery]
F --> G[Successor session]
G --> H[Recovery continuation]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new authority handoff can let a revoked runtime identity complete cloud-worker side effects before the later archive guard runs. PR surfaceSource +51, Tests +452, Other 0. Total +503 across 8 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Thread the recovery authority guard through the reclaim final-effect fences, reject revocation before workspace or environment effects, and retain the existing pre-archive lifecycle and SQLite compare-and-swap checks. Do we have a high-confidence way to reproduce the issue? Yes, from source: revoke the runtime guard after reclaim begins but before its workspace/environment completion; the current code checks it only after reclaim returns. This review did not execute the path because the checkout is read-only. Is this the best way to solve the issue? No. Reclaim-before-archive and the added SQLite lifecycle comparison are the right shape, but the authority check must guard final reclaim effects rather than only the later archive commit. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 92a074944d97. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
746cae3 to
578c883
Compare
|
@clawsweeper re-review Accepted and fixed the P1 on exact head The authority callback is now threaded through the canonical active and failed reclaim owners. It revalidates after waits and immediately before journal recovery, tunnel/workspace effects, result acceptance/finalization, and environment destruction. Recovery still revalidates source lifecycle/ownership and canonical persisted placement before the SQLite archive. The follow-up crash-consistency edge is also covered: once New production-boundary regressions cover:
Final rebased validation: 92 Gateway recovery/archive/reclaim tests plus 3 SQLite recovery tests passed; the complete changed-file gate passed with no warnings; fresh P0/P1 autoreview reported no accepted/actionable findings (0.90). Exact-head CI is running now. Please re-review only; do not merge. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready proof for exact head
ClawSweeper’s seven before-merge items are addressed:
Proof gap: the final paid-cloud restart/recovery matrix awaits the separately owned worker infrastructure ingress lane. The deterministic authority, workspace, environment, and SQLite owner boundaries changed by this PR are fully covered. |
|
Merged via squash.
|
…#128597) * fix(gateway): reclaim cloud workers before recovery * fix(workers): fence reclaim final effects * test(workers): track reclaim authority temp dirs
Closes #128596
What Problem This Solves
Fixes an issue where restart recovery could archive a source session and create its successor while the source still owned an active cloud worker. That could leave remote execution and final workspace changes attached to a session identity the Gateway had already retired.
Why This Change Was Made
Recovery now settles the source placement through the canonical archive/reclaim boundary before committing the SQLite source archive. Reclaim carries the runtime authority guard to each post-await workspace, tunnel, and environment effect; if authority closes before an effect, the placement stays retryable. Once environment destruction commits, durable local/reclaimed bookkeeping finishes even if authority closes during that await, avoiding a placement that points at a deleted environment. Recovery then re-reads the authoritative session, placement generation, owner epoch, environment, and lifecycle revision before the SQLite compare-and-swap.
Production LOC: +112/-38 (net +74) | Tests/test support: +597/-6 | Tooling baseline: +1/-1
The production growth establishes two coupled authority boundaries: recovery coordinates async placement reclaim outside the transaction, and the canonical reclaim owner fences every privileged final effect while preserving crash-safe completion after destruction. A downstream guard or post-archive cleanup cannot safely express either ordering.
AI-assisted: yes. I reviewed restart tombstones, session recovery ownership, placement reclaim/final synchronization, generation and owner-epoch checks, SQLite compare-and-swap inputs, archive lifecycle reuse, and failure guidance and understand the change.
User Impact
Recovering a cloud-backed session now either safely reclaims and synchronizes its worker before creating the successor, or fails visibly with instructions to stop/reclaim the worker and retry. Recovery no longer silently retires a session that still has a live remote owner.
Evidence
node scripts/check-changed.mjspassed with no new temp-directory, max-lines, type, lint, architecture, or database warnings.