Skip to content

fix: align OpenAI reasoning metadata handling with AI SDK#1017

Merged
omeraplak merged 1 commit intomainfrom
fix/openai-reasoning-metadata
Feb 4, 2026
Merged

fix: align OpenAI reasoning metadata handling with AI SDK#1017
omeraplak merged 1 commit intomainfrom
fix/openai-reasoning-metadata

Conversation

@omeraplak
Copy link
Member

@omeraplak omeraplak commented Feb 4, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

What is the new behavior?

fixes (issue)

Notes for reviewers


Summary by cubic

Aligns OpenAI reasoning metadata handling with the AI SDK to prevent losing non-reasoning metadata and to keep distinct reasoning parts during merges. ConversationBuffer now includes the OpenAI reasoning itemId in part signatures, and the normalizer only strips reasoning-linked metadata when no reasoning context exists.

  • Bug Fixes
    • Preserve non-reasoning OpenAI itemIds (msg*/fc*) when no reasoning parts exist.
    • Strip only reasoning-linked OpenAI fields (rs_*, reasoning_trace_id, reasoning) when reasoning is absent.
    • Include OpenAI reasoning itemId in ConversationBuffer signatures to avoid merging distinct reasoning parts.

Written for commit f7fd0ef. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of OpenAI reasoning metadata to preserve distinct reasoning parts with unique identifiers during message processing and merging.
    • Enhanced preservation of non-reasoning provider identifiers when reasoning context is absent.
    • Refined metadata cleanup logic to maintain data integrity across reasoning and non-reasoning scenarios.

@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2026

🦋 Changeset detected

Latest commit: f7fd0ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

Not sure what this means? Click here to learn what changesets are.

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

@joggrbot

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This patch updates OpenAI reasoning metadata handling in @voltagent/core to preserve non-reasoning itemIds (msg*, fc*) and selectively strip only reasoning-linked metadata fields (rs_/reasoning_trace_id/reasoning). It introduces helper functions to extract OpenAI identifiers and refines deduplication logic in conversation buffers and message normalization.

Changes

Cohort / File(s) Summary
Changelog
.changeset/large-meals-create.md
Documents patch release updates for OpenAI reasoning metadata handling, preserving non-reasoning itemIds and stripping only reasoning-linked metadata.
Conversation Buffer
packages/core/src/agent/conversation-buffer.ts, packages/core/src/agent/conversation-buffer.spec.ts
Introduces extractOpenAIItemId() helper and extends reasoning part signatures to include openaiItemId alongside reasoningId for proper deduplication and merge handling. Adds test case validating distinct reasoning parts are preserved separately when itemIds differ.
Message Normalizer
packages/core/src/agent/message-normalizer.ts, packages/core/src/agent/message-normalizer.spec.ts
Adds compactObject() helper and refactors stripReasoningLinkedProviderMetadata() to selectively preserve non-reasoning OpenAI metadata (msg*, fc*) while removing only reasoning-specific fields (rs_/reasoning_trace_id/reasoning). Updates tests to validate preservation behavior across reasoning-present and reasoning-absent scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hop through the metadata, preserve with care,
Reasoning traces dance in the buffer's air,
ItemIds kept, distinctions stay true,
OpenAI reasoning parts shine brand new! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: align OpenAI reasoning metadata handling with AI SDK' accurately summarizes the main change—updating metadata handling for OpenAI reasoning to align with AI SDK behavior.
Description check ✅ Passed The description includes most required sections with substantive content: current/new behavior context is provided via auto-generated summary, tests and changesets are confirmed, but current/new behavior sections remain empty and no specific issue is linked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/openai-reasoning-metadata

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: f7fd0ef
Status: ✅  Deploy successful!
Preview URL: https://49944eef.voltagent.pages.dev
Branch Preview URL: https://fix-openai-reasoning-metadat.voltagent.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/agent/conversation-buffer.ts (1)

523-541: 🛠️ Refactor suggestion | 🟠 Major

Replace JSON.stringify with safeStringify at lines 526 and 540.
Lines 526 and 540 use JSON.stringify which can throw on cyclic references and violates the project guideline. Use safeStringify from @voltagent/internal instead.

🔧 Proposed fix
-import type { Logger } from "@voltagent/internal";
+import { safeStringify, type Logger } from "@voltagent/internal";
@@
-        return `text:${part.text}:${JSON.stringify((part as any).providerMetadata ?? null)}`;
+        return `text:${part.text}:${safeStringify((part as any).providerMetadata ?? null)}`;
@@
-        return `${part.type}:${JSON.stringify(part)}`;
+        return `${part.type}:${safeStringify(part)}`;

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@omeraplak omeraplak merged commit c706872 into main Feb 4, 2026
23 checks passed
@omeraplak omeraplak deleted the fix/openai-reasoning-metadata branch February 4, 2026 04:53
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