Skip to content

fix: apply the stop holdback to /v1/completions too (#133) - #135

Merged
solderzzc merged 1 commit into
mainfrom
claude/fix-133-completions-stop
Aug 8, 2026
Merged

solderzzc merged 1 commit into
mainfrom
claude/fix-133-completions-stop

Conversation

@solderzzc

Copy link
Copy Markdown
Member

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:

streamed to client
before 'The quick brown' ← leaks own
after '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 .info event. The stop remainder now comes from characters actually released rather than fullText.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 emittedTextCount is exactly what the client received.

Coverage

tests/test-contract.sh gains the /v1/completions case, so CI now guards both endpoints: 8 passed, 0 failed, 2 skipped.

🤖 Generated with Claude Code

#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]>
@solderzzc
solderzzc merged commit f873d6e into main Aug 8, 2026
13 checks passed
@solderzzc
solderzzc deleted the claude/fix-133-completions-stop branch August 8, 2026 15:47
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.

/v1/completions leaks stop-sequence prefixes split across chunks

1 participant