Skip to content

fix(anthropic): filter out empty compaction blocks to prevent api rejection - #19990

Open
wasim-builds wants to merge 3 commits into
vercel:mainfrom
wasim-builds:fix/anthropic-empty-compaction
Open

fix(anthropic): filter out empty compaction blocks to prevent api rejection#19990
wasim-builds wants to merge 3 commits into
vercel:mainfrom
wasim-builds:fix/anthropic-empty-compaction

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Description

Fixes #13335.

When using Anthropic's native compaction (compact_20260112), the API occasionally returns a compaction block with empty/null content. Previously, @ai-sdk/anthropic persisted this faithfully, which caused the Anthropic API to throw a 400 error (content can't be empty) when the message history was sent back on the next turn.

This PR filters out compaction blocks with falsy/empty content during request building to prevent them from entering the payload sent to the API.

Testing

  • Added unit tests mocking Anthropic's empty compaction API response.
  • Verified tests pass locally.

Copilot AI lite review requested due to automatic review settings August 29, 2026 18:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wasim-builds
wasim-builds force-pushed the fix/anthropic-empty-compaction branch from c41846a to e68b907 Compare August 30, 2026 19:20
@wasim-builds
wasim-builds force-pushed the fix/anthropic-empty-compaction branch from e68b907 to db04e8d Compare August 30, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

anthropic: empty compaction content persisted then rejected on re-send

2 participants