Skip to content

[Bug]: Volume auto-cleanup marks a managed volume for deletion while it is in use under another name #4537

Backlog

Description

@peterschmidt85

Steps to reproduce

  1. Create an AWS volume named owned with region: eu-west-1, size: 1GB and auto_cleanup_duration: 1h.

  2. Run a short task with volumes: [owned:/data] to initialize its filesystem. Wait for the volume to detach.

  3. In the same project, register the same EBS volume under a second name. Use the ID from dstack volume get owned --json.

    type: volume
    name: registered
    backend: aws
    region: eu-west-1
    volume_id: <EBS volume ID>
  4. Run a task with volumes: [registered:/data] and keep it running past the one-hour idle interval for owned.

Actual behaviour

The server emits Volume marked for deletion due to exceeding auto_cleanup_duration for owned while the same EBS volume is attached through registered. The volume worker then calls EC2 DeleteVolume for that EBS ID.

The idle check reads attachments and the last job timestamp from the individual dstack volume record. Activity through registered is invisible to owned.

def _should_delete_volume(volume: VolumeModel) -> bool:
if volume.attachments:
return False
config = get_volume_configuration(volume)
if not config.auto_cleanup_duration:
return False
duration_seconds = parse_duration(config.auto_cleanup_duration)
if not duration_seconds or duration_seconds <= 0:
return False
idle_time = _get_idle_time(volume)
threshold = datetime.timedelta(seconds=duration_seconds)
return idle_time > threshold
def _get_idle_time(volume: VolumeModel) -> datetime.timedelta:
last_used = volume.last_job_processed_at or volume.created_at
idle_time = get_current_datetime() - last_used

Expected behaviour

A job using either registration keeps the underlying volume active. The idle interval starts after its last use through either name.

dstack version

master (61eb0f1dd). Reproduced with SQLite, the dstack volume service and workers, and a mocked EC2 client.

Activity

  1. added
    bug
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvolumes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions