Skip to content

fix(sandbox): keep erasure pending until workspace bytes are deleted - #4094

Merged
yannickmonney merged 12 commits into
mainfrom
fix/sandbox-erasure-pending-until-bytes-deleted
Oct 3, 2026
Merged

yannickmonney merged 12 commits into
mainfrom
fix/sandbox-erasure-pending-until-bytes-deleted

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • the erasure counted the workspace as erased;
  • the retirement audited sandbox_workspace.deleted as a success;
  • an organization's teardown went ahead.

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)

Finding Commit Regression
MEDIUM: an ask answered while a create under the same id writes its placement marks the new session's placement deleting (pending) or drops it (done). placeCreate counted the create only after awaiting placements.set. 8e52b72cb hub.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.writeSnapshot is gated, and the answer is released inside the window. At d52a5abf2 both fail with Expected [{pa-again, dev-1}], Received [].
LOW: the recheck went in insertion order, so past about 80 unresolved entries the later ones starved, and the cap of 8 was unpinned. 8e52b72cb hub.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. At d52a5abf2: Expected 90, Received 80.
Unpinned: the compatibility check, the sweep wiring, and the route drop when a create falls to the server. 8e52b72cb hub.test.ts: a device on another release is not asked; the sweep asks on its own, with nobody calling it, through a new test-only HubOptions.sweepIntervalMs, so this test can't run at d52a5abf2; a create under a deleting id that the server takes lets the route to the old bytes go. The other two pin existing behaviour.
INFO: devices.md:94 understated what an ask does, and "every 5 minutes" is a ceiling. 8e52b72cb devices.md and sessions.md now 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 awaited placements.set(...). A destroy answered during the write, the hub's own ask included, then finds the id created anew, and afterDestroy leaves 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 d52a5abf2 checkout, the round-3 hub tests: 38 pass, 4 fail.

  • The two race tests fail with Expected [{pa-again, dev-1}], Received [].
  • The backlog test fails with Expected 90, Received 80.
  • The sweep test fails because the test-only interval doesn't exist there.

At head 8e52b72cb:

  • sandbox bun test: 773 pass across 44 files;
  • hub, placements and session routes: 160 pass, 3 runs clean;
  • tsc, oxlint and lint:manual clean.

The platform code didn't change, so §5b and §5c and the M1 and M2 results stand. main wasn't merged this round: the PR was MERGEABLE.

Exact-head CI at 8e52b72cb: 52 pass, 11 skipping, 0 fail.

  • Backend integration passed 1509/1509 across 222/222 lanes, with every workspace cleanup: record passing (job 111242927094).
  • Playwright platform 11/16 passed (job 111243007566).
  • No empty commit was needed.

Repair round 2: review 168ebba2 (record 5967136448)

Finding Commit Regression
MEDIUM: deleting placements pile up without limit. A plain if_idle reclaim of a unique run id is answered pending, nothing destroys or creates the id again, and the entry stays in placements.json for good. 3f4c52551 hub.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 at 406803334, where no release mechanism exists.
LOW 1: a create routed back to a deleting device loses the 429/503/5xx fallback and inflightCreates. 3f4c52551 hub.test.ts: a create sent back to a device still deleting the id falls back like any create when that device cannot take it (at 406803334: Expected: 201, Received: 503)
LOW 5: surviving mutants. 3f4c52551 Each of these pins existing behaviour, kills its mutant, and passes at both heads: session-routes.test.ts a destroy whose deletion state cannot be read answers pending, never done; hub.test.ts a device that hands the volume off releases the route, and a destroyed session it still reports is no runtime session; placements.test.ts deleting()
INFO: with reclaimPolicy: Retain the volume's files stay. d52a5abf2 docs suite, 250 pass
CONFLICTING with main a7efe1c51. 848769daf only types.ts and session-routes.ts conflicted, each with side-by-side declarations, and I kept both sides; sandbox suite 767 pass

The release mechanism: the hub asks again. On its 30 s sweep, the hub asks each connected, compatible device about its deleting placements, at most every 5 minutes per placement and 8 per sweep.

  • It sends the platform cleanup's own conditional destroy: 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.
  • The answer goes through the same afterDestroy: done or handed_off ends 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.
  • Not a TTL: a TTL could drop a route that an unsettled erasure still needs.
  • What stays bounded: state is limited to bytes still on a connected device, and there is one write per release. A device older than the contract keeps its entries until it updates (devices self-update), and the next ask then ends them. The asked-at times are kept in memory only, so a restarted hub asks at once.
  • placements.json is unchanged from round 1 (deleting: true). Rollback: a hub from before this PR reads a deleting entry 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 answered pending to a plain if_idle reclaim of wf-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:

{"stillRouted":true,"persisted":{"deviceId":"dev-1","organizationId":"org_a","placedAtMs":1800000000000,"deleting":true}}

New hub tests on a 406803334 checkout: 33 pass, 3 fail.

  • 2 fail with TypeError: hub.recheckDeleting is not a function, because there is no release mechanism there.
  • 1 fails with Expected: 201, Received: 503.

At head d52a5abf2:

  • sandbox bun test: 767 pass, 0 fail (44 files), with the touched files run 3 times clean;
  • platform sandbox, session-client and erasure vitest: 391 pass (30 files) on the merge;
  • docs: 250 pass;
  • tsc, oxlint and lint:manual are 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.

  • Backend integration passed 1500/1500 across 219/219 lanes, with every workspace cleanup: record passing, including §5b and §5c.
  • Playwright platform 11/16 passed (job 111191936267).
  • No empty commit was needed in this round.

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

Finding Commit Regression (fails at 7d378b407, passes at head)
[P2] A destroy answer without deletion was read as complete. The immediate base 19776cf18 already answers {destroyed, busy:false} once the workspace is renamed into .trash, with the bytes deleted in the background, so absence proves nothing. 0ee40fff1, 406803334 workspace-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 (at 7d378b407: expected 'resolved'). Integration lane checkWorkspaceCleanup §5c: no field → deletion_unconfirmed, rows expired, no audit; settled once updated.
The hub released placement on that no-field answer, losing the route to a device still holding the bytes. 0ee40fff1 hub.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 session
Kubernetes' PVC hand-off can't be told apart from the older Docker answer by a missing field. 0ee40fff1, 406803334 k8s-session-backend.test.ts: states its own deletion contract… (route answers deletion: handed_off); session_client.test.ts (at 7d378b407: ZodError on handed_off); lane §5c: audit deletion: handed_off
The EN/DE/FR audit wording has to state the ownerless-inventory limitation. 406803334 docs suite (249 pass)
The browser gate was incomplete: shard 11/16 never ran. n/a exact-head CI below, with a real shard 11/16 run

The completion signal. SessionBackend.workspaceDeletion is now required, so every backend states its contract, and every destroy answer that isn't busy carries deletion:

Backend deletion Meaning Platform
Docker done no .trash/ses-<id>.* entry left settles
Docker pending still waiting or being deleted deleting, pending
Docker failed the last removal attempt failed deletion_failed, pending, failure audit
Kubernetes handed_off the PVC delete was accepted; the volume is the provisioner's under the StorageClass's reclaimPolicy settles; audit metadata.deletion: handed_off
a spawner or device older than this contract (e.g. 19776cf18) (absent) proves nothing about the bytes deletion_unconfirmed, pending

The 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:

  • the claimed rows stay expired and nothing is audited as deleted;
  • the sweep defers;
  • retire_workspaces and retire_organization throw for the queue's retry, and the devices and the spawner teardown wait;
  • the erasure's sandboxWorkspaces pass 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 done or handed_off. Any other answer (pending, failed, or an older device's answer with no field) keeps the placement, marked deleting and persisted in placements.json, so the platform's next destroy, an erasure's Retry included, reaches the device holding the bytes.

  • Such a placement is no session: the capacity overlay leaves it out.
  • A fresh create under the id goes back to that device while it is connected with room. Otherwise it is placed anew and the route is let go, so a new session never waits on an old workspace's bytes.

Integrated main 3b23bd2cb (b8aa26705, no conflicts) with a fresh bun install --frozen-lockfile for #4108's lockfile. #4095 gates only the interactive Destroy job, and composes: that path never reads deletion, and its device placements now keep their route while deleting.

The original fix (round 0)

  • Sandbox (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=1 waits up to 10 s, after the per-id serialization is released.
  • Platform (ee57301ae):
    • sessionDestroyWorkspace always sends await_deletion=1.
    • The deleting and deletion_failed outcomes are pending, as above.
    • deletion_failed writes sandbox_workspace.deleted with status failure (WORKSPACE_DELETION_FAILED).
  • 7d378b407 is the empty commit for the round-0 checkBellHintWire flake.

Docs:

  • the EN/DE/FR 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;
  • the EN/DE/FR admin/governance/data-subject-requests.md;
  • the EN/DE/FR self-hosted/install/kubernetes.md: what reclaimPolicy does to a deleted workspace's volume;
  • services/sandbox/docs/sessions.md, docs/devices.md and README.md;
  • the manual register.

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 19776cf18 WorkspaceTrash, DockerSessionBackend and SessionRoutes (from git archive) with a fake docker, the bytes held in .trash (pending) or failing (EIO), into a platform's real retireWorkspace and retireOrganizationSandboxes. Then a head process starts over the same root, as an update would.

bun predecessor-probe.ts <19776cf18 sandbox> <platform checkout> [<updated sandbox>]
platform 7d378b407 platform head 406803334
predecessor answer {destroyed:true, busy:false} (no field) same
erasure retire, deletion pending destroyed, settles, bytes readable deletion_unconfirmed, not settled, bytes readable
erasure retire, deletion failing destroyed, settles, bytes readable deletion_unconfirmed, not settled, bytes readable
organization retirement resolved, teardown ran threw: … org-slice (deletion_unconfirmed), no teardown
spawner updated (head process, same root) n/a answers deletion: done; both erasures settle, organization resolves and tears down, trash empty

New tests on a 7d378b407 checkout (the files copied over):

cd services/sandbox && bun test src/devices/hub.test.ts src/devices/placements.test.ts src/backend/kubernetes/k8s-session-backend.test.ts
  → 52 pass, 4 fail (the four new tests)
cd services/platform && bunx vitest run backend/domains/sandbox/workspace-cleanup.test.ts backend/core/node_only/sandbox/helpers/session_client.test.ts
  → 2 failed | 38 passed  (AssertionError: expected 'resolved' to match /: pa-1 \(deletion_unconfirmed\)$/; ZodError on handed_off)

On head 406803334:

cd services/sandbox && bun test        → 652 pass, 0 fail (39 files); the touched files 3× clean
cd services/platform && bunx vitest run --maxWorkers=2 backend/domains/sandbox backend/domains/erasure \
  backend/core/node_only/sandbox/helpers backend/auth/membership.cascade.test.ts \
  backend/domains/organizations/service.test.ts backend/domains/projects/service.delete.test.ts \
  backend/domains/projects/service.agents.test.ts backend/core/node_only/sandbox/agent_session.test.ts
                                       → 34 files, 467 passed
cd services/docs && bun run test       → 37 files, 249 passed
bunx knip                              → clean
bun run lint:manual                    → ok

oxlint --type-aware and tsc on the sandbox are clean. A targeted platform tsc reports only the existing pdfjs_loader.ts TS7016 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 gives erased 1.

Exact-head CI at 406803334: 52 pass, 11 skipping, 0 fail (comment).

  • Playwright platform 11/16 ran its suite: 4 passed on the first attempt (run 37106479834, job 111156136274).
  • Backend integration passed 1489/1489 across 218/218 lanes, including §5b and §5c.

Left open

In the reviewer's wording where it applies (record 5967136448):

  • INFO, 4xx create: a create for a deleting id that is refused with a 4xx other than 409 drops the old route (hub.ts, the placement loop's refusal branch). The trigger would be a malformed create.
  • INFO, ask timeout: a hub-originated ask has no timeout of its own. It relies on the device's limits, and a dropped tunnel answers 503, which keeps the route.
  • LOW 2: the audit can say the workspace wasn't found when it was. The common sequence of a pending answer followed later by {destroyed: false, deletion: 'done'} writes the only success audit row with workspaceFound: false (workspace-cleanup.ts:432). No test asserts workspaceFound.
  • LOW 3: one failure audit row per attempt (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.
  • LOW 4: the 10 s wait could overrun a retirement attempt. This is a hypothesis: the waits run one after another within a 500-session retirement slice, against a 900 s job expiry. If removals average more than about 1.8 s, the attempt expires and an overlapping retry is queued.
  • INFO, a route lost to device removal or re-placement: this can settle an erasure early on another host. A removed device's workspaces stay on the machine and out of reach, as before. A fresh create placed away from a deleting device lets go of that route. Either way, the erasure's next destroy reaches a host that never held those bytes, which answers done.
  • INFO, rollback: a hub from before this PR reads a deleting entry as a live placement, as described above.
  • Rolling update: in a rolling update that updates the platform before the server spawner, an older hub still drops a device placement on its first destroy. The updated hub can't restore that route.
  • Ownerless leftovers: a workspace that nothing owns, found only through the inventory, whose bytes outlast the 10 s wait, gets no success audit row. The docs say so.
  • Out of scope: Follow-ups from the #4095 review: a Destroy attempt settles a fresh incarnation, expiry overlap, id-only activation #4106, bug(platform): replacing or deleting a product's image deletes bytes a task lists #4110, Follow-ups from the #4099 review: a pending Destroy turns an automation step into a 2-hour wait, then runs it in an empty workspace #4122–Follow-ups from the #4097 review: a second steer lifts the first steer's hold, the no-shim rotation survivor, the per-exec environ scan #4125 and the ownerless-inventory listing.

Closes #4090

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 yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

yannickmonney added a commit that referenced this pull request Oct 3, 2026
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.
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.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Exact-head CI, repair round 1: 406803334. 52 pass, 11 skipping, 0 fail.

  • Playwright (platform 11/16) ran for real: run 37106479834, job 111156136274. Install Playwright Chromium succeeded, then Run E2E suite (shard 11/16) ran 4 tests and passed all 4 on the first attempt, with no diagnostics kept.
  • Backend integration passed 1489/1489 checks across 218/218 lanes, including the erasure-caller sequences:
    • §5b: pending gives (deleting), rows expired, no audits; failed gives (deletion_failed) and a [failure] audit; the Retry gives erased 1 with [failure, success].
    • §5c: an older spawner's answer without a state gives (deletion_unconfirmed), rows expired, no audits. After the update it gives erased 1 with deletion: done. Kubernetes gives erased 1 with deletion: handed_off.
  • Every other check passes: Knip, Lint, Lint commits, Type check, Unit, UI, Browser, Format, Opengrep, Storybook, the image builds, scans and the smoke test.

No empty commit was needed in this round.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4094 at 406803334c3c59d6b2c31704d10c6a3066ab90dd: changes required (1 MEDIUM, introduced by this repair round). Root's P2 is fixed and pinned.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run 6b60fb49-b479-4eeb-850a-951812ec31f3.
  • Implementation: agent add --chat-max-width CSS variable #3 4aec6e61, runs 39cf3515 and 923811f1. This run is distinct.
  • Method: my own runs, plus one read-only review agent; I re-checked the MEDIUM in source.

Local evidence at this head (on main 3b23bd2cb plus the PR):

  • Changed tests: the sandbox test files pass 170/170 (6 files) and the platform test files 40/40 (session_client.test.ts, workspace-cleanup.test.ts).
  • Real Postgres, ITEST_LANES=checkWorkspaceCleanup: 33/34. The one failure is BM25, which needs pg_search. Both new sequences pass: "not done while the files are still being deleted or their deletion fails; its Retry settles it" (§5b), and "an older spawner's answer without a deletion state never settles an erasure; an update does, and Kubernetes' hand-off is recorded as such" (§5c).
  • One-change mutants of destroyOnSpawner, each caught by the lane (32/34):
    • M1, an answer without deletion settles again (the predecessor's reading): §5c fails, whileLegacy: erased 1, status destroyed, audits [success]. This is root's P2.
    • M2, pending settles: §5b fails, whileDeleting: erased 1, status destroyed.
  • CI at the exact head (merge ee6dd55 into 3b23bd2cb):
    • 52 success, 10 skipped by design and Trivy neutral.
    • Backend integration: 1489/1489 across 218/218, with 0 FAIL lines.
    • Playwright platform 11/16 really ran: job 111156136274, 4 passed (34.6s).

Verified correct, from source (the review agent, cross-checked):

  • Every answer carries the field. Every non-busy destroy answer carries deletion, computed after the per-id serialization. A 502 carries none, and the platform treats it as pending.
  • Trash matching is safe. It matches ses-<id>. against ids [a-zA-Z0-9_-], so ses-1 never matches ses-10.*.
  • deletion() reads the disk, and settle() is bounded.
  • Pending holds everywhere. Every pending outcome leaves the rows expired with no success audit. The retire jobs throw before teardown, and the erasure pass fails, so the receipt reads Partial.
  • The erasure after fix(platform): refuse new work in a sandbox being destroyed #4095's interactive Destroy stays accurate. It destroys again with the wait (settled: true) and counts only done.
  • The hub releases a route only on done or handed_off. It excludes deleting placements from capacity and from forOrganization, and checks the organization before the deleting branch.
  • The EN/DE/FR docs state the ownerless-inventory limitation consistently.

MEDIUM: deleting placements pile up without limit when the platform never repeats a destroy.

  • Where:
    • hub.ts:514-552 (afterDestroy) marks a placement deleting on any answer other than done or handed_off.
    • It is released only by a later done destroy, a fresh create under the same id (hub.ts:445), or device removal (placements.ts:132).
  • Path:
    1. An automation run is placed on device D.
    2. The run ends, and reclaimEndedRunSessions sends destroyIfIdle without await_deletion (watchdogs.ts:455).
    3. D answers right after the rename, so its answer is typically pending.
    4. The hub marks the placement deleting.
    5. The platform settles the row (watchdogs.ts:470).
    6. Run ids are unique, so nothing ever destroys or creates that id again. The placement, and its creates entry, stay in placements.json forever.
  • The same happens on: the failed-create cleanup, fix(platform): refuse new work in a sandbox being destroyed #4095's interactive Destroy, and every destroy that reaches an older device (no field).
  • Why it matters: each placement write re-serializes the whole map, so the file and the write cost grow with every device-placed run.
  • Status: from source, and I re-read both sites. The PR's "Left open" list doesn't mention it, and the hub tests always destroy or create the id again.
  • Fix: let a deleting placement end on its own. For example, the device's status could list the trash ids still pending, the hub could re-probe deleting placements, or a TTL could apply.
  • Test: a device answers pending to a plain if_idle destroy, and the test asserts the placement is eventually released.

LOW

  1. A deleting placement loses the create fallback (hub.ts:430-450). A create routed back to device D that answers 429, 503 or 5xx fails the turn instead of trying the next device or local. The normal candidate loop would, and the comment at hub.ts:425-429 promises that a new session never fails for old bytes. The branch also skips inflightCreates.
  2. The audit can say the workspace wasn't found when it was. The common sequence of a pending answer followed later by {destroyed: false, deletion: 'done'} writes the only success audit row with workspaceFound: false (workspace-cleanup.ts:432). No test asserts workspaceFound.
  3. One failure audit row per attempt (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.
  4. The 10 s wait could overrun a retirement attempt. This is a hypothesis: the waits run one after another within a 500-session retirement slice, against a 900 s job expiry. If removals average more than about 1.8 s, the attempt expires and an overlapping retry is queued.
  5. Mutants that would survive:
    • deletionOf's catch reading pending (session-routes.ts:1231);
    • the hub's handed_off release;
    • the deleting exclusion in the capacity overlay.

INFO

  • reclaimPolicy: Retain: the data-subject-request pages don't say that with Retain the volume's files stay. Only kubernetes.md does, and the receipt reads complete either way.
  • A route lost to device removal or re-placement can settle an erasure early on another host. It is listed as left open, but its effect on the receipt isn't documented.
  • Rollback: a hub from before this PR would read deleting entries as live placements.

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).
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Exact-head CI, repair round 2: d52a5abf2. 52 pass, 11 skipping, 0 fail.

  • Backend integration passed 1500/1500 checks across 219/219 lanes, and every workspace cleanup: record passed, including §5b and §5c (job 111191804375).
  • Playwright platform 11/16 passed (job 111191936267).
  • Every other check passes: Knip, Lint, Lint commits, Type check, Unit, UI, Browser, Format, Opengrep, Storybook, the image builds, scans and the smoke test.

Round 2 fixes the MEDIUM: the hub now asks devices about deleting placements itself, so a placement ends once its bytes are gone. It also fixes LOW 1, adds the LOW 5 mutant tests, adds the Retain note, and merges main a7efe1c51. The PR body has the finding → commit → test map, the failing-at-406803334 evidence and the Left open list. No empty commit was needed in this round.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent re-review of PR #4094, round 2, at d52a5abf21f1f81219bb6e2a19758d7d63b34b09: changes required. There is one new MEDIUM, a race between the hub's own asks and a fresh create. I reproduced it at runtime, and it has a one-line fix. My round-1 MEDIUM is fixed apart from one LOW.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run dea040d6-b37f-49a1-a4a0-fdef67ce4ee8.
  • Implementation: agent add --chat-max-width CSS variable #3 4aec6e61, TALE-475. The runs are distinct.
  • Reviewed: the new commits since 406803334: 848769daf (the merge of a7efe1c51), 3f4c52551 and d52a5abf2.
  • Method:
    • I read them as an interdiff against git merge-tree a7efe1c51 406803334.
    • One read-only source reviewer, whose claims I cross-checked.
    • Hub mutants, and an untracked probe test.

Round-1 MEDIUM (deleting placements piled up): fixed.

  • The 30 s sweep asks each connected, compatible device about its deleting placements (hub.ts:229-264), and afterDestroy lets a route go on done or handed_off (:598).
  • The ask-time map is pruned on every sweep (:231-235), and markDeleting writes once (placements.ts:131).
  • My mutants that the tests catch:
    • no release on handed_off;
    • no 5-minute gate;
    • no if_stopped=1;
    • a missing deletion field read as done (3 tests fail);
    • no preferred-first sort;
    • an ask without await_deletion=1.

NEW MEDIUM: an ask answered while a create under the same id writes its placement either marks the new session's placement deleting or drops it.

  • Where:
    • placeCreate awaits placements.set(...) (hub.ts:534), and only after that calls countCreate (:539).
    • afterDestroy checks only that create count (:611), then calls delete (:615) or markDeleting (:618) on whatever placement is there now.
  • Interleaving:
    1. A sweep ask for X is in flight to D1.
    2. The user starts a new session under X (deterministic ids are re-created by design).
    3. placeCreate sets the new {D1} placement and awaits the file write.
    4. D1's answer lands in that window. recreated is false, so afterDestroy acts on the new placement.
  • Reproduced (untracked bun test probe, at the head): I built it from hub.test.ts's own helpers and held the ask, gating PlacementStore.writeSnapshot to keep the window open.
    • Answer pending: the create returns 201, then the placement reads {"deviceId":"dev-1",…,"deleting":true}. Five minutes later the hub sends its conditional destroy about the live new session.
    • Answer done: the create returns 201, but the placement is null and a GET for X is no longer routed.
  • Consequences, read from the source rather than run:
    • With pending, the asks repeat every 5 minutes. Once D1's idle sweep stops the session's compute, if_idle=1&if_stopped=1 no longer answers busy (session-routes.ts:1843-1849). The ask then destroys the session, and the preserved workspace goes to the trash (docker-session-backend.ts:730-775). The user's files are deleted without anyone asking.
    • With done, the session on D1 is orphaned: unroutable, and out of reach of a later erasure.
  • Window and reach: the window is one placements write, and longer behind queued writes. Round 1 had the same window for the platform's own destroys. Round 2 sends these asks every 5 minutes for every deleting placement, and right after an interactive Destroy, which is exactly when a new session under the id is likely.
  • Fix, tested: move this.countCreate(create.sessionId) before the awaited placements.set(...) in placeCreate.
    • With that one change, the same probe keeps a plain, routed {dev-1} placement and sends no ask, for both answers.
    • All 36 hub tests still pass.
    • Comparing the placement object the destroy was forwarded under would work too.
  • Regression test: the probe above. Gate the write, hold the ask, start the create, release the answer, then release the write. Assert the placement isn't deleting, that it stays routed, and that no ask goes out after now += 5 min.

LOW: the recheck goes in insertion order without rotating, so entries past about 80 starve.

  • placements.deleting() iterates in Map order (hub.ts:237), and the loop breaks after 8 asks (:238).
  • At 8 asks per 30 s sweep, at most 80 ids are asked per 5 minutes. With more than 80 unresolved deleting placements, for example persistent failed deletions on one device, the first 80 are asked again forever, and later entries, from any organization, never are. That reproduces the round-1 pile-up for them.
  • The per-sweep cap is unpinned: removing it passes every test.
  • Fix: ask the least recently asked first.
  • Tests: 9 placements give 8 then 1 ask; 90 failed placements over 20 sweeps are each asked at least once.

Other unpinned guards (each one-change mutant passes all 124 device tests):

  • dropping the compatible(device) check in recheckDeleting (:240);
  • dropping the route drop when a deleting id's create falls to the server (:501-503);
  • removing void this.recheckDeleting() from the sweep interval (:214). The tests call recheckDeleting() directly, so the wiring itself is untested.

INFO

  • devices.md:94 says an ask "only reads the trash". In fact it runs the full idempotent destroy (listSessions, inspect, rm -f, the volume removal, the markers, discard). That is harmless, but it costs one Docker round trip per ask.
  • "Every 5 minutes per placement" (sessions.md:333) is a ceiling, not a guarantee.
  • A create for a deleting id that is refused with a 4xx other than 409 drops the old route (hub.ts:563-565). The trigger would be a malformed create, so this is an edge case.
  • A hub-originated ask has no timeout of its own (hub.ts:256). It relies on the device's limits.

Verified correct

  • The question is safe while the placement invariant holds:
    • With no session under the id, settle retries the deletion (workspace-trash.ts:166-197).
    • While a create or compute is under the id, the ask answers busy: creating is checked before and after holdsCompute (session-routes.ts:1843-1849, 1878-1895).
    • Outdated devices are never asked, because versionsCompatible requires an equal version.
    • An offline device is skipped, and a drop mid-ask is a 503, which afterDestroy ignores.
    • There is a single hub process (the Docker backend), and asks never reject.
  • LOW 1 fixed: a create under a deleting id goes through placeCreate with that device first, with inflightCreates and the 429/5xx fallback.
  • The merge 848769daf:
    • types.ts keeps both sides, and workspaceDeletion stays required.
    • handleDestroy composes main's waiters.delete and endedReaping with the PR's deletion.
    • No exported symbol was renamed.
  • The EN/DE/FR Retain sentence matches Kubernetes always answering handed_off.
  • Tests at the head (mine): services/sandbox devices plus session-routes: 239/239.
  • CI at the head: all 5 workflows passed at attempt 1. Check runs: 52 success, 10 skipped and 1 neutral. I didn't re-trace the job logs, since changes are required.
  • Platform code: unchanged this round, so my round-1 M1 and M2 results on §5b and §5c still apply.

mergeStateStatus is BLOCKED by root's unresolved round-1 thread r4169908728 ("Preserve unknown legacy deletion as pending"). Its fix is pinned: my round-1 M1, and this round's mutant (e) fails 3 tests. It can be resolved when this PR is accepted.

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.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Exact-head CI, repair round 3: 8e52b72cb. 52 pass, 11 skipping, 0 fail.

  • Backend integration passed 1509/1509 checks across 222/222 lanes, and every workspace cleanup: record passed (job 111242927094).
  • Playwright platform 11/16 passed (job 111243007566).
  • Every other check passes: Knip, Lint, Lint commits, Type check, Unit, UI, Browser, Format, Opengrep, Storybook, the image builds, scans and the smoke test.

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-d52a5abf2 output and the Left open list. Root's thread r4169908728 is left for the reviewer.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent re-review of PR #4094, round 3, at 8e52b72cbb266da3c1c4c059ad0d9347917753f3: accepted.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run a721a46a-c362-49ac-8936-9fa055181d29.
  • Implementation: agent add --chat-max-width CSS variable #3 4aec6e61, TALE-475 run f768ad7f. The runs are distinct.
  • What this round answers: my round-2 record 5969884999 (TALE-475 bfdb28db).
  • The delta: the single commit 8e52b72cb on top of d52a5abf2, with no force push.
Round-2 finding Status at 8e52b72cb
MEDIUM: an ask answered during a create's placement write marked the new session deleting or dropped its route Fixed. countCreate now runs before the awaited placements.set (hub.ts:542-546). My untracked bun test probe (gated writeSnapshot, a held ask) now gives placement={"deviceId":"dev-1",…} with no deleting, routed=true and asksOnNewSessionAfter5min=0, for both the pending and done answers. Your committed test is the same scenario.
LOW: the recheck went in insertion order and starved entries past about 80 Fixed. It now asks least recently asked first, at most 8 per sweep (hub.ts:239-256). Removing the sort or the cap fails "a backlog of deleting placements is asked about 8 a sweep, least recently asked first, so none starves".
Unpinned guards Now pinned: without the compatibility check, "a device on another release is not asked" fails. Without the sweep wiring, or without the route drop on a server fallback, one test fails each.
INFO (docs) Fixed: devices.md now says an ask runs the whole idempotent destroy (one Docker round trip), and sessions.md says "at most every 5 minutes per placement".

Runtime (mine)

  • Sandbox device tests at the head: 132/132 (130, plus my probe's 2 cases).
  • Composition with current main aa2e73974: root's fix(sandbox): release resources safely under concurrent load #4150 (8cd10d7c1) also edits session-routes.ts, and CI tested a merge onto 3a28bff12, before fix(sandbox): release resources safely under concurrent load #4150. git merge-tree is clean. On a local commit of main + this head (1a1db0daf, never pushed):
    • the full services/sandbox suite passes 798/798;
    • real PG 16.14 lanes checkWorkspaceCleanup and checkAutomationStepDestroyPending pass 34/35 (only the BM25 boot check fails, for lack of pg_search).
  • Platform code: unchanged since round 1. A missing deletion field still becomes deletion_unconfirmed (workspace-cleanup.ts:379-395), and my round-1 mutants M1 and M2 stand.

Whole-PR CI at the exact head (merge ref 52f2bea, onto 3a28bff12)

  • Workflows: all five ran at attempt 1 and succeeded: Checks 37136294132, Build 37136294075, E2E 37136294083, SAST 37136294081 and Commitlint 37136294082.
  • Check runs: 52 success, 10 skipped by design (5 Candidate gates, 2 fork-PR jobs, 3 other services' container tests) and Trivy neutral.
  • Backend integration: 1509/1509 across 222/222 lanes.

Left open, as your PR body states:

  • a 4xx create for a deleting id drops the route;
  • a hub-originated ask has no timeout of its own;
  • the round-2 INFOs.

None blocks.

Root's round-1 thread r4169908728: the fix is pinned twice:

  • my round-1 M1 (checkWorkspaceCleanup);
  • round-2 mutant (e), which fails 3 hub tests.

I'm replying on the thread with that evidence and resolving it.

Merge: squash with --match-head-commit through my gate, which dry-runs first.

@yannickmonney
yannickmonney merged commit 106d43f into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-erasure-pending-until-bytes-deleted branch October 3, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(sandbox): erasure succeeds before trash bytes are deleted

1 participant