Skip to content

fix(memory): skip drift guard for add (append-only) action - #42880

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/memory-add-drift-guard
Closed

fix(memory): skip drift guard for add (append-only) action#42880
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/memory-add-drift-guard

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Skips the drift guard for memory(action=add) which only appends and never overwrites existing content. The drift guard (introduced for #26045) correctly protects replace/remove from clobbering un-roundtrippable content, but firing it on add causes false positives when prior add() calls in the same session shift the byte count of the on-disk file.

Related Issue

Fixes #42874

Type of Change

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

Changes Made

  • tools/memory_tool.py: Added skip_drift keyword parameter to _reload_target(); add() passes skip_drift=True while replace()/remove() continue using the drift guard unchanged
  • tests/tools/test_memory_tool.py: Updated test_add_succeeds_despite_drift (was test_add_refuses_on_drift) to verify add succeeds under drift; updated test_drift_backup_filename_is_unique_per_invocation to use replace/remove since add no longer triggers drift

How to Test

  1. Start a fresh Hermes session with existing MEMORY.md content
  2. Perform multiple memory(action=add) calls in the same session
  3. Verify subsequent add calls succeed without "Refusing to write" errors
  4. Verify memory(action=replace) still refuses when external drift is present
  5. Run pytest tests/tools/test_memory_tool.py -v — all 69 tests pass

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/tools/test_memory_tool.py -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: macOS

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

Code Intelligence

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Fixes NousResearch#42874
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround tool/memory Memory tool and memory providers labels Jun 9, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Changes Overview

  • Fixes issue #42874: add (append-only) action no longer triggers drift detection
  • Adds skip_drift parameter to _reload_target method
  • Updates tests to reflect the corrected behavior

Analysis

Correctness

  • The fix is logically sound: drift detection guards against clobbering un-roundtrippable content during replace/remove (which rewrite the full file), but add only appends — it can never overwrite existing content
  • The skip_drift=True parameter is cleanly implemented and well-documented in the docstring

Security

  • No security concerns: this is a pure in-memory/file storage fix with no user-input or network components

Code Quality

  • Well-scoped single concern (issue #42874)
  • Clear documentation explains the rationale for the behavior change
  • Good test coverage with descriptive test name (test_add_succeeds_despite_drift)
  • Test comment clarifies the intended behavior vs. the old (incorrect) behavior

Testing

  • Dedicated test for the new behavior
  • Existing test (test_drift_backup_filename_is_unique_per_invocation) updated to use remove instead of add for the second drift-inducing operation (since add no longer triggers drift)

Minor Note

  • The existing test name test_drift_backup_filename_is_unique_per_invocation still validates that unique .bak filenames are created, but now tests the remove path instead of add. The comment added to that test helps clarify the intent.

Reviewed by Hermes Agent

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jun 21, 2026
kshitijk4poor pushed a commit that referenced this pull request Jun 24, 2026
The drift guard (introduced for #26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from #42880 by @liuhao1024.

Closes #42874
pai-scaffolde pushed a commit to pai-scaffolde/hermes-agent that referenced this pull request Jun 28, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this PR's fix has already been implemented on main.

Evidence:

  • tools/memory_tool.py:251 now has _reload_target(..., skip_drift=False) and bypasses drift detection when skip_drift=True.
  • tools/memory_tool.py:311 shows MemoryStore.add() calling _reload_target(target, skip_drift=True), while replace/remove still use the drift guard at tools/memory_tool.py:366 and tools/memory_tool.py:423.
  • tests/tools/test_memory_tool.py:607 includes test_add_succeeds_despite_drift, covering the behavior this PR requested.
  • Commit 25e2312230ca95f843ee31a93c65899a9fe01272 landed the fix and explicitly notes it was salvaged from fix(memory): skip drift guard for add (append-only) action #42880 by @liuhao1024.

Thanks for the original fix — it made it into main.

@teknium1 teknium1 closed this Jun 29, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 29, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…rch#42874)

The drift guard (introduced for NousResearch#26045) correctly protects replace/remove
from clobbering un-roundtrippable content, but it also fires on the add
path. Since add only appends and never overwrites, the guard is
unnecessary and causes false positives when prior add() calls in the same
session shift the byte count of the on-disk file.

Add skip_drift parameter to _reload_target() and pass True from add().
Replace/remove continue to use the drift guard unchanged.

Salvaged from NousResearch#42880 by @liuhao1024.

Closes NousResearch#42874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High — major feature broken, no workaround sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] memory(action=add) refuses legitimate appends when disk MEMORY.md byte size differs from in-memory base cache (drift guard over-reach, ref #26045)

4 participants