Repository navigation
fix(sandbox): delete a destroyed workspace in the background - #4088
Merged
Merged
Conversation
A destroy deleted the session's workspace before it answered. A workspace of tens of GB in over a million files on network block storage takes longer than the 30 s the platform gives DELETE /v1/sessions/:id, so Settings > Sandboxes reported "action failed" and kept the row stopped while the spawner went on deleting. Once the container is confirmed gone, the Docker backend now renames the workspace into <root>/.trash/ under a name of its own and answers; one background pass per session root then empties the trash, entry by entry. The boot sweep empties what a restart or crash left there, and the periodic sweep retries what a pass could not remove. A repeated destroy finds nothing (destroyed: false), and a new session under the same id gets a fresh workspace beside the one still being deleted. Where the rename cannot happen (another filesystem, a full disk), the workspace is deleted in place as before, and a failure there still answers 502. Kubernetes already hands a deleted PVC to its provisioner.
The platform's hourly workspace cleanup reads this inventory. A destroyed workspace waiting in .trash/ under a ses- name must never be listed as a workspace, or the sweep could count it or ask for it to be deleted again. The colour-root walk already skips every dot-dir; this pins .trash/ in its test beside .pins/.
Contributor
Author
|
Independent post-merge review of #4088 at
What holds
MEDIUM: an erasure now records "deleted" before the bytes are gone, and hears nothing if the delete keeps failing.
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.
Summary
A Destroy deleted the session's workspace before it answered, with no time limit (
rm(workspaceHostDir, { recursive: true }), step 5 of #4086). A workspace of tens of GB in over a million files, on network block storage, takes longer than the 30 s the platform givesDELETE /v1/sessions/:id. Settings → Sandboxes then reported "action failed" and kept the rowstopped, while the spawner went on deleting. This happened on the production platform on 2026-10-02.Once the container is confirmed gone, the Docker backend now renames the workspace into
<root>/.trash/ses-<id>.<uuid>. That is one directory entry on the same filesystem, however much the workspace holds. Then it answers, and one background pass per session root empties the trash one entry at a time, so a burst of destroys doesn't flood the disk under running sessions.destroyed: false.ses-<id>, and every trash entry has its own random suffix, so the two never meet.This complements #4087, which queues the platform's Destroy and retries it. With this change, the spawner call that job makes answers within seconds instead of running into the 30 s cap and its retry ladder. The two PRs touch disjoint files. Refs #4086.
Checklist
bun run checkpasses — run for the touched workspace, not the whole monorepo:bun run --filter @tale/sandbox test(640 pass, 0 fail; 630 before),typecheck,lintandformat:checkall clean, plusbunx knip --workspace services/sandbox,bun run lint:conflictsandbun run lint:links. CI runs the full gate.bun run lint:sastpasses — Opengrep on the changed files: 0 findings.docs/{en,de,fr}/: nothing a user sees changes. fix(platform): run a sandbox Destroy as a job, not in the request #4087 covers the admin page. The sandbox's owndocs/sessions.mdandREADME.mddescribe the trash.README.md/README.de.md/README.fr.md— N/A.Test plan
New tests use the fake Docker CLI, as the existing ones do:
DELETEanswers 200 while a held deletion still has all 2,000 files on disk, and the tree is gone afterwards.Each of these was checked to catch the bug: making the destroy wait for the deletion, removing the boot sweep, or giving trash entries non-unique names each made the matching test fail.
Not observed yet: a real spawner deleting a large workspace. After deploy, destroy a stopped session with a realistic tree. The DELETE should answer in about a second,
<root>/.trash/should hold the entry briefly, and the volume's free space should come back.Behaviour to weigh: once the caller is told "destroyed", a failed background deletion shows only as a logged and retried entry in
.trash/, not as a 502. A destroy of a running session still waits fordocker rm --force(up to 30 s) and, with Docker-in-Docker, the inner volume removal (up to 10 s). Those were not the reported failure, which was on stopped sessions.