fix: handle list content in _serialize_for_summary for multimodal messages - #59994
AlexFucuson9 wants to merge 1 commit into
Conversation
…sages
msg.get('content') can return a list of parts for multimodal messages
(containing text, images, etc.). The old code passed this list directly
to redact_sensitive_text(text: str), which raised AttributeError on
list.replace(), causing context compression to fail entirely for any
session with attached images.
Fix: detect list content and extract text parts before redacting.
Image parts are replaced with '[image]' placeholder.
Duplicate of #32390 (@sontianye, opened 2026-05-26) — same fix at the same code site: |
|
Merged via PR #65046 with your commit cherry-picked onto current main — authorship preserved (8141a35). Note: the original crash premise turned out stale (redact_sensitive_text grew str() coercion in #52147, after your branch point) — but that coercion made your fix MORE valuable, not less: without flattening, the str() path dumps raw part-dict repr including base64 image data into the summarizer input. Your flattening fixes that. Follow-ups on top: remote http(s) image parts keep an '[image: ]' handle so the reference survives compaction, and unknown part types keep a '[]' marker instead of being dropped. Thanks for both contributions in this cluster. |
Summary
Fix
AttributeErrorcrash in_serialize_for_summarywhen a message has multimodal (list) content — e.g. user sends an image + text.Problem
agent/context_compressor.py:1416—msg.get("content")can return alistof content parts for multimodal messages (images, text, etc.). The code passed this list directly toredact_sensitive_text(text: str), which calls.replace()on its argument. A list has no.replace()method, so this raisesAttributeError, causing context compression to fail entirely.When compression fails, the session context grows unchecked until the provider rejects the request or the session becomes unusable.
Reproduction: Send a message with an attached image (e.g. via Telegram, Discord, or the dashboard) in a session with context compression enabled. When the compressor runs, it crashes on the multimodal message.
Fix
Detect
isinstance(content, list)before callingredact_sensitive_textand extract text/image placeholders from the parts list:{"type": "text", "text": "..."}→ extracted as-is{"type": "image_url"|"image"|"input_image"}→ replaced with[image]This follows the same pattern used in
tool_dispatch_helpers.pyandconversation_compression.pyfor handling multimodal content.Testing
3 new tests in
tests/agent/test_compressor_media_stripping.py: