Repository navigation
fix(rm): Remove compose volumes of a workspace whose containers are gone - #719
Conversation
rm and kill found a workspace's volumes only through the containers that mounted them. A workspace whose containers were already gone (NotFound) left its <uid>_bazel-output and every other compose volume behind, and so did a record devpod made again under a new uid. - workspace_volumes: also take every compose volume labelled with one of the workspace's projects under compose's default name, with or without a container left to mount it. - kept_copies: keep every uid devpod gave the workspace, oldest first; a copy from before reads its uid from the dind volume name. - delete: sweep the compose volumes of the projects whose leftover containers the delete removed; name a volume kept because another container still uses it. - kill: find the compose containers by devpod's uid, the project name, instead of by the workspace id.
Reviewer's GuideData structuresExtend the stored workspace copy with historical DevPod UIDs and expose Compose project labels on containers, so cleanup can identify projects even after containers or records change.
Carry Compose projects alongside orphan-sweep outcomes so deletion can distinguish projects whose containers were removed from those still present.
APIAdd the public lifecycle notice for workspace volumes retained because another container still uses them, and record it in the public API snapshot.
Uses of the APIUse the workspace's DevPod UID to find its running Compose containers during kill, falling back to the workspace ID when no UID is available.
ImplementationDiscover workspace-owned volumes from Compose labels across current and historical UIDs, retain existing ownership safeguards, and read volumes for swept leftover projects.
Identify eligible DevPod-made projects among leftovers, account for partial container-removal failures, and return those projects for volume cleanup.
Integrate volume recording and cleanup with deletion, including volumes from leftover projects on success, refusal, and timeout paths, and report volumes that remain in use.
Update launch handling for the richer orphan-sweep outcomes without changing its user-facing notice behavior.
UIRender the new retained-volume notice with a command for locating the container that still uses the volume.
DocumentationDocument which Compose volumes cleanup claims, the safeguards that preserve shared volumes, and the newly fixed missing-container case.
TestsCover persistence of historical UIDs, recovery of legacy UIDs, and preservation of saved copy data when a later result contains no substitutions.
Test label-based volume discovery, historical and swept projects, ownership safeguards, and volume-removal behavior across lifecycle paths.
Update integration-test command filtering and the expected Compose-container listing format for the added project-label field.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
The notice is a deliberate addition to the promised API: dl rm reports a compose volume that another container still holds instead of failing.
A leftover container matched by the clone alone can be a compose project somebody started by hand in the clone. Compose names that project after its folder, so its <project>_<key> volumes are shared by every folder of that name on the machine. Only a container whose labels name this workspace's devpod directory hands its project on to the volume read.
blooop
left a comment
There was a problem hiding this comment.
This was generated by AI during review.
Reviewed head d71d3145 against merge base 86081fac (git diff 86081fac...HEAD). The review ran in a session that did not write the code. Both axes ran in that one session, one after the other, and were not merged.
Standards
- Blocking, fixed in
d71d3145.OrphanSweep::Removedhanded on the project of every leftover container. A leftover can match by the clone alone: a compose project that a person started by hand in the clone. Compose names that project after its folder, and<folder>_<key>volumes are shared by every folder of that name on the machine.record_projectsthen removed those volumes when no container used them at that moment. Now only a container whose labels name this id's devpod directory hands on its project (devpod_projects). Test:only_the_project_devpod_made_names_volumes_to_remove, which fails without the check. - Blocking, fixed in
c55f3070. Thepublic-apijob failed:LifecycleNotice::WorkspaceVolumeInUseis a deliberate addition to the promised API, and the snapshot did not have it. - Non-blocking.
killfinds the uid withworkspace_volumes::workspace_uid, and falls back to the workspace id when devpod has no record. It does not use the uids inKeptCopies, sokillof a workspace with no record still finds no compose container. The PR body already names--pruneas follow-up; this is the same gap. - Fowler smells. No Duplicated Code:
uid_innow holds the one uid lookup thatrecordandworkspace_uidshare.read_mountswas split intoread_containersplus the label pass, which keeps each part to one job. Nothing else. - PR body. It gives the why and the change without the ticket, and it now describes
d71d3145.
Spec
No spec available. The PR closes no issue, and no commit names one.
Verdict
Approve at d71d3145. The two blocking findings are fixed at this head; finding 3 is non-blocking follow-up.
Codecov Report❌ Patch coverage is Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 12 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="rust/devlaunch-core/src/flows/workspace_volumes.rs" line_range="278-283" />
<code_context>
+ }
+ for volume in docker::compose_volumes(runner)? {
+ let default_name = volume.name == format!("{}_{}", volume.project, volume.key);
+ if default_name && uids.contains(&volume.project) {
+ // Compose made it for one of the workspace's own projects. Its label
+ // says so whether or not a container is left to mount it.
+ mounted.volumes.insert(volume.name.clone());
+ mounted.compose_made.insert(volume.name);
+ continue;
+ }
+ if !mounted.volumes.contains(&volume.name) {
</code_context>
<issue_to_address>
**Shared volumes are deleted**
When a volume has an explicit name matching `<project>_<key>` or is declared external, and no workspace container remains, `read_mounts` treats the compose labels and default-shaped name as proof that the volume is workspace-owned, without checking the compose configuration. `belongs` then accepts it and `sweep_mounted` removes shared data.
Check the compose configuration before treating a label-matched, default-shaped volume as workspace-owned, preserving volumes explicitly named or declared external.
Also at `rust/devlaunch-core/src/flows/workspace_volumes.rs:205`.
</issue_to_address>
### Comment 2
<location path="rust/devlaunch-core/src/flows/lifecycle/delete.rs" line_range="288" />
<code_context>
- let mounted = workspace_volumes::record(context.runner(), devpod_home, workspace_id);
+ let mounted = workspace_volumes::record(
+ context.runner(),
+ devpod_home,
+ &copies.uids(workspace_id),
+ workspace_id,
</code_context>
<issue_to_address>
**Cached uid crosses context ownership**
When the same workspace ID exists in multiple devpod contexts and the kept copy contains a uid from only one of them, `copies.uids(workspace_id)` is used even when `sole_workspace_record` cannot identify a unique context. If another context has the same workspace ID, the cached uid from the first context makes `record` claim and remove its unmounted compose volumes while deleting the second context’s workspace.
Use cached uids only when their context ownership is known to match the workspace being deleted, and otherwise skip uid-based volume cleanup.
</issue_to_address>
### Comment 3
<location path="rust/devlaunch-core/src/flows/workspace_volumes.rs" line_range="262" />
<code_context>
- let Some(ids) = NonEmpty::of(ids) else {
- return Ok(());
- };
+ for uid in uids {
+ ids.extend(docker::containers_labelled(
+ runner,
</code_context>
<issue_to_address>
**Shared literal volume can be removed**
When an older-uid container still mounts a literal shared volume whose name contains the workspace id, while the current config no longer declares that volume, `read_containers` adds the former container's literal mount, but `Mounted.literal` is populated from only the current result. If the current config no longer declares that shared name and it contains the workspace id, `belongs` treats it as owned and removes it when no container currently uses it, losing shared volume data.
Preserve the literal volume names associated with former uids, or otherwise ensure their mounts remain excluded from ownership inference.
</issue_to_address>
### Comment 4
<location path="rust/devlaunch-core/src/flows/orphan_containers.rs" line_range="180" />
<code_context>
+ .is_some_and(|owner| owner == workspace_id)
+ })
+ })
+ .filter_map(|c| c.project.clone())
+ .collect()
+}
</code_context>
<issue_to_address>
**Shared leftover project volumes are swept**
When a leftover container was manually started from the workspace’s devpod directory with a project name shared by another compose project, `devpod_projects` treats any leftover container whose paths are under this workspace’s devpod directory as a devpod-created project, without checking that its project label is the workspace’s uid. A manually started compose project there with a shared project name therefore passes its volumes to `record_projects`, which can remove its unmounted default-named volumes.
Only pass a leftover project to volume cleanup when its project label is verified as a uid devpod assigned to this workspace.
</issue_to_address>
### Comment 5
<location path="rust/devlaunch-core/src/flows/kill.rs" line_range="767" />
<code_context>
+ runner,
+ // devpod names the compose project after its uid, not the id. With
+ // no uid on record, the id is the only name left to try.
+ &workspace_volumes::workspace_uid(devpod_home, workspace_id)
+ .unwrap_or_else(|| workspace_id.to_owned()),
+ &holding,
</code_context>
<issue_to_address>
**Earlier containers keep running**
When devpod replaces a workspace record with a new uid while containers from an earlier uid are still running, `workspace_uid` supplies only the current uid to `kill_containers`, so containers from the earlier project are not signalled and keep running after `kill` completes.
Have `kill_containers` select containers for the workspace's earlier uids as well as its current uid.
</issue_to_address>
### Comment 6
<location path="rust/devlaunch-core/src/flows/lifecycle/delete.rs" line_range="287-292" />
<code_context>
// containers away. Removed only once devpod has let go, below.
- let mounted = workspace_volumes::record(context.runner(), devpod_home, workspace_id);
+ let mounted = workspace_volumes::record(
+ context.runner(),
+ devpod_home,
+ &copies.uids(workspace_id),
+ workspace_id,
+ );
// The lock line is answered the way a launch answers it (devlaunch#602): said,
// and then *cleared*, by the same sweep `up` runs. It used to be said and
// nothing more, with advice to run `kill` in another terminal, which left an
</code_context>
<issue_to_address>
**New compose volumes are left behind**
When an `up` creates a compose volume after `record` lists the workspace's projects but before `devpod delete` acquires its lock, `record` misses the new volume, and `devpod delete` can remove its container and record without a later volume scan, leaving the volume behind.
Re-read the workspace's project volumes after acquiring the delete lock and before removing the record.
Also at `rust/devlaunch-core/src/flows/workspace_volumes.rs:276-278`.
</issue_to_address>
### Comment 7
<location path="rust/devlaunch-core/src/flows/lifecycle/delete.rs" line_range="330" />
<code_context>
Err(NotRun::TimedOut) => {
context.forget_workspaces();
- sweep_leftovers(
+ let _ = sweep_leftovers(
context.runner(),
devpod_home,
</code_context>
<issue_to_address>
**Deleted containers leave volumes**
When `devpod delete` times out or exits unsuccessfully after `sweep_leftovers` removes a devpod-owned container, the timeout branch discards the projects returned by `sweep_leftovers`, and the non-success path returns before `record_projects` and `sweep_mounted` run, leaving the containers' compose volumes behind.
Preserve the projects returned by `sweep_leftovers` and sweep their volumes on timeout and non-success paths.
Also at `rust/devlaunch-core/src/flows/lifecycle/delete.rs:350-351`.
</issue_to_address>
### Comment 8
<location path="rust/devlaunch-core/src/flows/orphan_containers.rs" line_range="142" />
<code_context>
+ /// containers' removal leaves behind.
+ Removed {
+ names: NonEmpty<String>,
+ projects: BTreeSet<String>,
+ },
/// docker would not list the containers, in its own words.
</code_context>
<issue_to_address>
**Partially removed containers leave volumes**
When `docker rm` removes at least one leftover container but another listed container remains, `still_there` returns `NotRemoved` without the projects of containers already removed, so delete skips the volume read for those projects and leaves their unmounted volumes behind.
Include the removed containers' projects in the `NotRemoved` result and pass them to the volume sweep.
</issue_to_address>
### Comment 9
<location path="rust/devlaunch-core/src/flows/workspace_volumes.rs" line_range="179" />
<code_context>
+ let mounted = Mounted {
workspace_id: workspace_id.to_owned(),
- devcontainer_id: Some(uid.clone()),
+ devcontainer_id: uid,
literal: result.as_ref().map(literal_volumes).unwrap_or_default(),
..Mounted::default()
</code_context>
<issue_to_address>
**Former-uid volumes are left behind**
When an earlier-uid container mounts a non-compose-default volume whose name contains that uid, and the workspace has since acquired a different current uid, `read_containers` adds mounts from former-uid containers, but `Mounted.devcontainer_id` holds only the current uid. `belongs` therefore rejects a former-uid volume whose name contains that uid but is not marked as a compose default, so the delete leaves that volume behind.
Track all workspace uids in `Mounted` and use them when checking whether a volume name belongs to the workspace.
</issue_to_address>
### Comment 10
<location path="rust/devlaunch-core/src/flows/kept_copies.rs" line_range="178" />
<code_context>
+ .volumes
+ .iter()
+ .filter_map(|name| name.strip_prefix(DIND_PREFIX))
+ .filter(|uid| !uid.is_empty())
+ {
+ if !uids.iter().any(|known| known == uid) {
</code_context>
<issue_to_address>
**Legacy copies can lose old projects**
When a pre-change workspace copy has no `dind-var-lib-docker-<uid>` volume name and devpod has since assigned the workspace a new uid, `KeptCopies::uids` recovers a pre-change uid only from a volume name with the `dind-var-lib-docker-` prefix. A legacy copy made without that volume therefore supplies no former uid; after devpod assigns a new uid, `workspace_volumes::record` never checks the old project's labels, so its compose volumes remain on disk when its containers are already gone.
Preserve or recover legacy workspace uids from another durable source, or narrow the cleanup claim for legacy copies that lack the dind volume.
</issue_to_address>
### Comment 11
<location path="rust/devlaunch-core/src/flows/kept_copies.rs" line_range="131" />
<code_context>
+ let mut recorded = parse_result(&bytes);
+ // The uids of every earlier record go first: devpod forgets them when it
+ // makes a record again, and their compose volumes still carry them.
+ let mut uids = self.uids(workspace_id);
+ for uid in recorded.uids.drain(..) {
+ if !uids.contains(&uid) {
</code_context>
<issue_to_address>
**Incomplete results erase saved metadata**
When a workspace already has a copy with uids and a later result file is malformed or contains no recognized substitutions or image fields, `KeptCopies::keep` merges the previous uid list into a newly parsed result before checking `recorded.is_empty()`. If the new result has no recognized fields, the old uids make it nonempty, so the function overwrites the previous copy with only those uids and discards its saved volume names and image references.
Do not overwrite the existing copy when the new result contains no recognized facts; merge the uid history only into a result that will otherwise be recorded.
</issue_to_address>
### Comment 12
<location path="docs/cleanup.md" line_range="74-84" />
<code_context>
+A compose volume is also found by its label, not only by what mounts it. A volume compose
</code_context>
<issue_to_address>
**Cleanup guidance can drift**
When the duplicated cleanup behavior is later updated in only one of the two files, when the cleanup behavior changes and these summaries are not updated together, `docs/cleanup.md` and `CHANGELOG.md` can disagree about which volumes `rm` removes, leaving users with conflicting guidance and no parity test to catch it.
Add a test beside the descriptions that checks their shared facts against one source, or remove the duplicated hand-maintained description.
Also at `CHANGELOG.md:13-20`.
</issue_to_address>A volume only an older uid's containers mount came from an older config, so dl cannot tell whether that config spelled the name literally. The workspace id in its name no longer makes it the workspace's own; nor does it when devpod's create result was not read. A name holding any of the workspace's uids still counts, so an older uid's dind volume goes. The uids kept by workspace id are read only when one devpod context at most holds the id: with two, a kept uid may be the other workspace's.
The kept uids joined the parsed result before its emptiness check, so an unreadable result overwrote the copy with uids alone and dropped its volume names and images.
A partly failed docker rm now hands on the projects of the containers that went (none of whose containers is left). A devpod delete that times out or fails after the leftover sweep still removes those projects' compose volumes: dl removed the containers itself.
dl <ws> rmanddl <ws> killnow remove a workspace's compose volumes when its containers are already gone. Before this, each such delete left the volume on the disk, and nothing on the machine named it again.In short
A compose devcontainer gets named volumes from compose, for example kinisi_ros's
bazel-output. Compose names each one<project>_<volume>. devpod uses its uid for the workspace as the project name (for exampledefault-ki-9eb50). So the volume isdefault-ki-9eb50_bazel-output.Before this PR, the delete found a workspace's volumes in one way only:
workspace.json(workspace_volumes.rs:141).workspace_volumes.rs:189-220).When no container was left, step 2 found no volume and stopped. It said nothing. This is the usual state of a workspace that
dl --lsshows asNotFound. The same thing occurred when devpod made the record again under a new uid: the old project's containers and volumes keep the old uid, and the delete looked only for the new one. The only other names the delete knew were the two fixed templates<basename>-pixianddind-var-lib-docker-<uid>(delete.rs:565). Neither template matches<project>_bazel-output.Now the delete also reads compose's own volume labels. A volume that compose made for one of the workspace's projects, under the default name
<project>_<volume>, is the workspace's own, with or without a container. The workspace's projects are its current uid, each older uid that dl kept from an earlierup, and the project that devpod made for each leftover container that the delete removes. The checks that keep shared volumes did not change.One behaviour change goes the other way:
rmnow keeps one more kind of volume. The workspace id in a volume name (for example<id>-pixi) now claims the volume only when a container of the current uid mounts it and dl read the create result for that uid. Without both, the volume stays. Before, the workspace id alone claimed it, sormcould remove a shared volume that a container of an older uid still used.Evidence
On one development host on 2026-11-17,
docker volume ls --filter dangling=trueshowed 71 dangling*_bazel-outputvolumes. They were created from 2026-10-22 to 2026-11-13. I mapped each project name back to a workspace through devpod'sworkspace.json(uid) and dl'sworkspace-copies/*.json(thedind-var-lib-docker-<uid>entry). Both sources agree:On that host,
dl <ws> killon a workspace with a running dev container printedRemoved Docker volumes only <ws> used: default-ki-a8a47_bazel-output.dl <ws> killon three workspaces that dl showed asNotFoundprinted no volume line, and each volume stayed. Source:dl --ls --json,~/.devpod/contexts/*/workspaces/*/workspace.jsonand~/.cache/devlaunch/workspace-copies/*.jsonon that host.I did not do a live
rmagainst a real workspace. The0line comes from the new tests below, not from a live run. Six of the new tests fail when the label branch inread_mountsis turned off, and they pass with it.What this changes
workspace_volumes::read_mountsreadsdocker volume ls(the call that it already made) for every volume that compose labelled with one of the workspace's projects under the default name. It treats each one ascompose_made, whether a container mounts it or not. The literal, explicitname:andexternalchecks, and the "no container that is left uses it" check, did not change.KeptCopieskeeps a newuidslist, oldest first. Each completedupadds itsDevContainerID, and a new uid does not drop the old one. A copy from before this change still gives its uid, from thedind-var-lib-docker-<uid>name that it already holds.rmandkillpass these uids toworkspace_volumes::record.docker::compose_containersnow also readscom.docker.compose.project, andOrphanSweep::Removedcarries the projects of the containers that it removed. It carries a project only when the container's labels name devpod's directory for this workspace id. A container that the delete matched by the clone alone can be a compose project that a person started by hand in the clone. Compose names that project after its folder (for exampletools), and every folder with that name on the machine shares its<folder>_<volume>volumes. So those volumes stay. After a successful delete,workspace_volumes::record_projectsreads those projects' compose volumes, and the delete removes them in the same way.Kept Docker volume <name> of <ws>: another container still uses it. Find it with: docker ps -a --filter volume=<name>(LifecycleNotice::WorkspaceVolumeInUse). Before this, it stayed with no line.killfinds the compose containers.killfiltereddocker psoncom.docker.compose.project=<workspace id>. devpod names the project after the uid, so this filter matched no compose container. It now filters on the uid, and on the workspace id only when no uid is on record.f84dcc4c.recorddoes not read the kept uids, because they can belong to the other context. Commitf84dcc4c.3656f10c.docker rmremoves only some leftover containers, the delete keeps the projects of the containers that went. Whendevpod deletetimes out or refuses, the delete still removes the volumes of the leftovers that it removed. Commitb5b6a391.docs/cleanup.mdandCHANGELOG.mdsay what the delete now removes and keeps. The CHANGELOG entry links to thedocs/cleanup.mdsection and does not repeat it (commita7a0efae).Not in this PR:
dl --prunestill reclaims only the two template names. It does not yet use the kept uids to reclaim the compose volumes of a workspace that devpod forgot. Adl --prune --volumesthat lists<project>_*volumes with no record is a follow-up.Where this fits
How I checked it
The tests that failed before the fix and pass now:
a_delete_removes_the_compose_volume_of_a_workspace_with_no_container_left: no container, anddocker volume lslistsdc9a8b7c_bazel-output. The delete removes it, and it does not touchnamed-cache(an explicitname:) or another project's volume.a_delete_removes_the_compose_volume_of_a_uid_the_workspace_had_before: an earlierupkept uiddc0ld000, and the current record hasdc9a8b7c. The delete removesdc0ld000_bazel-output.a_delete_removes_the_compose_volumes_of_the_leftovers_it_swept: the delete removes a leftover container of projectdc0ld000, then removesdc0ld000_bazel-output.a_volume_something_else_still_uses_is_named: theWorkspaceVolumeInUseline.only_the_project_devpod_made_names_volumes_to_remove(orphan_containers.rs): the delete removes a devpod container and a hand-startedtoolscontainer from the clone. Onlydefault-ki-0ld11goes on to the volume read. This test fails when the devpod-directory check is turned off.the_containers_are_found_by_the_compose_project_devpod_named(kill.rs): the filter islabel=com.docker.compose.project=<uid>.workspace_volumes.rs:a_compose_volume_is_the_workspaces_own_when_no_container_is_left,a_compose_volume_of_a_former_uid_is_the_workspaces_ownandthe_compose_volumes_of_swept_projects_are_read_by_project. Inkept_copies.rs:a_completed_up_keeps_the_workspaces_uid,a_new_uid_does_not_drop_the_old_oneanda_copy_from_before_uids_were_kept_names_its_uid_through_the_dind_volume.Tests added after the review, each failing before its fix:
a_volume_only_a_former_uid_mounts_is_not_claimed_by_the_ida_volume_named_after_a_former_uid_is_the_workspaces_ownwith_no_config_to_read_the_id_claims_nothingkept_uids_are_not_read_when_two_contexts_hold_the_idkept_uids_are_read_when_no_context_holds_the_ida_result_that_names_nothing_leaves_the_copy_with_uids_alonea_partly_failed_removal_keeps_the_projects_of_what_wenta_delete_devpod_refused_still_removes_the_volumes_of_the_leftovers_it_sweptExisting tests that pin the exact docker argv now include the one
docker volume lscall that the mount read makes, and the new fifth field of the leftover listing format.Commands that I ran, all green
I did not run
pixi run test-e2e, which builds real containers.Merge danger
Door: two-way. A revert restores the old behaviour. The new
uidsfield in a kept copy is optional (#[serde(default)]), so an older build still reads a newer copy, and a newer build still reads an older copy.Blast radius: small. If the change is wrong,
rmorkillcould remove a<project>_<volume>volume that compose labelled with one of the workspace's uids. Only a workspace's own uids, which devpod wrote, select a project. A volume that any remaining container still uses always stays. A volume with an explicit composename:, or markedexternal, always stays. A volume that only the workspace id names, and that no container of the current uid mounts, now stays too.Review notes
kept_copies.rsanddelete.rs. It uses a different mechanism (the names that the recorded mounts spell). The two can conflict in text. They do not do the same work.d71d3145fixes it. Commitc55f3070addsWorkspaceVolumeInUseto the public-API snapshot.workspace_volumes.rs:283andorphan_containers.rs:180: not real. The volume names that get through hold devpod's per-workspace uid or come from devpod's own directory for this workspace.kept_copies.rs:178: not real. Nothing on the machine holds that old uid.delete.rs:292: out of scope. Anupthat runs during anrmis not supported, and the miss can only keep a volume, never remove one.kill.rs:767: follow-up.killdoes not read the kept uids yet, but the delete afterkillforce-removes the earlier containers.🤖 Generated with Claude Code
Summary by Sourcery
Remove workspace-owned Compose volumes during
rmandkilleven after their containers have disappeared.Bug Fixes:
rmandkillremove workspace-owned Compose volumes even when the workspace containers are already gone.killusing devpod's Compose project UID and report workspace volumes retained by other containers.Enhancements:
Documentation:
Tests: