Skip to content

fix(metadata): refresh a series when a by-date file is newer than its stored episodes - #3354

Merged
Quick104 merged 13 commits into
Silo-Server:mainfrom
Rhainland:fix/3340-date-episode-refresh
Nov 2, 2026
Merged

Quick104 merged 13 commits into
Silo-Server:mainfrom
Rhainland:fix/3340-date-episode-refresh

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3340
Related issue: N/A
Validation tasks: none (#1250 C1 and C2 cover series scanning and metadata routing but have not been run)

New episodes of daily series never appear when their files are named by air date (Sonarr's daily format, Show (2024) - 2024-05-06 - Title.mkv). The scan attaches the file to the series, but it stays unlinked with no season or episode until someone runs Refresh Metadata on the series by hand. Scheduled refreshes never pick the series up.

An SxxEyy file for an episode Silo doesn't know yet gets a scanner_fallback placeholder episode, and that placeholder's episode-incomplete debt drives the refresh that fetches the real episode. A by-date file has no episode number to build a placeholder from, so no debt is written. The completeness sweep then finds every stored episode complete and leaves the series alone.

Approach

The series completeness sweep (refreshSeriesEpisodeMetadataState) now checks the series' unlinked by-date files. If a matched series has one that aired after every stored episode and matches no stored episode, the stored list is behind the provider. The sweep then sets episode_metadata_incomplete on the series and queues episode-incomplete debt on the series item, due now, so the next refresh_metadata run refreshes the series and links the file. Setting the flag also lets a series detail view request the refresh, as it already does for incomplete series.

The rule stays narrow to avoid needless provider traffic:

  • An unknown date inside the stored range doesn't count. The provider has already listed that stretch, and an old unmatchable file would otherwise keep the series incomplete.
  • Only dates up to tomorrow (UTC) count. A file named for a date that hasn't aired anywhere yet, such as a mistyped year, would otherwise restart parked debt after every park.
  • If the check can't read the series' unlinked files, the episodes on their dates, or the series row, the sweep reports itself unfinished and leaves the flag and the series debt as they were, as it already does when it can't read the series' debt or episodes.
  • If the series item already has episode-incomplete debt, the sweep leaves its schedule and attempt count alone. A provider that never lists the episode gets the usual backoff and parking, not a fresh due-now request on every scan.
  • Series debt that has used up its attempts (three or more) restarts with no attempts for a file that aired on or after the day of its last attempt. This covers parked episode debt and debt that used up its attempts on another reason, such as missing ratings. That episode gets the full backoff, as a new scanner_fallback episode gets a debt row of its own. One file the provider never lists can't hold back later episodes of a daily show for 90 days, and a series with lasting core-metadata debt doesn't get one refresh for the new episode and then wait 30 days.
  • One atomic UPDATE records the episode reason on an existing debt row. It resets the attempt count, raises the priority and makes the row due only while the row is terminal, not due, unleased, and last attempted before the day after the file aired. A rejected reset preserves the schedule, attempts, priority and lease, while keeping the episode reason so a core-metadata refresh cannot settle it away. Other reasons, including queued trailer and artwork requests, survive. A row already holding the episode reason is not rewritten unless it qualifies for a reset.

The rule is documented in docs/architecture/media-naming.md, next to the existing air-date linking rules. Only the server changes; no API, jellycompat, or client change is needed.

Validation

  • Follow-up 4567822d2: TestByDateEpisodeDebtSurvivesCoreRefreshDB fails on ece2cc577 in both due and leased cases: core refresh settlement deletes the episode retry. Both cases pass after the fix, alongside the six DB guard cases and 11 service table cases. The full metadata suite passes with database tests enabled; changed-line lint and local-path checks pass. No live provider or client run was made for this follow-up.

  • Follow-up ece2cc577: the added older-file/other-reason case fails on e3ec4a8c0 because the debt becomes due immediately. All 11 service table cases pass after the fix, as does the metadata suite without a database. Changed-line lint reports zero issues. The SQL is unchanged; the database-backed results below predate this caller fix.

  • Focused tests: go test ./internal/metadata/... passes, including its DB-backed tests against a disposable migrated database.

  • TestEnsureSeriesEpisodeLinks_QueuesRefreshForFilesPastStoredEpisodes fails on main for the reported reason (no flag, no series debt). Its row for a date that hasn't aired fails on c79dadf, before the date cap. TestRefreshSeriesEpisodeMetadataState_KeepsSeriesDebtWhenByDateCheckFails fails on c79dadf, where a failed check cleared the flag.

  • Two new rows in TestEnsureSeriesEpisodeLinks_QueuesRefreshForFilesPastStoredEpisodes fail on 31fa7a5. There, terminal core-metadata debt kept five attempts after gaining the episode reason, and terminal debt that held the episode reason with another reason stayed 30 days out.

  • TestRestartTerminalEpisodeDebtDB (in scripts/ci/db-contracts.txt) checks that parked debt and terminal debt for other reasons restart in place and keep their reasons. It also checks that a row with attempts left, a due row, a leased row, and a row last attempted after the file aired retain their schedule, attempts, priority and lease while gaining the episode reason. Removing the lease, due, or last-attempt guard from the statement fails its matching row.

  • go build ./..., gofmt -l, go vet on the changed package, make lint-changed (0 issues), make lint-router-recovery, make verify-local-paths, make verify-size-ratchet, make verify-bidi: pass.

  • make test-go: the only failures are in packages this change doesn't touch. Under the host's umask 002, api/handlers, ebookconvert and uploads reject group-writable temp dirs, and they pass under umask 022. Two jellycompat Dolby Vision strip tests fail the same way on unmodified main on this host.

  • make test-db-pins: every pin and contract passes except TestAdminAPIKeyCreationHoldsOwnerRulesAgainstPromotionDB/v1, which fails only when the list shares a database. It passes when run alone, on this branch and on main.

  • Local build, before and after on the same data: a TV library of ffmpeg-generated files named by air date, matched by the TMDB plugin built to point at a local mock of the TMDB API whose episode list grows between scans.

  • Web checks were not run; the change has no web part.

Evidence

Before (main at 63ef34b): the stored episode list ends at 2024-05-03, a 2024-05-06 file is added and the provider lists that episode. After a subtree scan and a refresh_metadata run:

GET /api/v2/admin/items/series-tmdb-900001/files
Silo Daily Soap (2024) - 2024-05-03 - Friday 3rd May 2024 [HDTV-1080p].mkv season= 1 episode= 3
Silo Daily Soap (2024) - 2024-05-06 - Monday 6th May 2024 [HDTV-1080p].mkv season= None episode= None

media_items:            episode_metadata_incomplete = f
metadata_refresh_debt:  (0 rows)
provider requests during refresh_metadata: 0

After (this branch at 5e3ebc1): the same steps with a 2024-05-07 file:

after the subtree scan
media_items:            episode_metadata_incomplete = t
metadata_refresh_debt:  item | series-tmdb-900001 | reason 1 | priority 300 | attempts 0 | due now

after refresh_metadata (the provider's series and season 1 were fetched)
GET /api/v2/admin/items/series-tmdb-900001/files
Silo Daily Soap (2024) - 2024-05-06 - Monday 6th May 2024 [HDTV-1080p].mkv season= 1 episode= 4
Silo Daily Soap (2024) - 2024-05-07 - Tuesday 7th May 2024 [HDTV-1080p].mkv season= 1 episode= 5
metadata_refresh_debt:  (0 rows)

Also checked on the same build:

  • A newer file the provider doesn't list keeps the series flagged. Its debt backs off to the next day after one attempt, and rescans don't make it due again.
  • An unknown date inside the stored range queues nothing.
  • Parked debt (three attempts, 90 days out) stays parked when a rescan only touches the old file. A file dated on or after the day of its last attempt restarts it with no attempts, due now. With the provider still behind, that attempt backs off to the next day instead of parking again, and the file links once the provider lists the episode.
  • Debt held by a live lease, or already due after a claim's lease lapsed, is left unchanged when a new file arrives.

These live checks ran before the restart became an in-place update; the tests under Validation cover that change.

Evidence: https://evidence.siloserver.org/r/silo-server/3354-retry-reset/

Risks

  • Each series completeness sweep runs one more query: the series' unlinked files, filtered on content_id and episode_id IS NULL. Further queries run only when an unlinked by-date file is newer than every stored episode.
  • If an episode the provider never lists has parked the series debt, a later-aired by-date file restarts it with the usual backoff (at most three attempts before it parks again). A daily show whose provider never lists new episodes would get about three refreshes every five days.
  • The restart also restarts the backoff of the row's other reasons. A daily show with lasting missing ratings or artwork retries those as often as new episodes arrive, and each new episode already needs a series refresh.
  • No migration and no API 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 says there is none.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code (shell, file editing, GitHub CLI gh); Codex CLI codex exec for code review
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review); gpt-6-astra (Codex in T3 Code, terminal-backoff follow-up)
  • Involvement: Fully AI-generated, human verified
  • Review fixes: Claude Code (claude-opus-5-5) reviewed c79dadf with a cross-provider pass by Codex (gpt-6.1-sol), then added the date cap and the failed-check handling and merged main (a scripts/ci/db-contracts.txt conflict). After a maintainer decision, it replaced the parked-debt delete with the in-place restart of terminal debt, and merged main again.
  • Adversarial review: two independent reviews of the full branch diff (claude-opus-5-5 and gpt-6.1-sol, medium effort, covering correctness, repository standards, and the issue's expected behavior), reconciled against the code. Round 1: both found that parked series debt blocked later by-date files for up to 90 days. Fixed: parked debt restarts for a newly aired file. Claude also asked for the rule in docs/architecture/ (added), flagged one extra query per sweep (kept, listed under Risks), and flagged a repeated RequestDue call (kept, because its skip rule differs from the other callers on purpose). Each fix commit then got another round from both models. Those rounds found a woken row kept its terminal attempt count and missed same-day files (fixed with a fresh restart and an inclusive date check). They also found the restart could delete a row a running refresh had claimed, or one left due by a crashed claim (fixed: due and leased rows are skipped), and a test fixture that wasn't due (fixed). The final round found no medium or high issues. It noted two low items left for maintainers. A parked row whose 90-day delay has already expired is now treated as due and keeps its low priority instead of being lifted. And no table row covers a due row with a lapsed lease on its own. A later bot review found that a nudge and a claim landing between the sweep's read and its delete could lose the claimed row and queue a second one. Fixed: the delete now holds only while the row is unchanged, not due, and unleased. Both models then reviewed that commit; one asked to match the reason mask as well and to test the due-time check on its own (both done), and the re-review found nothing.

Note

Refresh series when an unlinked by-date file is newer than stored episodes

  • The series completeness sweep now treats qualifying unlinked by-date files as evidence of incomplete episode metadata and requests series-level episode refresh debt for them. See MetadataService.refreshSeriesEpisodeMetadataState and the new newestUnstoredFileAirDate helper in service.go
  • A file qualifies when its air date is later than the newest stored episode date, no later than tomorrow in UTC, and matches no stored episode. Dates already seen or in the future do not qualify
  • New RefreshDebtRepository.RestartTerminalEpisodeDebt in refresh_debt_repo.go atomically restarts terminal debt (reset attempts and schedule, raise priority) only when the row is not due and not leased, and the last attempt predates the cutoff. Otherwise it only adds the episode reason, preserving schedule, attempts, and lease
  • Covers rules in media-naming.md, with new tests in fallback_episode_test.go and database contract tests in episode_refresh_debt_db_test.go
  • Behavioral Change: a failed by-date episode lookup now reports failure without clearing the series incomplete flag or changing debt attempts and due time; existing non-terminal debt keeps its backoff schedule

Macroscope summarized 4567822.

… episodes

A file named by air date has no episode number, so no scanner_fallback
placeholder is built for it and no episode debt is written. When its date
is later than every stored episode, the completeness sweep found nothing
to refresh, and new episodes of daily series stayed unlinked until a manual
refresh.

The sweep now marks such a matched series episode-incomplete and queues
episode-incomplete debt on the series, so the scheduled refresh fetches
the new episodes and links the file. Debt that already carries that reason
keeps its own backoff and parking. Unknown dates inside the stored range
are not counted.

Closes Silo-Server#3340
Parked episode-incomplete debt on a series kept every later by-date file
waiting up to 90 days once one file the provider never lists exhausted
its attempts. A file that aired after the debt's last attempt is news that
attempt could not have seen, so it now makes the parked debt due again.

Document the by-date refresh rule in docs/architecture/media-naming.md.
A woken parked row kept its attempt count, so the new by-date file got a
single attempt before parking again for 90 days, and a file dated the
same day as the last attempt never woke it. When a file aired on or after
the day of the last attempt, the parked row now restarts with no attempts,
so a provider that lists the episode a little late still gets the usual
retries.
The sweep that restarts parked series debt can run inside the refresh
that claimed the row for its third attempt. Deleting the row there
dropped the claim's lease and left a due, unleased row that another node
could claim while the first refresh was still running. Skip the restart
while a lease is live; the claim settles the row itself.
A claim whose worker died leaves a parked-looking row due once its lease
lapses, and the scheduler can claim it again while a sweep restarts it.
A due row is refreshed anyway, so the sweep now restarts only parked
debt that is neither due nor leased.
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

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: c60c9b87-4cb3-4f78-b0ee-9cfa9a438800
Commits

Reviewing files that changed from the base of the PR and between e3ec4a8 and ece2cc5.

Files selected for processing: 2
  • internal/metadata/fallback_episode_test.go
  • internal/metadata/service.go

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

Walkthrough

The completeness sweep now detects newer unmatched by-date files for matched series. It marks episode metadata incomplete and queues a refresh. Terminal episode debt restarts only when the file date meets the last-attempt condition and the debt is not due or leased.

Changes: Date-named episode refresh

Layer / File(s) Summary
Unmatched file detection and refresh request
internal/metadata/service.go, internal/metadata/fallback_episode_test.go, docs/architecture/media-naming.md
The completeness sweep checks unmatched by-date files and requests episode-list refreshes when dates qualify. Tests and documentation cover date and debt conditions, including lookup failures.
Terminal episode debt restart
internal/metadata/refresh_debt_repo.go, internal/metadata/episode_refresh_debt_db_test.go, internal/metadata/service_test.go, scripts/ci/db-contracts.txt
The repository adds a conditional restart for terminal episode debt. Database and fake-repository tests cover eligibility and updates.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CompletenessSweep
  participant newestUnstoredFileAirDate
  participant requestSeriesEpisodeListRefresh
  participant RefreshDebtRepository
  CompletenessSweep->>newestUnstoredFileAirDate: inspect unmatched file dates
  newestUnstoredFileAirDate-->>CompletenessSweep: return latest qualifying date
  CompletenessSweep->>requestSeriesEpisodeListRefresh: request refresh for qualifying date
  requestSeriesEpisodeListRefresh->>RefreshDebtRepository: restart eligible terminal debt or queue episode-incomplete debt
Loading

Possibly related issues

  • No additional unlinked issue in the provided matches is addressed by this change.

Suggested labels: impact: usability

Suggested reviewers: quick104, blurbery

Merge Risk: Minimal · up to 45678

No actionable issue identified in the current change; it is mergeable after normal checks.

Security architecture risk: Low · up to 45678

The change retains safeguards around active refreshes, retry schedules, and eligible file dates. No security regression was established in the inspected paths. Recovery when the completeness flag and refresh request persist separately remains uncertain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — An actor able to influence scanned filenames already associated with matched series can newly cause eligible series to request metadata refresh work. The directly affected state is each series' completeness marker and refresh-debt row; aggregate exposure depends on how many series' files that actor can influence. Remote unauthenticated reachability was not established.

Trust Boundaries and Controls

  • observed — Filename-derived dates influence scheduling, not database statement structure or target selection outside the supplied series. The restart uses parameterized SQL keyed by normalized target type and content ID. Existing enqueueing also preserves active leases and applies a nudge cooldown.

Resilience and Maintainability Implications

  • observed — Existing failure-containment mechanisms remain relevant to the new work: debt already carrying the episode reason keeps its backoff, claims exclude live leases, and interrupted deferred batch settlement leaves claims to expire before retry. Inspected tests cover rejected restarts, a claim acquired after the service read, and retention of episode debt after core metadata completes.

Hardening Proposals

  • proposed — Consider coupling incomplete-marker persistence with debt enqueueing, or defining explicit partial-write recovery, so retention of unresolved by-date work and its backoff does not depend on both writes succeeding independently.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: the series completeness sweep now refreshes a series when an unlinked by-date file is newer than its stored episodes. The changeset matches this (service.go sweep logi…
Description check Passed The description states the problem (daily-series by-date files stay unlinked), the approach (sweep checks unlinked by-date files, marks series episode-incomplete, queues due debt, and restarts termina…
Linked Issues check Passed Issue #3340 requires an automatic series refresh for an unlinked by-date file newer than the stored episodes. The completeness sweep now detects qualifying files, excludes dates beyond tomorrow UTC an…
Out of Scope Changes check Passed The changes stay within issue #3340. The debt-restart logic supports the required refresh trigger. The tests and media-naming.md documentation verify and explain the behavior. No unrelated API, clie…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change: the series completeness sweep now refreshes a series when an unlinked by-date file is newer than its stored episodes. The changeset matches this (service.go sweep logic, RestartTerminalEpisodeDebt, tests, docs). The title is specific and in the conventional-commit form, and it does not use vague terms.

Full details: Description check

Explanation

The description states the problem (daily-series by-date files stay unlinked), the approach (sweep checks unlinked by-date files, marks series episode-incomplete, queues due debt, and restarts terminal debt in place), validation steps, evidence, and risks. These match the changeset summaries for service.go, refresh_debt_repo.go, the tests, and the docs file. The description is detailed and on-topic.

Full details: Linked Issues check

Explanation

Issue #3340 requires an automatic series refresh for an unlinked by-date file newer than the stored episodes. The completeness sweep now detects qualifying files, excludes dates beyond tomorrow UTC and dates already covered by the stored range, marks the series incomplete, and queues or restarts episode-incomplete debt. The change preserves existing SxxEyy fallback behavior. Tests cover the trigger, date rules, lookup failures, debt scheduling, and linking behavior.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #3340. The debt-restart logic supports the required refresh trigger. The tests and media-naming.md documentation verify and explain the behavior. No unrelated API, client, migration, or product-area changes are shown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 5 files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 1, 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 1, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 1, 2026

Copy link
Copy Markdown

The by-date file’s episode/season assignment after refresh is user-visible (internal/metadata/service.go), and the before/after API excerpts show it. However, “main” and “this branch” do not identify the exact builds or commits used for the captures. Please name the exact before/after commit or build for each excerpt.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

Comment thread internal/metadata/service.go Resolved
Comment thread internal/metadata/service.go Resolved
The parked-debt restart read the row, then deleted it unconditionally. A
nudge that made the row due and a refresh that claimed it between the read
and the delete lost their row, and the following RequestDue queued a second
row that another refresh could claim while the first still ran.

The delete now holds only while the row keeps the reasons, attempt count and
schedule the sweep read, is not due, and has no live lease. Otherwise the
sweep leaves the row to the writer that changed it.
@silo-kody

silo-kody Bot commented Nov 1, 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.


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: 112684c2-11b0-4e42-a1e1-defcc75fb697
Commits

Reviewing files that changed from the base of the PR and between 63ef34b and c79dadf.

Files selected for processing: 7
  • docs/architecture/media-naming.md
  • internal/metadata/episode_refresh_debt_db_test.go
  • internal/metadata/fallback_episode_test.go
  • internal/metadata/refresh_debt_repo.go
  • internal/metadata/service.go
  • internal/metadata/service_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; 0 remain after this review.

Comment thread internal/metadata/service.go Resolved
Quick104 and others added 3 commits November 1, 2026 22:22
A by-date file named for a date that has not aired yet, such as a
mistyped year, counted as newer than every stored episode. Its date is
always on or after the day of the series debt's last attempt, so each
sweep after the debt parked restarted it at priority 300 with no
attempts, and the series was refreshed about three times every five days
for as long as the file stayed.

Count only dates up to tomorrow in UTC, which covers every time zone's
today. Also describe the boundary as the newest episode the series has
in a library, which is what the sweep's episode list holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	scripts/ci/db-contracts.txt
The completeness sweep treated a failed read in the by-date check as "no
unlinked file is newer" and cleared episode_metadata_incomplete. The
settle that follows a series refresh then dropped the series' episode
debt, and the unlinked file was left with nothing to refresh it, the
state Silo-Server#3340 reports.

Return the error and report the sweep unfinished, as it already does
when it cannot read the series' debt or episodes. The flag and debt stay
as they were, and a scheduled refresh batch keeps its claims for the
retry.

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) review of c79dadf, with a cross-provider pass by gpt-6.1-sol.

Three findings below. I'm pushing fixes for the first two to this branch, along with a merge of main that resolves the scripts/ci/db-contracts.txt conflict. The third is left for the maintainers. A summary comment follows.

Comment thread internal/metadata/service.go Resolved
Comment thread internal/metadata/service.go Resolved
Comment thread internal/metadata/service.go Resolved
@silo-kody

silo-kody Bot commented Nov 1, 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

Quick104 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Claude Code (claude-opus-5-5) review summary. Reviewed head: c79dadf. Branch now: 4567822.

The approach holds up. The completeness sweep is where the missing trigger belongs, and the fix reuses the existing refresh debt instead of adding a schedule or a setting. TestEnsureSeriesEpisodeLinks_QueuesRefreshForFilesPastStoredEpisodes fails on main for the reported reason: no incomplete flag and no series debt.

Fixed on this branch

  • 4567822: due or leased terminal debt with only another reason could lose its episode retry when core metadata settled. The atomic update now records the episode reason even when reset guards fail, while preserving the schedule, attempts, priority and lease. The registered DB regression fails on ece2cc5 for both due and leased rows and passes after the fix. The full metadata suite passes with database tests enabled, and changed-line lint reports zero issues. No live provider run was made for this follow-up.
  • ece2cc5: a terminal row carrying only another reason could fall through to RequestDue after the guarded restart rejected an old file date. The terminal branch now returns after the guarded attempt. The added table case fails on e3ec4a8 and all 11 cases pass after the fix. The metadata suite passes without DB tests, and changed-line lint reports zero issues; the earlier DB results below cover the unchanged SQL.
  • 76afaeb: by-date files named for a date after tomorrow (UTC) no longer count, so a mistyped year can't restart parked debt after every park. The code comment and docs/architecture/media-naming.md now describe the boundary as the newest episode the series has in a library, which also covers the wording point in Kody's thread.
  • 31fa7a5: a failed read in the by-date check leaves the flag and the series debt alone and reports the sweep unfinished, instead of clearing the flag and letting the refresh settle drop the debt.
  • b9ac23e (maintainer decision on the attempt-count thread): series debt that has used up its attempts now restarts in place for a newly aired by-date file. This covers both parked episode debt and debt that used up its attempts on another reason, such as missing ratings. One conditional UPDATE adds the episode reason, resets the attempt count and makes the row due, and the row keeps its other reasons. It applies only while the row is terminal, not due, unleased, and last attempted before the day after the file aired, checked against the row as it stands. This replaces the delete and re-queue, which also closes CodeRabbit's two-statement thread. Restarting the row also restarts the other reasons' backoff, which the maintainers accepted.
  • 4c00388 and e3ec4a8: merged main. The first resolved a scripts/ci/db-contracts.txt conflict; the second merged cleanly and brings in test(playback): wait for the rollback stop in the relay-move audio test #3381, the fix for the [bug] TestRelayMovePreservesMandatoryAudio/legacy=true flakes: checks the stop before it is sent #3361 test flake that failed Go test on 31fa7a5.

Each new test or table row fails on the head before its fix and passes on the branch. The two attempt-count rows fail on 31fa7a5: a core-metadata row kept five attempts, and a row holding both reasons stayed 30 days out. TestRestartTerminalEpisodeDebtDB replaces TestDeleteParkedTargetDebtOnlyWhenUnchangedDB in scripts/ci/db-contracts.txt, and removing each of its guards fails a row. go test ./internal/metadata/ passes with the database tests enabled, make lint-changed reports 0 issues, and go build ./... passes on the merged tree. I didn't repeat the live provider run. The normal path is unchanged, so the existing evidence still holds; notes for the restart change are linked in the PR body.

Left for the maintainers

  • Not caused by this PR: a series detail view already starts an uncounted refresh, at most once an hour, for any series flagged incomplete, so regular viewing can postpone backoff and parking. This PR applies that to more series: daily shows whose provider lags.

Cross-provider round: one round by Codex (gpt-6.1-sol) on c79dadf, which found four things: the future-date restart and the failed-check flag clearing (both fixed above), the two-statement restart (fixed by b9ac23e), and the detail-view refresh (older than this PR).

Validated features: I couldn't read the v1.0 validation board here, so passed cases on other tasks weren't checked. #1250 C1 and C2 cover this area and are still "Not run", which matches the PR's Validation tasks: line.

User manual: no change needed. The media folders page already says files named by air date link to the episode that aired that day. This fix makes that hold for new episodes.

Apple, Android and jellycompat: server only. No API field changes, and jellycompat doesn't read the flag.

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

Fit: it fixes a core-library bug (new daily episodes never appear) inside the existing debt mechanism, with no new setting or API surface. Readiness: the fix is shown by tests that fail on main and on the pre-fix heads, and by the author's before-and-after run. The attempt-count decision is settled and implemented. The remaining item predates this PR.

Latest follow-up: 🤖 Codex (gpt-6-astra) in T3 Code.

@Quick104

Quick104 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

The failed Go test on 31fa7a5 is the existing playback cleanup race in #3361: TestRelayMovePreservesMandatoryAudio/legacy=true returned 502 with cleanup=0 before the asynchronous stop reached the fake node. The CI result job failed only because that Go test job failed.

CI used base 81ae2ce, on which I reproduced this exact failure five times in 20 runs while investigating #3357. This PR does not change the test or its rehome implementation.

The single retry failed on the same test and no other test: https://github.com/Silo-Server/silo-server/actions/runs/41357320553/job/125003369708. The aggregate job again propagated that failure. Required CI remains red; no further retry was requested.

The separate attempt-count and atomic-restart findings remain open pending the maintainer's retry-policy decision.

— Codex in T3 Code, gpt-6-astra

Quick104 and others added 2 commits November 2, 2026 13:40
…e file

A series row that had used up its attempts on another reason, such as
missing ratings, inherited that count when a newly aired by-date file
added the episode reason: one refresh, then 30 days. A row holding the
episode reason next to another reason never restarted at all, because
only pure parked debt did.

Replace the parked-debt delete and re-queue with one conditional UPDATE.
It adds the episode reason, resets the attempt count, and makes the row
due, but only while the row is terminal, not due, unleased, and last
attempted before the day after the file aired, checked against the row
as it stands. The row keeps its other reasons, so queued trailer and
artwork requests survive, and their backoff restarts with it.

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

silo-kody Bot commented Nov 2, 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 added the impact: usability Core flow broken or severely blocked label Nov 2, 2026
Comment thread internal/metadata/service.go Resolved
@silo-kody

silo-kody Bot commented Nov 2, 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 ❌

Comment thread internal/metadata/service.go Resolved
@silo-triage silo-triage Bot added size/XL 500–999 added + deleted lines (all files); change volume, not priority. and removed size/L 200–499 added + deleted lines (all files); change volume, not priority. labels Nov 2, 2026
@silo-kody

silo-kody Bot commented Nov 2, 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 ❌

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 impact: usability Core flow broken or severely blocked 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.

[bug] New episodes of date-named series never appear: unlinked by-date files don't queue a series metadata refresh

2 participants