Fix whitespace-only text block from orphaned CacheBreakpoint#4839
Merged
Fix whitespace-only text block from orphaned CacheBreakpoint#4839
Conversation
When a CacheBreakpoint had no preceding content block to attach
cache_control to, rawContentToAnthropicContent created a placeholder
{ type: 'text', text: ' ' } block. The Anthropic API rejects
whitespace-only text blocks with 'text content block must contain
non-whitespace text'.
This happens in long conversations after prompt-tsx prunes content to
fit the token budget, leaving a CacheBreakpoint with no real content
before it.
Fix: defer the cache_control to the next cacheable content block. If
no subsequent block exists, silently drop it (nothing to cache anyway).
Fixes microsoft/vscode#305956
5f638d0 to
ecd80ad
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Anthropic Messages API validation error triggered when prompt pruning leaves an orphaned CacheBreakpoint, which previously produced an invalid whitespace-only text block.
Changes:
- Update
rawContentToAnthropicContent()to defer orphanedcache_controlforward to the next cacheable content block (or drop it if none appears). - Update/extend unit tests to cover the new defer-forward behavior and the “drop if no content” case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/platform/endpoint/node/messagesApi.ts | Replaces whitespace placeholder block with a pending/deferred cache_control mechanism to avoid invalid Anthropic text blocks. |
| src/platform/endpoint/test/node/messagesApi.spec.ts | Updates the cache_control-only tool test expectation and adds a new test verifying deferred cache_control attachment to the next block. |
roblourens
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes microsoft/vscode#305956
Root Cause
In
rawContentToAnthropicContent(), theCacheBreakpointhandler'selsebranch (when no preceding block exists):Fix
Instead of creating an invalid placeholder, defer the
cache_controlto the next cacheable content block that gets added. If no subsequent block exists, silently drop it — there's nothing to cache anyway.pendingCacheControlflag tracks orphaned breakpoints internallycache_controlto itTest Coverage
cache breakpoint before content defers cache_control to next block— verified it fails on old code (2 blocks including whitespace placeholder) and passes on new code (1 block with correctcache_control)cache_control-only tool content— orphaned breakpoint with no content is now silently dropped (impossible in practice sinceaddCacheBreakpointsonly targets messages with content)