storage hygiene: duplicated observation content, unbounded WAL, snippet backlog #43

Open
opened 2026-11-05 08:37:03 +00:00 by david · 3 comments
Owner

Three measured storage issues, none urgent, all cheap to fix and each with a number attached.

1. Observation content is ~53% duplicated

content bytes total   40 MB
unique content bytes  19 MB

One 8 KB payload appears 114 times. observations.content_hash already 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_limit is 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 via knox_snippet_prune and knox_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).

Three measured storage issues, none urgent, all cheap to fix and each with a number attached. ## 1. Observation content is ~53% duplicated ``` content bytes total 40 MB unique content bytes 19 MB ``` One 8 KB payload appears 114 times. `observations.content_hash` already 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_limit` is 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 via `knox_snippet_prune` and `knox_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).
Author
Owner

Measured the duplication while verifying BookOrbit, and found the cause rather than just the symptom.

RecordObservation compared len(o.Content) (bytes in Go) with SQLite LENGTH(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):

source rows distinct versions
obsidian 8520 1180
opencode-session 1686 1153
gitea 358 104
karakeep 329 195
skills-catalog 543 227

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.

Measured the duplication while verifying BookOrbit, and found the cause rather than just the symptom. `RecordObservation` compared `len(o.Content)` (bytes in Go) with SQLite `LENGTH(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)`: | source | rows | distinct versions | |---|---|---| | obsidian | 8520 | 1180 | | opencode-session | 1686 | 1153 | | gitea | 358 | 104 | | karakeep | 329 | 195 | | skills-catalog | 543 | 227 | 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.
Author
Owner

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

before after
observations 16,069 8,897
database 174 MB 136 MB
entries 6,248 6,248
thread links 2,347 2,223
  • 7,172 rows removed, ~29 MB of content.
  • Thread membership was re-pointed at the surviving observation of the same content before deleting; 111 links collapsed because a thread had linked both copies.
  • entries.ref_count recomputed from the remaining observations (it had been counting duplicates).
  • 13 dangling thread_observations rows (pre-existing, also present in the backup) were removed.
  • VACUUM, then integrity_check = ok.

Proof nothing was lost

Set difference against the backup over (fingerprint, content, title, summary, created_at):

lost_tuples=0
new_tuples=2   # gitea data re-ingested after the watcher restart

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.

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 | | before | after | |---|---|---| | observations | 16,069 | 8,897 | | database | 174 MB | **136 MB** | | entries | 6,248 | 6,248 | | thread links | 2,347 | 2,223 | - 7,172 rows removed, ~29 MB of content. - Thread membership was re-pointed at the surviving observation of the same content before deleting; 111 links collapsed because a thread had linked both copies. - `entries.ref_count` recomputed from the remaining observations (it had been counting duplicates). - 13 dangling `thread_observations` rows (pre-existing, also present in the backup) were removed. - `VACUUM`, then `integrity_check` = ok. ## Proof nothing was lost Set difference against the backup over `(fingerprint, content, title, summary, created_at)`: ``` lost_tuples=0 new_tuples=2 # gitea data re-ingested after the watcher restart ``` 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.
Author
Owner

Server side trimmed too, so the two nodes stop disagreeing about how much history exists.

dhg.lol

before after
observations 15,294 8,779
database 189 MB 134 MB
entries 6,122 6,122
thread links 2,189 2,104
  • Backup: /DATA/AppData/knox/backups/index-20261108-1849-pre-dedupe.db (189 MB, integrity ok).
  • Containers stopped for the pass, restarted after; a trap restarted them on any failure.
  • Same rule as the laptop; VACUUM + integrity_check = ok; 0 orphan links afterwards.
  • Set difference against the backup over (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 hcl sets for node 6177c0e0…:

server-only: 0 | laptop-only: 0 | shared: 8781

Both nodes now hold exactly the same set. Gossip is healthy (in sync each 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.

Server side trimmed too, so the two nodes stop disagreeing about how much history exists. ## dhg.lol | | before | after | |---|---|---| | observations | 15,294 | 8,779 | | database | 189 MB | **134 MB** | | entries | 6,122 | 6,122 | | thread links | 2,189 | 2,104 | - Backup: `/DATA/AppData/knox/backups/index-20261108-1849-pre-dedupe.db` (189 MB, integrity ok). - Containers stopped for the pass, restarted after; a trap restarted them on any failure. - Same rule as the laptop; `VACUUM` + `integrity_check` = ok; 0 orphan links afterwards. - Set difference against the backup over `(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 `hcl` sets for node `6177c0e0…`: ``` server-only: 0 | laptop-only: 0 | shared: 8781 ``` Both nodes now hold exactly the same set. Gossip is healthy (`in sync` each 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.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#43