You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
/v1/completions leaks stop-sequence prefixes split across chunks #133
#126 was fixed for /v1/chat/completions in #132. The legacy /v1/completions streaming path has the same defect and was left out of scope, deliberately — recording it so it is not mistaken for fixed.
Where
Sources/SwiftLM/Server.swift (~2470, the text-completions streaming loop):
iflet(trimmedText, _)=checkStopSequences(fullText,stopSequences:stopSequences){letemittedSoFar=fullText.count-text.count...}else{cont.yield(sseTextChunk(modelId:modelId,text:text,finishReason:nil)) // leaks a partial stop
}
The stop check only fires on the chunk that completes the sequence, so one spanning two chunks has its first part streamed before the match is visible — identical to the chat-path bug. It also still uses the fullText.count - text.count arithmetic that #132 replaced, having been wrong in both directions on the chat path (dropping held text, then leaking the stop).
Fix
pendingStopPrefixLength(_:stopSequences:) already exists from #132 and is directly reusable. The chat path also now tracks characters actually released rather than deriving position from chunk boundaries; the same approach applies here. There is no thinking tracker on this path, so it is the simpler of the two.
Reproduction
The chat-path case reproduces with a stop that cannot be a single token, e.g. "own fox" against a prompt whose output contains "brown fox". Before the fix that returned The quick brown — the client receives own, which it asked to be cut. The same request shape against /v1/completions should show it.
Impact
Lower than the chat path — most clients use /v1/chat/completions — but the endpoint exists and its stop parameter carries the same contract.
Activity
fix: apply the stop holdback to /v1/completions too (#133) (#135)