You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this, and for the clean repro + tests — but we're going to close it, because both paths it touches have moved past this approach on current main.
Stream deltas (_fire_stream_delta) are already sanitized: there's a stateful streaming scrubber (#5719) that catches <memory-context> spans even when they're split across deltas. A per-delta sanitize_context() call is redundant here and actually weaker, since it can't span chunk boundaries.
Interim commentary (_emit_interim_assistant_message) is the more important one. The post-stream sanitize_context() scrub on this path was deliberately removed in commit 4a9ac5c3 ("fix(memory): drop scrub from interim commentary + final response"), which landed after this PR was opened. The reasoning there: post-stream scrubs mutate model output too broadly — a model legitimately writing docs or code that contains a literal <memory-context> string would have it silently stripped. Real leaks are handled delta-by-delta by the streaming scrubber upstream, so the post-stream scrubs were redundant and lossy.
There's now an existing test, test_interim_commentary_preserves_assistant_content, that uses the exact same input as your proposed test and asserts the opposite outcome (markers preserved). This PR would re-introduce the behavior that test was written to guard against.
So this is an intentional-design situation rather than a gap — appreciate the contribution and the thorough test plan regardless.
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
comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointP1High — major feature broken, no workaroundsweeper:blast-broadSweeper blast radius: broad — a core path most sessions hitsweeper:risk-compatibilitySweeper risk: may break existing users, config, migrations, defaults, or upgradessweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messagessweeper:risk-security-boundarySweeper risk: may affect sandboxing, auth, credentials, or sensitive datatool/memoryMemory tool and memory providerstype/bugSomething isn't working
3 participants
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
<memory-context>...</memory-context>blocks from appearing in visible assistant outputRepro
A visible assistant message included Hermes's internal memory wrapper.
[System note: The following is recalled memory context, NOT new user input. Treat as informational background data.]Example leaked shape:
Honcho Context
Example recalled memory content that should remain internal to the agent and never be shown in visible assistant output.
This should never be shown to the user.
Root cause
Two user-visible paths were missing memory-context sanitization:
AIAgent._emit_interim_assistant_message()AIAgent._fire_stream_delta()Final responses were already sanitized, but these intermediate output paths could still pass raw memory-context fences to UI callbacks.
Fix
Apply
sanitize_context(...)before surfacing:_emit_interim_assistant_message()_fire_stream_delta()Test plan