fix(sessions): guard _save_session_log against list-type assistant content - #29451
Open
EloquentBrush0x wants to merge 1 commit into
Open
fix(sessions): guard _save_session_log against list-type assistant content#29451EloquentBrush0x wants to merge 1 commit into
EloquentBrush0x wants to merge 1 commit into
Conversation
…ntent
When sessions.write_json_snapshots is enabled, _save_session_log iterates
messages and passes each assistant content value to _clean_session_content,
which expects a str. Assistant messages whose content is a list of
OpenAI-style content parts (multimodal turns, tool-use responses) cause
re.sub to raise TypeError. The outer try/except swallows the error
silently, so no session_{sid}.json is ever written for those sessions
despite the opt-in flag being set.
Add an isinstance(content, str) guard so list-type content passes through
unchanged (REASONING_SCRATCHPAD tags cannot appear in structured content
blocks, so skipping the normalisation is correct).
Add a regression test that exercises _save_session_log with an assistant
message whose content is a list containing text and tool_use parts,
asserting both that the file is written and that the list is preserved.
Contributor
|
Thanks for the focused regression fix. Current The proposed string guard is correct: list content proceeds to Automated hermes-sweeper review. |
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.
Problem
_save_session_log(introduced in #29490) silently writes no file when any assistant message in the session has list-type content — the kind produced by multimodal turns or tool-use responses where the API returns content as a list of parts rather than a bare string.The loop unconditionally calls
_clean_session_content(msg["content"]), which is typed and implemented forstr. Whencontentis a list,re.subraisesTypeError. The outertry/except Exceptionswallows it silently (only logged underverbose_logging), so users who setsessions.write_json_snapshots = truesee no JSON files and no error message._flush_messages_to_session_db, which handles the samemessageslist, already has an explicitisinstance(content, list)branch — confirming this format occurs in real sessions.Fix
Add an
isinstance(content, str)guard before the_clean_session_contentcall. List-type content passes through unchanged;REASONING_SCRATCHPADtags cannot appear in structured content blocks, so skipping normalisation for them is correct.Tests
Added
test_save_session_log_writes_with_list_contenttoTestSessionJsonSnapshotOptIn. It passes an assistant message whose content is[{"type": "text", …}, {"type": "tool_use", …}], asserts the snapshot file is written, and asserts the list is preserved unchanged.All 5 tests in
TestSessionJsonSnapshotOptInpass; 338/339 intest_run_agent.pypass (the 1 pre-existing failure is an unrelated missingopenaimodule in the local env).Checklist
write_json_snapshots = trueand a session containing tool calls before the fixwrite_json_snapshotsis false (fast no-op path is unchanged)