Skip to content
Source
Sign inSign up
TanStack/ai

fix(openai-base): preserve caller-supplied runId in chat completions adapter #2193

Openwillnie9(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2193/headopened View on GitHub

Closes #2115

Summary

  • Honor options.runId / chatOptions.runId in OpenAIBaseChatCompletionsTextAdapter (packages/openai-base/src/adapters/chat-completions-text.ts) for both chatStream() and structuredOutputStream(), falling back to generateId(this.name) when no runId is provided (matching the Responses and Anthropic adapters).
  • Added unit tests in packages/openai-base/tests/chat-completions-text.test.ts and packages/openai-base/tests/chat-completions-structured-output-stream.test.ts verifying RUN_STARTED and RUN_FINISHED carry the caller-supplied runId.

Verification

  • pnpm nx run-many --projects=@tanstack/openai-base --targets=build,test:oxlint,test:types,test:lib (all 38 test files / 479 tests passed)

Summary by CodeRabbit

  • Bug Fixes
    • Streaming chat and structured-output responses now preserve a caller-provided run ID across start and finish events.
    1. Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

      An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

    2. ⚠️ No Changeset found

      Latest commit: 44653e601e9d14aaec77df8f41a22859855af56f

      Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

      This PR includes no changesets

      When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

      Click here to learn what changesets are, and how to add one.

      Click here if you're a maintainer who wants to add a changeset to this PR

    3. tanstack-source added labelsbug

    4. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Both Chat Completions streaming paths now use a caller-provided run ID, generating one only when none is supplied. Tests verify that RUN_STARTED and RUN_FINISHED carry the supplied ID.

      Changes: Run ID streaming behavior

      Layer / File(s)Summary
      Preserve run IDs across streaming paths
      packages/openai-base/src/adapters/chat-completions-text.ts, packages/openai-base/tests/chat-completions-text.test.ts, packages/openai-base/tests/chat-completions-structured-output-stream.test.ts
      chatStream and structuredOutputStream use the supplied run ID when present. Tests verify that RUN_STARTED and RUN_FINISHED carry that ID.

      Estimated code review effort: 2 (Simple) | ~8 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: tombeckenham, alemtuzlak

      Merge Risk: Minimal · up to 44653

      Streaming now preserves the run ID supplied by the caller and still generates one when none is given. No merge-blocking risk was found.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: the chat completions adapter now preserves a caller-supplied runId. It matches the raw summary, which says chatStream and structuredOutputStream use options.runId or c…
      Description checkPassedThe description follows the template's main sections. It has a Summary and Verification section, and it links issue #2115. It does not fill in the template's Checklist or Release Impact sections. It a…
      Linked Issues checkPassedIssue #2115 requires that the Chat Completions base adapter use the caller-supplied runId in run events, with a generated fallback. At the reviewed head, chatStream() in packages/openai-base/src/ada…
      Out of Scope Changes checkPassedThe described changes are limited to the runId handling in OpenAIBaseChatCompletionsTextAdapter (chatStream and structuredOutputStream) and unit tests for that behavior in packages/openai-base/tests. …
      Full details: Title check

      Explanation

      The title names the main change: the chat completions adapter now preserves a caller-supplied runId. It matches the raw summary, which says chatStream and structuredOutputStream use options.runId or chatOptions.runId when provided. The title is 76 characters, which is within a normal title length.

      Full details: Description check

      Explanation

      The description follows the template's main sections. It has a Summary and Verification section, and it links issue #2115. It does not fill in the template's Checklist or Release Impact sections. It also does not state whether docs were updated or whether a changeset was added. The checklist items are not marked, and the description does not say why they were skipped. These are non-critical gaps, and the core content (what changed, why, and how it was tested) is clear.

      Full details: Linked Issues check

      Explanation

      Issue #2115 requires that the Chat Completions base adapter use the caller-supplied runId in run events, with a generated fallback. At the reviewed head, chatStream() in packages/openai-base/src/adapters/chat-completions-text.ts sets runId: options.runId ?? generateId(this.name) in aguiState. That value feeds RUN_STARTED, RUN_FINISHED, and RUN_ERROR in the stream, so the caller ID persists across events. structuredOutputStream() begins with the same aguiState pattern using chatOptions.runId, which matches the PR summary. The line is truncated in the read, so its exact expression was confirmed only in part. The PR summary and the raw summary both describe the change. The added tests in chat-completions-text.test.ts and chat-completions-structured-output-stream.test.ts cover RUN_STARTED and RUN_FINISHED carrying the supplied runId. The test files were not read directly. The diff tool was unavailable, so the whole-PR diff was not verified against the base.

      Full details: Out of Scope Changes check

      Explanation

      The described changes are limited to the runId handling in OpenAIBaseChatCompletionsTextAdapter (chatStream and structuredOutputStream) and unit tests for that behavior in packages/openai-base/tests. These changes directly implement #2115. No unrelated changes are described in the PR summary or the raw summary. The whole-PR diff could not be read because the changed blobs were unavailable, so this verdict relies on the summaries and the visible head source.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share

      Recent review info

      Run configuration

      • Source mode: Auto
      • Repository: TanStack/ai
      • Branch: main
      • File: .coderabbit.yaml
      • Commit: 2ed7e21
      • Layers: Repository YAML
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 3b4a3183-393c-487b-90de-ff3b86898bfb
      Commits

      Reviewing files that changed from the base of the PR and between 2ed7e21c676e4d8e308d724d074755942051b661 and 44653e601e9d14aaec77df8f41a22859855af56f.

      Files selected for processing: 3

      • packages/openai-base/src/adapters/chat-completions-text.ts
      • packages/openai-base/tests/chat-completions-structured-output-stream.test.ts
      • packages/openai-base/tests/chat-completions-text.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

    5. Thanks for the PR, @willnie9! 🙌 @tombeckenham will take a look.

      Automated pre-review checks

      • ✅ CI passing
      • ✅ No merge conflicts
      • ⚠️ No changeset found — run pnpm changeset if this changes published packages
      • ⚠️ No E2E test changes detected — behavior changes need coverage under testing/e2e/ (see CONTRIBUTING)
      Automated triage — a human review follows.
    6. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.