Skip to content

fix(memory): evict undated legacy milestones instead of crashing - #856

Open
Abolfazlrwm wants to merge 1 commit into
simplexai-labs:mainfrom
Abolfazlrwm:fix/memory-undated-milestones
Open

Abolfazlrwm wants to merge 1 commit into
simplexai-labs:mainfrom
Abolfazlrwm:fix/memory-undated-milestones

Conversation

@Abolfazlrwm

Copy link
Copy Markdown

What and why

keepRecentMilestones in apps/node-services/src/memory/user-memory.ts derived every milestone's event date with:

const eventDate = (entry: UserMemoryEntry) =>
  eventDatePrefix.exec(entry.text)![0];

The ! lies for any milestone whose text does not start with the YYYY-MM/YYYY-MM-DD prefix. The add/replace validation enforces the prefix only for new edits; entries loaded from a stored revision (written before that rule existed) are never re-validated. So a Human whose stored milestones hold one undated entry gets a hard crash: as soon as trimming runs (more than 8 milestones), eventDate throws TypeError: Cannot read properties of null (reading '0') and every subsequent daily/weekly memory update for that Human fails until someone hand-edits the store.

The fix sorts undated entries before every dated one (?? ""), so the trim loop evicts them first — which is also the semantically right order for undatable legacy events (the validation message itself says "omit an undatable event").

How it was verified

  • New test in tests/memory/user-memory.test.ts: 8 milestones (1 undated + 7 dated) plus one new dated add → no throw, length back to the limit, the undated entry evicted, the new entry kept.
  • Full file: 33/33 pass; prettier + eslint clean.

Boundary

No docs: internal trim-order fix of the same memory model; no contract, path, or schema change.

keepRecentMilestones read each milestone date with
eventDatePrefix.exec(entry.text)![0]. An entry whose text lacks the
YYYY-MM prefix - for example one stored by a revision written before
the date-prefix rule - made exec return null, so every later
applyUserMemoryEdits for that human threw TypeError and the whole
memory update failed. Sort undated entries before dated ones so the
trim loop evicts them first instead of crashing.

@linger-review linger-review 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.

Approve with nits (1 P3) · merge base 17f6016 · 1 commit, 2 files

Findings

P3

  • apps/node-services/src/memory/user-memory.ts:348 (and the test comment at tests/memory/user-memory.test.ts:289): the comment explains the guard with history ("a stored revision written before the date-prefix rule"). AGENTS.md asks comments to state an invariant, not history, and the history isn't backed by this repo: eventDatePrefix and the add/replace check (user-memory.ts:265) date from the initial release, and every in-repo writer goes through that check (edits via apply, rollback re-saves an earlier validated revision at user-memory.ts:682). The guard is still right because readUserMemorySections (user-memory.ts:594) only checks text/date are strings, so state outside the edit path can reach the trim. Reword to that invariant, e.g. "readUserMemorySections does not re-check the date prefix, so a stored milestone may be undated; sort it first so trimming evicts it."

Checked: prefix enforced on every add/replace (user-memory.ts:265) · stored sections not re-validated on load (user-memory.ts:594) · new test fails without the fix with the reported TypeError (tests/memory/user-memory.test.ts:288)

Process: 3 commits behind main, needs rebase · commit author Z User <z@container> is not linked to a GitHub account

CI: no checks reported; focused user-memory.test.ts passes locally (33/33)


Automated review of d50e967 by Claude Code.

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