Removes genuinely dead code (unused import, no-op cast, an unused
PendingGrab accessor, and TmdbClient's TV-search methods now that TVDB
fully covers that path), tightens len()>0 checks to is_empty(), swaps
two fixed-size test vec!s for arrays, restructures a match to avoid an
unnecessary unwrap_err, fixes doc-comment list indentation, and hoists
a locked-connection call out of a match scrutinee. Struct fields/enum
variants that are still meaningful but not read by current callers
(TorrentInfo::save_path, GrabCycleStats::items_seen, X1337 fallback
route, BacklogCandidate::path) get #[allow(dead_code)] rather than
deletion, same for the two 8-argument functions (too_many_arguments).
- transcode_job gains is_anime/force_reencode so a job can be
re-encoded even though it's already AV1 - needed for the rate-control
bug that left ~476 files larger than their originals; the normal
backfill query skips already-AV1 files, so this is find_oversized_
av1_candidates plus a dedicated retranscode-oversized CLI command
- relink-orphaned-files: read-only reconciliation for episode_file rows
that lost their association (DB-recovery incident) despite the real
file still sitting where the importer would have put it
- qbit: delete finished torrents from qBittorrent after import instead
of relocating them with set_location, since nothing is left seeding
from the old save path after the move
These four files mix two things too interleaved to commit separately:
in-progress work on anime pipeline tuning (quality/preset/thread
config, per-pipeline parallelism caps), sampled decode verification,
and subtitle-codec-aware remuxing that predates this commit, plus a
set of correctness fixes from an independent Opus 5 review applied
directly on top of it:
- Attached-pic (cover art) streams could be probed as the real video
stream when they came first, silently replacing the actual
codec/height (ffprobe.rs)
- probe_failed rows (null codec/height) were enqueued for transcode
and could never be claimed again, due to the unique partial index -
should_enqueue now rejects them
- tokio::try_join! cancelled the sibling pipeline's in-flight
spawn_blocking encode on the first Err instead of letting it finish
- Duplicate episode_file rows for the same media only had one swept on
an upgrade swap, leaving stale rows/files behind
- File-swap and DB-write on transcode completion weren't atomic;
wrapped in a transaction and made probe-refresh failure non-fatal
- In-progress transcode temp files were visible to library scans
(video extension, no dotfile prefix) and could get imported mid-encode
- Remux temp files leaked on error paths; a Jellyfin refresh failure
failed the whole import cycle instead of just logging
- insufficient_space could false-positive when the download and
library dirs are on the same filesystem (rename is free there)
- Config validation for reference_height and min_size_reduction_pct,
which previously could silently divide-by-zero or overflow deep
inside an encode
- Atomic claim on review-queue approval, closing a double-approve race
that could grab the same release twice (scheduler.rs)
- Constant-time comparison for the daemon API token, closing a timing
side channel
- RSS items wrapped in CDATA (common for titles with '&') were
silently dropped - only Event::Text was ever handled
- Reject malformed apibay info_hash values before building a magnet
link that extract_btih can't parse back out
- Parse sizes with no space before the unit ("38.1GiB")
- Fix "Season N - NN" episode parsing and stop misreading a
YYYY-MM-DD date as a bare episode range
- Query embeddings are no longer cached, fixing unbounded cache growth
over the daemon's lifetime (only library-side candidates need caching)
Requested and applied a full review of the AV1 transcode implementation.
Findings and fixes:
- Season-pack import bypassed upgrade_locked entirely: a season pack
scored higher than a locally-transcoded file's stale release score
would silently overwrite it. Fixed in import_season_pack_file (and
mirrored into import_one for defense-in-depth) to check
upgrade_locked before the score comparison, not after.
- The post-import enqueue hook only checked anime, silently skipping
the HDR/2160p exclusions find_backlog_candidates applies to the
backfill -- a freshly-grabbed HDR file would have gone through the
unverified HDR-via-VAAPI path. Centralized all eligibility rules
(anime, already-av1, HDR, height) into transcode::should_enqueue,
used by both import_one and the newly-added season-pack enqueue
hook (season packs previously had no transcode hook at all, despite
being the actual headline use case -- 100GB+ season packs).
- find_backlog_candidates: a NULL-height row was included as a
candidate but could never actually be claimed (claim_pending_jobs
requires non-null height), permanently stuck pending. Fixed the
WHERE clause.
- encode_and_verify now probes the real input file first and skips
the encode entirely if it's already AV1 -- closes a narrow crash
window where a rename-succeeded-but-DB-update-failed job would
otherwise re-encode an already-transcoded file on retry.
- finalize_job's success path could leak a verified temp file and
strand a job in 'running' forever if a filesystem operation failed
partway through; now wrapped so any failure there cleans up and
marks the job failed like every other error path.
- reset_orphaned_running_jobs now also sweeps each reset job's
leftover temp file (job-id-scoped paths, so this lookup is
unambiguous) rather than leaking them on a disk that's usually
already tight on space.
- Added a unique index preventing two active jobs for the same file
ever existing at once -- closes the remaining gap in last commit's
concurrency fix (a daemon restart's reset could otherwise race a
still-alive transcode-library backfill onto the same file).
- Made the VAAPI rate-control mode explicit (VBR) instead of
driver-inferred.
- The daemon's transcode ticker awaited each cycle inline in the
tokio::select! loop, blocking every other cycle (import, search,
upgrade, reconcile) for the full multi-minute duration of an
encode. Now spawns each cycle detached with a try-lock guard so
overlapping ticks skip cleanly rather than stacking (the
concurrency cap from the previous commit makes this safe).
Two items reviewed and deliberately left as documented, not fixed:
mp4 sources with mov_text subtitles will fail the encode cleanly (no
data loss, just no space saved) since Matroska can't hold that codec
via stream copy -- fixing this needs per-stream codec probing that
wasn't safe to add untested at this hour. Renaming an mp4 source's
extension to .mkv after transcoding is cosmetic (Jellyfin
content-sniffs fine) and left alone.
The daemon's steady-state transcode ticker and a manually-launched
transcode-library backfill process were both independently claiming
pending jobs from the same queue with no shared concurrency
awareness, each capping only at its own parallelism_max. Combined
with large files easily outlasting the 30s poll interval, this
stacked to 20+ simultaneous GPU encode/decode sessions and triggered
the kernel OOM killer on a shared 15GB host running a dozen+ other
containers (confirmed via dmesg; no services were lost, no library
files were touched — the original-file-safety design held under the
crash).
Fixes: claim_pending_jobs now treats its limit as a total concurrency
cap (subtracting already-running jobs, wrapped in a BEGIN IMMEDIATE
transaction so this is correct across concurrent processes touching
the same database, not just within one). Added reset_orphaned_running_jobs,
called on real daemon startup, so a crash never permanently strands
job slots in 'running'. Lowered the default parallelism_max from 4
to 2 given the observed real-world memory pressure.
Post-grab async background swap, upgrade_locked flag to prevent the
upgrade loop from re-inflating a locally-transcoded file, and a
transcode-library CLI backfill for the existing catalog. Bitrate model
calibrated against Silicon Valley's real HEVC bitrate, scaled by
resolution and AV1's encoding efficiency. HDR/2160p and anime excluded
from this first pass. Jellyfin session polling throttles batch
encoding back to 1 stream during active playback.
The "reject sub-1080p when a better resolution exists in this batch" gate
(and every other quality gate) only ran on the confident auto-match path —
a low-confidence match skipped straight to queue_for_review before ever
reaching it. A human review decision is about whether this is genuinely
the right show, not a backdoor around quality standards; a title match
being ambiguous is no reason to let a worse-quality release through
untested. Verified live: several 720p season-pack releases were sitting in
the review queue for shows that also had 1080p+ alternatives in the same
search batch. Moved the gate check ahead of the review-queue branch so it
applies uniformly.
process_item queued anything landing in the matcher's "needs review"
confidence band immediately, without ever checking whether the show/
season/episode/movie actually needed anything — that check only ran on
the auto-match path. A low-confidence match against an already-complete
show gained nothing from a human's yes/no, it was just noise that
reappeared every cycle the source kept re-listing the same old release
(verified live: fully-complete shows' season-pack re-releases piling up
in the review queue indefinitely). Reordered so the eligibility check
(movie/season-pack/episode) runs first regardless of confidence, and only
a genuinely-needed release ever reaches the queue-for-review decision.
SEASON_PACK_RE only matched an explicit parenthesized "(S01 Complete)"
form, so any other real-world season-pack naming convention — bare
"S10.COMPLETE", spelled-out "Season 8 Complete", "[Season 4 Four
Complete]", or no "Complete" marker at all ("Game of Thrones - Season 8
S08 - 2019") — came back with season = None entirely, not just an
unresolved episode. That fed straight into review-queue approvals
returning "could not resolve which episode this release is" for releases
that were genuine, resolvable season packs. Broadened to a bare season
marker, safe here since this is only reached after SXXEXX_RE/SXX_DASH_EP_RE
have already failed to find a real episode number.
Library tab gets a cycling filter (all/series/movies/missing/unmonitored)
and sort (title/missing/kind), color-coded kind tags and missing-count
severity, and monitor-toggle without opening detail. Keybinding hints move
out of cramped block titles into a context-aware status bar plus a `?`
help overlay, both driven by one shared keybinding table so they can't
drift apart. Episode status icons and review-queue confidence get the same
severity coloring. Stuck tab gains real selection/focus and can jump
straight to a show's Library detail (needed adding media_item_id to
StalledGrab's query — the one small backend touch in this pass). Adds a
manual refresh-now key.
Search results were sorted purely by seeder count, so a season pack only
won out over a single-episode release by accident. Season packs already
clear every missing episode of that season in one grab and go through the
same seeder/quality gate as anything else (an unviable pack still gets
rejected there and iteration falls through to the next candidate) — so
sorting packs first, seeders as the tiebreaker, is a strict improvement
with no new risk. Shared by both the automated search cycle and the
manual-search candidate list.
Season 0 is TVDB's catch-all for specials/recaps/shorts and often a tie-in
movie already tracked as its own separate media_item (verified live:
Chainsaw Man's season 0 included a movie already present as its own entry).
Monitoring these by default means the library never actually "completes"
and inflates the missing-episode count with content nobody asked to
acquire as an episode. Regular seasons are unaffected.
Plain /episodes/default returns names in the show's original airing
language — for a lot of anime that's Japanese with no English name at all,
which is what was ending up embedded in generated filenames. TVDB carries
real crowd-sourced English translations at /episodes/default/eng (same
numbering/air-date fields, just a better name) — try that first and only
fall back to the original-language endpoint if a show has no English data.
TVDB has no English episode title at all for some shows (entire seasons of
otherwise-English-titled shows came back Japanese-only) — using it verbatim
put unreadable-to-most-tooling script into an otherwise Latin-script library.
Falls back to the no-title filename shape instead.
"S01E01v2" (a fixed re-release of an episode) glued the version marker
directly onto the episode number with no separator, so the word-boundary
check after the digits never matched and the whole file fell through as
unparsed. Verified live: some shows had zero episode files linked because
every release happened to be a v2.
qBittorrent's newer WebUI API returns 204 (not 200 "Ok.") on login success,
and a JSON success/failure summary (not plain "Ok."/"Fails." text) from
torrents/add — both broke against the currently deployed version. Also had
scan_tv_root move already-tracked episode files into their Season NN
subfolder instead of just recording wherever they already sat on disk.
OrtEmbedder's tokenize -> tensor build -> mean-pool -> L2-normalize
pipeline was near-byte-identical to breadmill's own OrtEmbedder (same
truncation, same actual_seq.min(mask.len()) padding guard, same 1e-10
epsilon) — now both share bread_onnx::embedding::EmbeddingSession (path
dependency for now, see the TODO in breadarrd/Cargo.toml). This crate
stays CPU-only (Provider::Cpu), matching its existing documented rationale.
ensure_model's reqwest-based download function is replaced with
bread_onnx::download::ensure_file (sync/ureq, matching breadmill's own
downloader and this workspace's bakery convention) dispatched via
spawn_blocking from this async context.
Builds and tests clean across the whole breadarr workspace: 205 passed, 1
pre-existing network-dependent test ignored, 0 failed.
Both import_one and import_season_pack_file deleted the existing
episode_file row and unlinked the on-disk file *before* link_or_copy_file
placed the new one. If the link/copy (or the free-space check) then
failed, the original content and its DB row were already gone with
nothing to fall back to.
Now the stale file is renamed to a sibling (freeing dest for the
hardlink fast path, same as before) and the DB row is left alone. Only
after the replacement is confirmed on disk are the file and the
old row cleaned up; any failure in between restores the original file
before returning the error.