Skip to content

fix(opencode): surface empty model responses - #37732

Closed
CyberPunk-2022 wants to merge 2 commits into
anomalyco:devfrom
CyberPunk-2022:empty-response-error
Closed

fix(opencode): surface empty model responses#37732
CyberPunk-2022 wants to merge 2 commits into
anomalyco:devfrom
CyberPunk-2022:empty-response-error

Conversation

@CyberPunk-2022

@CyberPunk-2022CyberPunk-2022 commented Jul 19, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#37735

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When a provider finishes with stop and usage but emits neither text nor a tool call, OpenCode currently records the assistant turn as successful. This change stores an EmptyResponseError and emits the session error event instead, while retaining the finish reason and usage for diagnosis.

It is deliberately a harness-level safeguard: it does not claim to identify why a provider produced an empty completion. The related #28507 also contains the normal-stop/non-zero-usage variant, alongside its separate empty-loop report.

How did you verify your code works?

  • bun test test/session/prompt.test.ts --timeout 30000 in packages/opencode — 11 passed, 1 existing skip
  • bun typecheck in packages/opencode — passed
  • Regeneration: bun run script/build.ts in packages/sdk/js

The regression simulates a completed stop stream with usage but no text or tool call, and verifies the persisted assistant error is EmptyResponseError.

Screenshots / recordings

N/A (runtime-only change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actionsgithub-actionsBot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, I found several related PRs that are worth noting, though they address different aspects of the response handling:

Potentially Related PRs:

  1. PR fix(opencode): stop repeated empty tool loops #37110 - fix(opencode): stop repeated empty tool loops

    • Related to empty response handling but focuses on tool loops rather than overall empty responses
  2. PR fix(session): retry empty stream truncations and discard partial parts #26167 - fix(session): retry empty stream truncations and discard partial parts

    • Addresses empty stream scenarios but in the context of retries and truncations
  3. PR fix(core): surface refusal category and explanation on content filter #37392 - fix(core): surface refusal category and explanation on content filter

    • Similar pattern of surfacing specific error conditions (content filter refusals) alongside provider responses
  4. PR fix(llm): finalize pending response tool calls #37160 - fix(llm): finalize pending response tool calls

    • Related to provider response handling and finalizing incomplete tool calls

These PRs address overlapping concerns around provider response handling and error surfacing, but none appear to be direct duplicates of PR #37732. PR #37732 is specifically about surfacing empty responses as EmptyResponseError while retaining provider metadata, which is a distinct fix from the related PRs.

@github-actionsgithub-actionsBot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@CyberPunk-2022CyberPunk-2022 changed the title fix(opencode): surface empty model responsesfix(opencode): surface empty model responses [XHY-21]Jul 20, 2026
@CyberPunk-2022CyberPunk-2022 changed the title fix(opencode): surface empty model responses [XHY-21]fix(opencode): surface empty model responsesJul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty stop completions are recorded as successful responses

1 participant

@CyberPunk-2022