fix(honcho): flatten multimodal list content in sync_turn (#30252)#30264
Closed
luyao618 wants to merge 1 commit into
Closed
fix(honcho): flatten multimodal list content in sync_turn (#30252)#30264luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
…ch#30252) HonchoMemoryProvider.sync_turn previously passed user_content / assistant_content straight into sanitize_context, which expects a string. When the gateway forwarded an OpenAI vision-style multimodal turn (`content` as a list of `{type: text|image_url, ...}` parts), sanitize_context raised "expected string or bytes-like object, got 'list'". The exception was caught and logged at WARNING by the memory manager, so the chat completion still succeeded — but the turn was silently dropped from Honcho's memory, meaning the user representation never learned about anything visual the assistant was shown. Add a _flatten_content helper that collapses list-shaped content into a newline-joined string before sanitisation: - text / input_text / output_text parts contribute their `text` (non-string values are coerced via str() so a malformed part can't crash the join). - image_url / input_image parts become a literal '[image]' marker so the Honcho turn still records that visuals were exchanged. - Other typed parts become '[<type>]'. Bare strings inside the list are kept; non-dict / non-str items are skipped. Plain string callers are unaffected — _flatten_content returns the input unchanged when it is not a list. Scope kept to the Honcho plugin per the issue's scope note; other memory providers (mem0, supermemory, byterover, etc.) may share the same defect but were not investigated here. Tests: tests/honcho_plugin/test_sync_turn_multimodal.py exercises _flatten_content directly (string passthrough, multimodal flattening, input_text/output_text canonicalisation, non-string text coercion, unknown-type placeholder, empty list, bare strings, type-missing items) plus an integration check on sync_turn with a mocked manager / session that asserts list content no longer raises and the flattened text reaches the session.
af3ecae to
14ebb4f
Compare
Contributor
Author
|
Closing — open too long, no longer relevant. |
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
Fixes #30252.
HonchoMemoryProvider.sync_turnpreviously passeduser_content/assistant_contentstraight intosanitize_context, which expects astring. When the gateway forwarded an OpenAI vision-style multimodal
turn (
contentas a list of{type: text|image_url, ...}parts),sanitize_contextraisedexpected string or bytes-like object, got 'list'.The exception was caught and logged at WARNING by the memory manager, so
the chat completion still succeeded — but the turn was silently dropped
from Honcho's memory and the user representation never learned about
anything visual the assistant was shown.
Fix
Add a small
_flatten_contenthelper onHonchoMemoryProviderand callit from
sync_turnbefore sanitisation:text/input_text/output_textparts contribute theirtext(non-string values coerced via
str()so a malformed part can't crash"\n".join(...)).image_url/input_imageparts become a literal[image]marker sothe Honcho turn still records that visuals were exchanged.
[<type>]. Bare strings inside the list arekept; non-dict / non-str items are skipped.
unchanged when it isn't a list.
Scope
Per the issue's scope note, only the Honcho plugin is patched. Other
memory providers (
mem0,supermemory,byterover,retaindb,holographic,openviking) may share the same defect at theirsync_turn(user_content: str, ...)boundary but were not investigatedin this change.
Tests
New file
tests/honcho_plugin/test_sync_turn_multimodal.py— 16 tests:_flatten_contentunit coverage: string passthrough,None,text+image_url flattening,
input_text/output_textcanonicalisation, non-string
textcoercion,input_imagealias,unknown-type placeholder, empty list, bare strings inside lists,
items missing
type, non-dict/non-str items.sync_turnintegration: with a mocked_manager/ session, passinglist-shaped multimodal
user_contentno longer raises and theflattened text (
"what colour is this?\n[image]") reaches thesession; list-shaped
assistant_contentalso works; plain stringcallers still produce the unchanged messages.
Checklist