Repository navigation
fix(playback): rebuild header-authenticated sessions after an API restart - #2501
Conversation
…tart An attempt that negotiated header_authenticated_media_v1 publishes no stream token, so after a restart the API had nothing to rebuild its in-memory playback session from: the manifest and every segment answered 404, which AVPlayer skips to the end of its playlist (Apple apps then show "End of playback"). Keep the recipe the token would have carried in a new Redis key space (noderecipe.NewSessionRecipeStore) for API-origin transports, written once the transport commits and followed when a transcode moves off a dead node. A manifest, segment, /stream or sidecar request that finds no live session rebuilds it from that record, only for the authenticated owner and only while the durable attempt still names the recorded plan, matches the selected profile, and has neither expired nor been stopped. The rebuilt session keeps requiring media authorization. An unreadable attempt row answers a retryable 500 instead of a 404. Closes #2495 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ 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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f2f52e6a9
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gpt-6.1-sol, reviewed 1f2f52e)
I verified two dependency-failure paths in recovery. Both overlap with findings the automated review posted during this pass. The inline comments give the source traces and repairs; I did not reproduce these failures on a running deployment.
Focused recovery, tokenless transport, node-recipe and sidecar Go tests passed in internal/api/handlers, internal/noderecipe and internal/playback. The validation-board query was blocked by the missing read:project scope; #1177 C3 is recorded as Not run in its issue.
AI disclosure: Review performed with OpenAI Codex in T3 Code, model gpt-6.1-sol.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 1f2f52e6a9
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| if record == nil || record.StoppedAt != nil || record.CurrentPlanID != card.PlanID || | ||
| record.UserID != userID || record.ProfileID != card.ProfileID || | ||
| (!record.ExpiresAt.IsZero() && time.Now().After(record.ExpiresAt)) || | ||
| !playback.HasFeatureV3(record.NormalizedRequest.ClientFeatures, playback.FeatureHeaderAuthenticatedMediaV3) { | ||
| return nil, nil |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Reauthorize recovered sessions against current access
When Redis recovery is enabled and a header_authenticated_media_v1 request lands after an API restart or replica miss, a user whose library/profile access was revoked can replay the session URL they received earlier. This gate checks only the stored attempt/card identity, plan, stop state, and expiry; it never applies the request's current viewer scope or ItemAccess, and the profile comparison is skipped when no selector is present. Reconstruction then serves the recorded media for up to 24 hours. RequireAuth and user-ID matching block anonymous/cross-account use, but not stale same-account authorization. Reauthorize the media against current policy, or invalidate the recipe by policy revision, before returning the card.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Silo authorizes the file once, at start (loadAuthorizedFile in the v3 start path). After that, neither a live session's media requests nor token reconstruction (?st, web and Android) re-check library or profile access during the attempt's 24-hour lifetime. Recovery keeps that same posture: it requires the authenticated owner, the selected profile when one is sent (the same rule requireOwningProfile applies to live sessions), the current plan, and an attempt that is neither stopped nor expired. It does not widen access beyond what a live session or a token already allows. Re-checking access on every rebuild would be a broader policy change that should cover token reconstruction too, so I have left it out of this PR and listed it under Risks. Leaving this thread open for a maintainer to decide.
… policy A Redis read failure during recovery was answered like a missing session (404). The session-recipe reader now uses noderecipe's new Store.Lookup, which reports the read error, and the loaders answer a retryable 500 as they already do for an unreadable attempt row. Get keeps failing closed for the node and proxy readers. The rebuilt session's progress policy and requested file are now the live session's, recorded with the card and carried across node moves, instead of recomputed from a file lookup that could fail and leave a multipart part writing resume state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
…n down A system teardown keeps the recovery card so the next request can rebuild a transcode the API runs itself. For a remote transcode the same teardown stops the node job and drops the node's recipe, so the card could only rebuild a session that relays the node's 404; drop it there too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The PR changes visible playback behavior: header-authenticated playback now survives an API restart instead of ending when media requests return 404. The before/after results and evidence link are under Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
The recorded Please replace
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Problem
Closes #2495
Related issue: #333
Validation tasks: changes #1177 C3
Pairs with Silo-Server/silo-apple#802
After every server update, Apple apps playing a server transcode stop a minute or two later with "End of playback", well before the end of the film. Web and Android ride through the same restart. With this change the Apple apps keep playing through an API restart too.
The Apple apps opt into header-authenticated media (
header_authenticated_media_v1), so their media URLs carry noststream token. The token is what a restarted API rebuilds a lost in-memory playback session from. For these sessions the restarted API had nothing to rebuild from: the manifest and every segment answered404, which the v2 media routes turn into the genericnot_foundproblem. AVPlayer skips 404 segments until it reaches the end of the playlist it already loaded, and the app then shows "End of playback" (Silo-Server/silo-apple#801). The protocol doc listed this as the accepted cost of the mode and named server-side session state as the fix.Approach
For header-authenticated attempts served from the API origin, the API now keeps the recipe the token would have carried in a new Redis key space, next to the existing proxy grants and node recipes (
noderecipe.NewSessionRecipeStore). It is written once the transport commits, with the routing taken from the live session, and updated when a transcode moves off a dead node. When a manifest, segment,/streamor sidecar request finds no in-memory session, the API rebuilds the session from that record. From there the path is the token one: deny marker, route checks, copy-safety gate, admission caps, then the relay to the node (which rebuilds from its own stored recipe) or the local FFmpeg rebuild at the requested segment.The record only helps reconstruction; the durable v3 attempt row decides whether it may be used. It must name the same plan, so a record a later replan failed to overwrite is refused. It must also match the account and selected profile, and be neither expired nor stopped. All of this is checked before anything is registered or started. The rebuilt session still refuses unauthenticated requests. If Redis or the attempt row can't be read, the request answers a retryable 500 instead of telling the client its session is gone. The rebuilt session keeps the progress policy and requested file the live session had. Without Redis nothing changes: the session answers 404 after a restart and the client starts a new attempt.
Proxy-served attempts (
authorized_media_origins_v1) get no record. Their proxy grant already survives a restart, and a session the API rebuilt for them would be reaped on API-side activity alone. Progress, replan and the control socket are untouched, and a replan of a lost session still answers 404.No API contract change. The app side of the same failure is Silo-Server/silo-apple#801, fixed in Silo-Server/silo-apple#802: the app treats a premature end of a server stream as a lost connection and replans at its position, so it also recovers against servers without this change.
Validation
Reproduced on a dev deployment with an API, a transcode node and Redis, recreated together with
docker compose up -d --force-recreatethe way a production deploy does (8 s outage). Before, with a header-authenticated 480p transcode running on the transcode node: after the restart the master playlist and every segment returned404 not_found, progress stayed200, and a replan returned404. After: the same requests returned200, an unauthenticated segment request returned401, and a replan returned a plan. Video PTS stayed continuous across the restart (+180180 per segment). A far segment rebuilt after the restart started within 45 ms of its position in the playlist the client already held.The iOS app on a simulator, against that deployment, restarted 12 minutes before the end of a film at 480p:
The server log shows each session rebuilt on its first request after the restart. Against unfixed server main, the silo-apple#802 app hit the segment 404s, replanned, and resumed at the same position on a new session 3.7 s later (checked in that PR).
New handler tests cover:
/streamdirect play;Removing each guard fails its test.
make test-go,go vet ./...,make lint-changed,make verify-local-pathsand the route, playback-fixture, OpenAPI, contract and offline-route checks pass. No web changes.Validation impact: "Distributed transcode nodes — Server" (Distributed transcode nodes — Server #1177) C3 removes a worker during playback, which runs the failover path this change touches. For a header-authenticated session, a move to another executor now also points the recovery record at the new executor: one Redis read and one bounded write, taken after the move has succeeded and before the relayed request is answered. That's milliseconds against C3's 10-second bar. Token-bearing sessions move exactly as before. The task records C3 as not run; it should be run (or re-run) on a build with this change. I couldn't read the validation board itself (token scope).
Evidence
Surface and build: the iOS app on a simulator (silo-apple main, and the silo-apple#802 build) against a dev deployment of this branch, plus the server's media responses, logs and segment timestamps before and after the restart.
Evidence: https://evidence.siloserver.org/r/silo-server/issue-2495/
Risks
Follow-ups
Checklist
AI Disclosure
🤖 Generated with Claude Code