Skip to content

fix: surface actionable error when OpenCode prompt returns no response data#28

Merged
ben-vargas merged 3 commits into
mainfrom
claude/amazing-antonelli-f29504
Jun 11, 2026
Merged

fix: surface actionable error when OpenCode prompt returns no response data#28
ben-vargas merged 3 commits into
mainfrom
claude/amazing-antonelli-f29504

Conversation

@ben-vargas

Copy link
Copy Markdown
Owner

Summary

Extends the actionable error guidance from #24 to the no-data branch. On opencode CLI 1.17.x, an invalid or unavailable provider/model ID (e.g. github-copilot/gpt-5, the exact repro from #21) no longer produces an empty HTTP body — the SDK call succeeds but result.data is falsy, bypassing #24's EmptyJSONResponse wrapping and hitting the generic No response data from OpenCode error (errorType "Error", no guidance).

Changes

  • doGenerate: the no-data branch now throws an APICallError naming the model ID, suggesting opencode models, including the server error payload (result.error) when available, and carrying errorType: "EmptyResponseData" with isRetryable: false.
  • doStream: a prompt that resolves with no data previously left the stream hanging forever on the event subscription. It now surfaces the same actionable error as an error stream part and terminates the stream. The error enqueue is also guarded against an already-closed controller (the prompt promise routinely settles after session.idle closes the stream).
  • wrapError: now returns already-wrapped AI SDK errors (APICallError, LoadAPIKeyError) unchanged instead of re-wrapping them and losing their metadata. Needed because the new error is thrown inside doGenerate's try block whose catch funnels everything through wrapError; also fixes double-wrapping for direct callers.
  • Exports: new createEmptyResponseDataError factory exported alongside createAPICallError / createTimeoutError.
  • Tests: mirror the fix: clarify empty OpenCode response errors #24 coverage — createEmptyResponseDataError unit tests and a wrapError pass-through test in errors.test.ts; doGenerate no-data and server-error-detail tests plus a doStream hanging-stream test in opencode-language-model.test.ts.
  • CHANGELOG: entries added to the existing unreleased [3.0.5] section (no version bump here — main is already at 3.0.5 from fix: preconfigured-client example and singleton client manager dispose recovery #27; this work ships in that release).

Verification

Tested against dist/ with opencode CLI 1.17.3 and the invalid model github-copilot/gpt-5. Both generateText and streamText now produce:

OpenCode returned no response data for model "github-copilot/gpt-5". This usually means the configured provider/model ID is invalid or unavailable. Run opencode models to list available model IDs and check the OpenCode provider configuration. Original error: Unexpected server error. Check server logs for details.

with data.errorType: "EmptyResponseData", and the streaming call terminates instead of hanging.

npm run format:check and npm run ci (typecheck, lint, 366 tests) pass locally.

Refs #21, follows up on #24.

…e data

On opencode CLI 1.17.x an invalid or unavailable provider/model ID (e.g.
github-copilot/gpt-5 from #21) no longer produces an empty HTTP body; the
prompt call succeeds but result.data is falsy, bypassing the actionable
empty-JSON error from #24 and hitting the generic "No response data from
OpenCode" error with no guidance.

- doGenerate now throws an APICallError naming the model ID, suggesting
  `opencode models`, including the server error payload when available,
  and carrying errorType "EmptyResponseData"
- doStream surfaces the same error as an error stream part and terminates
  the stream instead of hanging on the event subscription
- wrapError returns already-wrapped AI SDK errors unchanged instead of
  re-wrapping them and losing their metadata
- export createEmptyResponseDataError, with tests mirroring the #24
  coverage in errors.test.ts and opencode-language-model.test.ts

Verified against dist/ with opencode CLI 1.17.3: both generateText and
streamText now produce the actionable message for github-copilot/gpt-5.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 61a33fd688

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/opencode-language-model.ts Outdated
Codex review flagged that the new no-data check in doStream assumed
fields-style SDK results. A client configured with responseStyle: "data"
(allowed by OpencodeClientOptions) resolves session.prompt to the payload
itself, or undefined on failure, so the check would flag every successful
prompt as missing data (terminating a healthy stream) or throw a TypeError
on undefined.

- Managed clients are now always created with responseStyle: "fields";
  clientOptions.responseStyle "data" is ignored with a warning, mirroring
  the existing baseUrl/directory normalization
- doGenerate/doStream normalize the prompt result shape, treating
  fields-style results ({ data, error }) and data-style payloads
  uniformly, so caller-supplied data-style clients get correct content
  on success and the actionable EmptyResponseData error on failure
@ben-vargas

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9442c9e091

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/opencode-language-model.ts
Codex follow-up: a preconfigured responseStyle "data" client without
settings.sessionId never reached the prompt-result normalization because
getOrCreateSession() still read result.data from session.create, treating
a successful data-style create payload as a failure.

Generalize extractPromptResult to extractSdkResult and apply it to
session.create as well, so data-style clients work end-to-end.
@ben-vargas

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ben-vargas
ben-vargas merged commit a68dcf0 into main Jun 11, 2026
3 checks passed
@ben-vargas
ben-vargas deleted the claude/amazing-antonelli-f29504 branch June 11, 2026 13:26
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