fix(stream): keep held text, fail on error chunks, buffer split think tags - #28
Merged
TheGreatAxios merged 1 commit intoSep 27, 2026
Conversation
… tags Held inline-JSON text is released as soon as its top-level keys or tool name rule out a declared tool call, so an early close or abort keeps it. A chunk with an `error` key throws ProtocolMismatchError instead of ending the turn as a truncated success. A `<think>` or `</think>` tag split across chunks is held until the next token completes it, and released at the terminal chunk otherwise.
TheGreatAxios
added this pull request to stack #25
September 27, 2026 01:06
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.
Closes CL-9444
Summary
src/inline-tool-json.ts: held text is released as text once its top-level keys ornamevalue rule out a declared tool call (e.g.{"answer": 4), so an abort or early close keeps it. Nested values are not inspected.src/adapter.ts: a stream chunk with anerrorkey throwsProtocolMismatchError, so the turn ends ininference.error(protocol_mismatch) with the partial text instead ofinference.done.src/think-tags.ts: a trailing partial<think>/</think>is held until the next token completes it; the terminal chunk (or a native thinking delta) releases it as the text or thinking it was.e2e/harness.test.tscome from the review repros: split think tag, abort after non-tool JSON, and an error chunk. All three fail without the fix.A held prefix that is still a valid tool-call start (e.g.
{"name":"memory_search","parameters":{"q":) is still dropped if the stream closes with no terminal chunk; the adapter gets no end-of-stream hook to release it.Verification
bun run check(49 pass),bun run build, Node pack smoke.OLLAMA_BASE_URL=http://100.113.184.123:11434 OLLAMA_REASONING_MODEL=gpt-oss:20b bun run test:e2e: 15 pass, 4 skip, 0 fail.