Skip to content

feat(agent-memory): Phase 3 — forget / forgetByScope#250

Open
jamby77 wants to merge 2 commits into
feature/agent-memory-phase2-recallfrom
feature/agent-memory-phase3-forget
Open

feat(agent-memory): Phase 3 — forget / forgetByScope#250
jamby77 wants to merge 2 commits into
feature/agent-memory-phase2-recallfrom
feature/agent-memory-phase3-forget

Conversation

@jamby77

@jamby77 jamby77 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Agent Memory — Phase 3: forget / forgetByScope

Stacked on #249 (Phase 2).

What's new

  • forget(id) → DEL {name}:mem:{id}; idempotent (returns whether the memory existed).
  • forgetByScope(scope & {tags?}) → finds matches via an escaped scope/tag FT.SEARCH filter, DELs them in batches, returns the count. Throws when no scope field or tag is given (prevents an accidental delete-everything).
  • Extracted shared buildScopeFilter (used by both recall and forget); escapeTag neutralizes glob chars so a threadId of '*' matches literally, not everything.

Design note

The plan says "SCAN-matches scope/tags", but scope/tags are HASH fields (TAG-indexed), not part of the key ({name}:mem:{uuid}) — a key SCAN can't filter on them. So forgetByScope uses an FT.SEARCH filter query, which is the correct mechanism.

Tests

27 unit tests; tsc --noEmit + prettier clean.

Review-driven change

  • Batched pagination instead of a 10000-row cap — the first pass deleted only the first 10k matches and reported that as success (silent truncation for large scopes). Now loops FT.SEARCH(LIMIT 0 500) → DEL batch → repeat, with a seen set so it terminates even under index-update lag.

Next

Phase 4 (recall reinforcement — bump lastAccessedAt/accessCount on recalled items).


Note

Medium Risk
Introduces destructive bulk deletes against persisted agent memory, though scoped filters, empty-scope errors, and batch-cap warnings reduce accidental data loss risk.

Overview
Adds memory deletion to MemoryStore: forget(id) removes one hash via DEL and returns whether it existed; forgetByScope finds memories with the same escaped scope/tag FT.SEARCH filter used for recall, deletes them in 500-key batches (loop until empty or no progress), and returns the total deleted count.

buildScopeFilter is extracted from buildRecallQuery so recall and forget share identical filter semantics (including escapeTag for literal * etc.). forgetByScope rejects an empty scope so callers cannot wipe the index by accident; hitting the 10k-batch safety cap logs a warning when more matches may remain.

New unit tests cover idempotency, filter shape, glob escaping, pagination, and the cap warning.

Reviewed by Cursor Bugbot for commit 8ab239a. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread packages/agent-memory/src/MemoryStore.ts
@jamby77 jamby77 force-pushed the feature/agent-memory-phase2-recall branch from 50a2011 to 13a2279 Compare June 16, 2026 16:59
@jamby77 jamby77 force-pushed the feature/agent-memory-phase3-forget branch from dad22d0 to a102ad0 Compare June 16, 2026 17:04
- forget(id): DEL {name}:mem:{id}, idempotent (returns whether it existed)
- forgetByScope(scope+tags): FT.SEARCH by escaped scope/tag filter, DEL the
  matches, return count; throws when no filter is given (prevents mass delete)
- Extract shared buildScopeFilter() used by recall + forget; escapeTag prevents
  glob over-match (a threadId of '*' matches literally, not everything)
@jamby77 jamby77 force-pushed the feature/agent-memory-phase2-recall branch from 13a2279 to df17cbd Compare June 18, 2026 06:57
@jamby77 jamby77 force-pushed the feature/agent-memory-phase3-forget branch from a102ad0 to 3dc84bb Compare June 18, 2026 06:57

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3dc84bb. Configure here.

Comment thread packages/agent-memory/src/MemoryStore.ts
A scope larger than FORGET_MAX_BATCHES would stop deleting and return a
partial count that reads as a completed operation. Emit a warning so the
silent cap is observable and callers know to re-run.
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.

1 participant