Repository navigation
Description
A deferred admin Destroy retry can delete a workspace that another turn resumed after the original Destroy request.
Found by Tale agent #2 in the independent #4087 review. Root independently confirmed the source path on main eee0a1098f433c96fe2d3c9b83779f6eed32d6cc (also unchanged in PR #4076 at 7afc5b349325a1d10fcd3daff4aa2d396430fdf0). This is a source-confirmed race; the same-row interleaving still needs a local runtime regression. No production Destroy or fault injection was performed.
Causal path
- An administrator queues Destroy for a stopped sandbox row. The first spawner request fails, leaving the row available.
- A chat or scheduled task resumes the same row before the retry.
resumeSessionSlot()inbackend/domains/sandbox/sessions.tsupdates that row to active in place, deliberately preserving its incarnation. - The
sandbox.destroy_sessionretry reachesteardownSession()inbackend/domains/sandbox/service.ts. Its guard excludes only a different row ID or an already-destroyed row. The resumed row therefore passes. await destroy(sessionArgs.sessionId)is unconditional. The new turn/workspace is removed and the platform settles the row, tokens and gateway keys.
backend/jobs/tasks.ts gives this job five retries, 30-second exponential backoff and a 900-second attempt expiry. The source comments describe a quarter-to-half-hour retry ladder. The row-ID guard correctly protects a new incarnation, but cannot protect work resumed in the same incarnation.
Expected repair and acceptance
Choose one coherent lifecycle rule: prevent resume/admission while that row has a pending destructive operation, or make delayed/retried deletion conditional on current idle state and preserve active work. Enforce it at the shared server boundary and under the existing lifecycle/admission locks, not only by disabling the admin-page controls.
Add a local real-database regression with a first failed Destroy, same-row resume, and retry; assert that new work is preserved or admission was refused before it began. Cover both lock orders, a newer incarnation, repeated Destroy, eventual success after idle, and all chat/agent/automation resume paths. Keep organization isolation, pin/key cleanup and accurate pending/failed UI state.
Suggested triage: High because a different user's newly started work can be lost. The erasure-acknowledgement/trash issue is separate. Assign through normal fleet intake with a distinct implementation/review pair.
Activity
fix(platform): keep the Destroy refusal private to the session verbs
test(platform): give the resume-path checks an organization of their own
test(platform): reproduce a resume reviving a row settled under it
fix(platform): never resume a session row settled under the resume
docs(platform): count the manual boxes again after integrating main