Skip to content

fix: prevent stale memory overwrites on session reset (#2670)#2675

Closed
devorun wants to merge 1 commit into
NousResearch:mainfrom
devorun:patch-7
Closed

fix: prevent stale memory overwrites on session reset (#2670)#2675
devorun wants to merge 1 commit into
NousResearch:mainfrom
devorun:patch-7

Conversation

@devorun

@devorun devorun commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #2670.

The Issue:
The gateway's memory flush mechanism spawns a temporary agent to review old conversation history when a session resets or the gateway restarts. This flush agent lacks awareness of recent memory changes (e.g., from cron jobs or concurrent sessions), causing it to silently overwrite live memory with stale context.

The Fix:
This PR addresses the root cause by adding two critical safeguards to _flush_memories_for_session:

  1. Cron Session Bypass: Completely skips memory flushes for headless cron sessions (startswith("cron_")), as they have no valid conversation history to summarize.
  2. Opt-out Configuration: Allows users to explicitly disable the flush agent via memory.flush_on_reset: false in config.yaml, enabling manual memory management without unpredictable reversions.

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

)

Fixes NousResearch#2670.

**The Issue:**
The gateway's memory flush mechanism spawns a temporary agent to review old conversation history when a session resets or the gateway restarts. This flush agent lacks awareness of recent memory changes (e.g., from cron jobs or concurrent sessions), causing it to silently overwrite live memory with stale context.

**The Fix:**
This PR addresses the root cause by adding two critical safeguards to `_flush_memories_for_session`:
1. **Cron Session Bypass:** Completely skips memory flushes for headless cron sessions (`startswith("cron_")`), as they have no valid conversation history to summarize.
2. **Opt-out Configuration:** Allows users to explicitly disable the flush agent via `memory.flush_on_reset: false` in `config.yaml`, enabling manual memory management without unpredictable reversions.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #2687. Your cron session bypass idea was incorporated directly — cherry-picked onto current main with attribution preserved. The salvage PR also added live memory injection into the flush prompt (so the flush agent can see what's already saved and avoid overwrites). Thanks for identifying the cron flush path as a problem!

@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