LL-HLS mid-segment retry: byte-range reassembly and Safari MEDIA_ERR_DECODE — evidence review

GitHub source

Inferred. This page is generated from GitHub Issue #55; GitHub remains the canonical authoring and discussion source.

Local reproduction and solution — 18 November 2026#

Status: Reproduced and fixed at the actual NetworkingEngine regression seam.

Source and evidence#

Upstream case · local report and evidence · portable reproduction instructions

Observed results are Reproduced only within the stated seam. Implementation explanations remain Inferred, not Apple Confirmed.

Reconstruct the scene#

A synthetic streaming scheme delivers a prefix, fails, retries from the same requested range, and can deliver a late chunk from the abandoned attempt.

The actual upstream browser tests fail 4/4 with the parent production file and pass 4/4 with commit 4753b11dfef70863bd1d3a3546636f0afdd22037.

Solution / guideline#

Use/backport PR #10965: retain the requested range, suppress already-delivered bytes across retries and ignore late chunks from abandoned attempts. The alternative Range-resume proposal #10940 was not the landed fix.

All pinned patches and results

Limits / remaining work#

Real Shaka code in Chrome Headless with synthetic stream delivery; no local Safari proxy-cut/decode-playback trial. Release-version containment is not claimed.

This update supersedes earlier no-local-run statements below only within the stated scope. Historical source reports are retained; no unresolved issue is closed by this publication.


Earlier investigation and source history

Verification update — 17 November 2026#

Status: reproducible upstream; fix merged. PR #10965 merged on 2026-11-13 as 4753b11dfef70863bd1d3a3546636f0afdd22037, explicitly fixing upstream #10939.

  • Reproduction: the reporter's proxy A/B harness cuts an LL-HLS response mid-body and reports Safari decode errors. The merged patch adds NetworkingEngine tests for streamed-response retries.
  • Solution actually merged: keep the same requested range on retry, suppress bytes already delivered to the streaming callback, and discard late chunks from abandoned attempts. This preserves an ordered, nonduplicated callback byte stream while leaving StreamingEngine and HTTP plugins unchanged.
  • Important distinction: the alternative Range-resume/reset design in PR #10940 was closed without merging. Do not describe that proposal as the landed fix.
  • Action: use a build containing #10965 or validate an exact backport. Upstream reproduction, merged diff and added tests were reviewed; no local Safari proxy A/B or byte-level playback capture was run here. Release inclusion remains unverified.

This update supersedes older statements below about missing fix verification; the historical investigation and prompt are retained.


Source: shaka-project/shaka-player#10939
Reproduction project: https://github.com/geniussportsgroup/shaka-ll-hls-stall-repro

Problem and observed behavior#

A developer reports intermittent MEDIA_ERR_DECODE (HTMLMediaElement code 3; Shaka 3014) on Safari when an LL-HLS fMP4 segment response is interrupted mid-body with hls.allowLowLatencyByteRangeOptimization enabled. Their controlled proxy cuts a response after a configurable byte count. Playback may subsequently recover, making the terminal decoder error misleading as a description of the initiating event.

The published trace includes SEGMENT attempt=0 Range=(none) streamCB=yes, followed by attempt=1 Range=(none) and committed=0. The reporter supplies a public proxy and a local patched build for A/B testing. Exact Shaka release/commit and physical-device environment remain to be pinned.

Evidence and current verdict#

Claim Evidence Status
A mid-response cut can be followed by code 3 / Shaka 3014 Reporter trace in upstream issue Reported; not independently reproduced here
The retry starts without a Range header Reporter trace Reported for failing run
An incomplete mdat is retained and concatenated with a retry from byte zero Reproduction project's README Proposed mechanism; requires pinned source and byte-level proof
A local patched build avoids the decode error Reporter-provided A/B harness Claimed; not independently verified
Native AVPlayer has the same defect No evidence Not established

Current verdict: LL-HLS retry/reassembly corruption is a plausible explanation, but the first internal causal divergence and upstream fix status are not independently verified.

Causal boundary#

EXT-X-PART / coalesced byte-range request
  → streaming HTTP response
  → partial moof/mdat delivery
  → mid-body cut / retry
  → retry offset + retained bytes
  → assembled fMP4 buffer
  → MSE append
  → HTMLMediaElement decode error

The decisive check is whether the bytes handed to MSE after retry exactly match the uninterrupted segment. A code 3 error alone cannot distinguish corrupted media assembly from an independent decoder problem.

Verification plan#

  1. Pin Shaka source commits for upstream and patched versions. Locate streaming callback, retry, byte-range coalescing and remaining buffer handling.
  2. Capture manifest snapshots, EXT-X-PART and byte-range metadata, moof/mdat box boundaries, request/response headers, body hashes, committed-byte counts and retry offsets.
  3. Inject a deterministic cut before moof, inside moof, inside mdat, and after a complete box. Compare optimization on/off and patched/unpatched builds.
  4. Compare reconstructed bytes to the original segment, then correlate MSE append events and media errors. Repeat at least 10 trials per condition.
  5. Test native AVPlayer independently on the same LL-HLS bytes; do not assume Safari Shaka MSE internals are native AVFoundation internals.

Client-only guidance#

As a temporary mitigation candidate, A/B test disabling hls.allowLowLatencyByteRangeOptimization for affected Shaka clients, or use a pinned verified patched build after byte-accurate regression testing. Avoid treating a terminal decode error as proof of invalid source media. Proxy, CDN and origin modifications are separate proposals, not client-only fixes.

Reusable insight#

An interrupted streaming response must preserve byte-exact reassembly semantics across retries. A downstream decode error can originate from a transport retry that duplicates or drops bytes.

Evidence gaps and next milestone#

No local proxy experiment, byte-level diff, pinned patch diff or native AVPlayer reproduction was performed in this investigation. Next: compare attempt=1 Range, retained buffer size and the SHA-256 of the reconstructed moof/mdat payload against the uninterrupted reference.

References#

Extended investigation prompt#

Show the full second-AI reverse-engineering prompt
Act as a senior iOS/tvOS reverse engineer, AVFoundation/CoreMedia investigator, WebKit MSE analyst, LL-HLS transport engineer, and FairPlay DRM/security specialist.

CASE: https://github.com/shaka-project/shaka-player/issues/10939
REPRO: https://github.com/geniussportsgroup/shaka-ll-hls-stall-repro

Reported: On macOS Safari/Apple devices, Shaka LL-HLS with hls.allowLowLatencyByteRangeOptimization may produce HTMLMediaElement MEDIA_ERR_DECODE (code 3), Shaka 3014 after a proxy cuts an in-flight m4s response mid-mdat. Reporter logs show retry attempt=1 Range=(none), streamCB=yes, committed=0. The independent reproduction README proposes a partial 'remaining' buffer followed by byte-zero retry and corrupt MSE append. Treat that mechanism as a source-backed HYPOTHESIS until pinned implementation and A/B traces establish it.

GOAL: determine the FIRST PROVEN causal divergence and identify whether the failure is in HTTP retry offset, byte-range coalescing, streaming callback buffer ownership, fMP4 framing, MSE append, or platform decoder. Distinguish transport failure from terminal decoder error.

STRICT EVIDENCE HIERARCHY:
T1 normative: official Apple Developer Documentation (HLS, AVFoundation, FairPlay), Apple HLS Authoring Specification, RFC 8216 and current LL-HLS draft, HTTP Range RFC 9110/9111, ISO BMFF, W3C MSE/EME.
T2 verified implementation: exact version/commit of Shaka NetworkingEngine, StreamingEngine, HLS parser, byte-range optimization, stream callbacks, fMP4 processing; verified WebKit source and credible peer-reviewed/verified security research. Cite repository URL, commit SHA, file, function, line range, and control flow. WebKit code is NOT evidence of private native AVPlayer implementation.
T3 experiments: byte-hashed manifests and segment responses, Content-Range/ETag/Content-Length/Accept-Ranges, exact received/committed bytes, aborted connection, retry Range, MSE append bytes and errors, reproducible Safari physical-device A/B runs, independent native AVPlayer control.
T4 hypotheses: clearly labeled, confidence and falsification tests. Never invent measurements, code locations, private symbols or fixes.

TRACE:
EXT-X-PART / EXT-X-BYTERANGE / EXT-X-MAP / EXTINF / media sequence -> coalesced open-ended segment request -> response body chunks -> streaming callback -> committed bytes and remaining buffer -> transport stall/abort -> retry start offset and validator -> byte-accurate reassembly -> moof/mdat box boundaries -> SourceBuffer.appendBuffer -> media decode outcome.

EXPERIMENT:
Pin both upstream and proposed fixed Shaka commits. Run proxy cut at offsets (a) before moof, (b) inside moof, (c) inside mdat, (d) after full box. A/B optimization on/off and fixed/unfixed build; compare 200 full-body retry vs 206 range-resume, with and without ETag changes; simulate timeout and connection reset separately. Repeat >=10 trials per cell; capture raw bytes and hashes. Confirm whether reassembled bytes equal uninterrupted reference bytes. Check MSE append errors and HTMLMediaElement.error separately. Run same media on native AVPlayer only as an independent comparison, not as proof of shared implementation.

DRM:
Only enter FairPlay branch if clear vs authorized protected playback diverges. Trace EXT-X-KEY, SKD identity, AVContentKeySession callbacks, SPC request, authorized KSM response, CKC acceptance and protected decoding. Never reveal keys, certificates, tokens or SPC/CKC payloads; never bypass DRM.

ROOT CAUSE STANDARD: require reproducible symptom, proven first divergence, controlled intervention reversing it, and major alternatives falsified. Otherwise explicitly state ROOT CAUSE UNVERIFIED.

OUTPUT: concise executive verdict, evidence ledger, manifest audit, request/retry timeline, byte-offset accounting table, box-level integrity, pinned source review, Safari/WebKit vs AVPlayer boundary, hypotheses with falsification, measured A/B results, client-only mitigation, separately labeled CDN/origin proposals, regression tests, exact URLs, and a publication-ready article. Clearly separate upstream reporter claims from experiments you performed.