Repository navigation
fix(vault): trim the changes log in the daily prune pass - #236
Merged
Merged
Conversation
The changes table grew without bound: PruneChanges existed, but nothing called it. The daily prune pass now deletes the durable events older than Config.Keep (30 days, as for versions) and all but the newest Config.KeepEvents (100,000). A subscriber older than the retained log gets resync, as the protocol says. events.subscribe now reads the oldest retained seq again after it reads the replay, so a prune between its reads gives resync, not a replay with a gap. ADR-0044 (Proposed) records the rule; docs/design/vault.md and docs/specs/rpc-protocol.md describe it. Closes #219
An event's time is the wall clock at its commit, and the clock can go back, so `at < cutoff` could delete an event between two kept ones. A subscriber from before the gap then got a replay with a gap and no resync, since the broker checks only the oldest retained seq. The age rule now deletes up to the newest event recorded before the cutoff. The docs also say that the limits hold after each pass, not between passes. Guard: store.TestPruneChangesByAgeLeavesNoGap, and a record in .memory/corrections/ (cross-review of #236).
bketelsen
approved these changes
Nov 14, 2026
1 task done
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.
Summary
notesd's durable event log, the
changestable, grew without bound:store.DB.PruneChangesexisted, but nothing called it. Closes #219.Manager.Prune) deletes the durable events recorded more than 30 days ago (Config.Keep, the same window as local versions) and all but the newest 100,000 (Config.KeepEvents, about 20 MB). The age rule follows ADR-0021's need to replay moves made while an app was closed. The count cap bounds the table during a burst (a first scan, a bulk move).resync: both apps reload the vault list and the open vault on every connection already. A client away longer than the retained log loses only this: its tabs do not follow the moves of that time (ADR-0021). The latest seq survives a prune (AUTOINCREMENT), so a client that saw it resumes even when the log is empty.events.subscribereads the log.store.ChangesSinceandstore.OldestSeqhave one caller,events.Broker.Subscribe. Thechangesinstore.Pending(internal/store/remotes.go) is a CTE alias overfilesandsync_files, not the table. The sync loop subscribes withoutsinceSeq(internal/syncer/loop.go), and the hub's log is therevisionstable.Broker.Subscribe: a prune between the check of the oldest seq and the replay read could give a replay with a gap and noresync. The broker now reads the oldest seq again after the replay. A prune deletes only from the oldest end, so this second read is enough.PruneChangesstays in the store (grooming: dead and duplicated code after the native desktop move #213). It now takes an age cutoff and returns the number of rows it deleted.Risk tier
Risk tier: 2 — behaviour change in code: notesd now deletes rows of its own event log, and
events.subscribeanswersresyncto a client older than the retained log. No vault file, version, sync state or API contract changes. No path in.github/risk-paths.jsonmatches.Docs housekeeping
TEMPLATE.mddocs/README.mdVerification
make checkgreen (host)PruneChangescall removed fromManager.Prune,go test ./internal/vault -run TestPruneTrimsTheChangesLogfails ("want resync").internal/events/broker.gofrommain,go test ./internal/events -run TestResyncWhenPrunedDuringTheReplayReadfails ("want resync at seq 4").internal/store/changes.gofromcf96312,go test ./internal/store -run TestPruneChangesByAgeLeavesNoGapfails ("PruneChanges = 1, ; want seqs 1 and 2 deleted")..memory/corrections/Review
Cross-review by
openai/gpt-6.1-sol(coderanthropic/claude-opus-5-5), basebac5e976271515126740f6b736eda6ce989ca8d6:cf96312af19b015d00fd9654bc7f11b654f4c3d8: Not ready, 2 findings.at < cutoff) could delete an event between 2 kept ones when the wall clock went back. A subscriber from before the gap then got a replay with a gap and noresync. Fixed ine32b3d0: the age rule deletes a seq prefix (up to the newest event recorded before the cutoff). Guard:store.TestPruneChangesByAgeLeavesNoGapand.memory/corrections/2026-11-13-pr-236-prune-a-seq-prefix.json.e32b3d0(ADR, design, spec).e32b3d0bb35e862b263ad9b67819d9e2e9e530f4: Ready, Blocking: none.