Skip to content

fix(intromarkers): detect markers again after a file's markers are invalidated - #3086

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/1147-redetect-invalidated-markers
Oct 28, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/1147-redetect-invalidated-markers

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1147
Validation tasks: unblocks #1148 C1

Intros and credits that Silo detects locally disappear for good when a file's identity changes without its contents changing. Re-identifying a series or movie (fixing a match, adding an ID to an NFO) or touching a file so a rescan sees a new modification time is enough. The database clears the file's derived markers, as designed, but the nightly Detect markers on this server task never writes them back. Admins see skip prompts vanish from episodes and movies that had them, and nothing brings them back short of re-detecting each episode by hand. Playing an episode restores its intro, but not its credits.

The task skips a season group whose stored analysis is settled with an unchanged input signature, and a movie whose credits tail is stored for the file's hash, size, and duration. A rematch or a touch changes none of those, so both stay settled after their markers are gone.

This change records when the database invalidates a file's markers, and makes both checks notice that time, so the next run writes the markers again from the cached fingerprints and tails without decoding the files again.

Approach

  • A migration adds media_files.markers_invalidated_at. invalidate_file_markers() sets it after its existing identity check, so the time is stamped exactly when markers are cleared. The migration also adds the same column to the media analysis artifact table.
  • Episodes: the season input signature includes each file's invalidation time when it has one, so a group analyzed before an invalidation is analyzed again, even when the invalidation lands while a run is working on the group. A file that was never invalidated contributes nothing, so existing signatures stay valid and the upgrade re-analyzes nothing.
  • Movies: a stored credits tail records the invalidation time it was stored with, and settles the movie only while the file still has that time. After an invalidation the run lists the movie, places its credits from the cached tail, and stores the tail again with the new time. That also happens when the silence pass times out, because a failure would not replace the complete row and the movie would otherwise be listed every night.
  • docs/architecture/intro-detection.md describes both rules.

Server only; no API, client, or jellycompat change.

Validation

  • Reproduced on a local build of main with synthetic episodes and movies: after touching an episode or re-identifying a series or movie, the scheduled run left its intro and credits empty (3 of 3 runs).
  • Same scenario on this branch: the next scheduled run restored the episode's intro and credits from cached fingerprints and the movie's credits from its cached tail, and the following run analyzed neither again.
  • Unit tests cover the season signature cases, including an invalidation during the analysis, and re-storing a stale movie tail, including after a silence-pass timeout. Postgres tests cover the trigger stamp and the movie listing before and after a re-run. A migration test covers which existing files the upgrade stamps. All three Postgres tests are in scripts/ci/db-contracts.txt.
  • go build ./..., gofmt, go vet, make lint-changed, make migrate-validate, make verify-migration-ledger, make verify-migrations, make verify-local-paths: pass. The migration's Down and Up both apply cleanly on a migrated database.
  • make test-go: everything passes except TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute and TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped in internal/jellycompat, which fail the same way on main on the test host.

Evidence

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

The web player at 5:17 in the credits of a touched episode after the scheduled detection run, on main and on this branch with the same library and data. Before, no credits control appears because the credits were cleared and never detected again; after, the restored credits show the Up next countdown. The change is server-side, so phone-width web and native clients change the same way.

Risks

Migration: one nullable column on media_files and one on media_intro_fingerprints, a CREATE OR REPLACE of invalidate_file_markers() that only adds one assignment, and a one-time stamp of the files described below. It runs without a wrapping transaction, so the ALTER TABLE lock does not last the backfill, which takes only row locks; every statement is safe to re-run. Down restores the previous function and drops the columns.

Markers lost before this upgrade come back too. Nothing records which files lost them, so the migration stamps every episode missing an intro or credits range and every movie missing credits, outside extras. The next scheduled run re-analyzes those seasons over cached fingerprints and those movies from cached tails; a movie's audio is read again only where its tail places credits. Movies with credits and episodes with both ranges stay settled.

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 says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, Codex CLI (review only)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two rounds of independent review of the full diff by claude-opus-5-5 and gpt-6.1-sol on correctness, repository standards, and the stated goal. Round one found that settling a movie by comparing transaction-start timestamps could hide an invalidation from a concurrent transaction, that a stale movie tail whose silence pass timed out was never settled, and that a second trigger duplicated the identity check. All three were fixed by recording the invalidation time on the tail and comparing it for equality, re-storing the stale tail, and stamping inside invalidate_file_markers(). Round two found no correctness issues and asked for a test of the timeout case, which was added.

Note

Track marker invalidation timestamps so intro markers are detected again after file identity changes

  • Adds a nullable markers_invalidated_at column to media_files and media_intro_fingerprints, and the invalidate_file_markers trigger now stamps it on identity changes while preserving manual markers and clearing derived ones (20261025203537_track_marker_invalidation.sql)
  • Season-group InputSignature includes each file's invalidation timestamp, so groups re-analyze when a file is invalidated (repository.go)
  • Movie analysis reuses a cached credits tail after invalidation, rewrites the artifact with the new timestamp, and re-lists the movie as a candidate when timestamps differ (analyzer_movie.go, repository_movie.go)
  • Backfill stamps incomplete episodes and credit-less movies so existing files are re-analyzed
  • Behavioral Change: ListMovieCandidates now re-includes settled movies whose artifact timestamp differs from the file's invalidation time; migration is non-transactional with a full rollback path for the trigger function and new columns

Macroscope summarized 9e86344.

…validated

A rematch or a new modification time clears a file's derived markers, but the scheduled detection run kept skipping the season group or movie because nothing its analysis reads had changed. invalidate_file_markers now records when it clears a file's markers. Season input signatures include that time, and a movie's credits tail records the time it was stored with and settles the movie only while the file keeps it, so the next run writes the markers again from cached fingerprints and tails.
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Oct 25, 2026
@silo-kody

silo-kody Bot commented Oct 25, 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 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

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: d577880c-a3e8-4682-bea0-ca287df5f4a2
Commits

Reviewing files that changed from the base of the PR and between ea0bbee and 9e86344.

Files selected for processing: 3
  • migrations/sql/20261025203537_track_marker_invalidation.sql
  • migrations/track_marker_invalidation_test.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; 3 remain after this review.

Walkthrough

The change records marker-invalidation timestamps on media files and analysis artifacts. Season-group signatures and movie settlement checks use these timestamps. Movie analysis reuses cached tails after invalidation and stores the current timestamp with the artifact.

Changes: Marker Invalidation and Analysis

Layer / File(s) Summary
Record marker invalidations
migrations/sql/20261025203537_track_marker_invalidation.sql, migrations/track_marker_invalidation_test.go, internal/intromarkers/repository_movie_db_test.go
The migration adds invalidation timestamp columns, stamps identity changes, clears non-manual marker data, and backfills eligible files. Database tests cover invalidation timing and backfill results.
Propagate invalidation timestamps
internal/intromarkers/types.go, internal/intromarkers/repository.go, internal/mediaartifact/*, internal/intromarkers/analyzer_test.go, docs/architecture/intro-detection.md, scripts/ci/db-contracts.txt
Candidates and artifacts carry invalidation timestamps. Season-group signatures include candidate timestamps. Tests cover reanalysis when invalidation occurs after or during analysis.
Restore movie credits from stored tails
internal/intromarkers/repository_movie.go, internal/intromarkers/analyzer_movie.go, internal/intromarkers/analyzer_credits_tail.go, internal/intromarkers/analyzer_movie_test.go, internal/intromarkers/repository_movie_db_test.go, docs/architecture/intro-detection.md, scripts/ci/db-contracts.txt
Movie settlement checks compare artifact and file timestamps. Analysis reuses a cached tail after invalidation, places credits, and stores the current timestamp with the artifact. Tests cover tail reuse and timeout behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Repository
  participant analyzeMovie
  participant movieTail
  participant ArtifactStore
  Repository->>analyzeMovie: provide eligible movie candidate
  analyzeMovie->>movieTail: request cached tail and stale status
  movieTail->>ArtifactStore: load stored tail artifact
  ArtifactStore-->>movieTail: return tail and stored invalidation timestamp
  movieTail-->>analyzeMovie: return tail and stale status
  analyzeMovie->>ArtifactStore: store tail with current invalidation timestamp
Loading

Possibly related issues

  • Silo-Server/silo-apple#311: The issue validates skip-intro and skip-credits behavior, which uses markers restored by the server.
  • Silo-Server/silo-apple#312: The issue validates tvOS skip-intro and skip-credits behavior, which uses markers restored by the server.

Possibly related PRs

Suggested reviewers: quick104

Merge Risk: Minimal · up to 9e863

The backfill enables eligible files with missing markers to be reconsidered on a scheduled run. No outstanding issue identified here prevents merging after normal checks.

Security architecture risk: Low · up to 9e863

The change restores derived markers while preserving existing file-identity and manual-marker controls. No introduced security weakness was established. Remaining uncertainty concerns deployment and rollback coordination, which were assessed statically rather than exercised.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The upgrade backfill applies database-wide to unstamped, non-extra files missing credits or episodes missing intros. Its scope is broader than files proven to have lost markers previously, because that history was not recorded. It schedules renewed analysis rather than directly replacing marker ranges.

Trust Boundaries and Controls

  • observed — The existing marker writer locks the media-file row and rejects a supplied expected-file identity that differs from current state. These controls are unchanged by the PR and constrain renewed analysis from writing results onto a replacement file.

Resilience and Maintainability Implications

  • inferred — Per-row serialization and freshness comparison provide complementary containment: an identity change can reject an older marker write or clear markers written before that change, while an older artifact timestamp does not settle the newly invalidated file. This conclusion is based on static control flow, not an executed concurrent-transaction test.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 73.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 11 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the marker invalidation problem, the timestamp-based fix, validation, risks, and scope. It directly matches the changeset.
Title check Passed The title clearly and concisely states that intro markers are detected again after marker invalidation. It matches the primary change.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 73.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 11 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026

Copy link
Copy Markdown

The visible playback change lacks reviewable captures. The Evidence section describes a before/after for credits in one touched episode, but includes no screenshots or recording and does not show the other affected behavior:

  • internal/intromarkers/repository.go: restored episode intro and credits markers after invalidation need before-and-after captures of the same episode/player state.
  • internal/intromarkers/analyzer_movie.go: restored movie credits need before-and-after captures of the same movie/player state.

Please attach the captures for desktop and phone-width web, plus any native surfaces the PR says are affected, and identify the exact build or commit for each. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@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 Oct 25, 2026
Comment on lines +8 to +9
ALTER TABLE media_files ADD COLUMN markers_invalidated_at timestamptz;
ALTER TABLE media_intro_fingerprints ADD COLUMN markers_invalidated_at timestamptz;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Missing invalidation stamps in migrations/sql/20261025203537_track_marker_invalidation.sql leave existing files whose markers were cleared before this migration with NULL stamps, so InputSignature preserves their settled season signature and ListMovieCandidates still treats their complete NULL-stamped tails as settled. Initialize invalidation stamps for existing files during the migration, or explicitly invalidate existing season and movie settlement state once, so upgrades also restore markers already lost to the reported bug.

Prompt for LLM

File migrations/sql/20261025203537_track_marker_invalidation.sql:

Line 8 to 9:

Missing invalidation stamps in migrations/sql/20261025203537_track_marker_invalidation.sql leave existing files whose markers were cleared before this migration with NULL stamps, so InputSignature preserves their settled season signature and ListMovieCandidates still treats their complete NULL-stamped tails as settled. Initialize invalidation stamps for existing files during the migration, or explicitly invalidate existing season and movie settlement state once, so upgrades also restore markers already lost to the reported bug.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Agreed, fixed in 9e86344 (with b9b88f4 and 7bf75ff). The migration now stamps existing files once: every episode missing an intro or credits range and every movie missing credits, outside extras. Those seasons get a new input signature, and those movies no longer match their tail's stamp, so the next scheduled run re-analyzes them from cached fingerprints and tails. Movies with credits and episodes with both ranges stay settled, so the upgrade doesn't re-analyze the whole library. The migration runs without a wrapping transaction, so the ALTER TABLE lock does not last the backfill. TestTrackMarkerInvalidationBackfillPostgres covers which rows are stamped.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks—the backfill you described addresses the original finding: previously affected files receive an invalidation stamp, making their settled signatures or tails stale so the next scheduled run restores markers from cached analysis.

Keeping movies with credits and episodes with both ranges settled avoids a library-wide re-analysis. TestTrackMarkerInvalidationBackfillPostgres covers the relevant upgrade behavior.

Based on your description, this suggestion is addressed; I haven’t independently verified those commits.

@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026

Copy link
Copy Markdown

#1148 C1 is ready for a focused re-test after merge. Its October 25 task comment reports that the scheduled run left locally detected markers empty after a rematch or touch on main and identifies this PR's retest for that behavior. Human acceptance is pending, and the accuracy target remains unresolved, so this is not an accepted result. The existing Validation tasks: unblocks #1148 C1 line matches the reported finding.

I could not read Silo-Apple #311/#312 or Silo-Android #321/#322 because those repositories are inaccessible in this run; their client cases remain unclassified.

Suggested fix: No diff — re-test the invalidation scenario after merge and record it once the accuracy target is agreed.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

Stamp every file missing an intro or credits range once during the
migration, so the next scheduled run detects those seasons and movies
again from their cached fingerprints and tails.
Commit each statement on its own so the ALTER TABLE lock does not last
the backfill, and stamp only files missing a range local detection
places, so movies with credits are not analyzed again.
@silo-kody

silo-kody Bot commented Oct 26, 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 ❌

@Rhainland

Copy link
Copy Markdown
Contributor Author

The before/after captures are on the evidence page linked in the Evidence section; this check can't open that page. The movie path shows the same restored credits control in the same player, and the change is server-side only, so phone-width web and native clients get the same markers without client changes.

@macroscopeapp

macroscopeapp Bot commented Oct 26, 2026

Copy link
Copy Markdown

Web #1149 C1 needs re-validation after merge. Its recorded result is from server build 6de6d5e5e; this PR restores marker ranges after a file identity change, and the Web player's GET /api/v2/watch/{id} data drives Skip-control availability. The recorded result does not cover that changed outcome. The PR must explain why this behavior changes and record a build-specific re-validation.

Suggested Validation tasks line: Validation tasks: unblocks #1148 C1; changes #1149 C1

Suggested fix: No diff — after merge, have a human re-run #1149 C1 with a touched or rematched marker fixture and record the build-specific result.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104
Quick104 merged commit 5c1751d into Silo-Server:main Oct 28, 2026
20 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 go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants