Skip to content

fix(rm): Remove compose volumes of a workspace whose containers are gone - #719

Merged
blooop merged 7 commits into
mainfrom
fix/compose-volume-leak
Nov 18, 2026
Merged

blooop merged 7 commits into
mainfrom
fix/compose-volume-leak

Conversation

@blooop

@blooop blooop commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

dl <ws> rm and dl <ws> kill now 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 example default-ki-9eb50). So the volume is default-ki-9eb50_bazel-output.

Before this PR, the delete found a workspace's volumes in one way only:

  1. It got the uid from devpod's workspace.json (workspace_volumes.rs:141).
  2. It listed the containers with that uid as a label, and read the volumes that they mount (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 --ls shows as NotFound. 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>-pixi and dind-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 earlier up, 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: rm now 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, so rm could 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=true showed 71 dangling *_bazel-output volumes. They were created from 2026-10-22 to 2026-11-13. I mapped each project name back to a workspace through devpod's workspace.json (uid) and dl's workspace-copies/*.json (the dind-var-lib-docker-<uid> entry). Both sources agree:

- 64  dangling bazel-output volumes with no workspace record at all (the workspace was deleted, the volume stayed)
-  7  dangling bazel-output volumes of workspaces that still exist, all NotFound (no container left)
+  0  expected after this change, for a workspace deleted with dl rm or dl kill

On that host, dl <ws> kill on a workspace with a running dev container printed Removed Docker volumes only <ws> used: default-ki-a8a47_bazel-output. dl <ws> kill on three workspaces that dl showed as NotFound printed no volume line, and each volume stayed. Source: dl --ls --json, ~/.devpod/contexts/*/workspaces/*/workspace.json and ~/.cache/devlaunch/workspace-copies/*.json on that host.

I did not do a live rm against a real workspace. The 0 line comes from the new tests below, not from a live run. Six of the new tests fail when the label branch in read_mounts is turned off, and they pass with it.

What this changes

  • A volume found by label. workspace_volumes::read_mounts reads docker 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 as compose_made, whether a container mounts it or not. The literal, explicit name: and external checks, and the "no container that is left uses it" check, did not change.
  • Every uid is kept. KeptCopies keeps a new uids list, oldest first. Each completed up adds its DevContainerID, and a new uid does not drop the old one. A copy from before this change still gives its uid, from the dind-var-lib-docker-<uid> name that it already holds. rm and kill pass these uids to workspace_volumes::record.
  • Leftover projects. docker::compose_containers now also reads com.docker.compose.project, and OrphanSweep::Removed carries 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 example tools), 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_projects reads those projects' compose volumes, and the delete removes them in the same way.
  • A volume in use is named. A volume of the workspace's own that stays because another container uses it now prints 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.
  • kill finds the compose containers. kill filtered docker ps on com.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.
  • The workspace id claims less. A volume name that holds the workspace id is the workspace's own only when a container of the current uid mounts it and dl read the create result for that uid. A volume name that holds any of the workspace's uids is always its own. Commit f84dcc4c.
  • Two contexts, one id. When two devpod contexts hold the same workspace id, record does not read the kept uids, because they can belong to the other context. Commit f84dcc4c.
  • A bad result keeps the copy. When a result file names nothing, the kept copy and its uids stay as they were. Before, the uids were added first, so the empty result replaced the saved copy. Commit 3656f10c.
  • Partial failures still clean up. When docker rm removes only some leftover containers, the delete keeps the projects of the containers that went. When devpod delete times out or refuses, the delete still removes the volumes of the leftovers that it removed. Commit b5b6a391.
  • Docs. docs/cleanup.md and CHANGELOG.md say what the delete now removes and keeps. The CHANGELOG entry links to the docs/cleanup.md section and does not repeat it (commit a7a0efae).

Not in this PR: dl --prune still 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. A dl --prune --volumes that lists <project>_* volumes with no record is a follow-up.

Where this fits

 workspace_delete(ws)
   named   = devcontainer_volumes(ws)                    # <basename>-pixi, dind-var-lib-docker-<uid>
-  mounted = record(ws)                                  # uid -> containers -> their mounts
+  mounted = record(ws, copies.uids(ws))                 # every uid -> containers -> their mounts
+                                                        #   + every <uid>_<key> volume compose labelled with a uid
   devpod delete ws
-  sweep_leftovers(ws)
+  projects = sweep_leftovers(ws)                        # the compose projects of the containers it removed
   sweep_mounted(mounted)                                # rm each owned volume that nothing uses
+  sweep_mounted(record_projects(ws, projects))          # the same, for the leftovers' projects
+  # a volume kept because it is in use -> WorkspaceVolumeInUse line
   sweep_volumes(named - tried)

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, and docker volume ls lists dc9a8b7c_bazel-output. The delete removes it, and it does not touch named-cache (an explicit name:) or another project's volume.
  • a_delete_removes_the_compose_volume_of_a_uid_the_workspace_had_before: an earlier up kept uid dc0ld000, and the current record has dc9a8b7c. The delete removes dc0ld000_bazel-output.
  • a_delete_removes_the_compose_volumes_of_the_leftovers_it_swept: the delete removes a leftover container of project dc0ld000, then removes dc0ld000_bazel-output.
  • a_volume_something_else_still_uses_is_named: the WorkspaceVolumeInUse line.
  • only_the_project_devpod_made_names_volumes_to_remove (orphan_containers.rs): the delete removes a devpod container and a hand-started tools container from the clone. Only default-ki-0ld11 goes 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 is label=com.docker.compose.project=<uid>.
  • In 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_own and the_compose_volumes_of_swept_projects_are_read_by_project. In kept_copies.rs: a_completed_up_keeps_the_workspaces_uid, a_new_uid_does_not_drop_the_old_one and a_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_id
  • a_volume_named_after_a_former_uid_is_the_workspaces_own
  • with_no_config_to_read_the_id_claims_nothing
  • kept_uids_are_not_read_when_two_contexts_hold_the_id
  • kept_uids_are_read_when_no_context_holds_the_id
  • a_result_that_names_nothing_leaves_the_copy_with_uids_alone
  • a_partly_failed_removal_keeps_the_projects_of_what_went
  • a_delete_devpod_refused_still_removes_the_volumes_of_the_leftovers_it_swept

Existing tests that pin the exact docker argv now include the one docker volume ls call that the mount read makes, and the new fifth field of the leftover listing format.

Commands that I ran, all green
cd rust
pixi run cargo fmt --check
pixi run cargo test --workspace
pixi run cargo clippy --locked --all-targets -- -D warnings
cd ..
pixi run prek          # prek run -a
pixi run test -q       # 885 passed (at a7a0efae), 7 skipped, 42 deselected

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 uids field 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, rm or kill could 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 compose name:, or marked external, always stays. A volume that only the workspace id names, and that no container of the current uid mounts, now stays too.

Review notes

  • Open PR #687 — fix(rm): remove volumes a devcontainer named after the workspace also changes kept_copies.rs and delete.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.
  • A self-review (wf-review) found that a hand-started project in the clone could reach volumes of other folders with the same name. Commit d71d3145 fixes it. Commit c55f3070 adds WorkspaceVolumeInUse to the public-API snapshot.
  • The Sourcery review left 12 threads. Seven are fixed, with the commits above. Five got a reply that says why they stay as they are:
    • workspace_volumes.rs:283 and orphan_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. An up that runs during an rm is not supported, and the miss can only keep a volume, never remove one.
    • kill.rs:767: follow-up. kill does not read the kept uids yet, but the delete after kill force-removes the earlier containers.

🤖 Generated with Claude Code

Summary by Sourcery

Remove workspace-owned Compose volumes during rm and kill even after their containers have disappeared.

Bug Fixes:

  • Ensure rm and kill remove workspace-owned Compose volumes even when the workspace containers are already gone.
  • Recover volumes associated with previous workspace UIDs and Compose projects from containers removed during cleanup.
  • Find containers for kill using devpod's Compose project UID and report workspace volumes retained by other containers.

Enhancements:

  • Track all devpod UIDs associated with a workspace and use Compose volume labels to identify owned default-named volumes without relying on remaining container mounts.
  • Preserve ownership safeguards for explicit, external, shared, and still-in-use volumes.

Documentation:

  • Document Compose volume cleanup behavior, ownership rules, and retained-volume notifications.

Tests:

  • Add coverage for cleanup of volumes from missing containers, former UIDs, swept leftovers, and volumes still in use.

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.
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Extend 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.

  • rust/devlaunch-core/src/clients/docker.rs L554-558 (+3 small edits)
  • rust/devlaunch-core/src/flows/kept_copies.rs L128-145, L164-188, L255-260 (+3 small edits)

Carry Compose projects alongside orphan-sweep outcomes so deletion can distinguish projects whose containers were removed from those still present.

  • rust/devlaunch-core/src/flows/orphan_containers.rs L45, L64-79

API

Add the public lifecycle notice for workspace volumes retained because another container still uses them, and record it in the public API snapshot.

  • rust/devlaunch-core/public-api.api.txt L211-213, L906-908
  • rust/devlaunch-core/src/flows/lifecycle/notices.rs L82-85

Uses of the API

Use the workspace's DevPod UID to find its running Compose containers during kill, falling back to the workspace ID when no UID is available.

  • rust/devlaunch-core/src/flows/kill.rs L763-770, L914-918, L1820-1846 (+1 small edits)

Implementation

Discover workspace-owned volumes from Compose labels across current and historical UIDs, retain existing ownership safeguards, and read volumes for swept leftover projects.

  • rust/devlaunch-core/src/flows/workspace_volumes.rs L156-241, L641-731, L1236-1348 (+20 small edits)

Identify eligible DevPod-made projects among leftovers, account for partial container-removal failures, and return those projects for volume cleanup.

  • rust/devlaunch-core/src/flows/orphan_containers.rs L156-208, L482-525, L739-778 (+12 small edits)

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.

  • rust/devlaunch-core/src/flows/lifecycle/delete.rs L398-407, L460-468, L485-505 (+8 small edits)

Update launch handling for the richer orphan-sweep outcomes without changing its user-facing notice behavior.

  • rust/devlaunch-core/src/flows/launch.rs L1344-1349, L1356

UI

Render the new retained-volume notice with a command for locating the container that still uses the volume.

  • rust/dl/src/render.rs L1279-1282, L6327-6337

Documentation

Document which Compose volumes cleanup claims, the safeguards that preserve shared volumes, and the newly fixed missing-container case.

  • CHANGELOG.md L10-18
  • docs/cleanup.md L71-88, L105-106

Tests

Cover persistence of historical UIDs, recovery of legacy UIDs, and preservation of saved copy data when a later result contains no substitutions.

  • rust/devlaunch-core/src/flows/kept_copies.rs L290-291, L504-573

Test label-based volume discovery, historical and swept projects, ownership safeguards, and volume-removal behavior across lifecycle paths.

  • rust/devlaunch-core/src/flows/lifecycle/tests.rs L2748, L2799-2814, L3066-3249

Update integration-test command filtering and the expected Compose-container listing format for the added project-label field.

  • rust/dl/tests/lifecycle.rs L430-432, L1479-1480

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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

  1. Blocking, fixed in d71d3145. OrphanSweep::Removed handed 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_projects then 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.
  2. Blocking, fixed in c55f3070. The public-api job failed: LifecycleNotice::WorkspaceVolumeInUse is a deliberate addition to the promised API, and the snapshot did not have it.
  3. Non-blocking. kill finds the uid with workspace_volumes::workspace_uid, and falls back to the workspace id when devpod has no record. It does not use the uids in KeptCopies, so kill of a workspace with no record still finds no compose container. The PR body already names --prune as follow-up; this is the same gap.
  4. Fowler smells. No Duplicated Code: uid_in now holds the one uid lookup that record and workspace_uid share. read_mounts was split into read_containers plus the label pass, which keeps each part to one job. Nothing else.
  5. 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

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.09236% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.78%. Comparing base (86081fa) to head (a7a0efa).

Files with missing lines Patch % Lines
rust/devlaunch-core/src/flows/workspace_volumes.rs 95.88% 11 Missing ⚠️
rust/devlaunch-core/src/flows/orphan_containers.rs 95.86% 6 Missing ⚠️
rust/devlaunch-core/src/flows/lifecycle/delete.rs 88.63% 5 Missing ⚠️
Additional details and impacted files
Flag Coverage Δ
python 42.98% <ø> (ø)
rust 94.98% <96.09%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
shipped code (rust) 94.98% <96.09%> (+<0.01%) ⬆️
harness and tooling (python) 42.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blooop
blooop marked this pull request as ready for review November 17, 2026 15:08

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread rust/devlaunch-core/src/flows/kill.rs Resolved
Comment thread docs/cleanup.md Resolved
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.
@blooop
blooop merged commit 3765ecd into main Nov 18, 2026
15 checks passed
@blooop
blooop deleted the fix/compose-volume-leak branch November 18, 2026 11:33
@blooop blooop mentioned this pull request Nov 18, 2026
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.

1 participant