Repository navigation
fix(platform): run a sandbox Destroy as a job, not in the request - #4087
Merged
Merged
Conversation
An adapter row's refetchInterval may now be a function of the fetched body, so a list can poll faster while one of its rows is changing and fall back to its usual cadence (or stop) once nothing is.
…equest The Sandboxes page's Destroy ran the whole teardown inside the request: the session's lifecycle lock (which a pinned recreate holds for minutes), the spawner's unpin and its delete of the workspace, then the settled row. The confirmation spun for all of it and the row stayed until it ended; past the spawner client's 30 s the admin got an error while the delete went on. The request now checks that the organization holds an undestroyed row under the id and queues `sandbox.destroy_session` (exclusive per session, six tries over a quarter to half an hour), then answers 202. The job runs the same `teardownSession`, so its lock order, unpin-first and settle rules are unchanged. The teardown stays one step under the lock rather than ending the row early: a turn started while a split-off delete was still queued would resume the very files it is about to remove. The list reads each row's latest Destroy job back: Destroying while it is queued, retrying or running (the list then polls every 2 s), and Destroy failed once its ladder ran out, for the incarnation it was asked of. The dialog closes as soon as the job is queued; the row's menu offers nothing while it is pending. Copy in en/de/fr, the admin docs, and manual boxes SET-F73 and SET-B29 follow. Closes #4086
2 of 5 tasks
A Destroy job carried only the session id. Its retry can run long after the request: if an attempt's answer was lost after the spawner deleted the workspace, the reconcile heals the row, and a turn opens a fresh incarnation under the same deterministic id (a project agent's is the same every time). The retry then deleted that fresh workspace mid-turn and settled its row, and the list read it as being destroyed. The job now names the latest row it was asked for. The teardown leaves a session alone when that row is no longer the latest under the id, or is already settled. The exclusive queue is keyed by the row, so a Destroy of the newer incarnation is queued on its own rather than absorbed by the older one still retrying. The list reads each job against the live row it names.
A pending Destroy held every row action. Pin and Destroy must wait for it, since the teardown unpins and deletes the workspace whatever is asked meanwhile, but stopping a task does not touch the pin or the row. A task that runs while the Destroy retries could no longer be stopped from the page.
The Destroy confirmation and the admin docs promised a fresh environment on the next agent start. While a Destroy waits for its next attempt, an agent that starts still works in the old workspace, and removing it cancels that work. Only a start after the row is gone gets a fresh one.
Contributor
Author
|
Independent post-merge review of #4087 at
What holds
M1 (MEDIUM): a retrying Destroy still kills and deletes a workspace a turn resumed after the click.
LOW
No production contact, and nothing was merged by this run. |
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4086.
What was wrong
Settings → Sandboxes → Destroy ran the whole teardown inside the request: it waited, with no time limit, for the session's lifecycle lock (a pinned recreate holds it for minutes), then the spawner's unpin, then the spawner's delete (the recursive workspace
rmhas no timeout), and only then settled the row. The dialog spun the whole time and the row stayed listed. Past the spawner client's 30 s cap the admin got an error toast while the delete kept going.What changes
POST /api/app/sandbox/sessions/:id/destroytakes the latest row under that id. It answers 404 when the organization holds no such row or the row is already destroyed. Otherwise it queuessandbox.destroy_sessionfor that row (newdomains/sandbox/destroy-schedule.ts) and answers 202. The queue isexclusiveper row, so a second ask while one is queued, retrying or running adds nothing. The job runsteardownSessionwith 5 retries (30 s doubling with jitter, a quarter to half an hour in all), so lock order, unpin-first and settle rules stay exactly whatlifecycle.integration.tsproves. The teardown's one addition: it does nothing when the row it was asked for is no longer the latest under the id, or is already settled. Without that, a retry could run after the reconcile had healed the row and a turn had opened a fresh incarnation under the same deterministic id, and it would delete that fresh workspace mid-turn.retireWorkspaceis safe only because its claim and delete run back to back under the lock.GET …/sessions/viewaddsdestroyState: 'pending' | 'failed' | nullto each row, read from the latest job asked for the row it lists now:pendingwhile it is queued, retrying or running;failedonce the ladder ran out. A job for an earlier incarnation never marks a fresh workspace. The list polls every 2 s while a row is pending; an adapter row'srefetchIntervalmay now be a function of its answer (first commit).SET-F73andSET-B29, plus anautomation.mdrow.Review
An adversarial review before merge found three real problems, fixed in the last three commits: a retry could delete a fresh incarnation under a reused id; the docs and the confirmation promised a fresh environment during a pending Destroy; Stop task was held during one for no reason. A fourth claim was refuted.
Behaviour change to be aware of
A Destroy the spawner refuses is now retried for up to half an hour instead of stopping at the first error. If a turn resumes the workspace in that window, a later retry still force-deletes it. That matches the confirmation's "Any running task is cancelled", and the row reads Destroying throughout.
Verification
destroy-schedule.test.ts(new),routes.test.ts,sandboxes-settings.test.tsx,settings-sandbox.test.ts,use-backend-query.test.ts. The sandbox, jobs and adapter suites pass (1,129 tests), as do the settings UI and hooks suites (1,468). Typecheck, oxlint, oxfmt, i18n, docs,lint:links,lint:manual,check-guideand opengrep: 0 findings.ITEST_LANES=checkSandboxSpawner,checkSandboxLifecycle: all three new checks pass, and CI's full run passed 1323/1323 before the review fixes.pending; the row settles once the delete is released.pending, a duplicate ask adds no job, and the row readsfailed(stillactive) once the ladder is marked run out. Asking again finishes it.freshKept=false.workspace-tool door … hit=false, fails identically on cleanmainin the same filtered run (it needs an earlier lane's data).retryand the list polled every ~2 s. Once the ladder was marked run out, the row read Destroy failed and Destroy was enabled again. Asking again finished in about 4 s.Not observed: a real spawner deleting a large workspace, and the full half-hour ladder (stood in for by marking the job failed).