Repository navigation
fix(memory): evict undated legacy milestones instead of crashing - #856
Open
Abolfazlrwm wants to merge 1 commit into
Open
Abolfazlrwm wants to merge 1 commit into
Abolfazlrwm wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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 attests/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:eventDatePrefixand the add/replace check (user-memory.ts:265) date from the initial release, and every in-repo writer goes through that check (edits viaapply, rollback re-saves an earlier validated revision atuser-memory.ts:682). The guard is still right becausereadUserMemorySections(user-memory.ts:594) only checkstext/dateare strings, so state outside the edit path can reach the trim. Reword to that invariant, e.g. "readUserMemorySectionsdoes 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.
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 and why
keepRecentMilestonesinapps/node-services/src/memory/user-memory.tsderived every milestone's event date with:The
!lies for any milestone whose text does not start with theYYYY-MM/YYYY-MM-DDprefix. 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 storedmilestoneshold one undated entry gets a hard crash: as soon as trimming runs (more than 8 milestones),eventDatethrowsTypeError: 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
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.Boundary
No docs: internal trim-order fix of the same memory model; no contract, path, or schema change.