Repository navigation
remote-worker: a worker sweeps leftover workspaces at start (part of #338) - #954
Conversation
…ss left A restarted worker's runs map starts empty, so its idle sweep never reached a workspace the previous process left, and on a host with no janitor (deploy/microvm) those stayed on disk for good (rossoctl#338's restart leak). - microVM tier: vmpool.New sweeps WorkspaceRoot once before serving. It removes every .reclaiming-* tombstone, and every key-named directory no run owns whose newest mtime (the directory's or its workspace.img's) is older than WorkspaceIdle: the host janitor's rule for an unknown directory. The rename happens under p.mu, the delete on the reclaim goroutine; a symlink is removed as the link itself; the key's lease state is retired as the idle sweep does; entries no key can name (.lease-state, _probe) are left alone. - Container tier: the worker removes tombstones only at startup. Its root is also the shared workspace, so a name alone cannot tell a key's workspace from shared content, and it still never adopts an unknown directory. - Docs: the P4 page's workspace-lifetime section and the P4 spec's rossoctl#338 note. Part of rossoctl#338 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review — remote-worker: a worker sweeps leftover workspaces at start (part of #338)
The leak is real and the shape is right: a restarted worker's runs map is empty, so nothing ever reached the previous process's directories, and on a host with no janitor they stayed for good.
- Order in
Newis correct:Normalize(soWorkspaceIdleis the 30-minute default, never zero), thenmarkLeaseBoot, thenendLeasesOpenAtStart, then the sweep — andreclaimLoopis already running, so the detach happens underp.muand the recursive deletes run off the constructor, as the idle sweep's do. - The rule is the janitor's for an unknown directory: a name
checkKeyaccepts, in no run here, whose newer mtime — the directory's or itsworkspace.img's — is older thanWorkspaceIdle.workspace.imgmatters because the guest's writes land in the image, not the directory. A younger one is kept, which is the case that would otherwise eat a session between turns. - What cannot be adopted is left alone:
checkKeyrefuses.lease-state,_probeand anything else not a key, live runs are skipped, and the container tier removes tombstones only — its root doubles as the shared workspace, so a name alone cannot tell a key from shared content. That asymmetry is the right call and both docs say so. - Lease state:
retireLeaseStatewith no state file isremoveLeaseState, a no-op when the file is absent, so calling it unconditionally is safe on a lease-off pool; when the file exists the mode and epoch outlive the tree, as the idle sweep has it. - A symlink is judged by the link's own mtime and removed as the link (
Lstat, rename,RemoveAllnever follows) — tested, target intact. Files:newestWorkspaceMtimealso accepts a non-directory named as a key, so an old plain file at the root would be removed too.
One optional note, not blocking: that last case is the one place the "the janitor's rule" claim is a little broader than the janitor, which leaves every non-directory alone ("not a directory (symlink or file); left alone"). The symlink half is deliberate and documented; if the plain-file half is too, a clause in the comment would keep the comparison exact — or require IsDir and skip files, which costs nothing since the worker only ever creates directories.
Tests cover the sweep and its edges well: old, young, old-with-recent-image, a live run's workspace, an old symlink, tombstones, and _probe/.lease-state kept. Checks 18/18 green. Author: webchang (MEMBER — maintainer). One commit, signed off.
Keeps both tests in workspace_release_test.go: the startup sweep's and rossoctl#953's failed-rename Release. Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up review — head moved to 8b1c4c72 (merge of main only)
Nothing of the PR's own changed since the APPROVE at e8be2aed. git log --no-merges origin/main..refs/pr/954 is still the single commit e8be2aed; this head adds one merge of main (39aa27ed, through #957).
- Merge resolution:
git show --remerge-diff 8b1c4c72reports one conflict, inremote-worker/internal/exec/workspace_release_test.go. It is resolved the right way — both tests are kept, this PR'sTestStartupSweepRemovesTombstonesOnlyand #953'sTestReleaseWhoseDetachFailsAnswersAnErrorNotReleased, with the closing braces landing on the right functions and no assertion dropped. Nothing else was resolved silently, so there is no evil merge. - State: mergeable CLEAN, 18/18 checks green at this head.
Still open from the first round, non-blocking and unchanged: the sweep also removes an old plain file named as a key, while the janitor leaves every non-directory alone. The symlink half is deliberate and documented; if the plain-file half is too, one clause in the comment keeps the "the janitor's rule" comparison exact.
This approval is a formality — the repo does not dismiss stale approvals, so e8be2aed still governs. Author: webchang (MEMBER — maintainer).
…the janitor does newestWorkspaceMtime judged a plain file by its own mtime, so an old file whose name checkKey accepts was detached and removed at startup. The host janitor leaves every non-directory alone, and no workspace is ever a plain file: the sweep now keeps it. A symlink named as a key is still removed as the link, as documented. Follow-up to #954's review note. Signed-off-by: Rong Chang <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]>
remote-worker: the startup sweep keeps a plain file named as a key, as the janitor does (follow-up to #954)
Summary
A restarted worker starts with an empty runs map, so its idle sweep never reaches a workspace the previous process left; on a host with no janitor (
deploy/microvm), those stayed on disk for good. This is the startup sweep from the #338 design note, approved alongside the release frame (#949, #951).What changes
vmpool.New): before anything is served, one sweep ofWorkspaceRoot:.reclaiming-*tombstone is removed: at startup none is this process's;workspace.img's) is older thanWorkspaceIdleis renamed to a tombstone underp.muand removed on the reclaim goroutine, as the idle sweep does. This is the host janitor's rule for an unknown directory (deploy/sbx/janitor.sh). The key's lease state is retired as the idle sweep retires it;.lease-state,_probe) are left alone;cmd/worker): removes tombstones only at startup. Its root doubles as the shared workspace (an empty-key session'sgit clonesits beside the keys' directories), so a name alone cannot tell a key's workspace from shared content; it still never adopts an unknown directory.Tests
TestStartupSweepFreesAnOldUnknownWorkspaceTestStartupSweepRemovesAnOldSymlinkNotItsTargetTestStartupSweepRemovesTombstonesAndKeepsNonKeys_probeand.lease-statekeptTestStartupSweepKeepsAYoungWorkspaceTestStartupSweepKeepsAKnownRunsWorkspaceTestStartupSweepRemovesTombstonesOnly(container)go vet ./...is clean;go test ./...passes (15 packages);-racepasses oninternal/vmpoolandinternal/exec.Known interactions
deploy/sbx): a worker that restarts while the janitor is removing a workspace can remove the janitor's own.reclaiming-<wsk>-<s>tombstone first.RemoveAlltolerates the race, so nothing fails, but the janitor'sremove_treethen fails its directory re-check (remove_treeindeploy/sbx/janitor.sh) and prints one "not a directory inside" line to stderr. That line is noise from the race, not a failure; nothing is left behind.SH_WORKSPACE_IDLEkeeps an old mtime, so a restart at that moment frees its workspace. The janitor already applies the same rule on sandbox-service hosts, so this is new behavior only ondeploy/microvmhosts, which have no janitor. The idle sweep of a running worker is unchanged (it judges by the run's last Exec, not by mtime).A question
No setting turns the sweep off: its threshold is
SH_WORKSPACE_IDLE, already configurable, and it never touches anything younger. Say if you'd want an off switch anyway.Part of #338
Assisted-By: Claude Code