Skip to content

Decode a video again when its reader fails, and keep the cause - #1851

Merged
davidtai merged 11 commits into
devfrom
fix/video-decode-transient
Nov 6, 2026
Merged

davidtai merged 11 commits into
devfrom
fix/video-decode-transient

Conversation

@davidtai

@davidtai davidtai commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A failed AVAssetReader pass on a valid video was refused as a client fault: GLM 5.3 mapped any reader end state except .completed to invalid_media (400) and dropped reader.error. So the coordinator did not retry the request on another provider, and no log showed the cause. This PR, with Layr-Labs/mlx-swift-lm#389, keeps the reader's error codes and decodes the video once more with a new reader before it refuses. When the reader fails twice, a transient decoder fault is refused as a retryable 503, and every other failure is still invalid_media (400).

Linked issue

Closes #1847

Test plan

  • Provider Unit Tests: GLM5NextMediaRoutingTests (the readiness test, plus three tests with the in-memory loader failing partway through the MP4), VideoReaderFailureMappingTests and NemotronSuperVideoReaderRetryTests pass. The final head 206b31a0 passes in CI (dev) run 42173742752: Build provider test products, both Provider Unit Tests shards and the Provider Tests gate.
  • Readiness-test loop in CI (temporary commit 192ea87, reverted in 206b31a): 50 of 50 passed on darkbloom-3b28f3ec… (shard 1) and 50 of 50 on darkbloom-ec55826e… (shard 2), run 42170865597. No iteration logged a failed reader pass.
  • The GLM fault tests logged these reader codes: the partway retry video reader status 3: NSURLErrorDomain -1100 < NSPOSIXErrorDomain 2 (retrying=true, once); the truncated video the same, then retrying=false; the transient case AVFoundationErrorDomain -11839 < NSOSStatusErrorDomain -11839, twice.
  • Keep the video reader error and retry a failed reader pass once mlx-swift-lm#389 Fork Tests are green on bb7fa8b0 (VideoReaderRetryTests, 8 tests).
  • python3 scripts/docs-impact-check.py (with the changed files) and python3 scripts/changelog.py check pass. Nothing was built or tested on the laptop.
  • Not green, and not caused by this PR: the Vercel – d-inference and Vercel – d-inference-console-ui-dev deployments, which failed the same way on test: disable the flaky GLM video readiness test (#1847) #1848.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX (the libs/mlx-swift-lm pin)
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. The wire keeps its failure codes. A video whose reader fails twice with a transient decoder code now gets the existing capacity 503 (requestRejected), which the coordinator already retries. The PR adds no new wire code. A new WARN engine_health telemetry event, operation video_reader_failed, carries retrying, transient, reader_status and reader_error (status and error domains and codes only).
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/architecture/inference.md (Vision constraints, Failure modes) and docs/provider/direct-mode.md (refusal table).
  • No documentation needed — reason:

Changelog

  • Added changelog.d/video-decode-transient.md. I ran python3 scripts/changelog.py check; I did not run make changelog-check on the laptop.
  • No user-visible change, or an explicitly authorized release/history change.

Notes for reviewers

  • Pin. libs/mlx-swift-lm points to the head of Keep the video reader error and retry a failed reader pass once mlx-swift-lm#389. After that PR merges, the pin moves to its merge commit.
  • Sites changed. In the fork (fix(routing): relaunch safety — debounce cold-dispatch kick, real-free cold-load admission, safe-by-default flags #389): GLM 5.3 decodeFrames, MiMo V2.6 inspectVideo and the sampled-frame pass, and the Qwen4 count and decode passes. In this repo: Nemotron Super sampleTiming (run again once) and Frames. If its frame reader fails, SerialReader.reopenAfterFailure() replaces that reader once and decodes from the first frame again; the frames already produced are skipped, so the output does not change.
  • Error mapping after two failed passes. A transient code (VideoReaderFailure.isTransient: AVFoundation outOfMemory (-11801), decoderTemporarilyUnavailable (-11839), and by value mediaServicesWereReset (-11819) and operationInterrupted (-11847); VideoToolbox kVTInvalidSessionErr, kVTAllocationFailedErr, kVTVideoDecoderMalfunctionErr, kVTVideoDecoderNotAvailableNowErr, kVTVideoDecoderRemovedErr, as the error or an underlying error) refuses as requestRejected (503, capacity). The shared media funnel does this through the retryable construction refusal, and MiMo and Super through requestRejected. Every other failure is invalid_media (400). GLM, MiMo and Super keep their refusal text.
  • Qwen4 behavior change. Before, every Qwen4 reader failure was a retryable 503, because its error type was internal. Now Qwen4 is the same as the other models: 503 only for a transient code, else invalid_media.
  • Logging. streamChatCompletion and the Super video path bind VideoReaderRetry.failedPassObserver. Each failed pass sends one telemetry event and one private provider log line.
  • Readiness test. Revert #1848: run the GLM video readiness test again #1849 (the revert of test: disable the flaky GLM video readiness test (#1847) #1848) removed the .disabled trait on dev, and this branch merges dev in (signed merge 98f3072). I changed only the test's doc comment, which now names both clips.
  • How the tests inject faults. AVFoundation requests a failed range again, so one failed loader data request never fails a reader pass. The GLM tests keep a VideoDataRequestFault armed until the first pass fails, and disarm it from the failed-pass report. A compressed-sample pass (Super timing, MiMo, Qwen4) that loses its bytes can end .completed with fewer samples, not .failed. It did so once on a Darkbloom VM and on both clips on the fork's macOS 26 runners. A later pass also reads bytes that an earlier pass already loaded. So the Super tests, like the fork's MiMo and Qwen4 tests, end a real reader partway through the test-only VideoReaderRetry.beforeReadForTesting hook. SerialReader captures that hook at setup and runs it on its queue, between reads. The production loader serves bytes from memory and cannot fail this way. A short compressed-sample count still ends in a refusal there (the decoded pass disagrees), never in wrong frames.
  • Not changed. These readers have the same status check, but they read audio, not video: MiMoV26EncodedAudiovisualDecoder (audio pass), MiMoV26EncodedAACAudio, and UserInput+Audio in the fork.

Before And After

Before

flowchart LR
  A[Video request] --> B[AVAssetReader pass]
  B -- completed --> C[Frames reach the engine]
  B -- "failed (cause dropped)" --> D["invalid_media 400, not retried, no log"]
Loading

After

flowchart LR
  A[Video request] --> B[AVAssetReader pass]
  B -- completed --> C[Frames reach the engine]
  B -- failed --> L1[WARN video_reader_failed: status and codes]
  L1 --> R[Second pass, new reader, same asset]
  R -- completed --> C
  R -- failed --> L2[WARN video_reader_failed]
  L2 --> T{Transient decoder code?}
  T -- yes --> S["503 capacity: coordinator retries on another provider"]
  T -- no --> D[invalid_media 400]
Loading

Refactor Pass

Not run. This agent cannot start a subagent, so the dedicated refactor pass is open. The coordinator runs it, as the brief says.

🤖 Generated with Claude Code

A failed AVAssetReader pass on a valid video was refused as a client
fault: GLM 5.3 mapped it to invalid_media (400), the coordinator did not
retry it, and no log showed the reader's error (#1847).

- Pin libs/mlx-swift-lm to Layr-Labs/mlx-swift-lm#389, which keeps the
  reader status and error codes (VideoReaderFailure) and runs a failed
  GLM 5.3, MiMo V2.6 or Qwen4 reader pass once more with a new reader.
- Nemotron Super: the timing pass runs again once, and the frame reader
  replaces its reader once and decodes from the first frame again.
- Refusal after two failed passes: a transient decoder, hardware or
  interruption code is a retryable 503 (requestRejected, capacity); any
  other failure stays the deterministic invalid_media 400. GLM keeps its
  refusal text; Qwen4 now refuses such a failure as invalid_media.
- Each failed pass logs a WARN engine_health event video_reader_failed
  with the reader status and error codes only.
- Correct the multimodal_rejected doc comment, name both clips in the
  readiness test's doc comment, and add fault-injection tests on the real
  in-memory resource loaders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Nov 6, 2026 1:20pm UTC
d-inference-console-ui-dev Error Error Nov 6, 2026 1:20pm UTC
d-inference-landing Ready Ready Preview Nov 6, 2026 1:20pm UTC
darkbloom-status Ready Ready Preview Nov 6, 2026 1:20pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 6, 2026 1:20pm UTC

Request Review

AVError.Code.operationInterrupted is declared on iOS only. The tests now
inject decoderTemporarilyUnavailable, and libs/mlx-swift-lm moves to the
fork head that keeps the iOS-only codes by value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps dev's removal of the .disabled trait and this branch's doc comment
naming both readiness clips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI showed that AVFoundation requests a failed range again, so one failed
data request never failed a reader pass. The tests now keep the fault
armed until the first pass fails and disarm it from the failed-pass
report; the Super frame-reader tests arm it after inspection. Pins
libs/mlx-swift-lm to the fork head with the armed fault.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The frame reader reads bytes the timing pass already loaded through the
same asset, so a loader fault armed after inspection never reached it
(CI: no data request at the offset). A test hook runs on the reader's
queue before each read, as readerCancelledForTesting does after a stop,
and the tests cancel a real reader partway there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits November 5, 2026 23:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reverted before review. Echoes each failed reader pass to the test log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits November 5, 2026 23:59
Pins libs/mlx-swift-lm to the fork head whose decoders read through
VideoReaderRetry.nextSample and its test hook. The Super SerialReader
captures that same hook at setup and runs it on its queue, so the Super
tests end the timing-pass reader or the frame reader partway the same way
as the fork tests. The Super loader's fault hook, which no test needs
now, is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The loop ran 50 iterations on each of two Darkbloom VMs: 100 passes, and
no video reader failure in any iteration.

This reverts commit 192ea87.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits November 6, 2026 07:18
…99695c0

The gitlink was the only conflict: pinned to #389's merge commit 2e499695c0,
which contains dev's 62b29ecd96 and #389. The docs merged without conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SuperHTTPErrors.map keeps only the transient reader failure as its own
case. Any other VideoReaderFailure joins the Super video failures that
refuse with the one multimodalRejected message, which it repeated before.
No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai
davidtai merged commit b0fadbb into dev Nov 6, 2026
20 of 23 checks passed
@davidtai
davidtai deleted the fix/video-decode-transient branch November 6, 2026 13:44
jonathan308 added a commit that referenced this pull request Nov 6, 2026
dev pins mlx-swift-lm 2e499695c0 (#389), which 7994762ef9 contains: the pin
stays 7994762ef9. #1851's provider handles #389's new GLM5Next vision error
case, which failed the provider build at 607a70b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – eigen-homepages-darkbloom — 4604f90d Deployed Nov 6, 2026 by vercel[bot]
Preview – d-inference-landing — 4604f90d Deployed Nov 6, 2026 by vercel[bot]
Preview – darkbloom-status — 4604f90d Deployed Nov 6, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 4604f90d Deployed Nov 6, 2026 by vercel[bot]
Preview – d-inference — 4604f90d Deployed Nov 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant