Skip to content

fix(stream): keep held text, fail on error chunks, buffer split think tags - #28

Merged
TheGreatAxios merged 1 commit into
cl-9397-ollama-adapter-align-repo-scaffolding-with-the-packagefrom
cl-9444-ollama-adapter-keep-held-text-and-surface-mid-stream-errors
Sep 27, 2026
Merged

TheGreatAxios merged 1 commit into
cl-9397-ollama-adapter-align-repo-scaffolding-with-the-packagefrom
cl-9444-ollama-adapter-keep-held-text-and-surface-mid-stream-errors

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Closes CL-9444

Summary

  • src/inline-tool-json.ts: held text is released as text once its top-level keys or name value 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 an error key throws ProtocolMismatchError, so the turn ends in inference.error (protocol_mismatch) with the partial text instead of inference.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.
  • Tests in e2e/harness.test.ts come 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.

… 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
TheGreatAxios added this pull request to stack #25 September 27, 2026 01:06
@TheGreatAxios
TheGreatAxios merged commit 72372b2 into main Sep 27, 2026
1 check passed
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.

1 participant