Skip to content

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

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

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.

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