Repository navigation
feat(playback): formalize resumable direct streams and stall observability - #464
Conversation
…ility Implements #443: strong stat-based ETag + If-Range on original-file direct play (via http.ServeContent), stream-end outcome classification in RollingDeadlineWriter (stalled_reap vs client_gone vs completed) with a structured log event and Prometheus counters, the direct_stream_resume_v1 protocol-v3 capability, and a contract doc. Progressive remux is explicitly excluded from the resume contract. Code written by OpenAI Codex CLI (gpt-5.6-sol) from a Claude-authored spec; reviewed and verified by Claude. Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds Protocol v3 direct-stream resumption signaling, HTTP range and ETag handling, stream outcome telemetry, Prometheus metrics, and tests covering response contracts and session grace behavior. ChangesDirect stream resumption
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ServeDirectPlay
participant MediaFile
participant RollingDeadlineWriter
Client->>ServeDirectPlay: Request Range with If-Range
ServeDirectPlay->>MediaFile: Serve content
MediaFile->>RollingDeadlineWriter: Write response bytes
RollingDeadlineWriter-->>ServeDirectPlay: Return status, byte count, and outcome
ServeDirectPlay-->>Client: Return 206 partial content or 200 full content
Possibly related issues
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (6)
internal/api/handlers/playback_v3.go (5)
1270-1274: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSame duplicated
ServerFeaturesliteral (replan path).Identical literal to
startPlannedPlaybackV3anddecisionResponseFromAttemptV3; same consolidation opportunity as noted above.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/playback_v3.go` around lines 1270 - 1274, Replace the duplicated ServerFeatures literal in the replan response construction with the shared feature-list symbol or helper already used by startPlannedPlaybackV3 and decisionResponseFromAttemptV3. Preserve the exact feature values and response behavior while consolidating the common definition.
536-540: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSame duplicated
ServerFeaturesliteral (start-playback path).Shares the root cause noted on the capability handler above and in
internal/playback/protocol_v3.go'sNewTerminalResponseV3; consolidating into a shared helper would have made this single-flag addition a one-line change instead of four.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/playback_v3.go` around lines 536 - 540, Replace the duplicated ServerFeatures literal in the start-playback response construction with the shared helper used by the capability handler and NewTerminalResponseV3. Update the helper’s feature list to include the required flag so this path inherits the centralized capability definition.
1846-1850: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSame duplicated
ServerFeaturesliteral (idempotent-replay path).Identical literal to
startPlannedPlaybackV3andexecuteReplanV3; same consolidation opportunity as noted above.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/playback_v3.go` around lines 1846 - 1850, Consolidate the duplicated ServerFeatures literal in the idempotent-replay response path by reusing the shared feature-list symbol introduced for startPlannedPlaybackV3 and executeReplanV3. Update this playback.DecisionResponseV3 construction while preserving the existing RuntimeCorrections initialization and response fields.
1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
ServerFeatures/Featuresslice literals are hand-duplicated across 5 sites in 2 files and have already drifted. The root cause is the lack of a single shared source for these lists; this PR's own change (adding one flag) had to touch all five copies, and the copies already disagree on which features they advertise.
internal/api/handlers/playback_v3.go#L353-359: canonical 8-itemFeatureslist for the capability response; use this (or a new shared constant) as the source of truth.internal/playback/protocol_v3.go#L813-819:NewTerminalResponseV3's 5-item list omitsFeatureRouteDiagnosticspresent in the other decision-response builders — replace with a shared helper/constant.internal/api/handlers/playback_v3.go#L536-540:startPlannedPlaybackV3's 6-item list is byte-for-byte identical to two other sites below — replace with the same shared helper/constant.internal/api/handlers/playback_v3.go#L1270-1274:executeReplanV3duplicates the same 6-item list — replace with the shared helper/constant.internal/api/handlers/playback_v3.go#L1846-1850:decisionResponseFromAttemptV3duplicates the same 6-item list — replace with the shared helper/constant.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/playback_v3.go` at line 1, Consolidate the duplicated ServerFeatures/Features slice literals into one shared helper or constant, using the canonical capability-response list around the Features declaration in playback_v3.go as the source of truth. Update NewTerminalResponseV3, startPlannedPlaybackV3, executeReplanV3, and decisionResponseFromAttemptV3 to reuse it, ensuring every response advertises the same complete feature set including FeatureRouteDiagnostics.
353-359: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCapability
Featureslist is a fourth divergent copy of the same server-features literal.This 8-item list, the 6-item lists in
startPlannedPlaybackV3/executeReplanV3/decisionResponseFromAttemptV3(this file), and the 5-item list inprotocol_v3.go'sNewTerminalResponseV3are all hand-maintained copies that have already diverged (e.g.,FeatureDetailedDecodeV3/FeatureLayoutPassthroughappear only here). Confirm whether decision responses intentionally omit those two features, or whether this is a maintenance gap.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/playback_v3.go` around lines 353 - 359, Unify the server feature advertisement used by the capability response and the response builders startPlannedPlaybackV3, executeReplanV3, decisionResponseFromAttemptV3, and NewTerminalResponseV3 instead of maintaining separate literals. Confirm whether FeatureDetailedDecodeV3 and FeatureLayoutPassthrough are intentionally excluded from decision responses; preserve that distinction only if intentional, otherwise include them through the shared canonical feature set. Ensure all advertised feature lists remain consistent with the chosen behavior.internal/playback/protocol_v3.go (1)
813-819: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
ServerFeaturesliteral duplicated and already diverged across call sites.This list is repeated near-verbatim in
internal/api/handlers/playback_v3.go(capability response,startPlannedPlaybackV3,executeReplanV3,decisionResponseFromAttemptV3). This copy already differs from those: it omitsFeatureRouteDiagnostics, which the other three decision-response builders include. Adding one flag required editing 4+ places, and drift has already occurred.Extract a shared exported slice/function (e.g.
PlayableServerFeaturesV3()/TerminalServerFeaturesV3()) in this domain package so all response builders stay in sync.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/playback/protocol_v3.go` around lines 813 - 819, Extract the duplicated V3 server-feature list into a shared exported slice or function in the playback protocol domain, including FeatureRouteDiagnostics. Update NewTerminalResponseV3 and the capability, startPlannedPlaybackV3, executeReplanV3, and decisionResponseFromAttemptV3 builders to reuse it instead of defining separate literals, preserving consistent feature contents across all responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/api/handlers/playback_v3.go`:
- Around line 1270-1274: Replace the duplicated ServerFeatures literal in the
replan response construction with the shared feature-list symbol or helper
already used by startPlannedPlaybackV3 and decisionResponseFromAttemptV3.
Preserve the exact feature values and response behavior while consolidating the
common definition.
- Around line 536-540: Replace the duplicated ServerFeatures literal in the
start-playback response construction with the shared helper used by the
capability handler and NewTerminalResponseV3. Update the helper’s feature list
to include the required flag so this path inherits the centralized capability
definition.
- Around line 1846-1850: Consolidate the duplicated ServerFeatures literal in
the idempotent-replay response path by reusing the shared feature-list symbol
introduced for startPlannedPlaybackV3 and executeReplanV3. Update this
playback.DecisionResponseV3 construction while preserving the existing
RuntimeCorrections initialization and response fields.
- Line 1: Consolidate the duplicated ServerFeatures/Features slice literals into
one shared helper or constant, using the canonical capability-response list
around the Features declaration in playback_v3.go as the source of truth. Update
NewTerminalResponseV3, startPlannedPlaybackV3, executeReplanV3, and
decisionResponseFromAttemptV3 to reuse it, ensuring every response advertises
the same complete feature set including FeatureRouteDiagnostics.
- Around line 353-359: Unify the server feature advertisement used by the
capability response and the response builders startPlannedPlaybackV3,
executeReplanV3, decisionResponseFromAttemptV3, and NewTerminalResponseV3
instead of maintaining separate literals. Confirm whether
FeatureDetailedDecodeV3 and FeatureLayoutPassthrough are intentionally excluded
from decision responses; preserve that distinction only if intentional,
otherwise include them through the shared canonical feature set. Ensure all
advertised feature lists remain consistent with the chosen behavior.
In `@internal/playback/protocol_v3.go`:
- Around line 813-819: Extract the duplicated V3 server-feature list into a
shared exported slice or function in the playback protocol domain, including
FeatureRouteDiagnostics. Update NewTerminalResponseV3 and the capability,
startPlannedPlaybackV3, executeReplanV3, and decisionResponseFromAttemptV3
builders to reuse it instead of defining separate literals, preserving
consistent feature contents across all responses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b8f04446-2221-4d52-a719-711d050ea0c3
📒 Files selected for processing (10)
docs/architecture/direct-stream-resume.mdinternal/api/handlers/playback_v3.gointernal/api/handlers/playback_v3_test.gointernal/httpstream/rolling_deadline.gointernal/httpstream/rolling_deadline_test.gointernal/playback/directplay.gointernal/playback/directplay_metrics.gointernal/playback/directplay_test.gointernal/playback/protocol_v3.gointernal/playback/session_paused_grace_test.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f93cd675e
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/playback/directplay_revision_fallback.go`:
- Around line 7-9: Update the ETag-related assertions in directplay_test.go for
ServeDirectPlay to account for an empty filesystem revision from
directPlayFilesystemRevision on fallback GOOSes. Skip or guard the HTTP-contract
and stale If-Range assertions when the validator is empty, while preserving the
existing strong-ETag checks where a revision is available.
In `@internal/playback/protocol_v3_test.go`:
- Around line 21-43: The test
TestServerFeaturesV3ReturnsCompleteIndependentSlices should validate the full
eight-entry feature contract: define the complete expected Feature* set, verify
every expected constant is present, and detect duplicate or unexpected entries
rather than checking only four memberships. Preserve the existing length and
independent-slice assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b81ef1d-623a-4120-9d2d-38147fb1f5ec
📒 Files selected for processing (12)
docs/architecture/direct-stream-resume.mdinternal/api/handlers/playback_v3.gointernal/api/handlers/stream_test.gointernal/playback/directplay.gointernal/playback/directplay_etag.gointernal/playback/directplay_revision_darwin.gointernal/playback/directplay_revision_fallback.gointernal/playback/directplay_revision_linux.gointernal/playback/directplay_revision_windows.gointernal/playback/directplay_test.gointernal/playback/protocol_v3.gointernal/playback/protocol_v3_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/architecture/direct-stream-resume.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9dac2d805
ℹ️ 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".
| stat.Ctim.Sec, | ||
| stat.Ctim.Nsec, | ||
| info.ModTime().UnixNano(), | ||
| info.Size(), |
There was a problem hiding this comment.
Use a byte-validating direct-stream ETag
On Linux filesystems with coarse or unchanged ctime/mtime after a same-size replacement, this revision string can repeat for different file bytes, so If-Range with the old strong ETag still gets 206 and lets a client splice cached bytes from the old entity with bytes from the new one. Fresh evidence: running go test ./internal/playback on this diff fails in TestServeDirectPlayChangedEntityRejectsOldIfRange because the stale If-Range request returns 206 instead of the expected full 200, so the validator needs to come from content or another durable byte revision before advertising resumable direct streams.
AGENTS.md reference: AGENTS.md:L13-L17
Useful? React with 👍 / 👎.
Implements #443.
Problem
Progressive clients buffer ahead, stop reading, and reverse proxies with default client-facing timeouts (nginx
send_timeout 60s) kill the healthy-but-backpressured response. Clients need a formal contract to discard and reopen direct streams at an exact byte offset — and operators need to tell a stalled-write reap apart from an ordinary disconnect.What this does
ServeDirectPlay): emits an opaquedsr1validator from the open file's identity, change time, modification time, and size on Linux, macOS, and Windows. This detects same-size replacements even when mtime is restored. Platforms without a durable file revision omit the tag instead of hashing a multi-gigabyte file on every request, so ETag-based resumes safely fall back to a full 200.http.ServeContentenforces the conditional/range contract: matchingIf-Range→ 206 at the requested byte; stale validator → full 200; 416 carriesContent-Range: bytes */<size>.RollingDeadlineWriter:stalled_reap(rolling deadline fired with no write progress) vsclient_gone(reset/broken pipe/context canceled) vscompleted, with byte counting through both the plain-write and sendfile (ReadFrom) paths. One structuredslogevent per stream end.Content-Range; ignored/stale ranges record-1. A separaterange_requestedfield preserves request intent.silo_direct_stream_active,silo_direct_stream_ends_total{outcome},silo_direct_stream_range_resumes_total,silo_direct_stream_invalid_range_total,silo_direct_stream_bytes_sent_total(no high-cardinality labels). Deterministic tests now assert stalled-write and suffix-resume counters.direct_stream_resume_v1is advertised from one centralized protocol-v3 feature list across capability, start, replan, replay, and terminal responses. It applies only to deliveryoriginal_http; progressive remux remains explicitly excluded.Range+If-Rangerequest without creating a new session.Additive-only within
/api/v1: one new feature string, new response headers, no field or status-code changes. Legacy clients that never sendIf-Rangecontinue to work.Risks / notes
If-Rangeround trip remains the available end-to-end evidence.Coordination
Verification
GOWORK=off go test -count=1 ./...also ran. It reached and passed the changed direct-stream tests but the repository-wide run remains red on unrelated baseline/environment cases (fake-FFmpeg/GPU probe processes killed under load, Jellycompat autoscan expectation drift, JWT tamper, and a policy timeout). No failing test touches this diff.The original dev-host validation remains recorded: capability advertised
direct_stream_resume_v1, live metrics observed completed ranged streams and client disconnects, and iOS confirmed the ETag/If-Rangeround trip end to end.AI Disclosure
🤖 Generated with Claude Code
Summary by CodeRabbit