fix: thinking block content leak in execute() text extraction#11
Open
fix: thinking block content leak in execute() text extraction#11
Conversation
content_models.ThinkingContent has a .text attribute (distinct from message_models.ThinkingBlock which uses .thinking). The hasattr-based filter was letting thinking text leak into final_content, polluting downstream consumers of the response (e.g., parse_json in recipe steps). Replaces hasattr check with explicit block.type check. Same fix pattern as amplifier-module-loop-streaming PR #25 (merge df5c0e1). Adds regression test verifying ThinkingContent blocks are filtered while TextBlock/TextContent pass through.
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
Cross-ecosystem companion fix to amplifier-module-loop-streaming PR #25 (df5c0e1).
Root Cause
Two content block model systems exist in amplifier-core:
content_models.ThinkingContent→ has.text(bug hazard)message_models.ThinkingBlock→ has.thinking(already safe)The inline text extraction in
execute()usedhasattr(block, "text")which allowedThinkingContentobjects through unchanged, leaking internal reasoning text intofinal_contentand downstreamparse_jsoncalls.Fix
Replaces
hasattr(block, "text")with an explicitblock.type == "text"check using the getattr/enum-value pattern. Also adds the type check to the dict block branch for consistency.Tests
New file
tests/test_thinking_block_leak.pywith 6 regression tests covering both model systems and both object/dict block paths.