Repository navigation
fix(sandbox): repair pruned cache volumes, keep the destroy mount lookup - #4154
Merged
Merged
Conversation
A package cache volume pruned inside the five-minute "volume ready" window (#4116) came back from the next session's `docker run --mount` as Docker makes a missing volume: no `tale.sandbox-cache` label, root-owned, 0755. The sessions' unprivileged uids could not write `/cache/{pip,npm,bun}`, and the ensure past the window read any existing volume as ready, so it was never repaired; the teardown refused it as unlabelled. The ensure now reads the volume's label, through the same inspect the teardown used, now one helper. A volume without it is removed and made again with its label and mode; one a session still holds is made writable (`chmod 1777`) with a warning, and replaced at a later check once free. An inspect that fails for another reason fails the ensure instead of reading as missing, and a volume whose chmod failed is removed, so a labelled volume always means a writable one. The teardown forgets a volume only after removing it, and an ensure in flight across a removal no longer marks the removed volume ready. Refs #4123
#4116 skipped the legacy workspace lookups (the container's /agent mount, the colour-directory scan) for every caller whenever the session root holds no colour directory. A destroy therefore stopped asking the container where its workspace is mounted: after a move of SANDBOX_HOST_SESSION_ROOT or of a device's state directory, a live session still mounted from the old root was destroyed without its data, and the answer counted it gone. The shortcut is now the caller's choice: a create and the hub's placement check take it, a destroy keeps the lookups. New tests also hold the filters that decide what counts as a colour directory (dot directories, lost+found, workspaces, plain files). Refs #4123
The removal of a volume whose chmod failed is dropped again: with busybox out of reach (pruned, rate-limited, a daemon without registry access) it turned every create of an organization without caches into a failure, where the previous code fails the first one and runs the rest without a writable cache. A volume a session holds that cannot be made writable now only warns, rather than failing creates that went through before. The "already exists" branch gets its tests, the volume fake clears its gates between tests, the state fake spins only on EEXIST, and the mount adoption log no longer says "resuming" on a destroy. Refs #4123
Contributor
Author
|
Independent review of PR #4154 at
Runtime (mine)
Source review, cross-checked
LOW (follow-ups; both are among your "decisions left open")
INFO
Merge: squash with |
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.
Why
Agent #2's post-merge review of #4116 (record 5967320911) found one MEDIUM and two LOWs on
main.The MEDIUM. A package cache volume pruned inside the five-minute "volume ready" window comes back from the next session's
docker run --mountthe way Docker creates a missing named volume: notale.sandbox-cachelabel, root-owned, mode 0755./cache/{pip,npm,bun}.What changes
The ensure checks the label (
volume.ts).volume inspect --format '{{json .Labels}}'the teardown used. That read is now one helper,cacheVolumeLabel.chmod 1777, as before.volume rm, then recreated with its label and mode.chmod 1777, plus a[sandbox.volume] … lacks the tale.sandbox-cache label and could not be replaced (…)warning. It then counts as ready for the window, and a later check replaces it once it is free. If the chmod cannot run either (busybox out of reach), the ensure only warns and the create goes on, as it did before this PR, with that cache still unwritable.Two more cases.
volume create(a refusal Podman gives; Docker answers success for an existing volume), the ensure succeeds only if the volume carries the label.The window comment at
volume.ts:138-142now says what really happens.LOW 1, teardown ordering (fixed).
removeCacheVolumesforgets a volume in afinallyafter the removal, not before. A counter of the volumes forgotten so far stops an ensure that was in flight across a removal from marking the removed volume ready.LOW 2, destroy lookup (fixed). The no-colour-directory shortcut is now opt-in (
flatRootShortcut).hasWorkspace) take it.destroySessionkeeps thedocker inspectmount lookup, as it had before perf(sandbox): ask the docker daemon less on every session create #4116, so a live session still mounted from an oldSANDBOX_HOST_SESSION_ROOTor device state directory is destroyed with its data.destroySession's lines changed, so nothing conflicts with fix(sandbox): keep erasure pending until workspace bytes are deleted #4094:git merge-treeagainst its head8e52b72cbis clean.INFO: tests for the named mutants. A clock going backwards, a failed ensure not counted as ready (set-before-await), and the dot-directory,
lost+found, workspace-directory and plain-file filters ofhasLegacyRoots.Docs. The
DELETE /v1/organizations/:idbullet inservices/sandbox/docs/sessions.mdnow says what a cache label means, why a volume can lack it, and how it is repaired.Verification
No Docker daemon was used. Everything runs against fake docker CLIs that model Docker's documented behaviour:
--mountof a missing named volume creates it unlabelled and 0755;volume createof an existing name succeeds and leaves its labels unchanged;volume rmrefuses a volume that is in use.Acceptance test (new
docker-session-cache-volumes.test.ts): a realDockerSessionBackendwith only runnerd mocked, against a stateful fake whoseruncreates a missing volume unlabelled.A second case keeps the window's session running, so the volumes are made writable at once, with three warnings. They are replaced at a later check once nothing holds them, and the teardown then succeeds.
Failing before (the final tests at
33a288bb6, run againstmain'svolume.tsanddocker-session-backend.tsat the merge base8cd10d7c1): 14 of 60 fail across the 5 files. They include:checkedCreatereads{write: false, labelled: false});exists(mounted)staystrue).Four of the 14 fail only because the inspect call now carries
--format.Passing after, at head
33a288bb6on8cd10d7c1:docker-workspaces: 60/60;services/sandboxbun test: 778/778.At
2eaefc3b0, before the third commit, exact-head CI read 28 pass, 13 skipped, 0 fail. Its Unit job ran the sandbox suite at 777/777, including the new tests by name.Static checks:
oxlint --type-aware --type-checkon the changed files: clean. A planted probe file proved it reports.oxfmt --check: clean.tsc --noEmit -p services/sandbox: clean.Mutation checks: 15 mutants, all killed:
hasLegacyRootsfilters dropped.The third commit comes from an adversarial pre-review by a separate read-only subagent (not the independent review).
Decisions and left open
/cache/{pip,npm,bun}at 1777, so that Docker's copy-up gives a recreated volume that mode (an image change, not verifiable without a daemon).docker-workspaces.test.ts:682-705. An organization deleted before any check repairs its volume gets a 502 on every sweep. The refusal also stops the teardown before it reaches that organization's later cache names, which was already the case. Making the teardown judge such a volume as the ensure does would reverse feat(platform): delete sandbox workspaces whose owner is gone or unused #4028's rule; that is the maintainer's call.listCacheVolumeOrganizationsstill lists by label only, so such a volume stays invisible to the orphan sweep until it is repaired.hasWorkspacekeeps perf(sandbox): ask the docker daemon less on every session create #4116's shortcut. A held session never reaches it, and a stopped one has no container to ask.main. This happens when the chmod fails, when the create times out after the daemon made the volume, or when the spawner restarts between the two. A removal on failure only helps once the chmod no longer depends on a lazily pulledbusybox:1.36. It could run in the always-present runtime image instead, or busybox could be pulled at boot.Closes #4123