Repository navigation
fix(playback): back off the lifecycle sweep when an end's history write fails - #3951
Conversation
…te fails When the sweep ended a session from its start row and the admin history write failed, the row stayed at the head of the oldest-first batch and was retried every 15 seconds on every server, logging an error each time. Enough such rows would fill the 100-row batch and stop the sweep from ending any other session. A failed write now counts as activity on the lifecycle row: the session stays live so the history row is still written once the cause is fixed, but it waits another idle grace before the next try and moves behind sessions idle for longer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 5 minutes. View limit details
Pre-merge checks:
|
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:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Problem
Related issue: N/A
Validation tasks: none
When the lifecycle sweep ends a session nobody holds and the admin history write fails, it retries that session every 15 seconds on every API server, logging an error each time, for as long as the write keeps failing. Failing sessions also stay at the front of the sweep's oldest-first batch of 100, so once 100 of them pile up, the sweep stops ending any other abandoned session, and those sessions never get a history row either. This change makes a failed write wait another idle grace before the next try and moves the session to the back of the queue. The session stays live, so its history row is still written once the cause is fixed.
A development deployment showed this: 89 sessions retried their write about 350 times a minute (89 sessions, four sweeps a minute) for days. The write failed because that database had run a migration from an unmerged branch that made
admin_playback_history.client_nameand its sibling columnsNOT NULL DEFAULT ''. Main defines them as nullable (20261027185055), and itsADD COLUMN IF NOT EXISTSskipped them. The sessions were/api/v2starts from scripted HTTP clients that sent no client identity, so their recorded client name is NULL, which main stores as "unknown". A database migrated only from main does not hit that NOT NULL violation, but any other persistent write failure would cause the same retry loop and the same blocked batch.Approach
recordAdminStopHistoryandrecordEndnow return the write error as well as logging it. When the sweep's end from the start row (endLifecycleFromFacts) gets an error, it records the current time as the lifecycle row's activity. The Jellyfin branch already uses the same mechanism to move a still-reporting play behind idle ones. The schema is unchanged. Dropping the session after a failed write was rejected because it would lose a history row that a later fix could still recover.A session whose attempt is stopped is still selected every sweep regardless of activity until its attempt row expires. This change does not alter that path.
Validation
internal/api/handlerstests and the whole package against a migrated Postgres: pass. One existing test,TestHandleStartPlaybackV3DoesNotWaitForSessionSync, is timing-sensitive onmain: it waits one second for a goroutine, fails when run on its own on the machine used (onmainas well as here), and failed once in a package run under heavy load. This change does not touch the start path it exercises.scripts/ci/db-contracts.txt): fails without the change, passes with it.gofmtclean;make lint-changed: 0 issues;make verify-local-paths: pass.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3951/
No user-visible change.
Risks
A session whose history write fails is now retried once per idle grace (5 minutes while playing) instead of every sweep, so after the cause is fixed its row can arrive up to one grace later. No migration.
Checklist
AI Disclosure
🤖 Generated with Claude Code