Skip to content

[bug] Orphaned download artifacts keep transcoding after their downloads are deleted #998

Closed

Description

@zZebrahz

Summary

The Prepare Download Artifacts task can continue preparing an artifact after every download referencing it has been deleted. If its output file subsequently disappears, recovery queues another encode without checking whether any download still needs it.

This was observed in a Docker deployment where PostgreSQL retained the artifact record but the artifact output directory was not persistently mounted. Container recreation removed the generated file, and the surviving database record caused recovery to prepare it again.

Retained logs show six missing-output requeue events for the same artifact. During investigation, its encoder was actively producing output despite there being no associated download records.

The operation does not require administrator privileges. Any user permitted to create the relevant download can encounter this behavior.

User workflow

  1. A user requests a download requiring preparation.
  2. The server creates a download record and a shared artifact record.
  3. The user deletes the download.
  4. No other download references the artifact.
  5. Artifact preparation continues, or a later missing-output recovery starts it again.

Deleting the download removes the user-visible entry, but does not remove the artifact’s eligibility for background preparation.

Expected behavior

  • Queued preparation should not begin when no download requires the artifact.
  • Deleting the last consumer during preparation should follow an explicit cancellation or completion policy.
  • Missing output should be regenerated only when a valid consumer requires it.
  • Deleting one consumer must preserve preparation needed by other downloads sharing the artifact.
  • Retaining an existing artifact for possible cache reuse should not require rebuilding it whenever its bytes disappear.
  • Recovery, cleanup, and new download creation must coordinate so a concurrent consumer cannot lose valid work.

Actual behavior

  • Download deletion leaves the artifact record independently eligible for processing.
  • The worker claims queued artifacts without checking for remaining download references.
  • Missing-output recovery requeues ready artifacts without checking for consumers.
  • The orphan sweep only considers ready artifacts unused for 30 days.
  • Recovery and queue processing occur before the task’s cleanup phase.
  • Successful preparation updates last_used_at, refreshing the timestamp used by orphan retention.
  • Missing-output requeue resets the attempt counter, so it does not represent lifetime preparation attempts.

Environment and scope

The observed environment used:

  • Docker for the application.
  • PostgreSQL for durable download and artifact state.
  • The application artifact directory /tmp/silo-download-artifacts, without a persistent mount covering it.
  • Container recreation during application updates.

No particular media title, user role, or administrator-only action is required by the identified mechanism.

The observed artifact used the audio_v2_running lifecycle state and was performing video and audio preparation. That status name does not mean the operation was audio-only.

Source analysis was performed on branch apiv2 at:

8771e3a02e71575e562c1eb10e9662e60f63c18e

The exact source commit embedded in the inspected container was not verified. Runtime observations and source findings are separated below.

Observed timeline

All timestamps are UTC. Resource identifiers, media details, account information, and deployment identifiers are omitted.

Timestamp Observation
September 5, 06:14:30 A download creation request returned 202. The artifact’s recorded creation time falls within the same second.
September 5, 06:15:04 A download deletion returned 204, approximately 34 seconds later. A repeated deletion of the same download returned 404.
September 5, 06:15:12–06:15:24 Another download creation and successful deletion occurred. Its relationship to the artifact could not be established from the retained audit fields.
September 5, 20:00:30 Recovery reported the artifact’s output missing and requeued it.
September 6, 21:53:35 Recovery requeued the same artifact for missing output.
September 7, 01:24:15 Recovery requeued the same artifact for missing output.
September 7, 16:14:34 Recovery requeued the same artifact for missing output.
September 8, 03:13:15 Recovery requeued the same artifact for missing output.
September 8, 03:37:10 Recovery requeued the same artifact for missing output.
September 8, 03:39:08 The inspected application container started.
September 8, 03:42:59–03:43:10 The artifact’s partial output grew between observations, confirming active encoding. No download referenced the artifact.

The repeated operational log message was:

download artifact output missing, re-queuing

What was directly verified

  • The artifact existed and was actively being encoded.
  • No download row referenced its artifact ID.
  • No download row remained for its media file ID.
  • Its worker lease was being renewed.
  • Its partial output file was growing.
  • Six retained missing-output requeue messages identified the same artifact.
  • The artifact output directory was not persistently mounted.

What remains uncertain

The original download row had been deleted, so its former artifact_id could not be inspected. The closely matching creation times strongly suggest the initial download and artifact were associated, but the retained audit record does not conclusively preserve that relationship.

The logs establish six requeue events, not six independently verified completed encodes.

Container recreation explains how the unmounted output can disappear while the database record survives. The cause of every historical output disappearance was not individually established.

Reproduction procedure

This procedure is derived from the observed incident and inspected implementation. It has not yet been executed as an isolated regression test.

  1. Start Silo with persistent PostgreSQL storage and a nonpersistent artifact output directory.
  2. Using a user permitted to download, request a download requiring remux or transcode preparation.
  3. Record the download-to-artifact association.
  4. Delete that download.
  5. Verify that no other download references the artifact.
  6. Observe whether queued or running preparation continues.
  7. If necessary, allow preparation to reach ready state.
  8. Recreate the application container while preserving PostgreSQL and discarding the temporary artifact output.
  9. Allow Prepare Download Artifacts to execute.
  10. Check for a missing-output requeue message and a new preparation process.
  11. Confirm that the artifact is being encoded despite having no download references.
  12. After completion, repeat container recreation to test repeated regeneration.

Also test deleting the last consumer while preparation is queued or running without recreating the container. That separates the consumer-lifecycle defect from the temporary-storage trigger.

Technical findings

Download deletion does not coordinate artifact preparation

In internal/downloads/service.go, Service.Delete:

  • Deletes managed entries through Repository.DeleteManaged.
  • Cancels or deletes ephemeral entries according to their state.

The inspected deletion paths do not coordinate with ArtifactManager to determine whether preparation has lost its final consumer.

Keeping shared artifacts independently is reasonable for reuse. The missing part is coordinating whether their preparation remains necessary.

Artifact claiming does not require a download reference

In internal/downloads/artifact_repo.go, ArtifactRepository.ClaimNext selects candidates using:

  • Queued or running artifact state.
  • Retry timing.
  • Lease expiry.

The candidate query does not require a corresponding download reference.

An orphaned queued artifact therefore remains eligible for preparation. An orphaned running artifact can also be reclaimed when its lease expires.

Missing-output recovery requeues artifacts without checking demand

In internal/downloads/artifacts.go, ArtifactManager.recoverReadyArtifacts:

  1. Lists ready artifacts.
  2. Checks their local output paths.
  3. Requeues artifacts when the filesystem check fails.

The local recovery path does not check whether a download still needs the artifact before requeueing it.

This matches the retained missing-output messages and the actively running artifact with no consumers.

Recovery runs before orphan cleanup

ArtifactManager.RunOnce performs:

recoverQueueState
drain
recoverReadyArtifacts
drain

The enclosing task calls Cleanup afterward.

Consequently, a missing ready artifact can be requeued and processed before orphan cleanup is reached.

Orphan cleanup excludes queued and running work

ArtifactRepository.ListUnlinkedReadyBefore selects artifacts that:

  • Have a ready status.
  • Have no download references.
  • Have a last_used_at older than the cutoff.

The configured unlinked-artifact retention is 30 days.

This leaves two gaps:

  • Queued and running orphans do not qualify for the ready-only sweep.
  • Recently used ready orphans can be regenerated even when no download needs them.

Successful regeneration refreshes retention

ArtifactRepository.MarkReady sets both:

completed_at = now(),
last_used_at = now()

An unnecessary successful regeneration therefore refreshes the timestamp used to determine when an unreferenced artifact becomes eligible for cleanup.

Repeated regeneration can postpone age-based cleanup.

Requeue resets the attempt counter

ArtifactRepository.Requeue resets:

attempts = 0

It also clears error, retry, completion, and lease state.

The observed attempt count therefore did not represent the artifact’s lifetime number of preparation attempts. The retry limit does not bound repeated successful preparation followed by output loss and requeue.

Temporary storage amplifies the defect

The durable database record survives container recreation, while an unmounted artifact directory does not.

A persistent artifact mount would prevent this particular source of output loss. It would not fix orphaned queued/running work or prevent regeneration after other forms of output loss.

Impact

  • Unnecessary CPU/GPU use after the user has deleted the download.
  • Repeated reads of source media and writes of generated output.
  • Preparation slots occupied by work with no current consumer.
  • Additional background load after container recreation.
  • Confusing task activity when the user-visible download list is empty.

No data corruption or cross-user disclosure was established in this investigation.

Task observability

The task reports:

0%: Processing download artifact queue
100%: Download artifact queue drained

It does not report individual encode progress.

That is separate from the lifecycle defect, but makes the symptom harder to understand: the task can remain at 0% while an unnecessary encode is actively progressing.

Suggested fix scope

The implementation should distinguish retaining cached bytes from retaining demand to produce bytes.

Potential requirements:

  • Define which download states count as consumers requiring preparation.
  • Skip or retire orphaned queued work.
  • Avoid requeueing missing output when no consumer requires it.
  • Define cancellation behavior when the final consumer disappears during preparation.
  • Preserve preparation required by other consumers.
  • Coordinate consumer attachment, deletion, claiming, recovery, and cleanup.
  • Preserve lease fencing and prevent obsolete workers from publishing output.
  • Apply equivalent demand rules to local and remote artifacts.
  • Handle cleanup of partial output according to the chosen lifecycle policy.

Concurrency constraint

A separate EXISTS check before encoding is not sufficient by itself.

The inspected creation path ensures the artifact before creating the linked download row. During that interval, a valid new artifact can temporarily have no download references.

A worker or cleanup pass must not interpret that temporary state as proof that the artifact is abandoned.

Similarly, deletion of the last observed consumer can race with another consumer attaching. Any fix must preserve shared-artifact behavior across devices, profiles, and accounts.

Regression tests

Consumer lifecycle

  • Delete the sole consumer while preparation is queued.
  • Delete the sole consumer while preparation is running.
  • Delete one of multiple consumers and verify remaining downloads still complete.
  • Replace a download’s quality/artifact while its previous preparation is running.
  • Verify canceled or otherwise inactive download states follow the defined demand policy.

Recovery and storage

  • Missing ready output with no consumers does not start another encode.
  • Missing ready output with a valid consumer is regenerated.
  • Container recreation with PostgreSQL retained does not regenerate orphaned artifacts.
  • Repeated output loss does not cause an unbounded orphan regeneration cycle.
  • Expired leases on orphaned work follow the same demand policy.
  • Partial outputs are cleaned up safely.
  • Existing unreferenced cached artifacts follow retention policy without being rebuilt solely to preserve the cache.

Concurrency

  • Download creation races with worker claiming.
  • Download creation races with orphan cleanup.
  • Final-consumer deletion races with a new consumer attaching.
  • Worker completion races with final-consumer deletion.
  • A worker that loses its lease cannot publish stale output or alter the replacement worker’s result.

Artifact variants

  • Ordinary artifact states.
  • Tone-map artifact states.
  • Audio-v2 artifact states.
  • Local preparation.
  • Remote preparation and cleanup.
  • Readiness updates and notifications for legitimate remaining consumers.

Investigation status

This report is based on read-only inspection of application processes, output growth, PostgreSQL records, retained operational logs, request audit records, container mounts, and the source paths above.

No work was canceled or deleted during the investigation. No implementation or deployment changes were made. An isolated automated reproduction and regression fix remain outstanding.

Activity

  1. changed the title [-]bug(downloads): orphaned download artifacts keep transcoding after their downloads are deleted[/-] [+][bug] Orphaned download artifacts keep transcoding after their downloads are deleted[/+] on Sep 8, 2026
  2. added
    bug
    on Sep 8, 2026
  3. added
    triaged
    and removed
    triaged
    on Sep 20, 2026
  4. added theissue type on Sep 20, 2026
  5. removed
    bug
    on Sep 20, 2026
  6. scottrobertson commented on Sep 23, 2026

    @scottrobertson

    I'm also seeing this, on build-787 (8e5ae2f, Docker, no persistent mount for /tmp/silo-download-artifacts).

    A couple of things that might be useful on top of the original report:

    Cancelling the task doesn't stop it. I requested a movie download from the iOS app, then the next morning cancelled "Prepare Download Artifacts" from the admin UI and deleted the download 15 seconds later. The artifact's last_used_at still updated 13 minutes after that, and file_size was filled in, so the encode kept running and finished anyway.

    From activity_log (UTC):

    2026-09-21 22:27:11  POST   /api/v1/downloads                                      202   (artifact created_at same second)
    2026-09-22 07:46:03  POST   /api/v2/admin/tasks/encode_download_artifacts/cancel   200
    2026-09-22 07:46:18  DELETE /api/v1/downloads/{id}                                 204
    2026-09-22 07:59:12  artifact last_used_at updated
    

    Same audio_v2_running state as yours. When today's image update recreated the container, the artifact was re-queued and started a full transcode again, with nothing in downloads or user_downloads:

    time=2026-09-23T11:22:55.315+01:00 level=WARN msg="download artifact output missing, re-queuing" component=downloads artifact_id=144221027545645074 path=/tmp/silo-download-artifacts/1208_transcode_2fbedc28baa308ba.mp4

    status=audio_v2_running, audio_recipe_version=4, attempts=1/3, and it's the only row in download_artifacts.

    My source files are on a network mount, so every image update re-reads the whole 13 GB source. That makes this a bit more painful than just the CPU time. I've left the row in place in case you want me to check anything else.

    AI disclosure: I used Claude Code (claude-opus-5-5) to run the read-only DB and log queries and to help write this up. I checked it before posting.

  7. Rhainland commented on Nov 13, 2026

    @Rhainland
    Contributor

    Reproduced on origin/main at 85d1c16: with two managed transcoded downloads, one encoding and one queued, deleting both left the running ffmpeg going to the end and then started the queued job. Both finished as ready files no download used.

    Cause: deleting a download never touched its preparation job, and the claim query picked up queued or lease-expired jobs whether or not any download still needed them. #1468 fixed missing-output recovery for ready files, but not work that was queued or running.

    Fix in #4085: when the last waiting download of a job is deleted, revoked, or moved to another quality, the job is retired and its encode stops; a job another download still waits on keeps going. The preparation run also retires jobs nothing has needed for ten minutes, which covers other removal paths and orphaned rows left by earlier versions. Checked on a local build of the fix with the same steps: both jobs were retired during the delete requests, ffmpeg exited, and the partial file was removed. Deleting one of two downloads that share a job let the other finish, and asking for a deleted file again prepared it. DB-backed tests cover the delete, shared-job, late-link and stale-orphan cases, and a re-request while the stopped worker may still be running.

    AI disclosure: reproduced and fixed by Claude Code (claude-opus-5-5) at the maintainer's direction.

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

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions