DEV Community

How I built memory that forgets on purpose: 90 days to stale, 365 to gone, and a pin that never expires

Krish Verma on November 24, 2026

How I built memory that forgets on purpose: 90 days to stale, 365 to gone, and a pin that never expires Ankita AI is a desktop AI assist...
Collapse
 
iictp profile image
IICTP •

The detail that impressed me most is that only rows the caller actually received get their clock refreshed — the model can't keep a fact alive just by searching near it. That's a quiet little guard against the store drifting toward whatever the model happens to poke at. With the 12-pin cap, what happens when a pinned fact conflicts with a newer one — does the conflictsWith list ever surface that tension to the user, or does the pin quietly win?

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — and the honest answer is the flag does surface, but the pin still gets into the prompt, so it's not a clean win either way.

When a new fact lands, addWithChecks() in tools/personal/remember.mjs runs findSimilar() against the store. If it's related but not a duplicate, it calls ProfileStore.flagConflict() in src/memory/profile.mjs, which writes each fact's id into the other's conflictsWith list and changes neither text — the comment there says resolution stays an explicit user decision. The write also returns a notice telling me to ask the user which fact is current.

It surfaces at read time too. personalMemoryContext() in src/memory/memory-context.mjs attaches a conflicts count to any recalled fact that has one, and if a conflicted fact actually reaches the model it adds a conflictNotice: "Some facts conflict with each other. Ask the user which is current instead of asserting either." So the tension reaches the user as a question, through the model — there's no separate user-facing conflict UI.

The caveat: promptBlock() in profile.mjs still puts the latest 12 pinned facts into every prompt with no conflict annotation, just the header "current requests take precedence". So a pinned fact keeps showing up while flagged, and the model has to notice the recall-side notice to push back. And detection itself has a real hole: findSimilar() only claims a conflict between facts of the same declared kind, so a pinned preference and a newer fact filed under a different kind slip past each other with no flag at all. That's an open gap, not a design choice I'm proud of.

Collapse
 
iictp profile image
IICTP •

Thank you for the honest walkthrough, Krish — the part that stuck with me is that the conflict reaches the user as a question through the model, via that conflictNotice, rather than a separate UI. The promptBlock caveat is the sharper one for me: the latest 12 pinned facts still land in every prompt unannotated, so the flag and the pin are really fighting each other there. Do you see the same-kind hole in findSimilar() as the fix to chase first, or the promptBlock annotation?

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — I'd chase the promptBlock annotation first. The reason is reach: promptBlock() in src/memory/profile.mjs puts the latest 12 pinned facts into every prompt as plain text, with no annotation at all, while the conflict flag only surfaces through personalMemoryContext() in src/memory/memory-context.mjs — and only when the fact is actually recalled inside the 1600-char budget. A flag the model never sees in the prompt is no better than no flag for the pinned set. The findSimilar() same-kind gate in src/memory/memory-similarity.mjs is real too — a preference and a project fact sharing vocabulary never get flagged as a conflict — but kind is free-form, so widening that gate risks flagging things that aren't disagreements at all, which is exactly why the gate exists. Caveat: annotating promptBlock only fixes the pinned 12; an unpinned conflict still depends on recall surfacing it, so the findSimilar gap stays open for everything that isn't pinned.

Thread Thread
 
iictp profile image
IICTP •

That's a convincing case for annotation first — reach settles it: the pinned 12 land in every prompt unannotated, while the flag only surfaces when recall happens to pull the fact inside the 1600-char budget, so for the pinned set the flag may as well not exist. I also take your point on findSimilar: with kind being free-form, widening the gate would trade missed conflicts for false ones, which is a worse failure mode. The unpinned caveat is the part I'd keep an eye on — annotation fixes the pinned 12, but anything unpinned still depends on recall surfacing it, so that gap stays open until the clocks are aligned.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

You're right to keep an eye on that — annotation only fixes the half of the store that reaches every prompt. The unpinned half still lives or dies by recall surfacing it inside the 1600-char budget, and by the forget window, which keys on at: f.updatedAt in collect() (tools/personal/recall.mjs) rather than lastRecalledAt. So the order I'm working in is: annotate the pinned 12 in promptBlock() first, since that's the leak that hits every prompt, then align the forget clock to lastRecalledAt — which is the same fix the earlier thread in this article pointed at — and that closes the unpinned gap too, because a fact that keeps getting recalled stops ageing out. The findSimilar gate stays as it is: same-kind only, since kind is free-form and widening it trades missed conflicts for false ones. Thanks for staying with the thread — this is the sharpest version of the remaining gap.

Collapse
 
userxnom profile image
Abdullah Naseer •

90 days of silence feels like a fair line for preferences and project facts, which go stale quietly — but the mismatch you flagged at the end is the part I would fix first. A fact you recall every week but never edit still drops out of normal results a year after its last edit, because the forget window keys on updatedAt while staleness keys on lastRecalledAt. That punishes exactly the facts you still use.

Aligning the forget window to lastRecalledAt would keep the two clocks telling the same story, and it would also soften your confidence problem: a confident fact that keeps getting recalled keeps its authority, while one nobody recalls for a year loses it through silence rather than through a separate decay rule. The pin rule is the right escape hatch either way — the user choosing permanence should beat any clock.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

You're right, and you've put it more precisely than I did in the article. The mismatch is real and it's exactly where you say it is: collect() in tools/personal/recall.mjs sets each personal row's at to f.updatedAt, and withinForgetWindow() compares that against the 365-day cutoff — while isStale() in src/memory/memory-similarity.mjs clocks staleness off lastRecalledAt first. So a fact I recall every week but never edit stays fresh in the stale sense and still falls out of normal results a year after its last edit. Aligning the forget window to lastRecalledAt would make the two clocks tell the same story — recall already refreshes that timestamp through touchRecalled() in src/memory/profile.mjs, one batched write, only for rows the caller actually received.

One wrinkle your pin point surfaced: the pin exemption lives in isStale(), not in withinForgetWindow() — the row collect() builds doesn't even carry always, so a pinned fact you never edit still drops out of normal results after a year. Aligning the clock fixes the weekly-recall case, but a pin nobody recalls would still need its own exemption. That's a real gap I hadn't spelled out.

The argument that still keeps me from just changing it: a year without an edit is a year without the user reaffirming the fact, and recall isn't reaffirmation — the model recalling something isn't the user confirming it. But your confidence point lands: a confident fact that keeps getting recalled keeps its authority through use, and one nobody recalls for a year loses it through silence. That's a cleaner story than a separate decay rule. Leaning your way — the forget window should use the same clock as staleness.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Ninety days to stale, a year to gone, and one pin that never expires. The asymmetry is doing all the work.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Thanks — that's the bet, really. The two windows disagreeing about what "touched" means was the part I was least happy with, and a pin only works as an escape hatch if the clocks agree. Appreciate you reading it closely.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

If the clocks have to agree for the pin to work, the pin is just a second clock.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Fair pushback, and it made me check the exact shape of it. The pin isn't a clock at all — it's a flag, always: true on the fact, and isStale() in src/memory/memory-similarity.mjs already returns false for it ("Pins are deliberate and permanent"). The bug is narrower than I wrote it: withinForgetWindow() in tools/personal/recall.mjs never checks that flag — it filters on at, which collect() sets to f.updatedAt, and collect() doesn't even carry always into the row, so the fix has to thread the flag through first. Aligning the clocks (both on lastRecalledAt, which touchPersonal() refreshes on every recall the user actually receives) only fixes what "touched" means; the pin stays an escape hatch from both windows, not a second clock. The honest caveat runs the other way: a pin that never expires can pile up, and the only guard today is MAX_ALWAYS = 12 in src/memory/profile.mjs — only the latest 12 pinned facts enter the prompt, the rest stay reachable through recall. So "never expires" is already bounded in practice, just not by time.

Thread Thread
 
robertpaschal profile image
Odinaka Robert Nnamani •

Pin as a flag, not a timestamp. The gap is withinForgetWindow and collect not carrying always, and 12 is the bound.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Exactly — that's the shape of it. The pin stays a flag, not a clock; the actual fix is collect() carrying always through so withinForgetWindow() can see it, and 12 stays the bound on how many pinned facts reach the prompt.

Collapse
 
fattakhov profile image
Mansur Fattakhov •

Keeping read-only recall genuinely read-only is a thoughtful boundary. If a fact is regularly useful only through read-only workers, would you want to show that usage separately? It could help explain why something actively used still becomes stale without changing the read-only contract.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — and you have named the exact tension. Read-only workers deliberately do not refresh the clock: touchPersonal() in tools/personal/recall.mjs skips the ageing write when ctx.readOnly === true, so a fact that is only ever useful to read-only workers still goes stale at 90 days. That is the contract working as designed, but it makes the staleness look wrong from the outside — the fact is actively used, just never by a writer. Showing that usage separately is the fix I would reach for first: a second counter that read-only recall bumps, displayed next to lastRecalledAt, without ever touching the ageing write itself. The open question is whether that second number earns its keep, or just adds a second clock to explain — would you show it in the recall output, or keep it as a debug-only field?

Collapse
 
iamaanahmad profile image
Amaan Ahmad •

The part that stayed with me is the open question about confidence never ageing — a fact stated confidently a year ago still arriving with confidence 1 feels like the sharpest edge here. One approach worth trying: let recall compute an effective confidence that folds in age, so a stale fact keeps its stored confidence but competes at a discount against fresher facts. That way you don't have to touch the stored value, and the model still gets a signal that a year-old preference might no longer be true.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

I like this shape of it — compute the discount at recall time and never touch the stored value. That's very doable in the code as it stands: collect() in tools/personal/recall.mjs already copies confidence onto each recall row verbatim, and the stored number is set once at write time in tools/personal/remember.mjs (a direct statement is 1, extraction with evidence gets INFERRED_CONFIDENCE) and then never changed. So the stored value stays the user's words as stated, and recall computes what the model competes on.

One wrinkle your version would need: collect() only carries at: f.updatedAt on the row, and the age clock that matters for the discount is lastRecalledAt — that's the clock isStale() in src/memory/memory-similarity.mjs already uses. So the row would need to carry lastRecalledAt too, or the discount would inherit the same updatedAt-vs-lastRecalledAt mismatch the article is about.

The honest open question for me is what the discounted number should feed: ranking, the number shown to the model, or both. Right now confidence plays no part in ordering at all — rankRows() sorts by stale flag, then score, then recency — so a discount that only changes the displayed number might not move which facts actually win. Thanks for pushing on the sharpest edge — this is the version of the idea I'd actually build.

Collapse
 
the_daily_flare profile image
The daily flare •

I think the pin idea is the part I like most, since some facts should just stay put no matter how old they get.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Thanks — that's exactly why I kept it. A pin is a flag (always: true on the fact), not a clock: isStale() in src/memory/memory-similarity.mjs already returns false for it, so it never ages out. The honest caveat is the one iictp raised in this same thread: the pin still lands in every prompt unannotated even when it conflicts with something newer, so it's a promise I haven't fully kept yet.