Skip to content

Don't lose a playlist to one failed status poll - #8

Merged
Gabriel-Lewis merged 1 commit into
devfrom
fix/monitor-poll-resilience
Aug 30, 2026
Merged

Gabriel-Lewis merged 1 commit into
devfrom
fix/monitor-poll-resilience

Conversation

@Gabriel-Lewis

Copy link
Copy Markdown
Owner

Audit findings 1 and 2 — they're the same bug, so they're fixed together.

The bug

MonitorDownloads treated any error from GetDownloadStatus as fatal and returned immediately, ending monitoring for every track at once. Since filterLocalTracks keeps only tracks marked Present, everything still downloading was then dropped before the playlist was built.

What made it fire in ordinary operation: slskd's GetDownloadStatus returned no files found to monitor when the status map came back empty — conflating "nothing queued yet" with "the request failed." The first poll happens one SLSKD_MONITOR_INTERVAL (default 1 minute) after queueing, so a slskd that hadn't yet surfaced its transfers ended the run before it started.

The fix

  • An empty result is no longer an error. The monitor already decides how long to wait for a file to appear (2 ticks), so that decision stays in one place.
  • Real request failures are still reported, but the monitor rides out up to 3 consecutive ones instead of aborting on the first. The downloads themselves keep going regardless; only the monitor loses sight of them.
  • A successful poll resets the budget, so unrelated blips spread across a long run don't accumulate into a false "3 in a row."

Testing

Six tests, all mutation-checked by reverting to the old behaviour — each one fails with the old code:

  • a transient failure doesn't abandon the track (want nil after recovering)
  • a success resets the failure budget
  • a genuinely unreachable service still ends the run, after exactly 3 polls
  • an empty status map completes normally
  • slskd returns an empty map rather than an error when nothing is queued
  • slskd still reports a real HTTP failure

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

🤖 Generated with Claude Code

Monitoring ended for every track at once whenever a status poll failed,
and tracks that never reach Present are dropped before the playlist is
built. One blip -- a restarted slskd, a dropped connection -- therefore
cost every download still in flight.

Two things caused it. The monitor treated any error from
GetDownloadStatus as fatal, and slskd's implementation returned an error
when it found nothing to report, which is the normal state a minute
after queueing rather than a failure. The first poll happens one
CheckInterval after the downloads are queued, so a slskd that had not
yet surfaced the transfers ended the run before it had begun.

An empty result is now just an empty result; the monitor already decides
for itself how long to wait for a file to appear. Genuine request
failures are still reported, but the monitor rides out up to three in a
row before giving up, and a success resets the budget so unrelated blips
spread across a long run do not accumulate into one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Gabriel-Lewis
Gabriel-Lewis merged commit 0d5e770 into dev Aug 30, 2026
4 checks passed
@Gabriel-Lewis
Gabriel-Lewis deleted the fix/monitor-poll-resilience branch October 19, 2026 21:12
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