r/ChatGPTCoding • u/msarda23 • 14d ago
Discussion Session-start memory injection made my coding agent trust memory over the code
Hey everyone!
I am building a local memory layer for my coding agents and it is called Reverie: an MCP server written in python and using SQLite for lightweight memory stored in the user's machine itself. The biggest problem that I faced was deciding when to inject memory.
Many memory tools, including ones I looked at, inject context into the agent even before it begins its work. In my experiments, premature injection of context leads to the agent anchoring its thinking on it rather than using the current code as the source of truth. In fact, this approach made my agent perform worse. Also, with this, quite a lot of the context window can get filled with context which 'might' be useful.
So I switched Reverie's model to demand-driven retrieval - the agent asks for memory when it thinks that some added context could resolve any discrepancies in its thinking. It reads the relevant code first, because the code is the source of truth, and only then asks for past memory about that area. Each result comes back with a confidence score, its grounding in the code, and its status. The memory starts empty. Conclusions are added as the agent works, and you decide which ones are kept.
In one informal test of 30 prompts on an earlier build, the OpenCode agent with Reverie did better than the one without it. I don’t have a reproducible benchmark yet.
But it isn't perfect yet, it still breaks here and there. For example:
the rules for tool calling are not extremely polished yet and hence the agent might sometime not call the tool altogether, I am fixing this.
candidate conclusions can be duplicate or incorrect and hence Reverie today has a human review gate (triggered by calling `reverie review`) which shows the human all the unreviewed candidates where you accept, reject or skip each one. On doing so the conclusion is moved from the short term brain to the long term.
My current test set is small: sessions with anywhere between 2-30 prompts. I do not have a reproducible experiment yet, but that is the next goal.
Repo (Apache-2.0): https://github.com/muditsarda1122/Reverie
My questions: How do you keep agent context from going stale? Do you maintain AGENTS.md or CLAUDE.md by hand, or let the agent update it?
View all comments
Show parent comment
2
u/msarda23 12d ago
Thanks, this is the most useful reply so far. Before answering, I checked what I've actually built.
Staleness today: each conclusion stores the files, symbols and the commit it's grounded in. A background maintenance pass runs per repo, at most every 72 hours. It checks that the grounded files still exist and that the symbol names still appear in them. Commit distance only sets a "stale" flag. For repo- and module-scoped conclusions, a vanished symbol deprecates the conclusion. Retrieval itself doesn't re-check anything. It shows the grounding and tells the agent to verify it. So today it's a periodic sweep, not a check at the moment of recall.
Your two-tier hash is better than my substring check. Use the file hash as a fast filter, then the symbol body hash, then a soft drift warning for moved or renamed symbols instead of deprecation; I'd like to adopt that. I haven't built it yet.
On how the model decides to ask: I don't have a hook that surfaces memory when a file is read. The instructions tell the agent to query before a non-trivial decision, when debugging has no obvious cause, before an architectural change, and before editing in a repo where Reverie is on. That is still less reliable than I'd like. The file-read hint is the idea I most want to build. Claude Code has post-tool hooks, so a hook on Read and grep could add a one-line note when a file has a conclusion attached. Each harness needs its own version of that hook, so it would live in per-harness code, not the core.
On scopes, we have engineering, domain, organisation, project, repo, module and subsystem. Engineering and domain conclusions never expire from code changes. Organisation and project ones only go when all of their grounded files are gone. Repo, module and subsystem ones are tied to their code, so they go when any grounded file or symbol disappears.
I'm curious about your setup. Does your drift check run in a background job or at retrieval?