Repository navigation
fix(metadata): refresh a series when a by-date file is newer than its stored episodes - #3354
Conversation
… 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 Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
The by-date file’s episode/season assignment after refresh is user-visible ( Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.

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
Files selected for processing: 7-
docs/architecture/media-naming.mdinternal/metadata/episode_refresh_debt_db_test.gointernal/metadata/fallback_episode_test.gointernal/metadata/refresh_debt_repo.gointernal/metadata/service.gointernal/metadata/service_test.goscripts/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.
-
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
left a comment
There was a problem hiding this comment.
🤖 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.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
🤖 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. Fixed on this branch
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. Left for the maintainers
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 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 Latest follow-up: 🤖 Codex (gpt-6-astra) in T3 Code. |
|
The failed Go test on 31fa7a5 is the existing playback cleanup race in #3361: 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 |
…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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
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
SxxEyyfile for an episode Silo doesn't know yet gets ascanner_fallbackplaceholder 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 setsepisode_metadata_incompleteon the series and queues episode-incomplete debt on the series item, due now, so the nextrefresh_metadatarun 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:
scanner_fallbackepisode 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.UPDATErecords 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:TestByDateEpisodeDebtSurvivesCoreRefreshDBfails onece2cc577in 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 one3ec4a8c0because 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_QueuesRefreshForFilesPastStoredEpisodesfails onmainfor 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_KeepsSeriesDebtWhenByDateCheckFailsfails on c79dadf, where a failed check cleared the flag.Two new rows in
TestEnsureSeriesEpisodeLinks_QueuesRefreshForFilesPastStoredEpisodesfail 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(inscripts/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 veton 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,ebookconvertanduploadsreject group-writable temp dirs, and they pass under umask 022. TwojellycompatDolby Vision strip tests fail the same way on unmodifiedmainon this host.make test-db-pins: every pin and contract passes exceptTestAdminAPIKeyCreationHoldsOwnerRulesAgainstPromotionDB/v1, which fails only when the list shares a database. It passes when run alone, on this branch and onmain.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 (
mainat 63ef34b): the stored episode list ends at 2024-05-03, a2024-05-06file is added and the provider lists that episode. After a subtree scan and arefresh_metadatarun:After (this branch at 5e3ebc1): the same steps with a
2024-05-07file:Also checked on the same build:
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
content_idandepisode_id IS NULL. Further queries run only when an unlinked by-date file is newer than every stored episode.Checklist
AI Disclosure
gh); Codex CLIcodex execfor code reviewmain(ascripts/ci/db-contracts.txtconflict). After a maintainer decision, it replaced the parked-debt delete with the in-place restart of terminal debt, and mergedmainagain.docs/architecture/(added), flagged one extra query per sweep (kept, listed under Risks), and flagged a repeatedRequestDuecall (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
MetadataService.refreshSeriesEpisodeMetadataStateand the newnewestUnstoredFileAirDatehelper in service.goRefreshDebtRepository.RestartTerminalEpisodeDebtin 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 leaseMacroscope summarized 4567822.