fix(openai-base): preserve caller-supplied runId in chat completions adapter #2193
main fromrefs/pull/2193/head·opened View on GitHubCloses #2115
Summary#
- Honor
options.runId/chatOptions.runIdinOpenAIBaseChatCompletionsTextAdapter(packages/openai-base/src/adapters/chat-completions-text.ts) for bothchatStream()andstructuredOutputStream(), falling back togenerateId(this.name)when norunIdis provided (matching the Responses and Anthropic adapters). - Added unit tests in
packages/openai-base/tests/chat-completions-text.test.tsandpackages/openai-base/tests/chat-completions-structured-output-stream.test.tsverifyingRUN_STARTEDandRUN_FINISHEDcarry the caller-suppliedrunId.
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
⚠️ 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
willnie9(GitHub profile, opens in a new tab) linked this to fix #2115
tanstack-source added labelsbug
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_STARTEDandRUN_FINISHEDcarry 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.tschatStreamandstructuredOutputStreamuse the supplied run ID when present. Tests verify thatRUN_STARTEDandRUN_FINISHEDcarry 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 to44653-
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:
4-
Check name Status Explanation Title check 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 c… Description check 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 a…Linked Issues check Issue #2115requires 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 check 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. … 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
#2115requires 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 setsrunId: 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 sameaguiStatepattern usingchatOptions.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.
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.tspackages/openai-base/tests/chat-completions-structured-output-stream.test.tspackages/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.
-
-
github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
Thanks for the PR, @willnie9! 🙌 @tombeckenham will take a look.
Automated pre-review checks
- ✅ CI passing
- ✅ No merge conflicts
- ⚠️ No changeset found — run
pnpm changesetif this changes published packages - ⚠️ No E2E test changes detected — behavior changes need coverage under
testing/e2e/(see CONTRIBUTING)
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
Sign in to join this conversation.
copilot-pull-request-reviewer[bot](GitHub profile, opens in a new tab) reviewed
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.