fix: use correct REST endpoint to classify OpenCode reasoning parts#515
Merged
Conversation
The previous fix fetched GET /session/{sid}/message/{mid}/part/{pid} to
determine a part's kind, but that single-part route is not served — it
returns the OpenCode SPA HTML with HTTP 200, so res.json() threw and
classifyPart fell back to its 'text' default, leaving reasoning leaking
into the transcript exactly as before.
Fetch the message instead (GET /session/{sid}/message/{mid}), which
returns { info, parts: [{ id, type }] }, and record the kind for every
part in one round-trip. Verified live that this returns the reasoning
part with type=reasoning mid-stream, when classification actually runs.
Also add a turn-end safety net (flushPendingParts) so any part still
awaiting classification is resolved and flushed before the result is
emitted — text is never dropped, reasoning stays hidden.
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
Follow-up to #514, which did not actually fix the reasoning leak. Verified live against OpenCode 1.15.
#514 classified each part via
GET /session/{sid}/message/{mid}/part/{pid}— but that single-part route isn't served: it returns the OpenCode SPA'sindex.htmlwith HTTP 200. Sores.okwas true,res.json()threw on HTML, andclassifyPartfell through to itstextdefault — every reasoning part was treated as visible text and leaked, exactly as before.Fix
GET /session/{sid}/message/{mid}, which returns{ info, parts: [{ id, type }] }, and record the kind for every part in a single round-trip.type: "reasoning"mid-stream (right after the first delta, which is when classification runs).flushPendingParts): any part still awaiting classification is resolved and flushed beforeresultis emitted, so answer text is never dropped and reasoning stays hidden even on a slow/failed lookup.Test plan
/message/{mid}→{parts:[…]}shapetype=reasoningfor the reasoning parttsc -bclean,eslint --quietclean, fullopencode-process.test.tssuite green (97 tests)🤖 Generated with Claude Code