Repository navigation
fix: apply the stop holdback to /v1/completions too (#133) - #135
Merged
Merged
Conversation
#132 fixed the chat path; the legacy text-completions path had the same defect and was explicitly left out of scope. Reproduced there: stop "own fox" — which cannot be a single token, so it must straddle chunks — returned "The quick brown", handing the client the "own" it asked to be cut. Applies the same treatment: withhold the tail that could still open a stop sequence via pendingStopPrefixLength, release it when the next chunk resolves the ambiguity, on normal completion, or via a post-loop safety net if the stream ends without an .info event. The stop remainder is computed from characters actually released, replacing the fullText/chunk arithmetic that was wrong in both directions on the chat path before it was replaced. This path has no thinking tracker, so it is the simpler of the two: released text goes straight to the wire and emittedTextCount is exactly what the client received. Verified red: reverting the holdback restores 'The quick brown'. The contract suite gains the /v1/completions case, so CI guards both endpoints — 8 passed, 0 failed, 2 skipped. Fixes #133. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Fixes #133. #132 fixed
/v1/chat/completions; this is the same defect on the legacy text endpoint, which that PR explicitly left out of scope.Reproduced
Stop
"own fox"— which cannot be a single token, so it necessarily straddles chunks:'The quick brown'← leaksown'The quick br'Verified red: reverting the holdback restores the leak.
Change
Same approach as #132 — withhold the tail that could still open a stop sequence via the existing
pendingStopPrefixLength, release it when the next chunk resolves the ambiguity, on normal completion, or via a post-loop safety net if the stream ends without an.infoevent. The stop remainder now comes from characters actually released rather thanfullText.count - text.count, which was wrong in both directions on the chat path before being replaced.This path has no thinking tracker, so it is the simpler of the two: released text goes straight to the wire, and
emittedTextCountis exactly what the client received.Coverage
tests/test-contract.shgains the/v1/completionscase, so CI now guards both endpoints: 8 passed, 0 failed, 2 skipped.🤖 Generated with Claude Code