Repository navigation
fix(sandbox): keep erasure pending until workspace bytes are deleted - #4094
Conversation
A destroy answered once the workspace was renamed into the trash, and the background pass that deletes it never reported back: an entry that kept failing stayed on disk while every caller read the destroy as done, and a repeated destroy kicked no removal at all. The trash now says how far one name's deletion has come (done, pending, failed), read from the trash itself so a restart never turns bytes still on disk into done, and matched by the entry name so a fresh workspace under the same id never counts. `settle` has the entries attempted now, a failed one again, and waits a bounded time, waking only for its own entries. DELETE /v1/sessions/:id answers `deletion`, and `?await_deletion=1` waits up to 10 s for it after the per-id destroy serialization is released, so a create of the id never waits for bytes. The device hub keeps a session placed while its device still deletes, so the destroy that asks again reaches the device holding the bytes. Kubernetes reports no field: its PVC delete stays the deletion it answers for. An interactive destroy does not wait.
The workspace cleanup read a destroy's `destroyed` as the deletion: an erasure counted the workspace as erased, the retirement audited `sandbox_workspace.deleted` as a success and an organization's teardown went ahead, while the spawner could still be deleting the files, or failing to. The cleanup's destroy now asks the spawner to await the deletion and reads its answer: `pending` and `failed` become the outcomes `deleting` and `deletion_failed`, which leave the workspace for the next attempt like a busy or offline one. The claimed rows stay expired and nothing is audited as deleted; the sweep defers, the owner's and the organization's jobs throw for the queue's retry, and the erasure's pass fails, so the receipt reads partial until a Retry finds the files gone. A deletion that keeps failing is audited as a failure, so it is not only a log line. A spawner or device that predates the field is read as before. Docs say when the receipt and the audit row are written, in en, de and fr, and the manual register names the new tests. Closes #4090
A mark for an entry removed by other means outlived it; each pass now drops the marks of entries it no longer lists. The docs say an audit row follows Tale's confirmation that the files are gone.
Backend integration run 37056656989 (job 111003756345) on b310528 truncated at lane 49 of 217: checkBellHintWire did not settle within 10 min because an /events SSE tail never ended, and the step then hit its 30-minute timeout. The lane passed on this branch's platform code at 19:48Z (job 111000862153) and on main, and nothing in this change touches notifications or the event stream. The run cannot be re-run with this token, so this empty commit retriggers it.
yannickmonney
left a comment
There was a problem hiding this comment.
Independent review verdict: changes requested. Reviewed by a separate agent and cross-checked by the coordinating reviewer; submitted as a comment because this repository shares one GitHub principal with the author. No GitHub approval is asserted.
Request changes for the legacy asynchronous-response completion gap described inline. For field-aware backends, the pending/failed/done flow, trash restart behavior, retry routing, and claimed-row settlement are coherent on source review. Hosted native integration is 1,432/1,432 across 217 lanes, including the new erasure/audit sequence.
The current browser gate is incomplete: E2E run 37060982277 platform shard 11/16 failed during the 12-minute Chromium-install step, and its actual E2E suite was skipped. The other 17 Playwright jobs succeeded with no retry diagnostics. This is a verified setup failure, not a reproduced product test failure. An empty retry commit has the same tree as b310528; it does not waive this required gate.
Please also qualify the EN/DE/FR sandbox audit wording to match the PR's acknowledged ownerless-inventory limitation: a pending trash deletion can disappear from inventory without a later completion audit. No local test, teardown, author-source change, push or merge was performed in this independent review.
Backend integration on 2e62a81 stopped at lane 49 of 217: "checkBellHintWire did not settle within 10 min", then the 30-minute step timeout (job 111128211899). The same hang, at the same lane, failed #4094 (run 37056656989) and #4097 (run 37086605668), neither of which changes a dependency. The integration run sets no SENTRY_DSN, and importing @sentry/node 10.48.0 or 10.54.0 without init subscribes to no diagnostics channel and patches nothing in node:http or fetch. No code change.
…ending-until-bytes-deleted
Review 5396936242 (r4169908728): a destroy answer without `deletion` was read as complete, but the immediate predecessor (19776cf) already answered that way once the workspace was renamed into its trash, with the bytes deleted in the background, or failing to be. Absence proves nothing. Every backend now states its contract: `SessionBackend.workspaceDeletion` is required, and every answer that is not busy carries `deletion`. Docker reads its trash (done, pending, failed); Kubernetes answers `handed_off`, the PVC delete accepted and the volume its provisioner's under the StorageClass's reclaimPolicy, never presented as done. The hub drops a destroyed session's placement only on an explicit completion (done, handed_off). A device still deleting, or one too old to say, keeps it, marked deleting in placements.json, so the destroy that asks again reaches the device holding the bytes. Such a placement is no session: the capacity overlay leaves it out, and a fresh create under the id goes back to that device while it can take one, else is placed anew.
The cleanup read a destroy answer without `deletion` as complete, so a new platform talking to a spawner or device older than the contract settled rows, audited the deletion and counted an erasure while the bytes could still be in the old spawner's trash. The rule at the boundary (destroyOnSpawner): a deletion settles only on `done`, or on Kubernetes' `handed_off`, which the audit row records as `deletion: handed_off`. An answer without a state maps to the new pending outcome `deletion_unconfirmed`: the rows stay expired, nothing is audited, the sweep defers, the owner's and organization's jobs throw for a retry and the erasure's pass fails, so its receipt reads partial until an updated spawner answers. An unknown state fails the parse and stays pending too. The EN/DE/FR docs say when the audit row and the erasure count follow, including the Kubernetes hand-off, a not-yet-updated sandbox service or device, and a leftover nothing owns that can end without an event; the Kubernetes install page states what reclaimPolicy does to a deleted workspace's volume. The manual register names the new tests.
|
Exact-head CI, repair round 1:
No empty commit was needed in this round. |
|
Independent review of PR #4094 at
Local evidence at this head (on
Verified correct, from source (the review agent, cross-checked):
MEDIUM:
LOW
INFO
Repairs go through the manager. I'll re-review the next exact head. Root's P2 and the browser shard are done, and need no further evidence. |
…ending-until-bytes-deleted # Conflicts: # services/sandbox/src/backend/types.ts # services/sandbox/src/session/session-routes.ts
Review 168ebba2 (record 5967136448), MEDIUM: a placement marked deleting ended only on a later destroy that answered done, a fresh create under the id, or the device's removal. A run's reclaim is a plain if_idle destroy, usually answered pending right after the rename, and a run id is never destroyed or created again, so every device-placed run left its entry in placements.json for good. On its 30 s sweep the hub now asks each connected, compatible device about its deleting placements itself, at most every 5 minutes and 8 a sweep, with the cleanup's conditional destroy (if_idle, if_stopped, await_deletion): with no session under the id it only reads the trash and has it attempted again, and with a create or compute under way it answers busy and touches nothing. The answer goes through afterDestroy, so the route ends on done and stays on anything else: it lasts exactly as long as the bytes it leads to, whether or not the platform still asks. No TTL; the file format is unchanged. LOW 1: a create under a deleting id now goes through the normal placement loop with that device tried first, so it keeps inflightCreates and falls back on the next device or the server when the device refuses. LOW 5: tests now pin deletionOf's unreadable trash as pending, the hub's handed_off release and a deleting placement's absence from runtimeSessions.
On Kubernetes an erasure counts a workspace once its volume is handed to the storage provisioner; with a StorageClass whose reclaimPolicy is Retain, its files stay until an operator removes the volume. The EN/DE/FR data-subject-request pages now say so (review 168ebba2, INFO).
|
Exact-head CI, repair round 2:
Round 2 fixes the MEDIUM: the hub now asks devices about |
|
Independent re-review of PR #4094, round 2, at
Round-1 MEDIUM (
NEW MEDIUM: an ask answered while a create under the same id writes its placement either marks the new session's placement
LOW: the recheck goes in insertion order without rotating, so entries past about 80 starve.
Other unpinned guards (each one-change mutant passes all 124 device tests):
INFO
Verified correct
Next: the author's head with the count-before-write fix and its probe test, ideally with the rotation fix too. I'll re-review the delta. |
Review bfdb28db (record 5969884999), MEDIUM: placeCreate counted a create only after awaiting its placement write, so a destroy answered inside that write (the hub's own ask, every 5 minutes for a deleting placement) passed afterDestroy's recreated guard and acted on the new session's placement: `pending` marked it deleting, and the asks went on until one destroyed the session once its compute stopped; `done` dropped it, leaving the session unroutable. The create is now counted before the write. LOW: the asks went in insertion order, so past 80 unresolved placements the later ones were never asked. They now go least recently asked first. Tests pin both, and the guards that were unpinned: a device on another release is not asked, the sweep asks on its own (a test-only interval), and a create the server takes lets the old route go. devices.md now says what an ask does — the whole idempotent destroy, one Docker round trip — and both sandbox docs call 5 minutes a ceiling.
|
Exact-head CI, repair round 3:
Round 3 fixes the MEDIUM: the create is now counted before its placement write. It also fixes the LOW rotation (least recently asked first) and pins the three guards. The PR body has the finding → commit → test map, the failing-at- |
|
Independent re-review of PR #4094, round 3, at
Runtime (mine)
Whole-PR CI at the exact head (merge ref
Left open, as your PR body states:
None blocks. Root's round-1 thread
I'm replying on the thread with that evidence and resolving it. Merge: squash with |
What changed
A sandbox destroy answers once the workspace is out of use: the container is gone and
ses-<id>has been renamed into.trash/. Before this PR, the platform's workspace cleanup read that answer as deleted:sandbox_workspace.deletedas a success;All of that happened while the background pass could still be deleting the bytes, or failing to (#4090). This PR keeps those two facts apart, and settles a deletion only on an explicit completion signal. Interactive Destroy admission stays as fast as before, and #4088's bounded background deletion and boot sweep are unchanged.
Repair round 3: review bfdb28db (record 5969884999)
deleting(pending) or drops it (done).placeCreatecounted the create only after awaitingplacements.set.8e52b72cbhub.test.ts: an ask answered pending while a create under the id writes its placement leaves the new session's route alone, and the same for done. The reviewer's probe is now committed: the ask is held at the device,PlacementStore.writeSnapshotis gated, and the answer is released inside the window. Atd52a5abf2both fail withExpected [{pa-again, dev-1}], Received [].8e52b72cbhub.test.ts: a backlog of deleting placements is asked about 8 a sweep, least recently asked first, so none starves. It pins 8 on the first sweep and all 90 asked within 20 sweeps. Atd52a5abf2:Expected 90, Received 80.8e52b72cbhub.test.ts: a device on another release is not asked; the sweep asks on its own, with nobody calling it, through a new test-onlyHubOptions.sweepIntervalMs, so this test can't run atd52a5abf2; a create under a deleting id that the server takes lets the route to the old bytes go. The other two pin existing behaviour.devices.md:94understated what an ask does, and "every 5 minutes" is a ceiling.8e52b72cbdevices.mdandsessions.mdnow say it: the whole idempotent destroy, one Docker round trip, least recently asked first, at most every 5 minutes.The fix.
this.countCreate(create.sessionId)now runs before the awaitedplacements.set(...). A destroy answered during the write, the hub's own ask included, then finds the id created anew, andafterDestroyleaves the new placement alone.afterDestroy's own update runs in the same tick as its check, so nothing slips in between. The asks are now ordered least recently asked first, with never-asked placements before any, keeping the cap of 8 per sweep and the 5-minute ceiling.On the
d52a5abf2checkout, the round-3 hub tests: 38 pass, 4 fail.Expected [{pa-again, dev-1}], Received [].Expected 90, Received 80.At head
8e52b72cb:bun test: 773 pass across 44 files;tsc, oxlint andlint:manualclean.The platform code didn't change, so §5b and §5c and the M1 and M2 results stand.
mainwasn't merged this round: the PR wasMERGEABLE.Exact-head CI at
8e52b72cb: 52 pass, 11 skipping, 0 fail.workspace cleanup:record passing (job 111242927094).Repair round 2: review 168ebba2 (record 5967136448)
deletingplacements pile up without limit. A plainif_idlereclaim of a unique run id is answeredpending, nothing destroys or creates the id again, and the entry stays inplacements.jsonfor good.3f4c52551hub.test.ts: a placement a plain if_idle destroy left deleting ends once the device has deleted the bytes, though nobody asks for the id again, and a route stays while its device still says the bytes are there, or cannot say. Both fail at406803334, where no release mechanism exists.inflightCreates.3f4c52551hub.test.ts: a create sent back to a device still deleting the id falls back like any create when that device cannot take it (at406803334:Expected: 201, Received: 503)3f4c52551session-routes.test.tsa destroy whose deletion state cannot be read answers pending, never done;hub.test.tsa device that hands the volume off releases the route, and a destroyed session it still reports is no runtime session;placements.test.tsdeleting()reclaimPolicy: Retainthe volume's files stay.d52a5abf2CONFLICTINGwithmaina7efe1c51.848769daftypes.tsandsession-routes.tsconflicted, each with side-by-side declarations, and I kept both sides; sandbox suite 767 passThe release mechanism: the hub asks again. On its 30 s sweep, the hub asks each connected, compatible device about its
deletingplacements, at most every 5 minutes per placement and 8 per sweep.DELETE /v1/sessions/<id>?if_idle=1&if_stopped=1&await_deletion=1. With no session under the id, that only reads the trash and has what is left attempted again. With a create or compute under way, it answers busy and touches nothing.afterDestroy:doneorhanded_offends the route, and anything else keeps it. So a route lasts exactly as long as the bytes it leads to, whether or not the platform will ask again. An unsettled erasure keeps its route, and a reclaim's route ends once the device has deleted.placements.jsonis unchanged from round 1 (deleting: true). Rollback: a hub from before this PR reads adeletingentry as a live placement, so a create under that id sticks to its device, and the entry ends only on a confirming destroy or the device's removal.Behavioural reproduction at
406803334: a device answeredpendingto a plainif_idlereclaim ofwf-run-1. After a simulated week of hourly hub sweeps, with the device reporting status each hour, the placement was still routed and still persisted:New hub tests on a
406803334checkout: 33 pass, 3 fail.TypeError: hub.recheckDeleting is not a function, because there is no release mechanism there.Expected: 201, Received: 503.At head
d52a5abf2:bun test: 767 pass, 0 fail (44 files), with the touched files run 3 times clean;tsc, oxlint andlint:manualare clean.The platform code didn't change in this round, so §5b and §5c and their mutants stand as reviewed.
Exact-head CI at
d52a5abf2: 52 pass, 11 skipping, 0 fail.workspace cleanup:record passing, including §5b and §5c.Interaction with #4122 (out of scope): none. A fresh create after a Destroy still gets an empty workspace, which is what #4122 tracks. On a device, that create now tries the device holding the old bytes first.
Repair round 1: review 5396936242 and r4169908728
7d378b407, passes at head)deletionwas read as complete. The immediate base19776cf18already answers{destroyed, busy:false}once the workspace is renamed into.trash, with the bytes deleted in the background, so absence proves nothing.0ee40fff1,406803334workspace-cleanup.test.ts: settles only on an explicit completion — Docker's done or Kubernetes' hand-off — never on an older spawner's answer without one (at7d378b407:expected 'resolved'). Integration lanecheckWorkspaceCleanup§5c: no field →deletion_unconfirmed, rowsexpired, no audit; settled once updated.0ee40fff1hub.test.ts: a destroyed session keeps its route to the device until the device confirms the bytes are gone and a fresh session under an id whose bytes a device still deletes goes back there while it can, else is placed anew;placements.test.ts: …survives a restart, and is no session0ee40fff1,406803334k8s-session-backend.test.ts: states its own deletion contract… (route answersdeletion: handed_off);session_client.test.ts(at7d378b407:ZodErroronhanded_off); lane §5c: auditdeletion: handed_off406803334The completion signal.
SessionBackend.workspaceDeletionis now required, so every backend states its contract, and every destroy answer that isn't busy carriesdeletion:deletiondone.trash/ses-<id>.*entry leftpendingdeleting, pendingfaileddeletion_failed, pending, failure audithanded_offreclaimPolicymetadata.deletion: handed_off19776cf18)deletion_unconfirmed, pendingThe compatibility rule is written as a source comment at the boundary (
destroyOnSpawner). An unknown value fails the client's parse and stays pending too.A pending outcome means:
expiredand nothing is audited as deleted;retire_workspacesandretire_organizationthrow for the queue's retry, and the devices and the spawner teardown wait;sandboxWorkspacespass fails, so the receipt reads Partial and Retry settles it once an explicit completion arrives.Against an old spawner, nothing settles until it is updated. That is the intended trade.
The hub stays routable. It drops a destroyed session's placement only on
doneorhanded_off. Any other answer (pending,failed, or an older device's answer with no field) keeps the placement, markeddeletingand persisted inplacements.json, so the platform's next destroy, an erasure's Retry included, reaches the device holding the bytes.Integrated
main3b23bd2cb(b8aa26705, no conflicts) with a freshbun install --frozen-lockfilefor #4108's lockfile. #4095 gates only the interactive Destroy job, and composes: that path never readsdeletion, and its device placements now keep their route while deleting.The original fix (round 0)
e250b36b1,9fa1e555a,b31052865):WorkspaceTrash.deletion()reads the id's trash entries from disk: done, pending, or failed. Failure marks are kept in memory and pruned once their entry is gone.settle()retries the id's entries and waits a bounded time, waking only for its own entries.DELETE /v1/sessions/:id?await_deletion=1waits up to 10 s, after the per-id serialization is released.ee57301ae):sessionDestroyWorkspacealways sendsawait_deletion=1.deletinganddeletion_failedoutcomes are pending, as above.deletion_failedwritessandbox_workspace.deletedwith statusfailure(WORKSPACE_DELETION_FAILED).7d378b407is the empty commit for the round-0checkBellHintWireflake.Docs:
admin/sandboxes.md: when the audit row is written, the Kubernetes hand-off, a not-yet-updated sandbox service or device, and an ownerless leftover that can end without an event;admin/governance/data-subject-requests.md;self-hosted/install/kubernetes.md: whatreclaimPolicydoes to a deleted workspace's volume;services/sandbox/docs/sessions.md,docs/devices.mdandREADME.md;No UI string and no schema changed, so there is no migration. New log lines name session ids only: no secrets and no host paths.
How I verified it
Cross-version probe. The script is attached to TALE-475. It feeds the real
19776cf18WorkspaceTrash,DockerSessionBackendandSessionRoutes(fromgit archive) with a fakedocker, the bytes held in.trash(pending) or failing (EIO), into a platform's realretireWorkspaceandretireOrganizationSandboxes. Then a head process starts over the same root, as an update would.7d378b407406803334{destroyed:true, busy:false}(no field)destroyed, settles, bytes readabledeletion_unconfirmed, not settled, bytes readabledestroyed, settles, bytes readabledeletion_unconfirmed, not settled, bytes readableresolved, teardown ranthrew: … org-slice (deletion_unconfirmed), no teardowndeletion: done; both erasures settle, organization resolves and tears down, trash emptyNew tests on a
7d378b407checkout (the files copied over):On head
406803334:oxlint --type-awareandtscon the sandbox are clean. A targeted platformtscreports only the existingpdfjs_loader.tsTS7016 that the narrowed program surfaces.The round-0 evidence still stands. On
7d378b407, Backend integration passed 1432/1432, including §5b: pending gives(deleting), failed gives(deletion_failed), and Retry giveserased 1.Exact-head CI at
406803334: 52 pass, 11 skipping, 0 fail (comment).Left open
In the reviewer's wording where it applies (record 5967136448):
hub.ts, the placement loop's refusal branch). The trigger would be a malformed create.pendinganswer followed later by{destroyed: false, deletion: 'done'}writes the only success audit row withworkspaceFound: false(workspace-cleanup.ts:432). No test assertsworkspaceFound.workspace-cleanup.ts:293-295). An undeletable tree gets about 24 failure rows a day from the hourly sweep, for as long as it stays.done.deletingentry as a live placement, as described above.Closes #4090