Skip to content

fix(markers): stop recording abandoned lookups as provider failures - #2067

Merged
Quick104 merged 5 commits into
Silo-Server:mainfrom
blurbery:fix/markers-cancelled-lookup
Oct 10, 2026
Merged

Quick104 merged 5 commits into
Silo-Server:mainfrom
blurbery:fix/markers-cancelled-lookup

Conversation

@blurbery

@blurbery blurbery commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none (the change reaches #1148 C2 and C3, which have no result yet)

If someone opens a title and leaves before the online marker lookup finishes, Silo records that as a failed provider request. A read that runs out its own 5-second marker budget is recorded the same way. The file then sits in failure backoff (1 minute, doubling to an hour), and opening the title again in that window gets no online markers from that provider. If the provider had already answered, that answer is thrown away as well. This change treats an abandoned lookup as abandoned: no failure, no failure backoff, and an answer that already arrived is saved. A provider too slow for a 5-second read is left alone by those reads for a minute instead, while the playback lookup still asks it.

How it happens in PopulationService.populate:

  • Plugin providers report the caller's cancellation as a gRPC Canceled or DeadlineExceeded status. recordFetchFailure stores it as outcome=error, adds one to failures, sets retry_at from fetchRetry and logs "marker provider fetch failed" at WARN. Claim won't take the row again until retry_at passes, and force only skips the wait for hit and miss rows.
  • If the answer arrives and then the caller leaves, the settings re-check and checkIdentity after the loop run on the cancelled context and fail. Every fresh answer is then completed as an error ("marker settings changed" or "marker storage failed"), so the quota it cost is wasted and the failure count still goes up.
  • The v1 and v2 marker reads, Jellyfin media segments and download manifests give the lookup 5 seconds, while a provider gets 45. A slow answer on those paths ends the same way.

On my server, marker_fetch_state had 198 error rows whose last error is a cancellation or deadline (171 with no cached result, up to 11 failures on one file) and 14 rows from the two post-fetch errors. The log had 16 "marker provider fetch failed" warnings with code = Canceled in 26 hours.

Approach

  • When the pass context is done, a failed fetch hands its claim back through a new PopulationStore.Release instead of completing it. Release clears the lease and leaves outcome, failures, retry_at, last_error and the cached result as they were. The one exception is a claim for a new identity: Claim has already dropped the old result, so Release makes the row due now instead of leaving it behind the old answer's retry_at with nothing cached. Nothing is logged for these.
  • The check is on the pass context, not the error, so it covers gRPC statuses, the 5-second read budget and the pass's own 90-second limit. A provider's own 45-second timeout while the caller is still waiting is still a failure, and a rate-limit answer is still recorded as a cooldown even if the caller has gone.
  • Once the context is done the loop asks no more providers, but still adds their cached answers, so the save doesn't drop markers from providers it didn't reach.
  • If anything new was fetched, the settings re-check, identity check, write, completions and notify run on a context detached from the caller. It keeps the pass deadline while the caller is there and gets 5 seconds once the caller has gone, which keeps it well inside the 2-minute leases. If nothing new was fetched, the pass returns straight away.
  • An abandoned lookup returns context.Canceled or context.DeadlineExceeded, so callers can recognise it with errors.Is.
  • In on-demand mode, answers are completed as they arrive rather than saved at the end, so the early return checks whether the pass fetched anything, not whether anything is waiting to be saved. An answer fetched before the caller left is applied to the returned file and sent to players.
  • A pass whose caller has less than the 45-second provider timeout left is a short read, which today means the four 5-second read paths. When a short read runs out of time waiting for a provider, the claim is still released and no failure is counted, but other short reads skip that provider for that file for one minute and use its cached answer if there is one. A viewer leaving (context.Canceled) sets no hold. The 10-minute playback lookup, the admin refresh and Sync ignore the hold, so the playback lookup that usually follows a detail read still asks the provider.
  • The hold is kept in memory on each replica, next to the on-demand answer cache, and capped at 512 entries the same way. A hold in marker_fetch_state would also block the stored-mode playback lookup, because Claim checks retry_at for it, and on-demand rows ignore retry_at altogether.

Validation

  • New unit tests on the populationRecorder fake cover a viewer leaving and a read deadline passing mid-request (claim released, no completion, no WARN), a fresh answer saved when the viewer leaves before the settings re-check or the identity check, a cached second provider kept in that save, and a provider's own timeout and a rate limit still being recorded. The first three fail on 6e208ef: the cancelled request is stored as outcome=error, and the fetched answer is never written.
  • TestPopulationOnDemandAppliesFetchedMarkersAfterViewerLeaves covers on-demand mode: the first provider answers and the viewer leaves while the second is asked. It failed before 7f9d3d6 (no markers returned or sent to players).
  • TestPopulationShortReadsHoldSlowProvider covers the hold in stored and on-demand mode on testing/synctest fake time, with a provider that takes 10 seconds. A 5-second read is cut off, a second read inside the minute doesn't ask the provider, a read after the minute does, and a 10-minute lookup during a hold gets the provider's answer. It fails on 8b68ab0, where the second read asks again. TestPopulationViewerLeavingDoesNotHoldProvider checks that a viewer leaving sets no hold, and TestPopulationHoldsAreCapped checks the cap. The read-deadline case of TestPopulationCanceledLookupIsNotAProviderFailure now reports a 5-second deadline, so it runs as a short read.
  • On 6a6e488: go test ./internal/markers/... passes, -race -count=3 on the population tests passes, and go vet ./internal/markers/, go build ./cmd/silo/ and make lint-changed are clean. The DB-backed store tests skipped locally because I had no database running for this commit; the Release SQL is unchanged, and Go DB pins runs those tests in CI.
  • TestPopulationStoreReleaseKeepsFetchState checks the new SQL against Postgres: the row's state is unchanged, a wrong token leaves the lease alone, and a released new identity is due again. It passes against a local migrated PostgreSQL 18 database with the other population store tests, and fails if the retry_at reset is removed. I added it to scripts/ci/db-contracts.txt so Go DB pins runs it.
  • go build ./..., go vet ./internal/markers/ and make lint-changed: clean.
  • CI on c43dad4: every job passed, including Go DB pins, which runs the new Release test (run).
  • CI on 8b68ab0 (7f9d3d6 with main merged in): every Go job passed, including Go DB pins and Go lint. Web (build) fails the launch bundle budget, as it does on main ([bug] Web build fails the launch bundle budget on main after #2168 #2203); this PR changes no web code.
  • CI on 6a6e488 (run): every Go job passed, including Go DB pins (which runs the Release test), Go lint, Go test and Go integration, and the web tests passed. Web (build) fails the same launch bundle budget check as main ([bug] Web build fails the launch bundle budget on main after #2168 #2203), and CI result fails only because of it.
  • Not run on a server with this change.

Benchmarks

Not applicable. This changes what is recorded when a lookup is abandoned, not the cost of a lookup.

Evidence

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

Before: the production counts and log lines above, from a read-only query and the server log. After: the regression tests. Markers show up in players, but nothing renders differently; the change is whether a title has online markers after someone abandoned an earlier lookup.

Risks

  • The hold is per replica. With several API replicas behind a load balancer, each one can ask a slow provider once a minute per file, not once a minute across the cluster.
  • A provider that is always slower than 5 seconds is asked about once a minute while someone keeps reading the same title, where before the file backed off from 1 minute to an hour. The better fix is still letting a fetch outlive a short read budget in the background, which is a bigger change.
  • A short read can run out of time while waiting for the file lease or a request slot rather than on a slow provider. That provider is then held off reads of that file for a minute anyway; playback and Sync still ask it.
  • When an answer has arrived, the save can run up to 5 seconds past a 5-second read budget. In practice it's a few queries.
  • The handlers' "marker lookup failed" warning still logs for abandoned lookups. fix(api): stop counting and logging cancelled requests as server failures #2077 drops it to Debug when the request was cancelled.
  • Rows already in failure backoff keep it until they are next fetched.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code, with a subagent for an independent review of this diff; go, gh
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted
  • Adversarial review: A separate Claude Code subagent reviewed the diff against the source, checked the Release SQL against every row state Claim can leave, the lease timing and the other callers, and ran the race tests. It found no blockers. It found that a caller cancelled without a deadline gave the save the rest of the 90-second pass instead of the grace, and that the DB test compared the database clock with the host clock; both are fixed. Its point that abandoned lookups no longer back off is now covered by the short-read hold under Approach.
  • Maintainer review: Claude Code (claude-opus-5-5) with Claude subagents and a Codex (gpt-6.1-sol) cross-check reviewed c43dad4 and pushed 7f9d3d6, the on-demand fix and its test.
  • Follow-up: 6a6e488, the short-read hold, was written with Claude Code (claude-opus-5-5), with its design checked by Claude Code's advisor tool before implementation.

AI-assisted with Claude Opus. I directed the task and designed the work.

Note

Stop recording abandoned marker lookups as provider failures

Caller cancellation or pass expiry during marker population no longer marks the provider as failed. Abandoned claims release through a new PopulationStore.Release method that clears the lease without changing outcome, failure count, or retry state.

  • Markers already fetched when the caller leaves are still saved, using a 5-second cancellation-independent grace context instead of the dead caller context. The original context error remains in the returned errors.
  • Short reads (deadline shorter than the provider fetch timeout) that expire while waiting now place a 1-minute in-memory hold on that provider for the same identity, so later short reads skip it. The hold map is capped at the marker memory limit using earliest-expiry eviction in firstToExpire (population.go).
  • Provider-owned timeouts and rate limits after caller cancellation are still recorded as failures, and explicit viewer cancellation never creates a hold.
  • Adds database contract coverage for release (population_store_test.go) plus synctest-based tests for hold behavior and post-cancellation saves (population_test.go).
  • Behavioral Change: providers whose lookups were abandoned by a leaving viewer are now retried immediately instead of entering backoff; check populate in population.go and Release in population_store.go.

Macroscope summarized 6a6e488.

A marker lookup whose caller went away, or whose short read deadline
passed, was stored as a failed provider request. The file then sat in
failure backoff (1 minute rising to an hour) with no online markers,
and a provider answer that had already arrived was thrown away because
the settings and identity checks after the fetch ran on the dead
context.

When the pass context is done, a failed fetch now hands its claim back
through the new PopulationStore.Release, which keeps the row's
failures, backoff, last error and cached result. A rate-limit answer is
still recorded. Answers already fetched are saved on a context detached
from the caller, bounded by the pass deadline or a five-second grace,
and providers not asked keep their cached answers in that save.
A canceled caller with no deadline of its own left the save with the
rest of the 90-second pass. Use the short grace once the caller has
gone, and check the released row against the database clock.
@silo-kody

silo-kody Bot commented Oct 8, 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 added priority: P2 Limited scope, workaround exists, or polish impact: playback Can't play, stalls, or wrong media labels Oct 8, 2026 — with Cursor
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de931bf1-6b96-46db-84fa-06cabe40cb32





📥 Commits

Reviewing files that changed from the base of the PR and between 7f9d3d6 and 6a6e488.






📒 Files selected for processing (3)
  • internal/markers/population.go
  • internal/markers/population_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; 2 remain after this review.







📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Population passes release claims when pass deadlines interrupt provider fetches. Short reads hold timed-out providers for one minute. When a fetch succeeds, population can save or apply the results with a bounded context.

Changes

Marker population cancellation and save handling

Layer / File(s) Summary
Provider claim release contract
internal/markers/population_store.go, internal/markers/population_store_test.go, scripts/ci/db-contracts.txt
PopulationStore adds Release, which clears a matching lease without changing recorded fetch state. The database contract test checks release behavior and reclaiming a claim.
Cancellation-aware fetching and short-read holds
internal/markers/population.go, internal/markers/population_test.go
Population releases claims when pass deadlines interrupt fetches. Short reads skip providers held after a timeout, while longer lookups can still request them. Cached results remain available for providers that are skipped.
Saving fetched results after cancellation
internal/markers/population.go, internal/markers/population_test.go
When a provider returns results, population uses the pass deadline or a five-second grace period for writes and related operations. Tests cover stored and on-demand results, notifications, and save deadlines.

Priority: ⬇️ Low

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant PopulationService
  participant Provider
  participant PopulationStore
  PopulationService->>Provider: Fetch markers using pass context
  Provider-->>PopulationService: Return markers or fetch error
  PopulationService->>PopulationStore: Release claim when the pass deadline interrupts the fetch
Loading

Suggested reviewers: quick104












Merge Risk: ⚪ Minimal · up to 6a6e4

The claim-release, short-read, and save-after-cancellation paths show no outstanding issue requiring a change before merge.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: abandoned marker lookups no longer count as provider failures.
Description check Passed The description directly explains the problem, implementation, validation, risks, and user-visible behavior of the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR





🧪 Generate unit tests (beta)
  • Create a new PR









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

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.

@macroscopeapp

macroscopeapp Bot commented Oct 8, 2026

Copy link
Copy Markdown

This changes playback-visible marker availability after an abandoned lookup (internal/markers/population.go). The Evidence section's “link to follow” and production/test notes do not show that behavior; add before-and-after captures of the same title and playback surface, plus a short recording of the abandoned-lookup flow if needed to show the timing, and identify the client surface and build or commit. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

Comment thread internal/markers/population.go Resolved

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

Review of c43dad4. Two findings: one I'm fixing in a commit on this branch, and one that needs your call. A summary with validation and readiness follows as a PR comment.

AI disclosure: reviewed with Claude Code (claude-opus-5-5), with Claude subagents and a Codex (gpt-6.1-sol) cross-check, run for a maintainer.

Comment thread internal/markers/population.go Resolved
Comment thread internal/markers/population.go Resolved
On-demand answers are completed inside the loop and never added to
pending, so a pass whose caller left after one provider answered
returned the bare file: the response and players got none of it until
the next lookup. Return early only when the pass fetched nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

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

Copy link
Copy Markdown
Contributor

Review summary

Reviewed c43dad4. Head is now 8b68ab0: my fix (7f9d3d6) plus a merge of main.

Addressed

  • On-demand mode dropped an answer fetched before the viewer left, because the early return checked pending, which on-demand never fills. Fixed in 7f9d3d6 with TestPopulationOnDemandAppliesFetchedMarkersAfterViewerLeaves, which failed before the fix.
  • After that push, CI's Go lint flagged lines in internal/historyimport from main. The branch was 638 commits behind, so CI's lint-from-merge-base treated main's own changes as new. Merging main (8b68ab0, no conflicts) cleared it.

Remaining

  • Needs your call: nothing limits how often a provider slower than the 5-second read budget is asked (inline thread, line 303). You disclosed this under Risks. The thread lists two options: merge as is with a follow-up to move read-path lookups to the background, or release only on context.Canceled and give a read-budget timeout on an uncached row a short hold.
  • Low, no change made:
    • A provider that starts late in the 90-second pass inherits the pass deadline, so a provider that really hangs can be released instead of recorded for one pass. It corrects itself once the earlier provider is in backoff.
    • complete and release each start a fresh 5-second timeout. During a database stall, the save can therefore run past the grace you describe. That pattern predates this PR.

Other feedback

  • Kody's save-deadline thread: I agree with your reply. The deadline is chosen when the save starts, and the pass deadline still bounds it.
  • Macroscope's evidence comment predates the evidence link. The Evidence check passes, and the page (production counts and regression tests) still matches the head; 7f9d3d6 adds a test and doesn't change what the page shows.

Validated features

  • No passed case reaches this change. Validation tasks: none. Markers / skip intro & credits — Server #1148 C2 and C3 (marker providers; missing or failed markers not blocking playback) are reachable but not run yet. I updated the PR body's line to the passed-only format.

CI on 8b68ab0

Checks

  • User manual: unaffected. The marker pages don't describe lookup backoff or failures.
  • Apple and Android: no client-visible API change. Responses keep their shape. Clients get markers from the save sooner, through the existing fields.
  • Jellyfin: MediaSegments uses the same Populate path and gets the same behavior.
  • Not verified on a running server. Verification is unit tests, the Postgres Release test in CI, -race -count=3 on the population tests, and make lint-changed.

Fit: 8/10 · Readiness: 7/10 — conditional (head 8b68ab0)

  • Fit: this fixes a real gap in a core 1.0 feature (titles losing online markers after an abandoned lookup) at the boundary that owns it, and adds no setting or API surface. It stops short of 9 because it trades away the provider-health signal for providers slower than the read budget, rather than fixing the 5-second inline fetch that causes the mismatch.
  • Readiness: the approach and tests are sound. Two conditions remain. The retry-bound decision above is open, and the required CI result check is red until [bug] Web build fails the launch bundle budget on main after #2168 #2203 is fixed on main.

AI disclosure: Claude Code (claude-opus-5-5) with Claude subagents and a Codex (gpt-6.1-sol) cross-check, run for a maintainer.

Releasing a claim that a 5-second read ran out of time on left nothing
limiting how often a provider slower than that budget is asked: every
detail read, MediaSegments request or download manifest asked it again
and cut it off.

A pass whose caller has less than markerFetchTimeout left is now a short
read. When a short read runs out its deadline waiting for a provider, the
claim is still released with no failure counted, and other short reads
skip that provider for that file for markerReadHold (one minute), using
its cached answer if there is one. A viewer leaving (context.Canceled)
sets no hold. Lookups that can wait a provider's full timeout, such as
the 10-minute playback lookup, the admin refresh and Sync, ignore the
hold, so the playback lookup that usually follows a detail read still
asks the provider.

The hold is kept in memory per replica, next to the on-demand answer
cache and capped the same way. A database hold would also stop the
playback lookup, because Claim checks retry_at for it, and on-demand
rows ignore retry_at altogether.
@Quick104
Quick104 merged commit 9d37930 into Silo-Server:main Oct 10, 2026
20 of 22 checks passed
@blurbery
blurbery deleted the fix/markers-cancelled-lookup branch November 6, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants