Skip to content

fix(ai-sdk): log AI SDK v7 inline file data as attachments - #2752

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
solve-issue-2750-e2e-2571195e
Open

Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
solve-issue-2750-e2e-2571195e

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

build off of #2751
fixes #2750

🤖 This text was AI-generated.

Problem

With AI SDK v7, file parts carry their bytes in a tagged wrapper
(SharedV4FileData):

{ type: "file", mediaType: "image/png", data: { type: "data", data: Uint8Array } }

The AI SDK plugin only turned bare bytes into attachments, so it copied
this wrapper into the span as is. deepCopyEvent then turned the
Uint8Array into an object with one key per byte. 1 MB of image became
about 120 MB of heap on every model call
(#2750).

The plugin fix in #2751 had only a unit test. No e2e scenario sent a v7
tagged file part, so the real streamText path was never tested.

Solution

The plugin now converts the inner bytes to an attachment and keeps the
v7 wrapper around it. The logged span has the same shape as the v7 input
and matches how decision images are already logged:

before: data: { type: "data", data: { "0": 137, "1": 80, ... } }
after:  data: { type: "data", data: <braintrust_attachment image/png> }

The ai-sdk-instrumentation scenario gets a new
ai-sdk-stream-image-file-operation. It streams a real 32x32 red PNG to
OpenAI and checks that the top-level call span and the model call span
each log one PNG attachment and no raw bytes. v7 sends the tagged form;
v5 and v6 send plain bytes. The test fails without the fix.

Other changes in this commit:

  • Remove the plugin unit test and two live-API image tests in
    ai-sdk.test.ts, which the new e2e test covers. Delete their unused
    test-image.png fixture.
  • Replace gpt-4.1-nano (deprecated) and gpt-4o-mini with
    gpt-5.4-nano-2026-03-17. AI SDK v3 stays on gpt-4o-mini because its
    OpenAI provider sends max_tokens, which GPT-5 models reject.
  • Send providerOptions: { openai: { store: false } } on multi-step tool
    calls for AI SDK v5+. This sends earlier tool calls in full instead of
    by ID, so recording also works for OpenAI orgs with Zero Data Retention.
  • Re-record all scenario cassettes and snapshots.

- Keep the AI SDK v7 `{ type: "data", data }` envelope when logging inline
  file bytes as attachments, matching the decision-image logging shape.
- Add a streamText image-file e2e operation (v5+, tagged data on v7) that
  asserts file bytes are logged as attachments on both the parent and
  model spans. It fails without the fix.
- Replace the plugin unit test and two live-API wrapper image tests with
  this e2e coverage, and drop the unused test-image.png fixture.
- Move the scenario off the deprecated gpt-4.1-nano and gpt-4o-mini to
  gpt-5.4-nano (v3 keeps gpt-4o-mini because its provider sends
  max_tokens), send prior tool items inline with store: false, and
  re-record all cassettes and snapshots.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T21:45:18.173395Z 00c7c14 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00c7c14911

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

This branch has not been deployed

No deployments
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.

wrapAISDK copies AI SDK v7 file bytes one key per byte instead of turning them into attachments

2 participants