wrapAISDK copies AI SDK v7 file bytes one key per byte instead of turning them into attachments
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
What happens
With ai 7.0.145 and braintrust 3.32.0, file parts reach the doStream model span as { type: 'file', mediaType, data: { type: 'data', data: Uint8Array } }, the AI SDK 7 shape (SharedV4FileData). processContentPart passes part.data, the wrapper object, to convertDataToAttachment, which only handles a string, Uint8Array, Buffer or Blob, so no attachment is made. deepCopyEvent then runs JSON.stringify and JSON.parse on the raw Uint8Array, which becomes an object with one key per byte.
The same code is in 3.43.0 and on main as of e0b7107dc7.
Impact
1 MB of image bytes becomes 1,000,000 keys and about 120 MB of heap on every model call. We call Claude through Vertex, which takes no image URLs, so the AI SDK downloads every image in the conversation and each call carries all of them. A chat with 25 MB of images pushed the heap to about 3.1 GB, and our 4 GB serverless instances were killed for memory.
On a single 38-image call (24.5 MB of images), the heap peaked at 2,651 MB with wrapAISDK and at 117 MB without it, and deepCopyEvent alone allocated 5.4 GB.
Reproduction
processContentPart leaves this shape untouched, so the model span event is copied like this.
import { deepCopyEvent } from 'braintrust';
const copy = deepCopyEvent({
input: [{ type: 'file', mediaType: 'image/png', data: { type: 'data', data: new Uint8Array(1_000_000) } }],
});
// copy.input[0].data.data is a plain object with 1,000,000 keys, about 11 MB of JSON
Workaround we use
A one-line change in processContentPart, applied with pnpm patch to every build in dist, fixes it for us.
const fileAttachment = convertDataToAttachment(
- part.data,
+ part.data.type === "data" ? part.data.data : part.data,
part.mimeType || part.mediaType,
part.name || part.filename
);
With it, the same 38-image call peaked at 130 MB of heap with tracing on. A complete fix could also handle { type: 'url' } and the other SharedV4FileData variants in convertDataToAttachment.
Environment
braintrust3.32.0, also seen at runtime on 3.42.0 and in the source of 3.43.0ai7.0.145 with@ai-sdk/google-vertex5.0.117 (Anthropic on Vertex)- Node 22
- 主要语言
- TypeScript
- 星标
- 29
- 派生
- 22
- 平均合并
- 1 天 25 分钟
- 30 天内合并 PR
- 80
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
braintrustdata/braintrust-sdk-javascript 的其他 Issue
-
@braintrust/otel can't be installed alongside OpenTelemetry JS 3可能已有人在做 @lforst 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 57/100
braintrustdata/braintrust-sdk-javascript#2745 · 已指派 1 人 ·
维护者通常 1 天内回复
-
typescript
难度 3/5 1-2 天 新手友好度 45/100
braintrustdata/braintrust-sdk-javascript#2708 ·
维护者通常 1 天内回复
-
typescript
难度 4/5 3-5 天 新手友好度 35/100
braintrustdata/braintrust-sdk-javascript#2707 ·
维护者通常 1 天内回复
-
typescript
难度 3/5 1-2 天 新手友好度 45/100
braintrustdata/braintrust-sdk-javascript#2686 ·
维护者通常 1 天内回复
-
typescript
难度 4/5 3-5 天 新手友好度 45/100
braintrustdata/braintrust-sdk-javascript#2685 ·
维护者通常 1 天内回复
查看 braintrustdata/braintrust-sdk-javascript 的全部 Issue
相似的 Issue
-
Add: ESP 2 RO未关闭approved check:passed streams:add
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
ipaas: Configure form shows "Deploy to apply." and "Overrides selected Link" when they don't apply可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
wso2/integration-control-plane#1118 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
UTDNebula/utd-notebook#311 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复