Skip to content

bug(sandbox): a delayed Destroy retry deletes resumed work #4091

Closed

Description

@yannickmonney

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

  1. An administrator queues Destroy for a stopped sandbox row. The first spawner request fails, leaving the row available.
  2. A chat or scheduled task resumes the same row before the retry. resumeSessionSlot() in backend/domains/sandbox/sessions.ts updates that row to active in place, deliberately preserving its incarnation.
  3. The sandbox.destroy_session retry reaches teardownSession() in backend/domains/sandbox/service.ts. Its guard excludes only a different row ID or an already-destroyed row. The resumed row therefore passes.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions