Skip to content

Keep each reader in the test reader trackers so the audio fault tests end the audio reader - #1886

Merged
davidtai merged 4 commits into
devfrom
fix/audiovisual-reader-medium
Nov 7, 2026
Merged

davidtai merged 4 commits into
devfrom
fix/audiovisual-reader-medium

Conversation

@davidtai

@davidtai davidtai commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

dev has been red since #1867 merged. Two of its tests, the audio reader fault tests in MiMoV26EncodedAudiovisualIngressTests, failed on both push runs after the merge. The cause is the test helper ReaderEnder, not the provider. ReaderEnder identified each reader by ObjectIdentifier and did not keep a reference to it. The allocator can give a new AVAssetReader the address of a reader that was freed, so the new reader took the old reader's ordinal and read count. The helper then ended the video frame reader instead of the audio reader. This PR makes the helper keep every reader it sees and find each reader by identity.

Cause

MiMoV26EncodedMediaIngress.decode runs its reader passes one at a time, in one task, always in this order:

  1. MiMoV26EncodedVisualDecoder.inspectVideo counts the video samples (reader 1).
  2. MiMoV26EncodedAudiovisualDecoder.decode reads the LPCM audio track (reader 2, in passthroughPass).
  3. audiovisualFrames decodes the video frames (reader 3).

The passes do not run at the same time, and their order does not change. The production labels are correct: passthroughPass and the AAC pass throw VideoReaderFailure(reader:medium: .audio), and VideoReaderFailureReport names the operation from failure.medium.

Reader 1 is freed when its pass returns. If reader 2 gets the same address, ObjectIdentifier(reader2) equals the identifier of reader 1. Reader 2 then uses reader 1's entry: ordinal 1, with its read count already past 2. So reader 2 is never ended. The next new reader, the video frame reader, gets ordinal 2 (order.count + 1). The helper ends it at read 2, and the run reports video_reader_failed. The address is reused only sometimes, so the PR runs of #1867 passed and the two dev runs failed.

Evidence

  • Run 42332006438 (on 22338b4b), job 128282254866: testAnAudioReaderThatFailsTwiceIsRefusedAsInvalidMedia failed. failure.medium was video, the refusal was native media input is unsupported or exceeds its bound, and the reports were two video_reader_failed passes. In the same job, testAFailedAudioReaderPassIsReadAgainAndReported passed.
  • Run 42335000698 (on 1703f03a), job 128290701728: testAFailedAudioReaderPassIsReadAgainAndReported failed with [Pass(operation: "video_reader_failed", retrying: true, transient: false)]. In the same job, testAnAudioReaderThatFailsTwiceIsRefusedAsInvalidMedia passed.
  • In each run, the test that failed was a different one. The code did not change between the two runs.
  • In both runs, the ended counts were correct (1 and 2). This agrees with the address reuse: one reader was still ended, but it was the wrong reader.

Fix

  • ReaderEnder (provider-swift/Tests/ProviderCoreTests/Inference/Vision/ReaderEnder.swift) keeps each reader in an array, in the order of its first read, and finds a reader with ===. A reader that the helper keeps cannot be freed, so its address cannot go to a later reader. The ordinal is the reader's index plus 1. The API does not change, so the MiMo and Nemotron tests use the helper as before. All assertions stay as they were.
  • SlowRead in NemotronSuperVideoReaderRetryTests counted readers in a Set<ObjectIdentifier>, which has the same fault: address reuse can hide a second reader. It now keeps its readers in the same way.
  • Both helpers use one small type for this rule, ReaderOrder (in ReaderEnder.swift). It keeps each reader in the order of its first read and counts its reads.

The production code does not change.

Linked issue

None. This fixes the dev failure that came after #1867.

Test plan

  • CI (dev) run 42340216191 on the final head f3d1f4d8 is green: both Provider Unit Tests shards, the Provider Tests gate and Check the CI plans. Shard 1 passed both MiMo audio reader tests. In attempt 1, the shard 2 runner lost contact with GitHub during "Set up runner", before checkout and before any test ran. Attempt 2 of that job passed. The fix before the refactor (d3e40e93) was green in run 42339081354. The two Vercel deployments failed; they also failed on Decode a video again when its reader fails, and keep the cause #1851 and Read a MiMo audio track again when its reader fails, and keep the cause #1867, and this PR does not touch the landing or console code.
  • Loop: the temporary commit d82b4f40 ran the two tests 30 times in shard 1, each time in a new swift test --skip-build process on the built products. Run 42337995996, job 128300096991: LOOP: 30/30 iterations passed both tests. In the same job the full shard also passed both tests. On that commit, "Check the CI plans" failed only because ProviderCIWorkflowTests compares the workflow's run: lines to a fixed list and the loop step added one. d3e40e93 reverts the loop commit, so its tree is the same as the fix commit 892b58d4.
  • 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.

Components touched

  • provider-swift (Swift CLI): test helpers only
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release: a temporary loop step only, reverted on this branch
  • docs

Protocol / interface changes

  • No protocol/interface changes
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated
  • No documentation needed — reason: only test helpers change. The docs-impact check passes.

Changelog

  • Added or updated this PR's unique changelog.d/<topic>.md fragment and ran make changelog-check.
  • No user-visible change, or an explicitly authorized release/history change.

Notes for reviewers

  • The fork has the same helper with the same fault (Tests/MLXLMTests/ReaderPassFaults.swift in Layr-Labs/mlx-swift-lm). This fix does not need a fork change, so this PR does not change the fork. In the fork, testAudioReaderThatFailsTwiceThrowsItsFailure ends readers 1 and 2. If the retry reader gets the address of the reader that failed first, that test can fail in the same way. The fork can get the same change in a separate PR.

Refactor Pass

Done by a separate refactor reviewer. Result: one cleanup, in commit f3d1f4d8.

  • ReaderEnder and SlowRead each had their own copy of the reader-tracking code and of the comment about address reuse. The bug was in exactly that code. The new type ReaderOrder holds it once, and both helpers use it.
  • No other changes. The fix has the right shape and is minimal: retaining each reader is what stops address reuse. The names are clear, no dead code is left, and the comments describe the code, not its history. No test assertion and no production code changes.

🤖 Generated with Claude Code

davidtai and others added 2 commits November 6, 2026 22:19
ReaderEnder named a reader by ObjectIdentifier and did not keep it. When a
reader pass ends, its AVAssetReader is freed, and the next reader can get the
same address. That reader then took the freed reader's ordinal and read count.
In the MiMo audiovisual ingress tests, the audio reader took the ordinal of the
video count reader, so the video frame reader became reader 2 and was ended
instead of the audio reader. The tests then saw video_reader_failed and a video
refusal. The outcome depended on the allocator, so #1867's PR runs passed and
both dev runs after it failed.

ReaderEnder now keeps every reader it sees and finds a reader by identity, so
no two readers share an entry. SlowRead counts readers the same way, so a
freed reader's address cannot hide a second reader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
To be reverted before the PR is reported.

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

vercel Bot commented Nov 7, 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 7, 2026 4:52am UTC
d-inference-console-ui-dev Error Error Nov 7, 2026 4:52am UTC
d-inference-landing Ready Ready Preview Nov 7, 2026 4:52am UTC
darkbloom-status Ready Ready Preview Nov 7, 2026 4:52am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 7, 2026 4:52am UTC

Request Review

The loop (run 42337995996, job 128300096991) passed both tests in 30 of 30
iterations.

This reverts commit d82b4f4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both test helpers kept each reader in first-read order and found it by
identity, each with its own copy of the code and the comment. ReaderOrder
now holds that rule once; ReaderEnder and SlowRead use it. Behavior and
test assertions do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai
davidtai merged commit 81b4a2c into dev Nov 7, 2026
30 of 34 checks passed
@davidtai
davidtai deleted the fix/audiovisual-reader-medium branch November 7, 2026 05:15
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
ReaderEnder keyed its read counts by ObjectIdentifier and did not keep the
readers. A freed reader's address can go to a later reader, which then takes
the freed reader's ordinal and read count and can be ended on the wrong pass.
testAudioReaderThatFailsTwiceThrowsItsFailure can fail this way when the
retry reader gets the address of the reader that failed.

ReaderOrder keeps every reader that reads, in first-read order, and matches
readers with ===. This is the fix of Layr-Labs/d-inference#1886. No test
assertion or call site changes.

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 — f3d1f4d8 Deployed Nov 7, 2026 by vercel[bot]
Preview – d-inference-landing — f3d1f4d8 Deployed Nov 7, 2026 by vercel[bot]
Preview – darkbloom-status — f3d1f4d8 Deployed Nov 7, 2026 by vercel[bot]
Preview – d-inference — f3d1f4d8 Deployed Nov 7, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — f3d1f4d8 Deployed Nov 7, 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