fix(mesh): persist message history + send-seq counters across restarts

Both lived only in RAM: every archipelago restart/reboot wiped the whole
chat history (user-reported), and — worse — reset the per-target outbound
sequence counters, so peers' (sender_pubkey, sender_seq) dedup silently
dropped the first messages sent after a reboot as replays.

mesh-messages.json in the data dir (0600 — DM plaintext), restored in
MeshService::new before the listener spawns; a 5s debounced persister
task snapshots at one choke point instead of hooking every mutation path
(store, delivered/transport/encrypted stamps, edits, deletes, prunes).
Atomic write-then-rename; corrupt/missing file skips restore instead of
blocking mesh startup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
archipelago
2026-07-22 15:51:32 -04:00
co-authored by Claude Fable 5
parent 27331d66e4
commit 2f26cb2bc4
2 changed files with 108 additions and 1 deletions
+7
View File
@@ -691,6 +691,13 @@ impl MeshService {
}
}
// Restore the message history + outbound send-sequence counters, then
// keep them persisted. Until 2026-07-22 both were RAM-only: every
// restart wiped the chat history, and the reset sequence counters made
// peers drop the first post-reboot messages as (pubkey, seq) replays.
state.load_persisted_messages().await;
listener::spawn_message_persister(Arc::clone(&state));
Ok(Self {
state,
config,