fix(memory): skip drift guard for add (append-only) action - #42880
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(memory): skip drift guard for add (append-only) action#42880liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
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
tonydwb
approved these changes
Jun 9, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Changes Overview
- Fixes issue #42874: add (append-only) action no longer triggers drift detection
- Adds
skip_driftparameter to_reload_targetmethod - 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=Trueparameter 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 useremoveinstead ofaddfor the second drift-inducing operation (sinceaddno longer triggers drift)
Minor Note
- The existing test name
test_drift_backup_filename_is_unique_per_invocationstill validates that unique .bak filenames are created, but now tests theremovepath instead ofadd. The comment added to that test helps clarify the intent.
Reviewed by Hermes Agent
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
Contributor
|
Automated hermes-sweeper review: this PR's fix has already been implemented on main. Evidence:
Thanks for the original fix — it made it into main. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 protectsreplace/removefrom clobbering un-roundtrippable content, but firing it onaddcauses false positives when prioradd()calls in the same session shift the byte count of the on-disk file.Related Issue
Fixes #42874
Type of Change
Changes Made
tools/memory_tool.py: Addedskip_driftkeyword parameter to_reload_target();add()passesskip_drift=Truewhilereplace()/remove()continue using the drift guard unchangedtests/tools/test_memory_tool.py: Updatedtest_add_succeeds_despite_drift(wastest_add_refuses_on_drift) to verify add succeeds under drift; updatedtest_drift_backup_filename_is_unique_per_invocationto usereplace/removesinceaddno longer triggers driftHow to Test
MEMORY.mdcontentmemory(action=add)calls in the same sessionaddcalls succeed without "Refusing to write" errorsmemory(action=replace)still refuses when external drift is presentpytest tests/tools/test_memory_tool.py -v— all 69 tests passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/tools/test_memory_tool.py -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
tools/memory_tool.py—_reload_target()(callers: 3),_detect_external_drift()(callers: 1)add()path changed;replace()/remove()unchanged