Skip to content

Formalize resumable direct streams and expose stalled-write reaping #443

Closed

Description

@Quick104

Summary

Make Silo's direct-stream resumption contract explicit and observable so first-party clients can safely discard/reopen progressive HTTP responses instead of requiring long reverse-proxy timeouts.

The server already has the important foundations: byte-range delivery through http.ServeContent and a rolling 180-second no-progress write deadline. This issue adds entity validation, capability negotiation, and operational visibility around that behavior.

Context

Progressive clients commonly download faster than playback, fill their local buffer, and stop reading. A reverse proxy with nginx's default client-facing send_timeout 60s can terminate the response while the player drains its buffer. Clients should recover by issuing a new Range request at the exact byte cursor, without remounting the player.

A server-only heartbeat cannot solve this: once the client's receive window is full, the proxy cannot forward payload bytes, and injecting out-of-band bytes would corrupt the media response. Server byte pacing also fails during a user pause and keeps a connection occupied for the entire title.

Current implementation

Source baseline reviewed: 34573823242905ae38677c61ea49d96198a09794.

  • internal/playback/directplay.go wraps the response in httpstream.NewRollingDeadlineWriter and serves the file with http.ServeContent, providing standard byte-range and conditional-request behavior.
  • internal/httpstream/rolling_deadline.go uses a 180-second rolling stall window, configurable through SILO_STREAM_WRITE_STALL_TIMEOUT.
  • A write-deadline reap is currently difficult to distinguish operationally from an ordinary client disconnect.
  • Progressive remux is chunked ffmpeg output and is not byte-resumable like original-file direct play.
  • Protocol v3 already has additive playback capability features suitable for advertising a stronger resume contract.

Proposed PR scope

  1. Define and advertise a capability such as direct_stream_resume_v1 for original-file direct play. The contract should state:
    • Accept-Ranges: bytes;
    • correct 206/Content-Range behavior;
    • stable entity validation for the lifetime of the playback plan;
    • safe repeated idempotent GET/HEAD requests;
    • clear 416 behavior at/past EOF.
  2. Emit a stable ETag for direct-play files and support If-Range correctly:
    • unchanged entity → ranged 206;
    • changed/replaced entity → full 200 or explicit replan path, never a silently stitched mixed file.
  3. Preserve Last-Modified, Content-Length, HEAD, and existing authorization/session ownership behavior.
  4. Add observability that distinguishes:
    • rolling-deadline/no-write-progress reap;
    • client cancellation/reset;
    • completed response;
    • range resume request and starting offset.
  5. Add counters suitable for dashboards/alerts: active direct-stream transports, stalled-write reaps, ranged resumes, invalid ranges, and bytes requested/sent where practical.
  6. Document that progressive remux is not covered by the resume capability. Prefer segmented HLS/copy-codec HLS for remux as separate follow-up work.
  7. Keep the existing 180-second origin stall bound initially; lowering it is a separate rollout decision after client hardening.

Acceptance criteria

  • Direct-play responses include a deterministic validator and range headers.
  • Matching If-Range resumes at the requested byte with 206 and correct Content-Range.
  • A mismatched validator cannot combine bytes from different file revisions.
  • A stalled write is reaped within the configured rolling deadline and recorded distinctly from a normal disconnect.
  • Multiple sequential ranged requests for one playback session do not incorrectly expire or invalidate that session.
  • Legacy clients continue to work without sending If-Range or probing the new capability.
  • Progressive remux is never falsely advertised as byte-resumable.

Verification

  • Unit/integration tests for GET, HEAD, open-ended/suffix ranges, matching and mismatching If-Range, invalid ranges, 416 at EOF, and file replacement between requests.
  • A deterministic stalled-writer test that asserts timeout classification/metrics.
  • A playback-session lifecycle test covering close-while-paused followed by a ranged resume after a delay.
  • End-to-end test through nginx/OpenResty with a short client-facing send_timeout, confirming a hardened client resumes without creating a new playback plan.

Non-goals

  • Payload heartbeat bytes.
  • Server-side playback-rate pacing.
  • Making progressive ffmpeg remux output byte-resumable in this PR.
  • Replacing all original-file direct play with HLS.

Activity

  1. added
    enhancement
    go
    on Jul 21, 2026
  2. added
    triaged
    and removed
    triaged
    on Sep 20, 2026
  3. Quick104 commented on Oct 23, 2026

    @Quick104
    ContributorAuthor

    Fixed on main by #464 and #594. They add ETag/If-Range resume, stalled-write classification and metrics, If-Match outcomes, and the direct_stream_resume_v1 capability. The Apple and Android work has merged too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions