Fix cancellation submission race#389
Open
SpiraMira wants to merge 2 commits into
Open
Conversation
…submission
TokenIterator.next() calls asyncEval() to pipeline the next GPU evaluation. The
3.x loop `tokenLoop: while let token = iterator.next()` checked Task.isCancelled
only AFTER next() had already submitted work, allowing one extra asyncEval after
cancellation was observed.
Reorder to `while !Task.isCancelled { guard let token = iterator.next() else { break } }`
so the check happens before next(). The existing post-loop block already assigns
stopReason = .cancelled on a cancelled exit, and Stream().synchronize() still settles
any in-flight evaluation at the end of the task body, so the settlement boundary is
unchanged.
3.x re-authoring of the 2.x fix (0737a6e), adapted to the refactored tokenLoop shape.
Fixes the iOS/iPadOS lifecycle crash when the app backgrounds mid-generation:
[METAL] Command buffer execution failed: Insufficient Permission
(kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Ports the 2.x settlement tests (b03a2b7) to 3.x: stream-cancellation settle, immediate-cancel settle, .cancelled stopReason, and .length at maxTokens (the guard-nil natural-termination path). Compile-verified against 3.31.4. Co-Authored-By: Claude Opus 4.8 <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.
Proposed changes
Fixes #382
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes