feat(memory): add a minimum-age grace period before auto-prune - #108
Open
tars23364-bit wants to merge 1 commit into
Open
feat(memory): add a minimum-age grace period before auto-prune#108tars23364-bit wants to merge 1 commit into
tars23364-bit wants to merge 1 commit into
Conversation
AutoPrune's capacity check runs on every remember and import, so a store that sits over capacity prunes on every write. An insight written into such a store can be soft-deleted in the same second it is created, before anything has read it once -- and access_count, the only protection a low-importance insight has besides importance itself, cannot rise until something does. MNEMON_PRUNE_MIN_AGE sets a grace period (Go duration) below which an insight is never auto-pruned, regardless of importance, access count, or effective_importance. Unset or zero is the default and preserves current behavior exactly; an unparseable or negative value warns on stderr and is ignored rather than widening what auto-prune may take. Verified with make test, including new store tests covering the spared young insight, the unset-default path, and env resolution.
5 tasks
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
Adds
MNEMON_PRUNE_MIN_AGE, a grace period below whichAutoPrunewill not take aninsight. An insight younger than the configured duration is spared regardless of
importance, access count, or
effective_importance.Unset (the default) is an exact no-op: auto-prune behaves as it does today.
Why
AutoPrune's capacity check runs on everyrememberand everyimport. In a storethat sits over capacity, that means a prune pass fires on every single write — so a
newly created insight can be soft-deleted in the same second it was created, before
anything has read it once.
That is the hole this closes. A low-importance insight has exactly two protections:
importance >= 4andaccess_count >= 3. Neither can help a fresh write. Importanceis fixed at write time, and
access_countcannot rise until something reads theinsight — which is precisely what has not had the chance to happen yet. Age is the only
signal that distinguishes "this was judged and found weak" from "nothing has looked at
it yet."
On my own store this is not hypothetical: it runs permanently over the 1000 cap, so
every write triggers a prune pass, and I have measured writes reaped under a second
after insert.
v0.2.1's per-prune oplog row (#96) made that visible; this makes itavoidable.
This is request 2 of #83.
How
One extra predicate on the candidate query in
autoPrune:with the cutoff formatted the same way
GetRecentInsightsInWindowalready formats itswindow bound. Resolution happens at call time (
store.PruneMinAge()), so callers andtests that set the variable after start-up see the value they set. An unparseable or
negative value is reported on stderr and ignored rather than applied, so a typo cannot
silently widen what auto-prune is allowed to take.
Scoped deliberately to
AutoPrune.mnemon gc's suggest mode still lists younginsights as retention candidates — that path is advisory and drives an explicit
operator
forget, which should stay able to name anything. Happy to extend it theretoo if you would rather the two agreed.
One interaction worth naming: in a store already over capacity, a grace window
longer than the age of every prunable insight starves the candidate set — auto-prune
finds nothing on any pass and the store grows past the cap until the oldest
candidates age out of the window. That is the intended reading of an opt-in grace
period (the operator has said "never take anything this young"), not a bug, but it
means a large value trades the cap's firmness for the grace guarantee. The sibling
PR #109 making the insight ceiling configurable (#83 request 3) is the right lever for
anyone who finds themselves there deliberately.
Checklist
make test)make test-integration) — notaffected; no CLI surface, Agency, process, or Docker boundary changes
unset-default path, and env resolution including the typo and negative cases
MNEMON_PRUNE_MIN_AGEadded to the Configurationtables in
docs/USAGE.mdanddocs/zh/USAGE.mdchange
Notes
The default is off rather than some sensible non-zero value, to keep this a pure
opt-in with no behavior change for existing stores. If you would rather ship a default
grace period (24h would cover the same-second reaping case), say so and I will change
the constant.
Sibling PR: #109 (#83 request 3). Semantically independent; both touch the same Configuration table rows and lifecycle const block, so whichever merges second carries a trivial keep-both rebase — the conflicts are expected.