Skip to content

fix(ai): support streams without finish reasons - #40965

Closed
rekram1-node wants to merge 1 commit into
v2from
optional-finish-reason
Closed

fix(ai): support streams without finish reasons#40965
rekram1-node wants to merge 1 commit into
v2from
optional-finish-reason

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

  • honor compatibility.requireFinishReason, preserving strict behavior when unset or true
  • synthesize an unknown terminal finish after non-empty clean EOF when the option is false
  • make protocol halt finalization optionally effectful so OpenAI Chat can finalize accumulated tool inputs and preserve usage
  • keep empty streams, malformed events, incomplete tool identity, provider errors, and transport failures as errors
  • verify Core continues the agentic loop from recorded tool calls even when the finish reason is unknown

Behavior

For requireFinishReason: false, a non-empty stream that ends without a terminal reason completes with step-finish and finish events whose normalized reason is unknown. OpenAI Chat finalizes valid and malformed local tool inputs before emitting that finish. Core continuation remains content-driven, so valid local tools execute and cause the next model step without requiring a synthesized tool-calls reason.

Testing

  • packages/ai: bun typecheck
  • packages/core: bun typecheck
  • packages/core: bun test test/session-runner.test.ts (144 pass)
  • targeted generic and OpenAI Chat compatibility tests (10 pass)
  • Gemini and Bedrock protocol regressions (64 pass)
  • full packages/ai suite: 481 pass, 28 skipped, 4 unrelated base failures
  • Prettier and git diff --check

The existing full AI suite failures are Azure URL expectations with a duplicated /v1 and stale OpenRouter recorded request bodies expecting no usage option; neither path is changed by this PR.

@github-actions

github-actions Bot commented Sep 7, 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.

1 participant