Commit Graph

2 Commits

Author SHA1 Message Date
Maciej Lisiewski
c6f6de65b4 fix(memory): fence echoed memory-context out of completed replies
A model can echo the fenced <memory-context> recall block it was given.
Streamed deltas pass StreamingContextScrubber, but a non-streamed reply left
run_conversation raw in final_response, and adapters that never stream (the
email gateway) mailed it, memory notes and tokens included, to the sender.
Interim commentary had the same gap.

Apply the streaming scrubber's grammar once to final_response at the
run_conversation exit and to interim/commentary text. It drops only
block-shaped spans, so prose mentioning the tag inline survives (the reason
the old regex scrub was removed from these paths in 4a9ac5c355). The
persisted transcript row is unchanged; reloads already sanitize it.

Fixes #81312
2026-11-12 23:25:28 +01:00
unsupportedpastels
dfc2cbeaa1 refactor(memory): move memory-context fencing into agent/memory_context.py
agent/memory_manager.py mixes provider fan-out, background work and the
text formatting that fences recalled memory for the model. The formatting
half (sanitize_context, StreamingContextScrubber, build_memory_context_block
and their regexes) is pure text work with no provider calls or profile
state, so it moves unchanged to its own module. Callers import it from
there; nothing in plugins/ imported it, so no re-export is kept.

The only visible difference is the logger name on the "pre-wrapped
context" warning (agent.memory_context). This leaves the manager room for
the profile-ownership checks the next commit adds without crossing its
line cap.

Refs #134889 (PLG-11)
Refs #140208
2026-10-17 13:28:18 -04:00