fix(cli): strip memory-context fence tags from resumed history display#23393
Closed
suparious wants to merge 1 commit into
Closed
fix(cli): strip memory-context fence tags from resumed history display#23393suparious wants to merge 1 commit into
suparious wants to merge 1 commit into
Conversation
fd5d227 to
7ade8bb
Compare
66508da to
d02d58f
Compare
Two paths where memory-context fence tags leak into user-visible UI: 1. _display_resumed_history() (now in cli_agent_setup_mixin.py) renders user message content without sanitizing — raw <memory-context>...</memory-context> blocks appear in the resume recap panel. 2. chat() in cli.py stores result['messages'] directly into conversation_history without sanitizing user messages. Every turn, old blocks compound with new ones. Fix: import sanitize_context from agent.memory_manager and call it on user message text in both paths, matching the behavior of the live streaming path which already scrubs via StreamingContextScrubber.
92a2e5f to
23b2fef
Compare
Contributor
|
This looks implemented on current main. Automated hermes-sweeper review found the same leak class is now handled at the shared session-replay layer rather than inside Evidence:
Thanks for the focused fix here; main appears to have closed this via the shared replay chokepoint, which also covers sibling session-history consumers. |
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
Memory context blocks injected by memory providers (e.g., data-layer plugin, Honcho) via
build_memory_context_block()use<memory-context>fence tags. These are stripped from live streaming output byStreamingContextScrubberbut leak into the CLI's resumed history display (_display_resumed_history()).Users see raw
<memory-context>...</memory-context>blocks in their terminal when:hermes --continueAdditionally, these leaked XML-like tags can corrupt Rich Markdown parser state when backtick code spans interact with injected tags, causing response truncation in mid-sentence.
Root Cause
_display_resumed_history()at line 4282 callsstr(content)on user messages without callingsanitize_context(), unlike the streaming path at line 7431 which runs every delta throughStreamingContextScrubber.Fix
Two lines added to
cli.py:from agent.memory_manager import sanitize_contexttext = sanitize_context(text)after user message text is finalized but before displayThis strips
<memory-context>fence tags, system notes, and escapes from the display path, matching the behavior of the live streaming path.Testing
sanitize_contexttests pass (2/2)StreamingContextScrubbertests pass (17/17)Related
StreamingContextScrubberfix for streaming path)prefetch()(Honcho, data-layer, Mem0, etc.)