storage hygiene: duplicated observation content, unbounded WAL, snippet backlog #43
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Three measured storage issues, none urgent, all cheap to fix and each with a number attached.
1. Observation content is ~53% duplicated
One 8 KB payload appears 114 times.
observations.content_hashalready exists, so content-addressing the blob would roughly halve the index. The DB is 153 MB today.2. WAL is unbounded
Observed at 41 MB (
journal_size_limitis not set). It is preallocated, not leaked, but it is never capped.3. Snippet backlog
17,818 snippet rows; the extractor's own
junk/candidate heuristics are available viaknox_snippet_pruneandknox_snippet_stats, but nothing schedules the prune.Suggested order
3 (data hygiene, no schema change) → 2 (one PRAGMA) → 1 (needs a content-addressed blob table and a migration).
Measured the duplication while verifying BookOrbit, and found the cause rather than just the symptom.
RecordObservationcomparedlen(o.Content)(bytes in Go) with SQLiteLENGTH(content)(characters for TEXT). Any body containing an em dash or curly quote never matched, so the hash check was skipped and a duplicate observation was appended — with an identical content hash — on every sweep.Live index, rows vs distinct
(fingerprint, content_hash):Fixed in #51 (
LENGTH(CAST(content AS BLOB)), with regression tests both ways). The growth stops from the next tick onwards.Still open for this issue: the existing duplicate rows are untouched. A cleanup would keep the earliest row per
(fingerprint, content_hash)and rebuild entries — destructive, so it should be a deliberate pass with a backup, not a side effect of the fix.Cleaned up the accumulated duplicates, with the fix from #51 already in the running binary.
Backup first
~/.local/share/knox/backups/index-20261108-1504-pre-dedupe.db— 174 MB,PRAGMA integrity_check= ok, 16,069 observations. Restoring this file undoes the whole pass.Rule
A row is a duplicate when it shares its fingerprint with an earlier row and matches on content, title, summary and source timestamp (the content hash joins the key for hashed sources). Keep the earliest, delete the rest. This only ever removes byte-identical repeats — never a version with different content.
Result
entries.ref_countrecomputed from the remaining observations (it had been counting duplicates).thread_observationsrows (pre-existing, also present in the backup) were removed.VACUUM, thenintegrity_check= ok.Proof nothing was lost
Set difference against the backup over
(fingerprint, content, title, summary, created_at):Search smoke-tested after the pass; the 18 BookOrbit chapters and the 594 content-bearing Obsidian notes are intact.
Remaining risk is only regrowth, which #51 addresses. This pass is not a recurring job — if duplicates ever come back, the right next step is to find the source that changed, not to re-run the delete.
Server side trimmed too, so the two nodes stop disagreeing about how much history exists.
dhg.lol
/DATA/AppData/knox/backups/index-20261108-1849-pre-dedupe.db(189 MB, integrity ok).VACUUM+integrity_check= ok; 0 orphan links afterwards.(fingerprint, content, title, summary, created_at): lost_tuples=0. Entries unchanged at 6,122.Convergence
After the restart the laptop re-pushed a handful of rows (the server's vector for our node dropped to the highest surviving hcl — expected, idempotent). Comparing the
hclsets for node6177c0e0…:Both nodes now hold exactly the same set. Gossip is healthy (
in synceach sweep, no errors), containers healthy.The structural limitation this exposed — deletion does not propagate, and a replica cannot restore the origin's own history — is filed as #52.