Skip to content

fix(scanner): stop embedded fonts from inflating MKV bitrates - #4642

Merged
Quick104 merged 10 commits into
Silo-Server:mainfrom
Rhainland:fix/playback-exclude-attachments-from-bitrate-backfill
Nov 22, 2026
Merged

Quick104 merged 10 commits into
Silo-Server:mainfrom
Rhainland:fix/playback-exclude-attachments-from-bitrate-backfill

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

Other clients: N/A (server-side playback decision; clients need no change)

Pairs with the other fixes from the same report (ASS subtitles on an MKV with many large embedded fonts): #4639, #4640, #4641, Silo-Server/silo-android#1010, Silo-Server/silo-android#1011, Silo-Server/silo-android#1012, Silo-Server/silo-android#1013, Silo-Server/silo-apple#1237, Silo-Server/AetherEngine#30. Catalog text: Silo-Server/silo-translations#111.

MKV releases with many large embedded fonts are stored with a bitrate up to about twice the real one, so Silo sends them to transcode for bandwidth on clients that could direct play them. Matroska has no bitrate field, so FFmpeg derives the file's bit rate from its size and duration, and that counts the attached fonts. Fonts are read once when the file opens and are never streamed. This change stops new scans from counting attachments and corrects the files already in the library once.

Silo uses the stored rate for every play-method decision (native API and jellycompat), so correcting it fixes both surfaces.

Approach

  • Scans: the scanner subtracts the size of attachment streams (ffprobe's extradata_size) over the file's duration before storing the container bitrate. Files without attachments keep the same rate.
  • Existing rows: rescans skip unchanged files, so a new scheduled task, "Correct Bitrate of Files with Embedded Fonts" (backfill_attachment_bitrate), corrects them. It re-reads the format and stream entries of present MKV files with ASS or SSA subtitles, the releases that embed fonts. It writes only the bitrate column, and only over the row exactly as it read it. It runs at startup and daily under an advisory lock, so one node reads media across a cluster.
  • Progress: progress lives in a one-row table, attachment_bitrate_backfill_state. A restart or a stop on stalled storage resumes from a cursor. Files the task could not read, such as those under an offline library root, go on a list that later runs read again, so they are not skipped for good. Only timeouts count toward the stalled-storage stop, as in the HDR10+ backfill. A stall lists the whole batch it stopped in and moves past it. The retry list keeps its own position, so a root whose reads keep hanging holds up neither the walk nor the files listed after it. Once the walk is finished and the list is empty, a run is a single query.
  • The HDR10+ backfill and this one now share the stored-mtime normalizer.
  • The task's name and description are new web text, added in feat(catalog): add the embedded-font bitrate task text silo-translations#111. That change is merged, and main's catalog pin (2026.11.22-d00fa90) already carries both keys, so this branch changes no generated locale files.

Validation

  • Focused Go tests for internal/scanner, internal/taskmanager/..., internal/mediaprobe and internal/backup: pass. The two new database tests also pass through make test-db-contracts against a disposable pgvector database. The only other entries the contracts run reports are database tests that skip because this machine has no pg_dump/pg_restore.
  • make lint-changed, make verify-migrations, make verify-local-paths, make verify-size-ratchet: pass.
  • The web typecheck (tsc -b) passes after the locale sync.
  • make test-web was not run, because this change touches no web code beyond the generated locales.

Evidence

No screen changes. What changes is the stored bitrate that the play-method decision reads. I checked it with a synthetic file, "H264 MoreFonts (2018)": 60 s of 1080p H.264 at about 4 Mbps plus AAC audio, an ASS track, and six 5 MB font attachments. The probe ran through the scanner's ProbeFile at main and at this branch:

same encode without attachments (ffprobe format bit_rate): 4171 kbps
main   (975bbf41b): bitrate_kbps=8360 duration_s=60
branch (6e4b01220): bitrate_kbps=4169 duration_s=60

A client with a 6 Mbps limit transcodes this file on main and can direct play it on this branch.

The backfill's database tests cover these cases:

  • It corrects font-heavy rows.
  • It leaves non-candidates (SRT-only, MP4, missing) and rows changed on disk alone.
  • Nine fast read failures in a row (an offline root) neither stop the pass nor drop out of it, and those files are corrected once they can be read.
  • It resumes after a stall without re-reading finished batches.
  • A list of slow files that stalls while being read again keeps its unread entries and still lets the walk correct the files after the cursor.

Risks

  • Migration: one new table, attachment_bitrate_backfill_state, classified as server state for backups.
  • First run: the task reads the header of every present MKV with ASS or SSA subtitles once, four at a time, with the scan probe's 2-minute timeout per file. FFmpeg loads every attachment when it opens a Matroska file, so each read covers the file's whole font payload. On large anime libraries over network storage this adds read load for a while after the upgrade.
  • Hung storage: a run stops after 8 timeouts in a row, so a hung root with many candidates is passed one batch (200 files) per run, about one batch a day.
  • Catalog seed imports: rows a seed import inserts have no stored mtime, so the next scan reprobes them and stores the corrected rate. A seed import that overwrites existing rows from an export made before this change keeps the export's rate until the file changes.
  • Lasting read failures: a file that keeps failing to read (permission denied, a root that stays offline) stays on the list. Each daily run reads it again and the task message reports it, until it can be read or stops being a candidate.
  • Rolling upgrades: a node still on the old version that scans new files while upgraded nodes finish the task stores the old, inflated rate for those files. That needs new font-heavy imports during the upgrade window.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code; Codex CLI (review only)
  • Model(s): claude-opus-5-5 (implementation and review); gpt-6.2-sol, gpt-6.2-astra (Codex CLI review); Claude Fable 5.2 (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: four rounds of four independent reviewers (gpt-6.2-sol, gpt-6.2-astra, claude-opus-5-5, Claude Fable 5.2) covering correctness, repo standards and spec. Fixed: unreadable files were skipped for good, or an offline root blocked the pass; slow listed files blocked the walk; a root that keeps stalling blocked the walk and the retry list after it (also raised by Kody and CodeRabbit); retry progress was saved only at the end; the pending count was missing on early exits; the task text had no catalog entry. Dismissed, with reasons: restore of a pre-fix backup (the state table restores with the data), updated_at on the correction (same as the other backfills), and probe depth beyond the header (kept identical to a scan's probe so both store the same rate).

Note

Fix scanner to exclude embedded MKV attachments from stored bitrates

MKV files with attached fonts (e.g. ASS/SSA subtitle tracks) stored inflated bitrates because ffprobe's format bitrate includes attachment payload bytes. Adds a shared formatBitrateKbps helper in probe.go that subtracts attachment data, and adds a resumable backfill in attachment_bitrate_backfill.go that re-probes eligible MKV files and corrects their stored bitrate.

  • The backfill runs as a startup/daily task with a cluster advisory lock, a persisted cursor, retry handling for unreadable files, and a stop after repeated probe timeouts; progress is stored in a new attachment_bitrate_backfill_state table (migration)
  • Updates are guarded: a row is corrected only if its size, normalized mtime, and prior bitrate still match the values loaded for the pass
  • Adds DB contract tests for the backfill plus an ffmpeg/ffprobe integration test comparing files with and without an attached font
  • Behavioral Change: convertProbeData now subtracts attachment bytes from ProbeData.Bitrate; mediaprobe.Stream gains an ExtradataSize field

Macroscope summarized 19c75a4.

FFmpeg derives a Matroska file's bit_rate from its size and duration, so
attached fonts counted as streamed data. A fansub release carrying 90 MB
of fonts was stored at twice its real rate, which pushed it past client
bandwidth and server bitrate caps onto a transcode (a burn-in transcode
with ASS subtitles selected).

The probe now subtracts the attachment streams' bytes (reported as
extradata_size) over the format duration before storing the rate.
Rescans skip unchanged files, so MKV files scanned before attachments
were left out of the bitrate keep a rate up to twice their real one and
keep falling off direct play.

A one-off library task re-reads the header (format and stream entries,
no packets) of present MKV files with ASS or SSA subtitles, the releases
that embed fonts, and writes the attachment-free rate over the row
exactly as it was read. The stored probe keeps neither the format
bitrate nor attachment sizes, so it cannot be recomputed in the
database.

attachment_bitrate_backfill_state holds a resume cursor and marks the
pass done, so it runs once per deployment. It runs at startup and daily
under an advisory lock, so one node reads media; a run of failed or
timed-out reads stops the pass and rewinds the cursor to where the
failures began.
Fold the attachment backfill's failure-streak switch into its outcome switch.
Files the pass could not read went past the cursor and the pass then
recorded itself finished, so a brief storage drop left them with the
inflated rate for good. Eight fast failures in a row, such as files under
an offline library root, stopped every run at the same place instead.

The state row now lists the files a run could not read, and each later
run reads them again before walking on, saving after each batch. Only
timeouts count toward the stalled-storage stop, as in the HDR10+
backfill. A stall while re-reading the list keeps the rest listed and
still lets the walk continue, so one slow root does not hold up the
others. The pass is done once the walk is finished and the list is
empty; the task message says how many files are left.
Synced from a local silo-translations checkout until the catalog change is released.
@silo-triage silo-triage Bot added the size/XXXL 3000+ added + deleted lines (all files); change volume, not priority. label Nov 20, 2026
@silo-kody

silo-kody Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adjusts bitrate conversion to account for Matroska attachment payloads and adds a persisted, retryable backfill for eligible MKV files. A scheduled task runs the pass, and tests cover candidate selection, update conditions, retries, storage stalls, and attachment bitrate calculations.

Changes: Attachment bitrate backfill

Layer / File(s) Summary
Attachment-aware bitrate calculation
internal/mediaprobe/video.go, internal/scanner/probe.go, internal/scanner/probe_bitrate_test.go
Stream now exposes FFprobe’s extradata_size. Bitrate conversion estimates and subtracts attachment bitrate when duration and stream data permit. Tests check bitrate conversion with and without attachments and with a missing format bitrate.
Persisted backfill and candidate processing
migrations/sql/*attachment_bitrate_backfill_state.sql, internal/backup/tables.go, internal/scanner/attachment_bitrate_backfill.go, internal/scanner/attachment_bitrate_backfill_test.go, internal/scanner/hdr10plus_backfill.go, internal/scanner/matroska_track_backfill.go, scripts/ci/db-contracts.txt
A singleton table stores the cursor, retry IDs, and completion state. The runner probes eligible MKV files and updates bitrate only when the candidate still matches the stored row. Unreadable and timed-out files remain pending for later runs. Tests cover selection, retries, storage stalls, and font-attached files. HDR10Plus and Matroska track backfills now use a shared stored-modification-time normalizer.
Task scheduling and application registration
internal/taskmanager/tasks/backfill_attachment_bitrate.go, cmd/silo/main.go
The task runs at startup and every 24 hours, uses an optional cluster lock, and reports progress and results. The application registers it when a file repository is available.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant TaskManager
  participant BackfillAttachmentBitrateTask
  participant AttachmentBitrateBackfiller
  participant PostgreSQL
  participant FFprobe
  TaskManager->>BackfillAttachmentBitrateTask: Execute scheduled task
  BackfillAttachmentBitrateTask->>PostgreSQL: Acquire advisory lock
  BackfillAttachmentBitrateTask->>AttachmentBitrateBackfiller: Run with progress callback
  AttachmentBitrateBackfiller->>PostgreSQL: Load cursor, retry IDs, and candidates
  AttachmentBitrateBackfiller->>FFprobe: Probe candidate file
  FFprobe-->>AttachmentBitrateBackfiller: Return format and stream data
  AttachmentBitrateBackfiller->>PostgreSQL: Conditionally update bitrate and save progress
  AttachmentBitrateBackfiller-->>BackfillAttachmentBitrateTask: Return result and progress
  BackfillAttachmentBitrateTask-->>TaskManager: Report task result
Loading

Suggested reviewers: quick104

Merge Risk: Low · up to baf06

This change stops embedded fonts in MKV files from inflating stored bitrates, and backfills existing files at startup and daily. A known low-impact inefficiency remains: while a storage root is hung, a few extra probes repeat each run. No blocking defects were found, so it is reasonable to merge with owner awareness of that cost.

Security architecture risk: Minimal · up to baf06

Existing files are corrected through guarded updates and resumable progress. The inspected change did not establish a material new security, recovery or ownership risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The scheduled pass can read eligible media across the shared catalog using the server's existing filesystem privileges and update their bitrate metadata. Its scope is not limited to the account manually starting it, but the inspected invocation route retains the existing administrative classification.

Security Findings and Attack Paths

  • inferred — File-controlled content gains an additional scheduled path into ffprobe, but the inspected path does not introduce request-supplied executable selection, shell construction or unrestricted database writes. No introduced exploitable boundary bypass was established by this review.

Trust Boundaries and Controls

  • observed — The task acquires a cluster advisory lock before invoking the worker and defers release. The shared lock implementation retains a dedicated connection and destroys it if unlocking cannot be confirmed, including when the caller's execution context has already been cancelled.

Resilience and Maintainability Implications

  • observed — Failure containment includes four probe workers, batches of 200, per-probe deadlines, cancellation checks and stopping after eight consecutive timeouts. Timed-out and unreadable files remain eligible for later retry; probe rejections are deliberately terminal for this repair pass.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(scanner): stop embedded fonts from inflating MKV bitrates" matches the main change. The PR subtracts attachment payload size from the stored container bitrate for MKV files with embedde…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific to the changeset. It explains that MKV files with large embedded fonts store inflated bitrates because FFmpeg counts attachment bytes. It states that the scanner now subtra…
Full details: Title check

Explanation

The title "fix(scanner): stop embedded fonts from inflating MKV bitrates" matches the main change. The PR subtracts attachment payload size from the stored container bitrate for MKV files with embedded fonts, and adds a backfill to correct existing rows. The title is short, specific, and uses the conventional prefix. It does not mention the backfill task or the migration, but the summary of the main change is accurate.

Full details: Description check

Explanation

The description is specific to the changeset. It explains that MKV files with large embedded fonts store inflated bitrates because FFmpeg counts attachment bytes. It states that the scanner now subtracts attachment size from the stored bitrate. It describes the new backfill task, the attachment_bitrate_backfill_state migration, the retry and timeout behavior, the test coverage, and the risks. The description matches the code changes in probe.go, the backfill files, the migration, and the task manager files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a85ba57-2271-4636-8513-ade827a77584
Commits

Reviewing files that changed from the base of the PR and between 19c75a4 and baf0680.

Files selected for processing: 6

  • cmd/silo/main.go
  • internal/backup/tables.go
  • internal/scanner/attachment_bitrate_backfill.go
  • internal/scanner/attachment_bitrate_backfill_test.go
  • internal/scanner/matroska_track_backfill.go
  • scripts/ci/db-contracts.txt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd3f0812-d91e-4c6d-9712-3ba1ddf1c464
Commits

Reviewing files that changed from the base of the PR and between 975bbf4 and 6e4b012.

Files selected for processing: 54

  • .silo-translations
  • cmd/silo/main.go
  • internal/backup/tables.go
  • internal/mediaprobe/video.go
  • internal/scanner/attachment_bitrate_backfill.go
  • internal/scanner/attachment_bitrate_backfill_test.go
  • internal/scanner/hdr10plus_backfill.go
  • internal/scanner/probe.go
  • internal/scanner/probe_bitrate_test.go
  • internal/taskmanager/tasks/backfill_attachment_bitrate.go
  • migrations/sql/20261120112553_add_attachment_bitrate_backfill_state.sql
  • scripts/ci/db-contracts.txt
  • web/src/locales/ar-XB.json
  • web/src/locales/ar.json
  • web/src/locales/bg.json
  • web/src/locales/ca.json
  • web/src/locales/cs.json
  • web/src/locales/da.json
  • web/src/locales/de.json
  • web/src/locales/el.json
  • web/src/locales/en-XA.json
  • web/src/locales/en.json
  • web/src/locales/es.json
  • web/src/locales/et.json
  • web/src/locales/fi.json
  • web/src/locales/fr.json
  • web/src/locales/he.json
  • web/src/locales/hi.json
  • web/src/locales/hr.json
  • web/src/locales/hu.json
  • web/src/locales/id.json
  • web/src/locales/it.json
  • web/src/locales/ja.json
  • web/src/locales/keys.ts
  • web/src/locales/ko.json
  • web/src/locales/lt.json
  • web/src/locales/lv.json
  • web/src/locales/ms.json
  • web/src/locales/nb.json
  • web/src/locales/nl.json
  • web/src/locales/pl.json
  • web/src/locales/pt-BR.json
  • web/src/locales/pt-PT.json
  • web/src/locales/ro.json
  • web/src/locales/ru.json
  • web/src/locales/sk.json
  • web/src/locales/sl.json
  • web/src/locales/sv.json
  • web/src/locales/th.json
  • web/src/locales/tr.json
  • web/src/locales/uk.json
  • web/src/locales/vi.json
  • web/src/locales/zh-Hans.json
  • web/src/locales/zh-Hant.json

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Comment thread .silo-translations Outdated
Comment on lines +2 to +3
version=local-09c5150fe2b5
sha256=-

@coderabbitai coderabbitai Bot Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Data Integrity & Integration · Quick win

Pin a published catalog release before merge.

.silo-translations pins local-09c5150fe2b5. The sync script refuses to sync from a local-* pin, so the recorded version cannot be re-synced. AGENTS.md requires .silo-translations to name a published release, not local-<commit>, before the client pull request merges.

After the catalog change has a release, run scripts/sync-translations --version <release> and commit the regenerated locale files with .silo-translations. The release catalog must contain the new keys. scripts/sync-translations --version silently drops keys that the catalog lacks, so check the regenerated output for every new key before merge.

Source: Coding guidelines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. silo-translations#111 carries these keys. Once it merges and publishes a release, this branch gets re-synced with --version <release> before merge, and I'll check the new keys are in the output. Leaving this open until then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code (claude-opus-5-5)

Settled by the merge of main in d7964be. silo-translations#111 merged, and main's .silo-translations already pins the published release 2026.11.22-d00fa90, which carries web.admin.tasks.task.backfill_attachment_bitrate.name and .description. The branch takes main's generated files and pin unchanged, so it no longer has a local-* pin or any locale diff of its own.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

A stall left the walk's cursor and the retry list where they were, so a
root whose reads kept timing out was read first on every run and blocked
every file after it, in the walk and on the list.

A stall now lists the whole batch it stopped in and moves past it. The
retry list keeps its own position, retry_after_id, and wraps around from
there, so each run reaches files listed after the stalled ones.
@silo-kody

silo-kody Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b9be913-97c8-4739-a73a-ef8ae673ee7a
Commits

Reviewing files that changed from the base of the PR and between 6e4b012 and 19c75a4.

Files selected for processing: 3

  • internal/scanner/attachment_bitrate_backfill.go
  • internal/scanner/attachment_bitrate_backfill_test.go
  • migrations/sql/20261120112553_add_attachment_bitrate_backfill_state.sql

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Quick104 and others added 4 commits November 22, 2026 06:06
Main's catalog pin, 2026.11.22-d00fa90, already carries the task's two
keys from silo-translations#111, so the generated locale files take
main's copies.
… limit

FFmpeg loads every Matroska attachment when it opens the file, so the
backfill's "header read" of a font-heavy release reads the whole font
payload: 84 MB of an 85 MB test file. Its 30 s limit, a quarter of the
scan probe's, timed out on slow mounts where a scan reads the same file
fine, and eight such files in a row stopped the pass as stalled storage.
It now uses the scan probe's limit and the scan's timeout sentinel.

The listed files also get their own candidate statement. Shared with the
walk as "$4 IS NULL OR id = ANY($4)", the query moved to a generic plan
after a few walk batches, and that plan filtered every row after the
cursor to find a handful of listed IDs (302 ms over 400k rows, against
0.3 ms with the ID list as an index condition).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ite on the path

A retry pass dropped every listed file in the ID range it covered, not
only the ones it started from. When a run on another server takes the
lock after this one lost its session, a file that run lists while this
one is still pruning was dropped unread, and the pass could finish with
its inflated rate stored. Pruning now drops only files in the list the
run started from.

The bitrate write also requires the row's path to still be the one the
pass read: a relink keeps a row's ID, size, mtime and bitrate while
moving it to a new path, and a different file could sit at the old one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code (claude-opus-5-5)

Review of 19c75a4, with main merged in. The scanner fix is right, and the backfill's shape holds up: a finished pass costs one single-row read. Four findings below, each verified and each fixed in a commit I'm pushing to this branch. Two cleanups ride along in the same commits: the backfill reuses the scanner's existing errProbeTimeout sentinel instead of declaring a second one, and the Matroska track backfill now uses the shared normalizedStoredModifiedAt too, so this PR's refactor covers both backfills.

I'll post a summary comment with the merge from main, the catalog pin, validation and scores once the fixes are pushed.

@silo-triage silo-triage Bot added size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. and removed size/XXXL 3000+ added + deleted lines (all files); change volume, not priority. labels Nov 22, 2026
@silo-kody

silo-kody Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Quick104 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Claude Code (claude-opus-5-5)

Review summary

Reviewed head: baf0680 (19c75a4 with main merged in and three fix commits).

The scanner change is correct, and it fixes the stored rate for both the native API and jellycompat, because every play-method path reads media_files.bitrate. The backfill follows the pattern of the HDR10+ and Matroska track backfills, and a finished pass costs one single-row read. I considered adding these files to NeedsCriticalProbeRepair with a probe-date cutoff instead. That would run a full blocking reprobe, fonts included, before the first play of every older ASS MKV, so the dedicated pass is the better shape.

What changed on the branch

  • Merged main (d7964be). Only generated locale files conflicted. silo-translations#111 is merged, and main's pin, 2026.11.22-d00fa90, already has both task keys, so the branch takes main's locale files and no longer carries a local-* pin.
  • Header-read timeout (99620fe). FFmpeg loads every Matroska attachment when it opens the file, so the backfill's read covers the whole font payload: 84.2 MB of an 85.4 MB test file. The read now gets the scan probe's 2-minute limit instead of 30 s, and it reuses the scanner's errProbeTimeout.
  • Retry candidate query (99620fe). The listed files get their own statement. Under the generic plan Postgres switches to after a few walk batches, the shared statement filtered every row after the cursor to find a few listed IDs: 302 ms on 400k seeded rows, against 0.3 ms.
  • Retry prune and row guard (baf0680). Pruning drops only IDs from the list the run started from, so a file another server lists after this run loses its lock session stays listed. The bitrate write also checks file_path, so a relink can't take another file's rate.
  • Matroska track backfill (b9abdf3) now uses the shared normalizedStoredModifiedAt too.

Each finding has its own thread with the evidence.

Tests

TestConvertProbeDataExcludesAttachmentsFromBitrate fails on main and passes here. The backfill tests drive code this PR adds, so they can't fail on main, and they pass against a freshly migrated database along with the HDR10+ and Matroska track backfill tests. make lint-changed reports no issues. I checked the retry-prune fix with a temporary test that fails on 19c75a4 and passes on baf0680, and left it uncommitted.

ci / Go DB pins failed on 19c75a4 in TestBeforeMigrateBackupOnAnOldSchemaDB ("1 other clients are connected" during a restore). That test runs none of this PR's code, so I treat it as unrelated. It passed on the new head.

ci / Go vet and contracts fails on baf0680, as it has on main and on every other branch since about 06:00 UTC today. The route inventory check can't load packages from the runner's Go build cache (cache entry not found), and the same check passes locally on this tree. The cause is the vet job's Go build cache overflowing its tmpfs, and #5112 fixes it in the setup-go action. PRs run the actions from their own head, so this branch needs main merged once #5112 lands before vet can pass.

Other feedback

  • The CodeRabbit pin thread is settled by the merge. I replied there.
  • The author's replies to the other bot threads hold up: missing files are excluded, old-version writes after the pass are disclosed, subtitle_tracks is always an array, and a stalled batch is re-listed whole.
  • Not changed, for the maintainers: keeping the retry list in its own table would make the daily retry work scale with the list rather than its square while a large root is offline. I left the array because the cost stays small (about 16 MB of WAL a day at 20k listed files) and only lasts while a root is offline. Cover art that ffprobe reports as a picture stream still counts toward the rate, but a typical cover adds only a few kbps.
  • Pre-existing, not this PR's: with database.max_connections=1, a task holding the cluster advisory lock holds the only pool connection, and its next query waits forever. That applies to every task using advisoryClusterLock, and this PR adds one more. fix(taskmanager): hold cluster task locks on their own database session #5110 fixes it for all of them by giving the lock its own database session.

Remaining risks

The PR body's Risks section is updated. It now names the 2-minute read limit and covers catalog seed imports: rows a seed import inserts have no stored mtime, so the next scan reprobes them. Rows a seed overwrites from a pre-fix export keep that export's rate until the file changes.

Validated features

No passed case on the v1.0 board covers playback method selection, bitrate limits, scheduled tasks, or MKV scanning. The nearest, Distributed transcode nodes and Autoscan, share no code with this diff. Validation tasks: none holds.

User manual and other clients

The manual is unaffected: it already says a Maximum bitrate below a file's bitrate makes Silo convert it, and this change only makes the stored rate accurate. It doesn't list the backfill tasks. No client change is needed, and jellycompat reads the same column.

Council review

Round 1 on d7964be, before the fixes above:

Member Round 1
Sol (gpt-6.2-sol, medium) 5/10
Opus (claude-opus-5-5, medium) 7/10
Gemini (gemini-4-neon, medium) 9/10

Fixed: the retry prune and the path guard (Sol), on top of the timeout and query fixes. Answered: a bandwidth cap applies to the media rate, not the bytes a full direct-play download sends (Sol); the retry-list table and the scan's own probe (Opus, see above); the seed import, which the next scan covers (Gemini). No second round, because nothing substantive remained.

Verdict

Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)

Fit: it fixes needless transcoding for a common kind of release at the boundary where the rate is computed, and it follows the existing backfill pattern. It holds at 8 because a one-off correction adds a scheduled task, a state table and about 500 lines of resumable-pass code. That cost is justified, since rescans skip unchanged files. Readiness: no substantive concern remains. The fix is shown by a test that fails on main, and the validation board check ran.

@Quick104
Quick104 merged commit cf64c37 into Silo-Server:main Nov 22, 2026
35 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants