feat(outbox): local chat retry queue — queue sends and retry with backoff #45

Merged
sirius merged 1 commit from feat/local-outbox into main 2026-09-12 19:06:14 +00:00
Owner

What

Replaces the "compose → send failed" cliff for chat with a persistent local outbox. When a friend's v3 onion cannot be dialed, the message is stored locally and retried by a background worker with exponential backoff until it is delivered, terminal-fails, or the process exits. Still peer-to-peer: no server, no store-and-forward relay, no new wire prefix. Each attempt is a fresh Noise IK handshake straight to (friend.onion, 80), exactly the v1 one-shot session.

This reverses the no outbox / no retry queue lock for chat only, authorized on 2026-09-12. The "no hosted chat server / no store-and-forward relay" half of the lock stands.

Threat-model delta (2 lines)

  • Device seizure: a pending, never-delivered message now sits in the same db as the rest of the history, under the same per-row AEAD and the same passphrase-derived key — no weaker, but no shorter-lived. Seizure with the passphrase reveals messages that were never actually sent. /wipe clears outbox rows with chat history.
  • Traffic analysis: queued sends re-dial a peer's onion on a predictable backoff cadence while the app runs, so an observer of the Tor client can infer that you hold an undelivered message for someone (not the plaintext or the peer identity), and roughly when you composed it. Bounded: per-row, one attempt per 30 min at worst, 8 attempts then terminal.

Both are written up in docs/THREAT_MODEL.md ("Local outbox (chat retry queue) is local, and it re-dials on a schedule").

Design

  • src/outbox.rs (new): Outbox (store + Deliverer), ArtiDeliverer (the real transport), pure backoff_secs(), is_permanent_send_error(), background worker.
  • Backoff: 30s, doubling, capped at 30 min (30, 60, 120, 240, 480, 960, 1800, 1800 …), 8 attempts, then terminal Failed(reason). Schedule is a pure function asserted numerically by a unit test.
  • Retry triggers: (a) 15s timer scan of due rows, (b) unlock/foreground (spawn_flush_all in Node::start_with_passphrase), (c) that peer was just heard from (successful handshake in handle_incoming, or a successful connect_onion()), which ignores the backoff for that friend's rows. flush_outbox() lets a UI thread kick (b) on demand.
  • Node::send() now returns Result<OutboxStatus, String> — Sent / Queued, instead of Err on transport failure. Status enum: Queued, Sending, Sent, Failed(String).
  • Protocol errors — pinned-fingerprint mismatch, bad identity proof, bad frame version/length, oversize payload — are not transport failures: Node::send() still returns Err immediately and nothing is queued. session::Error::into_message() reuses the canonical fingerprint_mismatch_banner() string so the classifier cannot drift from the UI wording.
  • No duplicate plaintext at rest: the outbox row stores message_id + friend_id + attempts + next_attempt_at (absolute unix second, so scheduling survives restart) + status + last_error. The body is read back from the joined messages row, so it stays under that row's existing AEAD + AAD (owmsg1 || friend_id_le64 || dir || 0x00 || row_id_le64). The outbox table has no body column.
  • Node::start_with_passphrase calls Outbox::reset_stale() on unlock: a process killed mid-attempt leaves sending rows, which are requeued rather than stranded.
  • /wipe deletes outbox rows first, then zeroes + deletes messages (wipe_messages). /wipe-all removes the dir, which takes the table with it.

Deliberately not queued

src/file.rs transfers and payment/rcp frames stay fail-closed (send_once/try_send, one-shot, unchanged). Their chunk-level pacing/retry inside a live transfer is unchanged. No new frame prefix anywhere.

Forced one-line change in a PR-#27-owned file

src/tui.rs is owned by open PR #27, but Node::send()'s return type change makes today's Ok(()) arm not compile. The diff there is one arm (Ok(()) → Ok(_)) plus a two-line comment; no UI surfacing is added (that is child card t_d9a5b065). Expect a trivial conflict if both land — nothing worth resolving by hand beyond taking both sides. hotspot: src/tui.rs — signature change from send() forces one arm; the real UI work is t_d9a5b065.

Evidence

$ cargo test
test result: ok. 4 passed; 0 failed; 0 ignored        (lib)
test result: ok. 10 passed; 0 failed                  (tests/app_sig.rs)
test result: ok. 9 passed; 0 failed                   (tests/backup.rs)
test result: ok. 6 passed; 0 failed                   (tests/dispatch.rs)
test result: ok. 14 passed; 0 failed                  (tests/file.rs)
test result: ok. 10 passed; 0 failed                  (tests/hs.rs)
test result: ok. 10 passed; 0 failed                  (tests/outbox.rs)   <-- new
test result: ok. 10 passed; 0 failed                  (tests/pay.rs)
test result: ok. 12 passed; 0 failed                  (tests/profile.rs)
test result: ok. 3 passed; 0 failed                   (tests/protocol.rs)
test result: ok. 11 passed; 0 failed                  (tests/qr.rs)
test result: ok. 2 passed; 0 failed                   (tests/ratelimit.rs)
test result: ok. 7 passed; 0 failed                   (tests/rotate.rs)
test result: ok. 9 passed; 0 failed                   (tests/sanitize.rs)
test result: ok. 8 passed; 0 failed                   (tests/send.rs)
test result: ok. 18 passed; 0 failed                  (tests/store.rs)
test result: ok. 10 passed; 0 failed                  (tests/tui_chrome.rs)
test result: ok. 6 passed; 0 failed                   (tests/tui_frames.rs)
test result: ok. 7 passed; 0 failed                   (tests/tui_spec.rs)
test result: ok. 15 passed; 0 failed                  (tests/wallet.rs)
test result: ok. 9 passed; 0 failed                   (tests/wipe.rs)
   (tor_hs.rs / two_node.rs / rotate_hs.rs: 0 passed, 3 ignored — need live Tor, as on main)

$ cargo clippy --all-targets -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.11s

New coverage in tests/outbox.rs (all offline — the transport is a fake/flaky Deliverer, so no Tor needed):

  • send_to_dead_onion_is_queued_and_row_persists — dead onion → Queued, row in the store, not Err.
  • flaky_peer_is_flushed_by_the_worker_on_schedule — peer comes up later → worker flushes → Sent.
  • backoff_schedule_doubles_from_30s_and_caps_at_30m — schedule asserted numerically, incl. u32::MAX (no shift overflow).
  • max_attempts_reaches_failed_and_stops_retrying — terminal Failed, attempts stop.
  • queued_message_survives_reopen_and_flushes_after_unlock — close + reopen the db, then flush.
  • protocol_error_fails_immediately_and_is_not_queued — pinned-identity/protocol error → immediate Err, nothing queued.
  • transport_errors_are_retryable_protocol_errors_are_not — the classifier.
  • flush_friend_ignores_the_schedule_when_that_peer_was_seen — trigger (c).
  • missing_prekey_is_fatal_not_queued.
  • wipe_clears_outbox_rows — /wipe path.

README (deferred)

README.md is owned by open PR #38, so this PR does not touch it. Proposed replacement wording, for you to apply after #38 lands:

Line ~115 (usage paragraph), replace:

Footer shows sending, then sent or send failed — the TUI stays usable while Tor retries (up to 180s). Fail closed: if their onion is down, send fails — no outbox.

with:

Footer shows sending, then sent or send failed. If their onion is down, a chat message is queued locally and retried in the background with backoff (30s, doubling, capped at 30 min; 8 attempts) — no server and no relay, and the TUI stays usable throughout.

Line ~159, replace:

If a peer's onion is down, send fails. v1 has no outbox, no retry queue, no DHT, no name server. There is still no hosted chat server.

with:

If a peer's onion is down, a chat send is queued locally and retried straight to their onion — no relay, no hosted chat server, no store-and-forward. File transfer and payment frames still fail immediately: they are never queued.

Line ~167 ("never raw frames. No outbox, no resume, no images in the TUI.") → never raw frames. No resume, no images in the TUI.

Line ~312 ("Out of v1" list): outbox → server-side outbox / store-and-forward relay, keeping the list otherwise as-is.

## What Replaces the "compose → send failed" cliff for **chat** with a persistent **local** outbox. When a friend's v3 onion cannot be dialed, the message is stored locally and retried by a background worker with exponential backoff until it is delivered, terminal-fails, or the process exits. Still peer-to-peer: no server, no store-and-forward relay, no new wire prefix. Each attempt is a fresh Noise IK handshake straight to `(friend.onion, 80)`, exactly the v1 one-shot session. This reverses the `no outbox / no retry queue` lock for chat only, authorized on 2026-09-12. The "no hosted chat server / no store-and-forward relay" half of the lock stands. ## Threat-model delta (2 lines) - **Device seizure:** a pending, never-delivered message now sits in the same db as the rest of the history, under the same per-row AEAD and the same passphrase-derived key — no weaker, but no shorter-lived. Seizure with the passphrase reveals messages that were never actually sent. `/wipe` clears outbox rows with chat history. - **Traffic analysis:** queued sends re-dial a peer's onion on a predictable backoff cadence while the app runs, so an observer of the Tor client can infer that you hold an undelivered message for someone (not the plaintext or the peer identity), and roughly when you composed it. Bounded: per-row, one attempt per 30 min at worst, 8 attempts then terminal. Both are written up in `docs/THREAT_MODEL.md` ("Local outbox (chat retry queue) is local, and it re-dials on a schedule"). ## Design - `src/outbox.rs` (new): `Outbox` (store + `Deliverer`), `ArtiDeliverer` (the real transport), pure `backoff_secs()`, `is_permanent_send_error()`, background worker. - Backoff: **30s, doubling, capped at 30 min** (30, 60, 120, 240, 480, 960, 1800, 1800 …), 8 attempts, then terminal `Failed(reason)`. Schedule is a pure function asserted numerically by a unit test. - Retry triggers: (a) 15s timer scan of due rows, (b) unlock/foreground (`spawn_flush_all` in `Node::start_with_passphrase`), (c) that peer was just heard from (successful handshake in `handle_incoming`, or a successful `connect_onion()`), which ignores the backoff for that friend's rows. `flush_outbox()` lets a UI thread kick (b) on demand. - `Node::send()` now returns `Result<OutboxStatus, String>` — `Sent` / `Queued`, instead of `Err` on transport failure. Status enum: `Queued`, `Sending`, `Sent`, `Failed(String)`. - Protocol errors — pinned-fingerprint mismatch, bad identity proof, bad frame version/length, oversize payload — are **not** transport failures: `Node::send()` still returns `Err` immediately and nothing is queued. `session::Error::into_message()` reuses the canonical `fingerprint_mismatch_banner()` string so the classifier cannot drift from the UI wording. - No duplicate plaintext at rest: the outbox row stores `message_id` + `friend_id` + attempts + `next_attempt_at` (absolute unix second, so scheduling survives restart) + status + `last_error`. The body is read back from the joined `messages` row, so it stays under that row's existing AEAD + AAD (`owmsg1 || friend_id_le64 || dir || 0x00 || row_id_le64`). The outbox table has no body column. - `Node::start_with_passphrase` calls `Outbox::reset_stale()` on unlock: a process killed mid-attempt leaves `sending` rows, which are requeued rather than stranded. - `/wipe` deletes `outbox` rows first, then zeroes + deletes `messages` (`wipe_messages`). `/wipe-all` removes the dir, which takes the table with it. ## Deliberately not queued `src/file.rs` transfers and payment/`rcp` frames stay fail-closed (`send_once`/`try_send`, one-shot, unchanged). Their chunk-level pacing/retry inside a live transfer is unchanged. No new frame prefix anywhere. ## Forced one-line change in a PR-#27-owned file `src/tui.rs` is owned by open PR #27, but `Node::send()`'s return type change makes today's `Ok(())` arm not compile. The diff there is **one arm** (`Ok(())` → `Ok(_)`) plus a two-line comment; no UI surfacing is added (that is child card `t_d9a5b065`). Expect a trivial conflict if both land — nothing worth resolving by hand beyond taking both sides. **hotspot: src/tui.rs — signature change from `send()` forces one arm; the real UI work is t_d9a5b065.** ## Evidence ``` $ cargo test test result: ok. 4 passed; 0 failed; 0 ignored (lib) test result: ok. 10 passed; 0 failed (tests/app_sig.rs) test result: ok. 9 passed; 0 failed (tests/backup.rs) test result: ok. 6 passed; 0 failed (tests/dispatch.rs) test result: ok. 14 passed; 0 failed (tests/file.rs) test result: ok. 10 passed; 0 failed (tests/hs.rs) test result: ok. 10 passed; 0 failed (tests/outbox.rs) <-- new test result: ok. 10 passed; 0 failed (tests/pay.rs) test result: ok. 12 passed; 0 failed (tests/profile.rs) test result: ok. 3 passed; 0 failed (tests/protocol.rs) test result: ok. 11 passed; 0 failed (tests/qr.rs) test result: ok. 2 passed; 0 failed (tests/ratelimit.rs) test result: ok. 7 passed; 0 failed (tests/rotate.rs) test result: ok. 9 passed; 0 failed (tests/sanitize.rs) test result: ok. 8 passed; 0 failed (tests/send.rs) test result: ok. 18 passed; 0 failed (tests/store.rs) test result: ok. 10 passed; 0 failed (tests/tui_chrome.rs) test result: ok. 6 passed; 0 failed (tests/tui_frames.rs) test result: ok. 7 passed; 0 failed (tests/tui_spec.rs) test result: ok. 15 passed; 0 failed (tests/wallet.rs) test result: ok. 9 passed; 0 failed (tests/wipe.rs) (tor_hs.rs / two_node.rs / rotate_hs.rs: 0 passed, 3 ignored — need live Tor, as on main) $ cargo clippy --all-targets -- -D warnings Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.11s ``` New coverage in `tests/outbox.rs` (all offline — the transport is a fake/flaky `Deliverer`, so no Tor needed): - `send_to_dead_onion_is_queued_and_row_persists` — dead onion → `Queued`, row in the store, not `Err`. - `flaky_peer_is_flushed_by_the_worker_on_schedule` — peer comes up later → worker flushes → `Sent`. - `backoff_schedule_doubles_from_30s_and_caps_at_30m` — schedule asserted numerically, incl. `u32::MAX` (no shift overflow). - `max_attempts_reaches_failed_and_stops_retrying` — terminal `Failed`, attempts stop. - `queued_message_survives_reopen_and_flushes_after_unlock` — close + reopen the db, then flush. - `protocol_error_fails_immediately_and_is_not_queued` — pinned-identity/protocol error → immediate `Err`, nothing queued. - `transport_errors_are_retryable_protocol_errors_are_not` — the classifier. - `flush_friend_ignores_the_schedule_when_that_peer_was_seen` — trigger (c). - `missing_prekey_is_fatal_not_queued`. - `wipe_clears_outbox_rows` — `/wipe` path. ## README (deferred) `README.md` is owned by open PR #38, so this PR does not touch it. Proposed replacement wording, for you to apply after #38 lands: Line ~115 (usage paragraph), replace: > Footer shows `sending`, then `sent` or `send failed` — the TUI stays usable while Tor retries (up to 180s). Fail closed: if their onion is down, send fails — no outbox. with: > Footer shows `sending`, then `sent` or `send failed`. If their onion is down, a chat message is queued locally and retried in the background with backoff (30s, doubling, capped at 30 min; 8 attempts) — no server and no relay, and the TUI stays usable throughout. Line ~159, replace: > If a peer's onion is down, send fails. v1 has no outbox, no retry queue, no DHT, no name server. There is still no hosted chat server. with: > If a peer's onion is down, a chat send is queued locally and retried straight to their onion — no relay, no hosted chat server, no store-and-forward. File transfer and payment frames still fail immediately: they are never queued. Line ~167 ("never raw frames. No outbox, no resume, no images in the TUI.") → `never raw frames. No resume, no images in the TUI.` Line ~312 ("Out of v1" list): `outbox` → `server-side outbox / store-and-forward relay`, keeping the list otherwise as-is.
feat(outbox): local retry queue for chat sends
All checks were successful
ci / test (pull_request) Successful in 3m21s
ad59a171b3
Queue a chat send locally when the peer's v3 onion is unreachable and retry
it with exponential backoff (30s doubling, capped at 30 min, 8 attempts then
terminal Failed). Still peer-to-peer: no server, no store-and-forward relay,
no new frame prefix — every attempt is a fresh Noise IK handshake.

- src/outbox.rs: Outbox + Deliverer + ArtiDeliverer, pure backoff_secs(),
  is_permanent_send_error(), background worker (15s scan).
- store: `outbox` table (no body column — the body is read from the joined
  messages row, under that row's existing AEAD + AAD), append_message_id(),
  queue/due/pending/mark_* helpers, reset_sending_outbox(), wipe.
- Node::send() returns Result<OutboxStatus, String> (Sent/Queued) instead of
  Err on transport failure; protocol errors still fail immediately and are
  never queued.
- Retry triggers: timer, unlock/foreground (spawn_flush_all), and "that peer
  was just seen" (handshake or connect_onion -> spawn_flush_friend).
- File transfer and payment/rcp frames stay fail-closed.
- docs/PROTOCOL.md + docs/THREAT_MODEL.md: replace the no-queue statements;
  add the seizure/cadence delta to the threat model.

src/tui.rs gets one forced arm change (Ok(()) -> Ok(_)); UI surfacing is
child card t_d9a5b065.
sirius force-pushed feat/local-outbox from ad59a171b3
All checks were successful
ci / test (pull_request) Successful in 3m21s
to 068b655c19
All checks were successful
ci / test (pull_request) Successful in 3m22s
2026-09-12 17:53:35 +00:00
Compare
sirius left a comment

Merge order 6 of 7: #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46

Second of the core three. Two things to know before merging: (1) after #43 lands this needs one rebase — textual conflict in docs/THREAT_MODEL.md, verified by a real merge simulation, not guessed; (2) it touched src/tui.rs (a two-line Ok(_) compile fix at ~line 1366) although its card scoped that file away — reviewed as acceptable, and PR #27 has already merged, so the rebase onto main was clean.

Note: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account sirius, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto current main before this review, diff verified byte-identical.

**Merge order 6 of 7:** #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46 Second of the core three. Two things to know before merging: (1) after #43 lands this needs one rebase — textual conflict in `docs/THREAT_MODEL.md`, verified by a real merge simulation, not guessed; (2) it touched `src/tui.rs` (a two-line `Ok(_)` compile fix at ~line 1366) although its card scoped that file away — reviewed as acceptable, and PR #27 has already merged, so the rebase onto main was clean. Note: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account `sirius`, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto current `main` before this review, diff verified byte-identical.
sirius force-pushed feat/local-outbox from 068b655c19
All checks were successful
ci / test (pull_request) Successful in 3m22s
to d6d157765a
All checks were successful
ci / test (pull_request) Successful in 4m8s
2026-09-12 18:42:04 +00:00
Compare
Author
Owner

Rebased onto main after #43 / #44 landed — conflict resolved

docs/THREAT_MODEL.md conflicted with the merged SQLCipher PR (#43), as predicted in the sign-off review. Resolution:

  • "Out of v1" list merged: sqlcipher stays removed (it shipped in #43) and the list now names a server-side outbox / store-and-forward relay, with the note that the local retry queue "never leaves the device".
  • "Device seizure" bullet updated for the new store: it now says the pending message sits in the same SQLCipher store, so seizure with the passphrase reveals never-sent messages and seizure without it reveals nothing in that store.

No other file conflicted. src/store.rs auto-merged with the SQLCipher changes (outbox table + retry worker on top of the PRAGMA key path) and cargo check --all-targets passes locally on the rebased tree. Diff vs main is now 9 files, this PR's own changes only.

## Rebased onto `main` after #43 / #44 landed — conflict resolved `docs/THREAT_MODEL.md` conflicted with the merged SQLCipher PR (#43), as predicted in the sign-off review. Resolution: - **"Out of v1" list merged:** `sqlcipher` stays removed (it shipped in #43) and the list now names a **server-side** outbox / store-and-forward relay, with the note that the local retry queue "never leaves the device". - **"Device seizure" bullet updated for the new store:** it now says the pending message sits in the same **SQLCipher** store, so seizure *with* the passphrase reveals never-sent messages and seizure without it reveals nothing in that store. No other file conflicted. `src/store.rs` auto-merged with the SQLCipher changes (outbox table + retry worker on top of the `PRAGMA key` path) and `cargo check --all-targets` passes locally on the rebased tree. Diff vs `main` is now 9 files, this PR's own changes only.
sirius merged commit 2a53bc2b89 into main 2026-09-12 19:06:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!45
No description provided.