fix: stop OpenCode reasoning leaking into response text#514
Merged
Conversation
Some providers (e.g. Kimi via ollama-cloud) stream both reasoning and the visible answer as field=text deltas distinguished only by partID, and never emit message.part.updated. The old inReasoningPhase flag was only set from part.updated type=reasoning, so it never fired and the model's chain-of-thought was emitted as visible response text. Classify each partID via a cached REST lookup, buffering a part's deltas until its kind is known, then routing reasoning to a hidden thinking summary and text to the transcript. message.part.updated now also populates the cache so providers that send it skip the lookup. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
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.
Summary
When using the OpenCode provider with models that stream reasoning as
field=textdeltas (e.g.ollama-cloud/kimi-k2.7-code), the model's chain-of-thought was being rendered concatenated with the actual answer.Root cause (verified against a live OpenCode 1.15 SSE capture): for this provider the turn streams as
message.part.deltaevents only — nomessage.part.updated/message.updatedever arrive. Both the hidden reasoning part and the visible answer part come through asfield: "text"deltas, distinguishable only bypartID. The previous logic set itsinReasoningPhaseflag exclusively from apart.updated type=reasoningevent, which never fires here, so reasoning fell through toemit('text').Changes
partIDasreasoning/text/othervia a cached REST lookup (GET …/message/{mid}/part/{pid}).field=textdeltas until its kind is resolved, then route: reasoning → hiddenthinkingsummary, text → transcript.message.part.updatednow also populates the cache (recordPartKind) so providers/versions that send it avoid the REST round-trip.emitTextDelta/appendReasoningDeltahelpers.Parts stream sequentially, so this only adds a one-localhost-round-trip (a few ms) delay to the first delta of each part, and it correctly handles agentic flows where reasoning/text/tool parts interleave.
Test plan
tsc -bclean,eslintclean (0 errors)opencode-process.test.tssuite green (97 tests)🤖 Generated with Claude Code