Skip to content

Keep migrating a release until its files arrive - #7

Merged
Gabriel-Lewis merged 1 commit into
devfrom
fix/album-sibling-migration
Aug 30, 2026
Merged

Gabriel-Lewis merged 1 commit into
devfrom
fix/album-sibling-migration

Conversation

@Gabriel-Lewis

Copy link
Copy Markdown
Owner

Fixes album mode stranding most of each release. Follow-up to #4.

The bug

The recommended track is queued first and so normally finishes first. Migration ran exactly once — at that moment — so every sibling still transferring was skipped. The monitor then set track.Present = true and deleted the track from progressMap, so nothing ever came back for them.

From a real run:

migrated release album="Music, Fashion, Film" moved=2 "still downloading"=11

11 of 14 tracks finished downloading into slskd's directory and stayed there. moved=10 on another release only worked because it happened to complete in order. I flagged this as a limitation when I wrote #4, but it fires on the common path, not an edge case.

The fix

MoveAlbumSiblings now reports how many files are still in flight, and the monitor retries each release every tick until that reaches zero:

  • Migrated files are dropped from track.AlbumFiles, so repeated calls are idempotent.
  • Files slskd has given up on are dropped too, so a failed transfer can't hold a release open to the deadline.
  • Files still transferring are left alone, as before — copying a partial file would put a truncated track in the library.
  • The monitor's exit condition now waits on outstanding releases, which is what makes the retry reachable at all.
  • A release that stops progressing is abandoned on the same deadline a stalled track uses, so a peer that vanishes can't keep the monitor running forever. Its files are left in place, not deleted.

Progress is measured against the count the migrator last returned rather than against track.AlbumFiles. An earlier version read the field directly, and a test using a different migrator abandoned a release that was actively downloading — the deadline should depend on the interface, not on how an implementation keeps score.

Refactor carried along

Sibling migration moved out of MoveDownload, which now returns the directory the track landed in. Doing it there was wrong in principle: the work belongs where the retrying happens, not in a function that runs once. Directory cleanup moved with it, so a release directory is removed after the last sibling leaves rather than while siblings are still sitting in it.

errorState replaces the "Errored" literal so code reacting to a failed transfer can't drift from the code that labels one.

Testing

The end-to-end test drives MonitorDownloads with a release whose files arrive one pass at a time and asserts it doesn't return early. Mutation-checked by reverting the retry wiring — it fails with migrator called 1 times; the monitor stopped before the release finished and 2 files were left behind, which is the reported symptom exactly.

Also covers: a sibling that finishes on a later pass, migrated files not being retried, failed siblings not blocking completion, progress resetting the deadline, a stalled release being abandoned with its files left intact, and single-track downloads never being recorded for retry.

go build ./..., go vet ./src/..., go test ./src/... all pass.

🤖 Generated with Claude Code

Album mode stranded most of each release. The recommended track is
queued first and so normally finishes first, and migration ran once, at
that moment: every sibling still transferring was skipped and never
looked at again. The monitor then marked the track present and dropped
it from its progress map, so nothing came back. A real run migrated 2 of
14 tracks and abandoned the other 11 in slskd's directory.

MoveAlbumSiblings now reports how many files are still in flight, and
the monitor retries each release every tick until that reaches zero. It
drops migrated files from track.AlbumFiles so repeated calls are
idempotent, and drops ones slskd has given up on so a failed transfer
cannot hold a release open. Files still transferring are left alone, as
before -- copying a partial file would put a truncated track in the
library.

The monitor's exit condition now also waits on outstanding releases,
which is what makes the retry reachable. A release that stops making
progress is abandoned on the same deadline a stalled track is, so a peer
that goes away cannot keep the monitor running; its files are left in
place rather than deleted. Progress is measured against the count the
migrator last returned rather than against track.AlbumFiles, so the
deadline depends only on the interface, not on how an implementation
happens to keep score -- an earlier version read the field directly and
a test with a different migrator abandoned a release that was actively
downloading.

Sibling migration moved out of MoveDownload, which now returns the
directory the track landed in. Doing it there was wrong in principle:
the work belongs where the retrying happens, not in a function that runs
once. Directory cleanup moved with it, so a release directory is removed
after the last sibling leaves rather than while siblings are still in
it.

errorState replaces the "Errored" literal, so code reacting to a failed
transfer cannot drift from the code that labels one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Gabriel-Lewis
Gabriel-Lewis merged commit dba64ab into dev Aug 30, 2026
4 checks passed
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