Skip to content

Keep the readers that the reader ender counts and match them by identity - #393

Merged
davidtai merged 1 commit into
mainfrom
fix/reader-order-identity
Nov 9, 2026
Merged

davidtai merged 1 commit into
mainfrom
fix/reader-order-identity

Conversation

@davidtai

@davidtai davidtai commented Nov 9, 2026

Copy link
Copy Markdown

Proposed changes

This fixes a test helper bug from #391. ReaderEnder (Tests/MLXLMTests/ReaderPassFaults.swift) kept each reader's ordinal and read count in a dictionary keyed by ObjectIdentifier(reader), and it did not keep the readers. When a reader is freed, a later reader can get the same address. That reader then takes the freed reader's ordinal and read count, so the ender can cancel it on a pass it was not told to end, or not cancel it on the pass it was told to end.

testAudioReaderThatFailsTwiceThrowsItsFailure (MiMoV26EncodedAudiovisualDecoderTests) can fail now and then this way. It ends readers 1 and 2 at their second read. If the retry reader gets the address of the reader that failed, it counts as reader 1 at read 3 and is not ended, so the second audio pass completes.

What changes:

  • A new ReaderOrder struct keeps every reader that reads, in the order of its first read, and matches readers with ===. Each reader stays alive while the ender lives, so no two readers can share an address.
  • ReaderEnder counts reads through ReaderOrder.count(readBy:). Its interface and behavior for distinct readers do not change.
  • No test assertion or call site changes. ReaderEnder is the only reader helper in this fork with this pattern.

This is the same fix as Layr-Labs/d-inference#1886, where ReaderOrder is shared by ReaderEnder and the Nemotron SlowRead helper.

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes (I ran swift-format format with .swift-format on the changed file only, and it changed nothing. CI checks the pinned version.)
  • I have added tests that prove my fix is effective or that my feature works (test helper fix only. The existing reader tests that use ReaderEnder cover it. Fork Tests CI verifies it.)
  • I have updated the necessary documentation (if needed) (doc comment. fork.yaml already lists ReaderPassFaults.swift.)

Not built or tested locally. Fork Tests CI verifies it.

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: Claude Opus 5.5 (Claude Code) wrote the code and this description at David's request. The box above is left for David.

🤖 Generated with Claude Code

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>
@davidtai
davidtai merged commit 76284dc into main Nov 9, 2026
22 checks passed
@davidtai
davidtai deleted the fix/reader-order-identity branch November 9, 2026 13:12
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