Repository navigation
Keep the readers that the reader ender counts and match them by identity - #393
Merged
Merged
Conversation
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 was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 byObjectIdentifier(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:
ReaderOrderstruct 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.ReaderEndercounts reads throughReaderOrder.count(readBy:). Its interface and behavior for distinct readers do not change.ReaderEnderis the only reader helper in this fork with this pattern.This is the same fix as Layr-Labs/d-inference#1886, where
ReaderOrderis shared byReaderEnderand the NemotronSlowReadhelper.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (I ranswift-format formatwith.swift-formaton the changed file only, and it changed nothing. CI checks the pinned version.)ReaderEndercover it. Fork Tests CI verifies it.)fork.yamlalready listsReaderPassFaults.swift.)Not built or tested locally. Fork Tests CI verifies it.
AI usage
accurately describes the code changes.
🤖 Generated with Claude Code