fix(anthropic): coerce blank system text blocks at extraction (#70909) - #86643
Merged
Conversation
Residual from PR #70910 after #77509 landed the message-list scrub: a whitespace-only system content block carrying a cache_control marker still reached the wire and 400'd the whole request ("text content blocks must contain non-whitespace text"), wedging the session on every retry. The block cannot be dropped (it carries the cache breakpoint), so coerce its text to the shared non-whitespace placeholder when extracting the system param, copying the block so caller message dicts are never mutated. Adds SHL0MS's request-level regression suite from #70910; four of its five cases already pass on main via #77509 — the system-block case fails without this fix.
Contributor
૮ >ﻌ< ა ci reviewran on 608febc — fix(anthropic): coerce blank system text blocks at extractio
|
This was referenced Aug 15, 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.
Summary
Salvages the residual fix from #70910 (SHL0MS) after #77509 landed the message-list scrub.
_scrub_blank_text_blocks(fix(anthropic): drop whitespace-only text blocks reaching the Messages API #77509). The remaining leak: a whitespace-only system content block carryingcache_controlis passed through verbatim by the system-extraction path inconvert_messages_to_anthropic, and Anthropic rejects the whole request with HTTP 400 "text content blocks must contain non-whitespace text" — wedging the session on every retry (Session wedges on HTTP 400 'text content blocks must contain non-whitespace text' from a blank block synthesized during request assembly (compression/merge/pre-shaped content) #70909, [Bug]: Session can be poisoned into a permanent non-retryable 400 — whitespace-only user block built at request time #83037)._EMPTY_TEXT_PLACEHOLDER(blocks are copied first, so caller dicts are never mutated; thecache_controlbreakpoint is preserved — it cannot be dropped without losing the cache anchor).tests/agent/test_anthropic_request_blank_block_guard.pyfrom fix(anthropic): prepended leading user turn must be non-whitespace (#70909) #70910 (docstring updated to name the actual backstop on main). Sabotage-verified:test_blank_system_block_is_coercedfails on main without the fix, passes with it.Testing
tests/agent/test_anthropic_request_blank_block_guard.py— 5 passedtests/agent/test_anthropic_whitespace_text_blocks.py+tests/agent/test_anthropic_adapter.py— 110 passedAuthorship preserved: commit authored by SHL0MS. Closes #70909. Supersedes #70910.
Infographic