Skip to content

fix: use correct REST endpoint to classify OpenCode reasoning parts#515

Merged
alari76 merged 1 commit into
mainfrom
fix/opencode-reasoning-classify-endpoint
Jun 14, 2026
Merged

fix: use correct REST endpoint to classify OpenCode reasoning parts#515
alari76 merged 1 commit into
mainfrom
fix/opencode-reasoning-classify-endpoint

Conversation

@alari76

@alari76 alari76 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

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's index.html with HTTP 200. So res.ok was true, res.json() threw on HTML, and classifyPart fell through to its text default — every reasoning part was treated as visible text and leaked, exactly as before.

Fix

  • Classify via the message endpoint GET /session/{sid}/message/{mid}, which returns { info, parts: [{ id, type }] }, and record the kind for every part in a single round-trip.
  • Confirmed live that this endpoint returns the reasoning part as type: "reasoning" mid-stream (right after the first delta, which is when classification runs).
  • Added a turn-end safety net (flushPendingParts): any part still awaiting classification is resolved and flushed before result is emitted, so answer text is never dropped and reasoning stays hidden even on a slow/failed lookup.

Test plan

  • Updated regression test to the real /message/{mid}{parts:[…]} shape
  • Live verification: mid-stream message fetch returns type=reasoning for the reasoning part
  • tsc -b clean, eslint --quiet clean, full opencode-process.test.ts suite green (97 tests)

🤖 Generated with Claude Code

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>
@alari76
alari76 merged commit dc36fb8 into main Jun 14, 2026
2 checks passed
@alari76
alari76 deleted the fix/opencode-reasoning-classify-endpoint branch June 14, 2026 08:40
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