Skip to content

fix: Prevent memory overwrite by flush agent (add-only constraint)#2676

Closed
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:fix/memory-flush-overwrite
Closed

fix: Prevent memory overwrite by flush agent (add-only constraint)#2676
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:fix/memory-flush-overwrite

Conversation

@dlkakbs

@dlkakbs dlkakbs commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #2670

Summary

  • Flush agent was calling replace/remove on memory entries based on stale conversation history, silently overwriting changes made by the live agent, other sessions, or cron jobs after the session ended
  • Restrict flush agent to add-only action so existing entries are never modified with stale context
  • Fixes memory revert issue observed after gateway restarts and session timeouts

Test plan

  • Start a session, write specific memory entries via the memory tool
  • Confirm entries persist to ~/.hermes/memories/MEMORY.md
  • Restart the gateway
  • Verify entries written by the live agent are preserved after restart

Type of Change

Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py: Added add-only constraint to the flush agent prompt in _flush_memories_for_session(), preventing replace/remove actions on memory entries that may have been updated since the conversation ended

How to Test

  1. Start a gateway session and write specific memory entries via the memory tool - confirm they persist to ~/.hermes/memories/MEMORY.md
  2. Restart the gateway (systemctl --user restart hermes-gateway)
  3. Check MEMORY.md - entries written by the live agent should be preserved, not reverted

…raint)

Flush agent reviewed stale conversation history and called replace/remove
on memory entries that may have been updated by the live agent, other
sessions, or cron jobs since the conversation ended. Restrict flush agent
to add-only action so existing entries are never overwritten with stale
context.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #2687. Your identification of the overwrite mechanism was spot-on. The salvage PR took a different approach — instead of restricting the flush agent to add-only, we inject the current memory state directly into the flush prompt so it can make informed decisions with full tool access. Both contributors credited. Thanks!

@teknium1 teknium1 closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory flush agent overwrites live memory on session reset/gateway restart

2 participants