Skip to content

fix(migrations): store the real range type of Profile 10 tracks scanned before #4487 - #5472

Open
rangoDJ wants to merge 2 commits into
Silo-Server:mainfrom
rangoDJ:fix/5244-profile10-range-backfill
Open

rangoDJ wants to merge 2 commits into
Silo-Server:mainfrom
rangoDJ:fix/5244-profile10-range-backfill

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: none. Merge order: none. Follows #4487 (merged).

Problem

Closes #5244
Related issue: #4487
Validation tasks: none

Other clients: all native /api/v2 clients (web, Android, Apple) now read the corrected range type for these files. The Jellyfin-compatible API already corrected it on read, so it is unchanged.

AV1 Dolby Vision Profile 10 files scanned before #4487 kept video_range_type: "DOVI" in their stored video track, even when the Dolby Vision configuration record names a compatible base layer (dv_bl_compat_id 1, 2 or 4). #4487 made new scans store DOVIWithHDR10 (or DOVIWithHDR10Plus), DOVIWithSDR or DOVIWithHLG, and made the Jellyfin-compatible API correct old rows on read (compatVideoRangeType). Nothing rewrote the stored rows, so the native API returned the old DOVI until the file changed on disk.

Approach

  • A one-off migration (20261127143000_profile10_range_type_backfill.sql) rewrites stored tracks with dv_profile 10, video_range_type DOVI and dv_bl_compat_id 1, 2 or 4. It uses the mapping of mediaprobe.Profile10RangeType: 1 gives DOVIWithHDR10, or DOVIWithHDR10Plus with hdr10_plus; 2 gives DOVIWithSDR; 4 gives DOVIWithHLG.
  • A track with no compatibility id, or one Jellyfin doesn't map, stays DOVI, as a scan leaves it. Every other track in the row keeps its value and position.
  • Only rows with such a track are updated: a jsonpath filter (@?) selects them.
  • The Down section does nothing: the old DOVI can't be told apart from a genuine one, and the new value is what a scan stores today.
  • I left compatVideoRangeType's read-time correction in place. It is now a no-op for migrated rows, and removing it can follow separately.

Validation

  • New DB test TestProfile10RangeTypeBackfillPostgres (migrations/), with one row per case: compat ids 1, 1 with HDR10+, 2 and 4 get rewritten; no id, an unmapped id (6) and a Profile 8 track stay DOVI; a two-track row keeps its second track; a row without tracks is untouched. Passes.
  • go test ./migrations/ (with SILO_TEST_DATABASE_URL): pass. make verify-migrations: pass. go vet: clean. golangci-lint on the changed package (pre-commit): 0 issues.
  • Review fix: the update now builds each track array from the row it updates, so a scan that another server commits during the migration is not overwritten with the tracks read before it. A two-session PostgreSQL 18 run reproduced the overwrite on the first version and showed the newer scan kept after the fix.
  • The test is listed in scripts/ci/db-contracts.txt, so CI runs it.
  • go run ./cmd/silo --migrate-only applied the migration to a fully migrated database seeded with old rows: compat ids 1, 1 with HDR10+, 2 and 4 were rewritten; a track with no id and a Profile 8 track kept their values.
  • Not tested: the native API reading the result on a running server.

Evidence

Evidence: not needed. No visible change in the apps' layout; the change is a stored value the API returns, shown by the test above.

=== RUN   TestProfile10RangeTypeBackfillPostgres
--- PASS: TestProfile10RangeTypeBackfillPostgres (0.11s)
PASS
ok  	github.com/Silo-Server/silo-server/migrations	0.132s

Without this migration, the same rows keep DOVI, which is what the native API returns today.

Risks

  • The update scans media_files once at startup, but writes only rows that have a matching track.
  • Updating video_tracks fires the same change triggers a rescan of these files would.
  • No API shape change.

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 in the Claude desktop app
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, not yet human verified
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Backfill real range type for Profile 10 tracks in media-file migration

  • Adds an Up migration that rewrites stored profile 10 Dolby Vision range types based on base-layer compatibility ID: IDs 1, 2, and 4 map to DOVIWithHDR10/DOVIWithHDR10Plus (by hdr10_plus flag), DOVIWithSDR, and DOVIWithHLG respectively. See 20261127143000_profile10_range_type_backfill.sql
  • Rebuilds each matching track array in its existing order; tracks without a qualifying profile 10 entry are left untouched
  • Adds a PostgreSQL test covering compatibility IDs 1, 2, 4, HDR10+, unrecognized IDs, non-profile-10 tracks, mixed arrays, and null arrays: profile10_range_type_backfill_test.go
  • Registers the test in the database contract list: db-contracts.txt
  • Risk: migration rewrites existing range_type data in the media-file table; the Down migration does not roll it back

Macroscope summarized 138546a.

…ed before Silo-Server#4487

AV1 Dolby Vision Profile 10 tracks scanned before Silo-Server#4487 kept
video_range_type DOVI even when their configuration record names a
compatible base layer. New scans store DOVIWithHDR10 (or
DOVIWithHDR10Plus), DOVIWithSDR or DOVIWithHLG, and the Jellyfin API
corrects old rows on read, but the native /api/v2 returned the stored DOVI
until the file changed on disk.

A one-off migration rewrites those stored tracks with the mapping
mediaprobe.Profile10RangeType applies: base-layer compatibility id 1
(HDR10, or HDR10+ with hdr10_plus), 2 (SDR) and 4 (HLG). A track with no
id or an unmapped one stays DOVI, as a scan leaves it, and every other
track keeps its value and position.

Closes Silo-Server#5244

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: d2f4a286-a432-40fd-99e9-d98178d573d4
Commits

Reviewing files that changed from the base of the PR and between 0a631fb and 138546a.

Files selected for processing: 3

  • migrations/profile10_range_type_backfill_test.go
  • migrations/sql/20261127143000_profile10_range_type_backfill.sql
  • scripts/ci/db-contracts.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 27, 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 go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 27, 2026
The backfill built each new track array in a subquery over its own
snapshot of media_files and assigned it through UPDATE ... FROM. When
another server rewrote a matching row and committed while the migration
waited on that row's lock, PostgreSQL rechecked only the join condition
and wrote the array built from the old row over the newer scan.

Build the array from mf.video_tracks in SET instead, so PostgreSQL
re-evaluates both the filter and the new value against the committed row.

Also run TestProfile10RangeTypeBackfillPostgres in CI through
scripts/ci/db-contracts.txt, and drop the executable bit from both files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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)

Two findings below, both of which I'm fixing in a commit on this branch. The mapping matches mediaprobe.Profile10RangeType and what jellycompat already computes on read.

One nit, also fixed in that commit: both new files have mode 100755. They are the only executable files under migrations/.

@silo-kody

silo-kody Bot commented Nov 28, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@Quick104

Copy link
Copy Markdown
Contributor

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

Review summary

Reviewed head: 138546a (the contributor's 2b410c9 plus one review-fix commit).

The migration does what #5244 asks. Stored Profile 10 tracks with compat id 1, 2 or 4 get the range type a fresh scan stores, and every other track keeps its value and position. The mapping matches mediaprobe.Profile10RangeType and the read-time correction jellycompat already applies.

Addressed findings

  • Overwrite during an upgrade (fixed in 138546a). The first version assigned a track array computed from the statement's starting snapshot. A row that another server rewrote and committed during the migration got its old tracks back next to the new file size. The update now builds the array from the row it updates. A two-session PostgreSQL 18 run reproduced the overwrite before the fix and showed the newer scan kept after it.
  • CI skipped the test (fixed in 138546a). TestProfile10RangeTypeBackfillPostgres is now listed in scripts/ci/db-contracts.txt, and it passes through the dbpins runner against a fully migrated database without skipping.
  • File modes (fixed in 138546a). Both new files are now 100644.

Verification

  • The dev sandbox host couldn't start a new stack, so I checked the migration against PostgreSQL directly. Silo's migration runner (--migrate-only) applied it to a fully migrated database seeded with old rows: compat ids 1, 1 with HDR10+, 2 and 4 were rewritten. A track with no compat id and a Profile 8 track kept their values.
  • The PR's test passes on the head. On the base it can't run because the migration file doesn't exist there, which is expected for a migration test.
  • make verify-migrations passes.
  • Not observed live: the native API response. internal/apiv2/watch.go returns the stored value as is.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5472-review/

Considered and left as is

  • Batching. The statement scans media_files once at startup, but it locks and writes only rows with a matching Profile 10 track. That makes batching unnecessary at the sizes this affects.
  • Whitespace and dolby_vision-only rows. jellycompat also trims the stored value and falls back to parsing dolby_vision when dv_profile is missing. Probed rows always carry dv_profile and an exact range-type string, so the SQL doesn't need either.
  • Writers after the migration. A server still running a build from before fix(jellycompat): label Dolby Vision Profile 10 by its base layer #4487 during a rolling upgrade, or a catalog import of an older export, can still store DOVI. Keeping compatVideoRangeType's read-time correction, as the PR does, covers the Jellyfin surface in those cases.

Validated features

No passed 1.0 case is affected. Playback planning, tone mapping, and overlay ranking make the same decisions for DOVI and DOVIWith* on these tracks, and jellycompat output is unchanged. Validation tasks: none is correct.

Other checks

Council

Sol (gpt-6.2-sol), Opus (claude-opus-5-5) and Gemini (gemini-4-neon), each at medium effort.

  • Round 1 on 2b410c9: Sol 5/10, Opus 6/10, Gemini 5/10. All three raised the overwrite and the CI listing.
  • Round 2 on 138546a: Sol 9/10, Opus 9/10, Gemini 9/10. All marked the overwrite, the CI listing, and the file modes resolved, and none found anything new above a nit.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Profile 10 files scanned before #4487 keep video_range_type DOVI on the native API

2 participants