Skip to content

fix(memory): label recalled memory as informational, not authoritativ… - #28001

Closed
LifeJiggy wants to merge 2 commits into
NousResearch:mainfrom
LifeJiggy:fix/memory-recall-recency
Closed

LifeJiggy wants to merge 2 commits into
NousResearch:mainfrom
LifeJiggy:fix/memory-recall-recency

Conversation

@LifeJiggy

Copy link
Copy Markdown
Contributor

What does this PR do?

Two interacting problems caused the agent to report false project status and mutate files based on stale memory:

  1. Memory context system note told the LLM to treat recalled memory as "authoritative reference data" — directly encouraging trust in potentially stale information. Changed to "informational background data (may be stale)" so the model treats memory as suggestive context, not ground truth.
  2. No git baseline verification before file writes — the agent could write to files without checking whether the working tree was clean, making it impossible to detect when its memory was out of sync with actual project state. Added a _check_git_baseline() method that warns before write_file if uncommitted changes exist.

Related Issue
Fixes #17164

Type of Change

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

Changes Made

  • agent/memory_manager.py:
    • build_memory_context_block(): system note now says "informational background data (may be stale)" instead of "authoritative reference data"
    • _INTERNAL_NOTE_RE: updated regex to match both old and new phrasings
  • tools/file_operations.py:
    • ShellFileOperations._check_git_baseline(): new method that detects dirty git working trees
    • ShellFileOperations.write_file(): calls git baseline check before writing, includes warning in result when tree is dirty

How to Test

  1. Create a conversation where memory contains stale project status
  2. Verify the LLM treats it as informational rather than authoritative (checks git status or asks for confirmation)
  3. Make a file write in a dirty git repo — verify a "dirty working tree" warning appears in the result
  4. Make a file write in a clean git repo — verify no warning appears

…e, and add git baseline check before file writes

Changes:
- Change memory context system note from 'authoritative reference data' to
  'informational background data (may be stale)' so the LLM treats recalled
  memory as potentially stale rather than ground truth
- Update _INTERNAL_NOTE_RE regex to match both old and new phrasings
- Add _check_git_baseline() to ShellFileOperations — warns before write_file
  when the git working tree has uncommitted changes, preventing mutations
  based on stale or inaccurate memory
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/memory Memory tool and memory providers tool/file File tools (read, write, patch, search) labels May 18, 2026
@BoardJames-Bot

Copy link
Copy Markdown

BoardJames triage: I do not see a branch-local failure in the memory/file-operations change. All non-test checks are green (including build-arm64); the remaining blocker is the full Tests / test job cancelling after ~20m with no failed-log details, same as neighboring PRs/current shared suite drift. Local focused validation passed: python -m py_compile agent/memory_manager.py tools/file_operations.py and python -m pytest tests/run_agent/test_run_agent.py::TestMemoryContextSanitization tests/tools/test_file_operations.py::TestWriteResult -q --tb=short => 4 passed. Next action is shared CI/main unblock + rerun.

@outsourc-e outsourc-e left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Local read-through only for now. The memory-context wording change looks directionally right, but this PR also changes write_file behavior globally by adding a git-baseline warning path, and there are no focused regression tests for that broader behavior in the branch. I would split this: (1) the memory prompt wording/regex cleanup, and (2) any write-safety/file-op behavior with explicit tests on the returned warning contract.

…e_file

Adds TestGitBaselineCheck with 6 unit tests covering _check_git_baseline
and the warning field in write_file result:
- Git not available → None
- Not in a git repo → None
- Clean repo → None
- Dirty repo → returns warning string with branch name
- write_file result includes warning when dirty
- write_file result omits warning when clean
@teknium1

Copy link
Copy Markdown
Collaborator

Merged via PR #28583 (cherry-picked onto current main with your authorship preserved via rebase-merge — commit 0b89628). Thanks for the contribution!

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

Labels

P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) 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.

Critical: memory/session recall can report false project status and mutate files without verified baseline

5 participants