Repository navigation
fix(macos): append streamed translation tokens synchronously - #19
Merged
Merged
Conversation
OllamaService and TranslationQueue are both @mainactor and the token callback already runs on the MainActor, but TranslationQueue re-enqueued every append through Task { @mainactor in }. The final result is built from streamingText right after translateStreaming returns, so its correctness depended on the executor running the deferred appends first. The callback is now typed @mainactor and appends synchronously, guaranteeing every token is in the final result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Make the final streamed translation contain every token by construction.
OllamaServiceandTranslationQueueare both@MainActor, andtranslateStreaminginvokesonTokensynchronously on the MainActor.TranslationQueuenevertheless wrapped each append inTask { @MainActor in … }, deferring it. Right aftertranslateStreamingreturns, the queue builds the finalTranslationQueueResultfromstreamingText— so correctness relied on the executor having run all deferred appends first, which Swift does not guarantee.translateStreaming(onToken:)now takes an@MainActorclosure (documented: runs in stream order before the call returns).TranslationQueueappends tokens synchronously; the stale-generation guard is unchanged.Honest status
This was reported by Qoder while building F10 ("final translation empty when the mock returns instantly"). I could not reproduce an empty translation with the old code — neither with a new queue-level test that delivers content and
donein one response, nor through the full view-model path with an instant mock. The change removes the reliance on scheduler ordering rather than fixing an observed failure; the new tests lock in the contract.Test results
./Scripts/run_tests.sh: 506 tests, 0 failures, no new warnings; CLT build clean.TranslationQueueStreamingTests: multi-token and single-token streams whose content anddonearrive in one response produce the full text.dev-run.shquit my test instance), so I did not interfere.🤖 Generated with Claude Code