Skip to content

fix(opencode): fail runs when the model stream ends without a finish … - #40061

Closed
zhang17-24 wants to merge 1 commit into
anomalyco:devfrom
zhang17-24:fix/39968-truncated-stream-finish-error
Closed

fix(opencode): fail runs when the model stream ends without a finish …#40061
zhang17-24 wants to merge 1 commit into
anomalyco:devfrom
zhang17-24:fix/39968-truncated-stream-finish-error

Conversation

@zhang17-24

Copy link
Copy Markdown

Issue for this PR

Closes #39968

Type of change

  • Bug fix

What does this PR do?

When an upstream SSE connection dies mid-turn without a finish frame, the AI SDK synthesizes a finish-step with finishReason "other"/undefined. opencode mapped that to the benign "unknown" finish, so the truncated output was persisted as a successful turn and opencode run exited 0. This maps "other"/undefined to "error" instead, and a step-finish with reason "error" fails the turn, so the run exits non-zero while still keeping the partial output.

How did you verify your code works?

  • bun test test/cli/run/run-process.test.ts — 13 tests pass
  • bun test test/session/llm.test.ts — 28 tests pass
  • bun run typecheck — pass

Screenshots / recordings

N/A (not a UI change)

Checklist

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

…frame

An upstream SSE connection cut mid-turn (EOF with no finish frame, no error
event) made the AI SDK emit a synthesized finish-step with finishReason
"other"/undefined. opencode mapped that to the benign "unknown" finish,
persisted the truncated output as a completed turn, and `opencode run`
exited 0 — silently accepting partial generations as success (issue anomalyco#39968).

- ai-sdk adapter now maps "other"/undefined finish reasons to "error"
  instead of "unknown", matching the native runtime's semantics
- the session processor fails the turn on an "error" step-finish, publishing
  a session error so `opencode run` exits non-zero
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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

Found a potential related PR:

PR #39970: fix(opencode): make long-lived provider streams robust to silent SSE terminations
#39970

Why it's related: This PR addresses a similar issue with SSE stream terminations. While PR #40061 focuses on mapping the "other"/undefined finish reason to "error" to fail runs appropriately, PR #39970 appears to handle robustness for silent SSE terminations in long-lived provider streams. Both deal with incomplete/failed upstream connections affecting model streaming behavior.

You should check if these PRs are complementary or if one supersedes the other.

@github-actions

github-actions Bot commented Sep 1, 2026

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 free to 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.

Silent SSE terminations: EOF without a finish frame completes the turn, chunkTimeout misses stalled streams, provider error bodies are discarded

1 participant