fix: rebuild derived state on startup when the log has data but entries do not (#8)
build / test (push) Successful in 5m20s
build / image (push) Successful in 28s

A replica that restarts with a populated observation log and an empty entries
cache had no trigger to reconcile: pushes and pulls only fire on *new* rows,
and the node is already in sync. It now rebuilds once at startup.
This commit is contained in:
2026-11-04 17:48:16 -08:00
parent fdd9f9cacd
commit 10b0a3de6a
2 changed files with 27 additions and 0 deletions
+13
View File
@@ -209,6 +209,19 @@ func (w *Watcher) Start() error {
log.Printf("[knox] obsidian vault: %s", w.vault)
}
// A node that starts with a populated log but an empty entries cache — a
// freshly deployed replica, or any node whose derived state was wiped — has
// nothing to trigger a reconcile, so build it once at startup. Reconcile is
// only cheap-ish, not free, hence the guard.
if obs, entries, err := w.knoxDB.DerivedStateCounts(); err == nil && obs > 0 && entries == 0 {
log.Printf("[knox] derived state empty with %d observations: rebuilding", obs)
if created, linked, err := Reconcile(w.knoxDB); err != nil {
log.Printf("[knox] startup reconcile: %v", err)
} else {
log.Printf("[knox] startup reconcile done: %d created, %d linked", created, linked)
}
}
debounce := newFileDebouncer()
browserTicker := time.NewTicker(browserInterval)
giteaTicker := time.NewTicker(10 * time.Minute)