mirror of
https://github.com/ALLFATHER-BV/wadamesh.git
synced 2026-09-26 20:18:04 +00:00
Yoss101 reported the beta_62/63 fix helped but did not cure it: the freezes got rarer AND longer. Rarer is the blob-delete queue working; longer is what was left, and it was always the bigger half. MAX_CONTACTS is 2000 and a contact record is 152 bytes, so saveContacts was rewriting a 304 KB file on every change, with a same-sized .tmp alongside it for the atomic swap. On a card-less V4 that is ~608 KB of peak churn on a 3.375 MB SPIFFS volume that is already carrying one blob file per contact. SPIFFS GC cost scales with how full the volume is, and GC suspends the flash cache, which stalls BOTH cores — so the fuller the table, the longer the device is simply gone. The table never actually changes in bulk: eviction replaces contacts[oldest] in place (the array is unsorted and never shifts) and an advert refresh touches one entry. So compare each record against what is already on disk and write back only the ones that differ. An eviction now writes 152 bytes instead of 304 KB, an unchanged table writes nothing, and there is no .tmp and no free-space spike. Reads never trigger GC, so the compare scan is cheap. Falls back to the full atomic rewrite whenever the mapping is not provably safe (no live file, ragged size, or a table that shrank — there is no truncate here), and never truncates or renames, so a fallback always leaves a valid list on disk. Verified against the real function source with an in-memory FS harness: steady state, eviction, growth, shrink, filtered anon slots, missing file, ragged file, and 167 scattered changes all match a full rewrite byte-for-byte. Also: the blob-delete queue silently ORPHANED a blob on overflow — nothing else ever deletes it, so it leaked flash permanently on the one metric that drives GC cost. Depth 8 -> 32, and overflows are now counted and surfaced. New About > diagnostics block "Contact store": contact count, approximate on-disk size, internal-flash used percentage, and orphaned blobs. The used percentage is the number that predicts these freezes, so a reporter can photograph it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>