Skip to content

fix(memory): forget the older versions a forgotten memory superseded - #7269

Merged
kovtcharov-amd merged 2 commits into
mainfrom
autofix/issue-7266
Nov 12, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
autofix/issue-7266

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

When the user forgot a fact that had replaced an older version, only the current version was erased. The older versions stayed on disk with their full text. Recall and the Memory page hid them, but they were still stored, which broke the promise that "forget" erases the fact. Now forget erases every older version too, and records each one as forgotten so it isn't learned again from old chats. A sensitive version is recorded as word stems only.

Closes #7266

Test plan

  • python -m pytest tests/unit/test_memory_forget_superseded.py passes (2 of its 4 tests fail on main)
  • python util/lint.py --all passes
  • Memory/forget unit tests pass (pytest tests/unit -k "memory or forget": 2572 passed; 25 collection errors are modules this runner lacks, responses/matplotlib)
  • Tell GAIA a fact, then correct it so the newer memory supersedes the old one. Forget it, then open ~/.gaia/memory.db and confirm neither version is in knowledge
🔍 Technical details
  • MemoryStore.forget gathers the target plus every row that reaches it through superseded_by, using a recursive CTE. UNION rather than UNION ALL, so a cycle (consolidation can link two rows either way) terminates. Each row is checked against the privileged-category rule, removed from knowledge_fts and knowledge, and written to forgotten (stems if sensitive), all in one transaction.
  • Forgetting an older version leaves the newer one untouched: the walk only follows rows that were superseded.
  • No vector-index change is needed. Superseded rows are dropped from FAISS when they're superseded (_faiss_remove(old_id)), and the index is rebuilt from active rows only.
  • This may conflict textually with fix(memory): keep one copy of a sensitive fact, and forget every copy by id #7212, which also edits forget. The two changes are complementary.

Forgetting a fact deleted only the current row; the versions it had
replaced kept their full text on disk. forget() now walks the
superseded_by chain and deletes each older version too, recording it as
forgotten (word stems only when sensitive), in the same transaction.

Closes #7266
Resolves the conflict with #7212 in MemoryStore.forget: the superseded-chain
walk keeps main's sensitive argument, and if any version in the chain is
sensitive every version is kept as stems only, so an unflagged old version
can't leave a sensitive fact's words in forgotten.

Adds tests for that, for a supersede cycle, and for forget_with_copies
taking a copy's older versions with it.
@github-actions github-actions Bot added tests Test changes agents labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Verdict: Approve

Forgetting a memory now erases every older version it replaced, not just the current one. Before this, the earlier wording stayed on disk even after the user said "forget". The fix is correct and stays within one transaction, so a failure part-way leaves nothing half-erased. A replacement loop between two memories can't make it hang. Forgetting an old version leaves the newer one in place. The tests cover each of these cases, plus the sensitive-version and copy paths.

No blocking issues. Both callers (the chat agent's forget tool and the Memory page's delete) go through the changed method, so neither path keeps the old behaviour.

🔍 Technical details
  • Privileged rows in a chain: _validate_existing_category_locked now runs for every row in the chain, so a privileged older version would make the chat tool's forget fail with a ValueError. That can't happen through today's write paths: both supersede sites in memory.py (the extraction update around line 3034 and the contradiction pass around line 3547) only link extractable-category rows. Worth keeping in mind if a future path supersedes across categories.
  • Index cleanup: forget_with_copies still returns only the primary row and its copies, so the caller's _faiss_remove / _refresh_if_shown loop skips the older versions. That's fine: superseded rows are removed from FAISS when they're superseded, and they're already hidden from recall and the Memory page.
  • The new test file is in tests/unit/, so the unit lane collects it.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 07c75a0 Nov 12, 2026
47 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the autofix/issue-7266 branch November 12, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forget leaves superseded versions of a fact in the memory database

1 participant