Skip to content

fix(anthropic): allow null content in compaction_delta streaming schema#12471

Merged
aayush-kapoor merged 3 commits intovercel:mainfrom
leog25:fix/compaction-delta-nullable-content
Feb 20, 2026
Merged

fix(anthropic): allow null content in compaction_delta streaming schema#12471
aayush-kapoor merged 3 commits intovercel:mainfrom
leog25:fix/compaction-delta-nullable-content

Conversation

@leog25
Copy link
Copy Markdown
Contributor

@leog25 leog25 commented Feb 12, 2026

Background

PR #12384 introduced support for Anthropic's compaction feature, but the streaming Zod schema for compaction_delta events requires content to be a non-nullable string. Anthropic's API sends compaction_delta events with content: null (e.g. the initial frame before the compaction summary text), which causes Zod validation to fail at runtime.

Summary

Changed content: z.string() to content: z.string().nullish() in the compaction_delta streaming schema in packages/anthropic/src/anthropic-messages-api.ts. This matches the existing content_block_start schema for compaction, which already uses .nullish().

Manual Verification

Reproduction requires streaming a conversation that exceeds the compaction trigger threshold (50k+ tokens) with @ai-sdk/anthropic, which triggers a compaction_delta event with content: null. This is not practical to verify without an API key and a large conversation, but the added regression test simulates this exact scenario by streaming a compaction_delta chunk with content: null.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #12470

Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

The compaction_delta handler passes null/undefined content as the delta field of a text-delta stream part, violating the delta: string type contract.

Fix on Vercel

Co-Authored-By: Embedder <215220128+embedder-dev@users.noreply.github.com>
@leog25 leog25 force-pushed the fix/compaction-delta-nullable-content branch from e937cfe to 6229ccb Compare February 12, 2026 01:46
@leog25 leog25 requested a review from aayush-kapoor February 19, 2026 21:08
@aayush-kapoor aayush-kapoor added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Feb 19, 2026
@aayush-kapoor aayush-kapoor merged commit b094c07 into vercel:main Feb 20, 2026
20 of 21 checks passed
vercel-ai-sdk bot pushed a commit that referenced this pull request Feb 20, 2026
…ma (#12471)

## Background

PR #12384 introduced support for Anthropic's compaction feature, but the
streaming Zod schema for compaction_delta events requires content to be
a non-nullable string. Anthropic's API sends compaction_delta events
with content: null (e.g. the initial frame before the compaction summary
text), which causes Zod validation to fail at runtime.

## Summary

Changed content: z.string() to content: z.string().nullish() in the
compaction_delta streaming schema in
packages/anthropic/src/anthropic-messages-api.ts. This matches the
existing content_block_start schema for compaction, which already uses
.nullish().

## Manual Verification

Reproduction requires streaming a conversation that exceeds the
compaction trigger threshold (50k+ tokens) with @ai-sdk/anthropic, which
triggers a compaction_delta event with content: null. This is not
practical to verify without an API key and a large conversation, but the
added regression test simulates this exact scenario by streaming a
compaction_delta chunk with content: null.

## Checklist

- Tests have been added / updated (for bug fixes / features)
- Documentation has been added / updated (for bug fixes / features)
- A patch changeset for relevant packages has been added (for bug fixes
/ features - run pnpm changeset in the project root)
- I have reviewed this pull request (self-review)

## Related Issues

Fixes #12470

---------

Co-authored-by: Embedder <215220128+embedder-dev@users.noreply.github.com>
Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Feb 20, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Feb 20, 2026

✅ Backport PR created: #12718

vercel-ai-sdk bot added a commit that referenced this pull request Feb 20, 2026
…aming schema (#12718)

This is an automated backport of #12471 to the release-v5.0 branch. FYI
@leog25

Co-authored-by: leo <78882874+leog25@users.noreply.github.com>
Co-authored-by: Embedder <215220128+embedder-dev@users.noreply.github.com>
Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
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.

compaction_delta streaming Zod schema rejects content: null from Anthropic API

2 participants