fix: spend FL tokens even when .torrent is cached (v0.28.1) - #47
Merged
Conversation
v0.28.0 only sent usetoken=1 on a .torrent cache MISS, but the local .torrent cache is unrelated to freeleech: a token is registered server-side via action=download&id=X&usetoken=1, while the audio DATA is re-downloaded fresh each time (the cache holds only the tiny .torrent file). Every karaoke-gen download hits /download-by-id with a cached .torrent, so zero tokens were spent. - Register the token BEFORE the cache short-circuit; reuse the cached .torrent for the actual data fetch. - Local 7-day token ledger (on-disk <id>.tokened markers + in-memory fallback for when the cache dir is unwritable) prevents re-spending within RED's personal-freeleech window; a per-provider lock stops concurrent album-batch downloads of the same torrent each spending one. - Pace token spends >=1s apart (RED rejects faster); pacing trails only successful spends so an exhausted-token steady state adds no delay. - 6 new tests; full suite green (657). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After enabling
RED_USE_FL_TOKENon prod, zero freeleech tokens were being spent despite karaoke-gen downloads. Investigation of the flacup logs showed every RED/OPS download hits/download-by-id→fetch_artifact_by_id, which served the.torrentfrom local cache and returned before ever calling the RED download endpoint whereusetoken=1lives (5/5 downloads were cache hits, 0 token attempts).The v0.28.0 logic assumed "
.torrentcached ⇒ already have it ⇒ no token needed." That's wrong: a token is registered server-side viaaction=download&id=X&usetoken=1, and the.flacfetchcache holds only the tiny.torrentfile (2.2 MB total on the box) — the audio data is re-downloaded fresh every time and counts against ratio.Fix
.torrentis cached; the cached.torrentis still reused for the actual data fetch.<id>.tokenedmarkers (survive restarts) + in-memory fallback for when the cache dir is missing/unwritable (per CodeRabbit — avoids a double-spend race with no cache dir).Tests
Review
Local CodeRabbit: 1 major finding (double-spend when cache dir unavailable) → fixed with the in-memory ledger → re-review clean.
@coderabbitai ignore