Repository navigation
fix(playback): keep node-served sessions alive while media flows - #2156
Conversation
A session whose media a proxy node serves stayed alive only on its client's
progress reports. A Google Cast receiver pulls media itself but never reports
progress; its sender phone does. When the phone slept, the API reaped the
session five minutes later and the TV stopped mid-playback.
Proxy nodes now record playback delivery in Redis
(silo:playback-delivery:{session_id}) as media bytes reach the client: only
2xx playlist, segment, and progressive responses that send bytes count, and a
long progressive response keeps counting while it flows. Each node writes at
most once per 20 seconds per session, off the request path.
On every sweep the API reads the records of its remote-transport sessions and
counts a live record as activity at the time it was written, derived from the
record's TTL so node and API clocks need not agree. Merging on every sweep,
not only for sessions about to expire, keeps delivering streams counted
toward stream limits and lets the paused grace run from the last delivery.
Records live six minutes, longer than the five-minute remote grace, so a
session ends five minutes after its last delivery. A failed Redis read falls
back to the other activity, as before.
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.
ℹ️ 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⚙️ Run configuration
📒 Files selected for processing (14)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughProxy media responses now record successful delivery activity in Redis. Playback session cleanup reads these records to refresh remote-transport session activity. The change also adds delivery-record expiry, write throttling, tests, and architecture documentation. ChangesPlayback delivery activity
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Proxy
participant Tracker
participant Redis
participant SessionManager
Proxy->>Tracker: RecordDelivery(sessionID)
Tracker->>Redis: Write delivery key with expiry
SessionManager->>Redis: RecentDeliveries(active session IDs)
Redis-->>SessionManager: Delivery timestamps
SessionManager->>SessionManager: Refresh remote-session activity before cleanup
Merge Risk: ⚪ Minimal · up to No actionable issue remains that should block merging. Normal validation can proceed, with Redis-backed tests and device scenarios still subject to the reported testing limits. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 74.19% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 13 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
🛠️ Fix failing CI checks 💡
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. Comment |
|
The playback effect—Cast playback continuing after progress reports stop, then ending about five minutes after media delivery stops—has only a written before/after description. Add a recording that demonstrates this timing; the PR already names the surface and build. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
… deadline The idle sweep waits on the node delivery lookup. The API's shared Redis client takes its socket timeouts from the URL, which may disable them, so a Redis that stopped answering could hold the lookup, and with an abandoned lookup a pooled connection, indefinitely. The lookup now uses its own client whose sockets honor the caller's context deadline (cache.NewDeadlineRedisClientForRole), so a stalled read ends at the sweep's deadline and frees the connection. 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:
|
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:
|
Problem
Related issue: #666 (the reverse case, where progress reports keep a session alive after its media stops; not changed here)
Validation tasks: none passed yet; could reach #1177 C3 and #1206 C2 (session cleanup), both not run
Casting from the Android app to a Google Cast TV stops about five minutes after the phone goes to sleep. The Cast receiver never reports playback progress; the phone does. When the phone stops reporting, the idle sweep expires the session as abandoned, and the node stops the transcode while the TV is still playing.
With this change, the node that serves the media records that the client is still receiving it, and the idle sweep counts that as activity. The session now ends about five minutes after the TV stops fetching media, not five minutes after the phone stops reporting.
Approach
noteDelivery. Only a 2xx response that sends bytes counts, so HEAD, failed relays, unsatisfiable ranges and empty responses don't, and a long progressive response keeps counting while it flows. Subtitles, themes and downloads are not marked.silo:playback-delivery:{session_id}to Redis at most once per session every 20 seconds, off the request path. Records expire after six minutes. The node’s Redis client honors each write’s two-second context deadline on its sockets, including when the URL disables socket timeouts, so stalled writes release their connections.CleanInactivereads the records of all remote-transport sessions and treats the latest delivery as activity. The delivery time comes from the record's remaining TTL, which Redis counts on its own clock, so node and API clocks don't need to agree. Reading every remote session, not only those about to expire, keeps a delivering stream counted toward stream limits between sweeps and lets the paused grace run from its last delivery.Validation
go build ./..., gofmt,go vet ./..., andmake lint-changed(0 issues) pass. The full Go suite passed 173 packages and failedTestRunStatsWithRealFFmpegininternal/mediasamplewith FFmpeg 6.1.1 (a frame at 11.003 seconds falls outside the expected window). The same test fails on the original PR head,f71625a.-raceagainst Redis 7.0.15. Database tests were not run against a live database.make test-webpassed before the Redis write timeout fix; that fix changes Go startup, a Go test, and the protocol documentation.make verify-*targets in the gate and the committed-router check pass.-race; CI has no Redis, so they skip there like the repo's other Redis tests.Evidence
Surface and build: Silo Android 0.3.11 on a Pixel casting a server-transcoded HLS stream to the Google Cast Default Media Receiver on an Onn 4K, through a remote node. The phone run used an earlier revision of this branch that recorded delivery per request. The media delivery implementation was checked against the same TV with a scripted Cast sender on an isolated test deployment with a proxy and a transcode node. With no progress reports, the session stayed alive for 11 minutes, then ended 5 minutes 7 seconds after the TV stopped.
Risks
SETper active node-served session every 20 seconds, plus one pipelinedPTTLper sweep (every 15 seconds) covering the remote-transport sessions on that API replica.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Keep node-served playback sessions alive via Redis delivery records
Tracker.RecordDelivery, at most once per 20 seconds per session, with a 6-minute expiry. Only 2xx responses with positive body bytes count; HEAD requests and failed relays are excluded (delivery.go, delivery.go).SessionManager.refreshDeliveryActivity, so remote-transport sessions served by a proxy node are not expired while media still flows. A failed lookup falls back to normal activity instead of protecting sessions (session.go).NewDeadlineRedisClientForRoleso delivery reads and writes honor context deadlines and do not hold connections on stalled Redis servers (redis.go).Tracker.Cleanupno longer deletes delivery records on shutdown; they expire on their own 6-minute lifetime. Integration tests needSILO_TEST_REDIS_URLset.Macroscope summarized f9ad016.