Skip to content

fix(playback): back off the lifecycle sweep when an end's history write fails - #3951

Merged
Quick104 merged 2 commits into
mainfrom
fix/admin-history-client-name
Nov 11, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/admin-history-client-name

Conversation

@Quick104

@Quick104 Quick104 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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_name and its sibling columns NOT NULL DEFAULT ''. Main defines them as nullable (20261027185055), and its ADD COLUMN IF NOT EXISTS skipped them. The sessions were /api/v2 starts 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

recordAdminStopHistory and recordEnd now 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

  • Focused internal/api/handlers tests and the whole package against a migrated Postgres: pass. One existing test, TestHandleStartPlaybackV3DoesNotWaitForSessionSync, is timing-sensitive on main: it waits one second for a goroutine, fails when run on its own on the machine used (on main as well as here), and failed once in a package run under heavy load. This change does not touch the start path it exercises.
  • New database contract test (registered in scripts/ci/db-contracts.txt): fails without the change, passes with it.
  • gofmt clean; 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

  • 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 (in T3 Code)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5, reviewed by claude-fable-5-2
  • Involvement: Fully AI-generated at the maintainer's direction; the maintainer has not yet reviewed the diff
  • Adversarial review: the diff was read in full by a second model (claude-fable-5-2) before opening; no changes requested

🤖 Generated with Claude Code

…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>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

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: 2fffc1ec-55b0-4e30-bc44-015352a12f18
Commits

Reviewing files that changed from the base of the PR and between 0e95e55 and 695fbf0.

Files selected for processing: 7

  • docs/architecture/playback-lifecycle.md
  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_lifecycle.go
  • internal/api/handlers/playback_lifecycle_db_test.go
  • internal/api/handlers/playback_lifecycle_sweep.go
  • internal/api/handlers/playback_lifecycle_test.go
  • scripts/ci/db-contracts.txt
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T19:28:13.398971Z 695fbf0 New commits
🔒 Security Review ✅ Completed 2026-11-11T19:31:16.144997Z 695fbf0 New commits
ℹ️ 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 ab8258f into main Nov 11, 2026
17 checks passed
@Quick104
Quick104 deleted the fix/admin-history-client-name branch November 11, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant