Repository navigation
fix(memory): only extract knowledge the user or a tool established - #4060
Conversation
Post-turn extraction saw only the user's text and the final answer, so the answer's claims were stored as facts and replayed into later sessions: "rm is blocked" (false after a permissions change), "parse_deleted now accepts z" (the answer's own claim), plus per-session narration like "User is working in /…/b4-scoping". - Extraction now receives this turn's tool record: each call, its arguments, whether it succeeded, failed, or was refused, and a brief result. - Every add/update/delete must say it is grounded in the user's message or a tool result. An op grounded in neither is dropped, and so is one citing a tool when no tool succeeded this turn. - The prompt now rules out session narration and refusals/permission limits.
Request changesGood fix for a real problem: the agent was turning its own answers into permanent "facts", and requiring every extracted item to name its source (the user's message or a tool result) is the right shape. Two things should be settled before merge. The extractor can now silently stop learning anything, and nobody would notice. Every stored item must carry a new field; if the local model doesn't reliably emit it, every item is thrown away and memory quietly goes dark — the only trace is a debug-level log line. You flagged this risk yourself and left the eval unchecked in the test plan. Please run the memory eval against the committed baseline before merging, and make the "everything was dropped" case log loudly rather than at debug. The email agent doesn't get this fix. Because of how that agent's class is composed, neither the per-turn reset nor the tool recording runs there, so its extractor is always told "no tools ran this turn" and now discards anything the model attributes to a tool. It fails safe (it stores less, not wrong things), but it's worth either fixing or saying out loud, since the agent still looks covered from the outside. 🔒 SECURITY CONCERN: tool output now flows into the memory-extraction prompt as the authoritative source of truth. Before this change the extractor only saw the user's text and the assistant's answer; content the agent fetched or read is now presented to it as evidence worth storing. Worth confirming that's the intended trust boundary for memory writes. No exploit details here — @kovtcharov-amd for the call. Real-world evidenceNo evidence bundle was produced for this PR ( 🔍 Technical details🟡 Grounding is fail-closed with no visible signal (
|
|
Merged current 🔍 Technical detailsMerge commit Tests: |
Grounding fails closed, so a model that stops emitting the field stores nothing — and at a debug line that is indistinguishable from "nothing worth storing". Extraction now warns when every proposed write was dropped for a missing or unrecognised label, naming the count, so memory going dark is visible rather than inferred. Also from review: - A crash in the turn record could replace a tool's own exception, or turn a successful call into a failure. Both _record_tool_call sites are now wrapped, matching the log_tool_call blocks beside them. - The per-entry detail sliced the whole result before truncating it, building a million-element word list on a multi-MB read to keep 240 characters. - The outcome literals are module constants now that the "ok" one gates tool-grounded extraction, with a comment on why a failed or refused call is not evidence. - MemoryMixin._record_tool_call documents that an agent listing Agent ahead of the mixin shadows it, so its extractor always sees "no tools ran".
|
Pushed fixes for the code findings. The two that still need a human are the eval and the trust-boundary question — neither is something I can settle from here. Memory going dark is now loud. The review was right that this was the risk worth guarding: grounding fails closed, so a model that stops emitting the field stores nothing, and at debug level that looks exactly like "nothing worth storing". Extraction now warns, with the count, when every proposed write was dropped for a missing or unrecognised label. The email agent really is uncovered, and I did not paper over it. I confirmed it by resolving the MRO rather than reading it: 🔒 The security question from the review is still open and is yours to call, @kovtcharov-amd. Tool output is now presented to the extractor as evidence worth storing, where before only the user's text and the answer reached it. That is a deliberate widening of what can write to memory and it is the right shape for the bug being fixed, but it is a trust-boundary decision, not a code one. I have not changed it either way. Still outstanding: 🔍 Technical details1. Fail-closed with no signal — fixed ( 2. EmailTriageAgent coverage — documented, not patched. Resolved against the real MRO:
3. Bookkeeping can no longer break a tool call. Both 4. Detail truncation. 5. 6. Cap behaviour — now tested. A 25-call turn asserts the Validation. |
The agent's memory was storing its own answers as facts. After each turn, extraction saw only the user's message and the final answer, not what the tools returned. So a wrong or outdated claim in an answer became a permanent "Known fact". In a 2,121-task benchmark sweep it stored "run_shell_command is limited to read-only operations; rm is blocked", which became false after a permissions change. It also stored the answer's own "parse_deleted now accepts z", and throwaway narration like "User is working in directory /…/b4-scoping". About 40 of the 161 memories left behind were extractions of this kind.
Extraction now also gets this turn's tool record: each call, its arguments, whether it succeeded, failed or was refused, and a short result. Every stored item must say where it came from: the user's message or a tool result. Code drops anything that doesn't, and drops a "the tool showed it" claim when no tool succeeded that turn. The instructions also rule out session narration and permission refusals.
🔍 Technical details
MemoryMixin._execute_tool, reset per turn inprocess_query, and capped at 20 calls of 240 chars each in the prompt. "Refused" comes from the result'sexecuted: Falseflag.groundedfield is dropped. Explicit "remember this" requests go through theremembertool and are unaffected.Test plan
pytest tests/unit/test_memory_extraction_grounding.py: 6 new tests on a real SQLite store, all fail on main. Covers what the tool record looks like in the prompt (ok, failed, refused), the per-turn reset, which rows get stored (answer-only and unlabeled facts dropped, user and tool-grounded kept), a tool claim with no successful tool, and an ungrounded deletepytest tests/unit -k memory: 1094 passed.tests/integration/test_memory_eval.py: 38 passedpython util/lint.py --black --isortgaia eval agenton the memory categories vs the committed baseline (extraction prompt changed)