Skip to content

fix(server): handle OpenCode text response format in commit message g…#2202

Merged
juliusmarminge merged 1 commit intopingdotgg:mainfrom
imabdulazeez:fix/2199-opencode-text-response-format
Apr 20, 2026
Merged

fix(server): handle OpenCode text response format in commit message g…#2202
juliusmarminge merged 1 commit intopingdotgg:mainfrom
imabdulazeez:fix/2199-opencode-text-response-format

Conversation

@imabdulazeez
Copy link
Copy Markdown
Contributor

@imabdulazeez imabdulazeez commented Apr 19, 2026

What Changed

  • Updated the OpenCode git text-generation path to read JSON from text parts in the prompt response instead of requiring info.structured.
  • Surface OpenCode's returned structured-output error message when the provider reports one, and keep failing fast on empty responses.
  • Reused the existing JSON-object extraction logic from the Cursor implementation and moved it into apps/server/src/git/Utils.ts as shared logic so OpenCode and Cursor parse provider output the same way.
  • Updated apps/server/src/git/Layers/OpenCodeTextGeneration.test.ts to cover the failing OpenCode response shapes: empty output, JSON returned inside plain text parts, and upstream structured-output errors.
  • Tested both OpenCode and Cursor for git text generation to confirm the shared JSON extraction path still works for each provider.

Why

OpenCode is currently returning the generated payload as plain text parts rather than populating info.structured, so the existing implementation treated valid responses as failures and broke commit message generation.

Parsing the returned text locally and decoding it against the existing schema keeps the validation path intact while matching the response shape OpenCode actually sends.

UI Changes

Before

image

After

image

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes (not applicable)

Closes #2199

Note

Fix OpenCode text response parsing in commit message generation

  • Removes the json_schema structured output format from OpenCode requests; instead reads raw text parts and extracts JSON locally using extractJsonObject from Utils.ts.
  • Adds getOpenCodeTextResponse to concatenate text parts into a single string, and getOpenCodePromptErrorMessage to surface upstream info.error details as thrown errors.
  • Throws a typed 'OpenCode returned empty output.' error when no text parts are present, and maps info.error with StructuredOutputError to a readable message.
  • Moves extractJsonObject to Utils.ts and shares it with CursorTextGeneration.ts.
  • Behavioral Change: OpenCode prompts no longer request structured JSON output; JSON is parsed client-side from plain text responses.

Macroscope summarized 2a12331.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 19, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9a61e53f-226a-4211-8ace-980a3a8faab2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 19, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 19, 2026

Approvability

Verdict: Approved

This is a focused bug fix that adapts OpenCode response parsing from structured output to text format, moving a shared utility and adding error handling helpers. Changes are limited to text generation layers with comprehensive test coverage, no runtime behavior changes beyond fixing the response format handling.

You can customize Macroscope's approvability policy. Learn more.

Comment on lines -248 to -251
format: {
type: "json_schema",
schema: toJsonSchemaObject(input.outputSchemaJson) as Record<string, unknown>,
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nexxeln is your structured data not reliable?

@juliusmarminge juliusmarminge enabled auto-merge (squash) April 20, 2026 00:09
@juliusmarminge juliusmarminge merged commit 37965da into pingdotgg:main Apr 20, 2026
11 checks passed
aaditagrawal added a commit to aaditagrawal/t3code that referenced this pull request Apr 20, 2026
Upstream additions:
- fix(web): restore manual sort drag and keep per-group expand state (pingdotgg#2221)
- fix: Change right panel sheet to be below title bar / action bar (pingdotgg#2224)
- Refactor OpenCode lifecycle and structured output handling (pingdotgg#2218)
- effect-codex-app-server (pingdotgg#1942)
- Redesign model picker with favorites and search (pingdotgg#2153)
- fix(server): prevent probeClaudeCapabilities from wasting API requests (pingdotgg#2192)
- fix(server): handle OpenCode text response format in commit message gen (pingdotgg#2202)
- Devcontainer / IDE updates (pingdotgg#2208)
- Expand leading ~ in Codex home paths before exporting CODEX_HOME (pingdotgg#2210)
- fix(release): use v<semver> tag format for nightly releases (pingdotgg#2186)

Fork adaptations:
- Took upstream's redesigned model picker with favorites and search
- Removed deleted codexAppServerManager (replaced by effect-codex-app-server)
- Stubbed fetchCodexUsage (manager-based readout no longer available)
- Extended PROVIDER_ICON_BY_PROVIDER for all 8 fork providers
- Extended modelOptionsByProvider test fixtures for all 8 providers
- Inline ClaudeSlashCommand type (not yet re-exported from SDK)
- Updated SettingsPanels imports for new picker module structure
- Preserved fork's CI customizations (ubuntu-24.04 not Blacksmith)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenCode returns "no structured output" error during commit message generation

2 participants