Skip to content

fix(ai): harden compatible chat parsing - #40798

Merged
rekram1-node merged 4 commits into
v2from
openai-chat-parity
Aug 6, 2026
Merged

rekram1-node merged 4 commits into
v2from
openai-chat-parity

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #40690.

Summary

  • align OpenAI-compatible Chat stream schemas with the AI SDK's nullish usage and indexless tool-call tolerances
  • preserve provider-specific usage fields and prediction-token details in raw provider metadata
  • resolve indexless tool deltas using persistent call IDs, parallel positions, and sparse-stream state instead of per-chunk position alone
  • treat empty finish reasons as terminal unknown values and reject meaningful content after termination
  • intentionally omit Gemini's provider-specific OpenAI-compatible thought-signature extension pending dedicated Google routing support

Source comparison

Compared against ~/development/ai/packages/openai-compatible/src/chat/openai-compatible-chat-language-model.ts and convert-openai-compatible-chat-usage.ts. The native implementation retains its stricter incomplete-stream detection, undefined-vs-zero usage semantics, malformed tool-input isolation, and broader reasoning support where those are safer than AI SDK behavior.

Gemini's extra_content.google.thought_signature extension is intentionally excluded because it is specific to Google's OpenAI-compatible endpoint. Source links and follow-up context are documented next to the tool-call schema.

Validation

  • bun typecheck in packages/ai
  • 64 focused OpenAI Chat, OpenAI-compatible Chat, and ToolStream tests
  • full packages/ai run: 476 passed, 28 skipped; 2 existing OpenRouter recorded fixtures fail because their stored bodies omit the current usage.include request field

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