Skip to content

fix: thinking block content leak in execute() text extraction#11

Open
bkrabach wants to merge 1 commit intomainfrom
fix/thinking-block-text-leak
Open

fix: thinking block content leak in execute() text extraction#11
bkrabach wants to merge 1 commit intomainfrom
fix/thinking-block-text-leak

Conversation

@bkrabach
Copy link
Copy Markdown
Collaborator

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() used hasattr(block, "text") which allowed ThinkingContent objects through unchanged, leaking internal reasoning text into final_content and downstream parse_json calls.

Fix

Replaces hasattr(block, "text") with an explicit block.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.py with 6 regression tests covering both model systems and both object/dict block paths.

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.
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.

1 participant