Budget provider and translator calls with a token bucket #197
Closed
opened 2026-08-24 21:28:39 +01:00 by naps62-yolo
·
2 comments
No Branch/Tag Specified
main
ui-mobile-first
codex/fix-action-button-reload
translation
qbit-2
docker
bugs
blitz/subtitles
fix/255-provider-reorder
blitz/feedback-3
subtitles/251-icon-vocab
subtitles/237-relocate-subs
fix/248-title-move-creates-root
blitz/feedback-2
issue/227-abandoned-pack-visible
issue/245-backoff-anchor
issue/240-design-coherence
issue/211-waived-rule
issue/232-plainer-words
issue/246-policy-reclassify
issue/244-root-slash-stored
issue/231-settings-rows
issue/241-reclassify-on-root-change
issue/239-failure-window
issue/230-icon-only
issue/243-root-path-edges
issue/238-attention-liveness
issue/229-back-button
issue/236-root-path-move
issue/226-attention-threshold
issue/228-root-move
blitz/size-bands
size-bands/209-runtime-scale
size-bands/210-size-waiver
size-bands/208-runtime-design
blitz/reliability
reliability/155-sqlx-migrations
reliability/176-refresh-on-add
removal-nav/175-removal-controls
removal-nav/174-season-file-removal
removal-nav/172-search-titles
removal-nav/173-homepage-library
removal-nav/171-untrack-clears
removal-nav/170-chip-align
removal-nav/169-design-amendment
feedback/167-deck-autosearch
feedback/165-chip-colour
feedback/166-header-rail
feedback/163-drop-cast
feedback/164-control-geometry
feedback/162-season-ordering
feedback/161-search-episodes
feedback/160-autotrack-seed
feedback/159-design-amend
blitz/rich-metadata
rich/151-grid
rich/148-search-rows
rich/150-series-meta
rich/149-movie-page
rich/147-search-art
rich/156-rating-null
rich/146-meta-api
rich/145-poster-cols
rich/144-trailer
rich/143-meta-detail
rich/142-design-amend
blitz/153-empty-episode-titles
blitz/152-deck-routes
blitz/141-season-vanished-api
blitz/129-series-detail-view
blitz/140-attention-episode-numbers
blitz/137-season-removals
blitz/133-attention-tv-lanes
blitz/139-movie-id-episode-guard
blitz/134-stale-attention-queue
blitz/124-rss-episode-matching
blitz/136-imdb-series-lookup
blitz/132-manual-commands
blitz/128-series-delete-files
blitz/131-status-seasons-input
blitz/138-plural-season-range
blitz/135-pack-name-parse
blitz/122-upstream-removals
blitz/130-add-series-search
blitz/121-series-refresh
blitz/127-unified-search-tv
blitz/123-episode-matching
blitz/126-tv-attention
blitz/119-tracked-rule
blitz/125-season-deck
blitz/120-tvdb-id
blitz/118-season-zero
blitz/117-design-amend
issue/115-avail-search
issue/112-name-truncate
issue/111-score-colors
No results found.
Labels
Clear labels
area/api
area/ci
area/compat
area/core
area/daemon
area/db
area/dl
area/indexer
area/infra
area/meta
area/parse
area/probe
area/subs
area/web
difficulty/easy
difficulty/hard
difficulty/moderate
difficulty/trivial
phase/1-skeleton
phase/2-logic
phase/3-sourcing
phase/4-movies
phase/5-ui
phase/6-tv
phase/7-people
phase/8-compat
phase/9-subtitles
type/bug
type/chore
type/feature
type/test
arr-api
CI and test harness
arr-compat
arr-core
arr-daemon
arr-db
arr-dl
arr-indexer
workspace and tooling
arr-meta
arr-parse
arr-probe
arr-subs crate: providers, extraction, translation, sync
web/
bounded, obvious approach, few files
subtle correctness or cross-cutting
multiple files, judgement, an interface to design
one file, mechanical, no design decisions
workspace, CI, config, database, empty API and SPA
parsing and policy engine, pure, no network
TMDB and Prowlarr, read-only
movies end to end
search, buckets, library views, queues
seasons, episodes, tracking, derived status
owner tags and notifications
Jellyseerr shim
build order: subtitles, DESIGN.md §15
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Depends on
Reference: yolo/arr#197
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Bound how fast arr spends other people's APIs. Enabling subtitles on an
existing library means every media file wants two languages at once, and the
OpenSubtitles free tier is a single-digit number of downloads per day.
Per DESIGN.md §15 (added by #183):
daily allowance. The allowance is a database setting (#198).
backlog drains over days without starving current viewing.
missing-subtitles queue (#202) as waiting on budget, and nothing notifies.
using the usage the backends report (#192).
429still backs off independently — the bucket is arrbeing polite, not a guarantee about the other end.
Depends on: #196
Integration note from the milestone driver, carried forward from #192.
Backend::characters_billed()(added by #192, default zero so it is additive for the other backends) is cumulative since the backend was constructed, not per-call. #192 flagged that this issue may want a per-call number instead, since polling a counter on adyn Backendis awkward for a token bucket that has to attribute spend to one translation.The trait change is small if you decide per-call is the right shape — but decide it here rather than working around the counter, because this is the only issue that consumes it.
Also relevant:
just cinow runs--all-features(seeblitz/subtitles). Before that, no translation backend was compiled by the gate at all, so treat any pre-existing green CI on backend code as meaningless.Implemented DESIGN.md §15's token bucket, on branch
subtitles/197-subs-budget(based onblitz/subtitles).A new
subtitle_budget_spendtable (migration0027) tracks one row per (kind, name, day).arr_db::subtitle_budget::try_spendis a single atomic upsert-with-cap query, so concurrent reconcile closes (up to 4 in flight) can't both slip a spend past the daily allowance. No allowance configured for a name reads as unlimited, per the existingsubtitle_settingscomment from #198.Providers are charged one unit per download, claimed right before
Provider::downloadis called (search itself is not budgeted — the scarce resource DESIGN.md names is downloads, e.g. OpenSubtitles' free-tier daily cap). If the ranked winner's provider is over budget, the reconcile loop drops that provider's candidates and re-ranks rather than giving up on the gap, so a cheaper/lower-ranked candidate from another provider still gets downloaded when affordable. Only when every remaining candidate is budget-blocked does the gap recordcapped— it deliberately does not fall through to translation, since that would permanently settle the language with a worse (machine-translated) subtitle instead of waiting for the cap to refill.Translators are charged the source character count, computed from the parsed cues before the network call, and spent atomically before
arr_subs::translate::translateruns.Design decision on
Backend::characters_billed(): the milestone driver's comment on this issue flagged that the trait's cumulative counter (added by #192) can't attribute cost to one call under concurrent use. I removed it — DeepL and Google'sAtomicU64billing counters and their trait impl are gone — and moved billing to a simple upfront character count of the source text, computed once in the daemon before spending. This is the same math DeepL/Google already used internally (sum of characters sent), just relocated so it's available before the call instead of polled after, and it now also applies uniformly toopenai/command, which previously always reported zero and were never budgeted at all.just cipassed through the gate (fmt, clippy--all-features,cargo machete, full test suite, web checks).Findings
openaiandcommandtranslation backends were never subject to any character budget before this issue, sincecharacters_billed()defaulted to 0 for both and nothing else computed usage. Not a regression I introduced — just noting it as a pre-existing gap this issue happens to close as a side effect.cappedstate with alast_failurestring distinguishing them ("provider daily budget exhausted" / "translator daily budget exhausted" vs a provider's own error text). No queue UI exists yet to consume that, so nothing to fix here.