Skip to content

fix(markers): let quota-limited marker sync reach every file - #1830

Merged
Quick104 merged 1 commit into
mainfrom
fix/marker-sync-quota-rotation
Oct 3, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/marker-sync-quota-rotation

Conversation

@Quick104

@Quick104 Quick104 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

With stored online markers, the daily Sync online markers task can stop refreshing part of a library for good. TheIntroDB allows about 1,000 lookups a day per key, so a run on a library of a few thousand episodes ends once the quota runs out. Each run starts again at the lowest file IDs. The same older files therefore use the quota every day, and files with higher IDs, which are usually the newest episodes, are never refreshed. A community report showed this on a library of about 3,000 episodes: new episodes never got markers, although TheIntroDB had data for them.

The cache durations make it worse. Found markers were refetched after 7 days and empty results after 1 day, so on a mid-sized library the due refreshes alone can use the whole daily quota. TheIntroDB's developer recommends keeping found results for a month and retrying 404s after 14 days, which is what their Jellyfin and Emby plugins do.

Approach

Sync now makes one pass ordered by each file's oldest fetch, and files never fetched come first. When the quota stops a run, the next run continues with the files that have waited longest, instead of starting over at the lowest IDs. Candidates are still paged with a keyset cursor, now on (last fetch, file ID). Files fetched during a run move behind the cursor, and they stay out of the candidate list until their retry time.

Found markers are now cached for 30 days, and empty results are retried after 14 days. A newly aired episode that TheIntroDB doesn't have yet can therefore wait up to two weeks before it is retried. An admin refresh for an item still bypasses the cache. docs/markers-api.md describes the new order and durations.

Validation

  • Reproduced with a database test before the fix: with one lookup allowed per run, three daily runs refreshed the same file every time. After the fix, each file is refreshed once. Another test drives the store directly; with the old file-ID order restored, both tests and the updated candidate-order test fail.
  • go build ./..., gofmt, go vet ./..., make lint-changed (0 issues), make verify-local-paths: pass.
  • Marker package tests against PostgreSQL 18 with SILO_TEST_DATABASE_URL set: pass.
  • make test-go on macOS: all packages pass except TestAdminResourceCapabilitiesAndScope in internal/apiv2, which fails the same way on main because the host reports resource capabilities as unsupported.
  • On a seeded 50,000-file library, one page of 100 candidates took about 140 ms to query. Each page goes on to make up to 100 provider calls at no more than 2 per second.
  • Not run against a live TheIntroDB key or a real deployment.

Risks

  • No migration. Existing fetch-state rows keep their current retry times, and the new durations apply from each file's next fetch.
  • Libraries now ask TheIntroDB for each file less often, so a correction published upstream can take up to 30 days to reach a file that already has markers.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code review subagent, gh, Go toolchain 1.26.5, PostgreSQL 18 (pgvector image)
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verification pending
  • Adversarial review: a separate Claude Code review agent read the diff for cursor progress when sort keys change during a run, SQL NULL and type handling, behavior differences from the two-pass sync, and whether the tests fail on the old order. It found no defects. Its low-severity notes were accepted unchanged: with several providers a file can be refetched once in a run, a file added during a run waits for the next run, and each page now sorts all due files instead of stopping early on the ID index.

🤖 Generated with Claude Code

Note

Fix marker sync to rotate through all due files when quota-limited

  • Reworks PopulationService.Sync in population.go to use a cursor-driven loop instead of separate unqueried and refresh passes, so each quota-limited run advances to the next least-recently-fetched file instead of repeating the same ones.
  • Replaces the file-ID cursor in PopulationStore.Candidates with a SyncCursor (fetched timestamp + file ID) in population_store.go. The query orders due files by least recent eligible fetch time, with never-fetched and on-demand files first, and keeps existing library, media identity, cooldown, and lease filters.
  • Extends stored freshness for successful marker responses from 7 to 30 days and the empty-result retry period from 1 to 14 days, with docs updated in markers-api.md.
  • Adds integration tests covering rotation through due files under quota and resumption across runs in population_store_test.go.
  • Behavioral Change: freshness/retry TTLs move to 30/14 days, and candidate ordering is now fetch-time-ordered; existing callers of Candidates must use the new SyncCursor signature (the in-tree test fake is updated).

Macroscope summarized 7537f67.

The daily Sync online markers task refreshed due results in file ID order.
TheIntroDB's daily quota ends a run early, so every run spent the quota on
the same low file IDs and newer episodes were never refreshed. Sync now
makes one pass ordered by last fetch, never-fetched files first, so each
run continues where the previous one stopped.

Cache found markers for 30 days and retry empty results after 14 days,
as TheIntroDB asks of clients that sync a library.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32a4cbfc-591d-46d2-8fe2-9aeeaa9f8507
📥 Commits

Reviewing files that changed from the base of the PR and between 8f8895b and 7537f67.

📒 Files selected for processing (5)
  • docs/markers-api.md
  • internal/markers/population.go
  • internal/markers/population_store.go
  • internal/markers/population_store_test.go
  • internal/markers/population_test.go
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@silo-kody

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

@Quick104
Quick104 marked this pull request as ready for review October 2, 2026 23:54
Comment thread internal/markers/population_store.go Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T23:58:21.049046Z 7537f67 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104
Quick104 merged commit 9d82420 into main Oct 3, 2026
19 checks passed
@Quick104
Quick104 deleted the fix/marker-sync-quota-rotation branch October 3, 2026 00:12
Quick104 added a commit that referenced this pull request Oct 3, 2026
Follow-ups to the quota rotation in #1830, found in review after merge.

Sync now reads the ordered list of due files once per run instead of
paging a sort key that no index serves. Each page had re-sorted the
whole library, and a provider whose cooldown ended mid-run could move
files behind the page cursor so the run skipped them.

Titles released in the last 30 days or due within a week keep the old
7-day and 1-day cache durations, so a new episode that TheIntroDB does
not know yet is retried daily instead of after two weeks.

The @population lease records a fetch time only when a pass has
confirmed the file's external IDs against every provider, and every
completion in a pass is dated from the pass's claim. A metadata refresh
that leaves the IDs unchanged no longer keeps a file due until its
cache expires, and an edit made during a pass is not hidden.

A run waits out a rate limit of up to a minute on every provider, also
when one is already active at the start, and ends at a longer one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant