feat(tui): join outbox rows to chat rows by message id (drop the body match) #50

Merged
sirius merged 2 commits from feat/tui-msgid-join into main 2026-09-12 22:11:27 +00:00
Owner

What

The chat pane now joins each pending outbox row to its chat row by message
id
. store::Message carries the messages.id row id it was read from, and
chat_with_delivery looks up OutboxEntry::message_id == Message::id. The
body match and its newest-send-first fallback are deleted.

Why it mattered: with the body match, an outbound message that was still queued
showed a delivered ✓ whenever a newer send of the same text had already
crossed the circuit — the pending row was attached to the newest occurrence of
that body, not to the row that owns it. Exactly the false-delivery claim the
marker exists to prevent.

Stacked base — read this

This branch is ebd3a30 (the head of PR #48) plus one commit, so the diff
against main also contains PR #48 and its open parent PR #45
(feat/local-outbox). Review the src/store.rs / src/tui.rs /
tests/tui_spec.rs / docs/TUI.md hunks; everything else disappears once #45
and #48 land.

git log --oneline origin/main..HEAD
afff5f8 feat(tui): join outbox rows to chat rows by message id
ebd3a30 feat(tui): per-message outbox delivery state + `N queued` footer
7c6de69 Merge remote-tracking branch 'origin/feat/local-outbox' into feat/tui-outbox-state
068b655 feat(outbox): local retry queue for chat sends

Merge order: #45, then #48, then this. Do not merge before both.

Change

  • src/store.rs: Message gains pub id: i64 (the messages.id the row was
    read from). list_messages() keeps its exact signature and behaviour — this
    is an additive field, so the SDK, tests/store.rs, tests/outbox.rs,
    tests/wipe.rs, tests/two_node.rs and tests/rotate_hs.rs are untouched
    and still compile against it.
  • src/tui.rs: chat_with_delivery builds a message_id → OutboxEntry map and
    attaches the tag in a single forward pass. No by_body, no .rev(), no
    pop(). A hypothetical duplicate row for one message resolves to the newest,
    matching the store's own outbox_status_of_message (ORDER BY id DESC LIMIT 1).
  • tests/tui_spec.rs: the fixtures take an explicit id (out_msg(id, body),
    queued_row(message_id, …)), because ids are what the join uses now.
  • docs/TUI.md: the "Correlation" paragraph no longer describes a body match —
    it states the id join.

How it is verified

RED first, on the new test, before the src/tui.rs change:

$ cargo test --test tui_spec identical_bodies_join_by_message_id_not_body
test identical_bodies_join_by_message_id_not_body ... FAILED
panicked at tests/tui_spec.rs:517:5:
queued marker must land on the queued row (id 7): "you: same text  ✓"

That is the bug in one line: the queued row claimed delivery.

After the change:

$ cargo test
SUITES=26 PASSED=204 FAILED=0 IGNORED=3   (3 ignored = network/Tor tests, unchanged)
  tui_spec: 21 passed (was 20)

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

New test identical_bodies_join_by_message_id_not_body: two outbound messages
with identical text, only the older one queued (the ordering the body match
got wrong) → row 0 carries ◷ queued and no ✓, row 1 keeps ✓, footer says
1 queued.

renders_a_queued_row_from_a_real_outbox_send still passes unchanged: it reads
real Outbox::pending() rows (message_id set by the store) against real
list_messages() rows, so the id join is exercised against a real sqlite store,
not only against fixtures.

Honest finding, out of scope here — crates/onionwire-sdk does not compile

onionwire-sdk is a separate cargo workspace, and root CI only runs
cargo test / cargo clippy at the root, so neither #45 nor #48 caught this:

$ (cd crates/onionwire-sdk && cargo build)
error[E0308]: mismatched types
   --> src/lib.rs:195:9
      self.inner.send(&pk, body.as_bytes()).await.map_err(WireError::new)
      expected `Result<(), WireError>`, found `Result<OutboxStatus, WireError>`

Pre-existing on this stack, not caused by this commit — proven by stashing this
diff and rebuilding the SDK on ebd3a30 alone (same E0308). It is PR #45's
Node::send() -> Result<OutboxStatus, String> change; the SDK still expects
Result<()>. crates/onionwire-sdk/** is out of scope for this card, so it is
left alone and filed as a follow-up task rather than smuggled in here.

Scope

Changed files: src/store.rs, src/tui.rs, tests/tui_spec.rs, docs/TUI.md.
No new crate, no wire change, no new wire prefix, no server, no README change.
rustfmt was not run repo-wide (the tree is not rustfmt-clean and a plain
cargo fmt would add drive-by churn to parent-owned files).

## What The chat pane now joins each pending outbox row to its chat row **by message id**. `store::Message` carries the `messages.id` row id it was read from, and `chat_with_delivery` looks up `OutboxEntry::message_id` == `Message::id`. The body match and its newest-send-first fallback are deleted. Why it mattered: with the body match, an outbound message that was still queued showed a delivered `✓` whenever a *newer* send of the same text had already crossed the circuit — the pending row was attached to the newest occurrence of that body, not to the row that owns it. Exactly the false-delivery claim the marker exists to prevent. ## Stacked base — **read this** This branch is `ebd3a30` (the head of PR **#48**) plus one commit, so the diff against `main` also contains PR #48 and its open parent PR **#45** (`feat/local-outbox`). Review the `src/store.rs` / `src/tui.rs` / `tests/tui_spec.rs` / `docs/TUI.md` hunks; everything else disappears once #45 and #48 land. ``` git log --oneline origin/main..HEAD afff5f8 feat(tui): join outbox rows to chat rows by message id ebd3a30 feat(tui): per-message outbox delivery state + `N queued` footer 7c6de69 Merge remote-tracking branch 'origin/feat/local-outbox' into feat/tui-outbox-state 068b655 feat(outbox): local retry queue for chat sends ``` **Merge order: #45, then #48, then this.** Do not merge before both. ## Change - `src/store.rs`: `Message` gains `pub id: i64` (the `messages.id` the row was read from). `list_messages()` keeps its exact signature and behaviour — this is an additive field, so the SDK, `tests/store.rs`, `tests/outbox.rs`, `tests/wipe.rs`, `tests/two_node.rs` and `tests/rotate_hs.rs` are untouched and still compile against it. - `src/tui.rs`: `chat_with_delivery` builds a `message_id → OutboxEntry` map and attaches the tag in a single forward pass. No `by_body`, no `.rev()`, no `pop()`. A hypothetical duplicate row for one message resolves to the newest, matching the store's own `outbox_status_of_message` (`ORDER BY id DESC LIMIT 1`). - `tests/tui_spec.rs`: the fixtures take an explicit id (`out_msg(id, body)`, `queued_row(message_id, …)`), because ids are what the join uses now. - `docs/TUI.md`: the "Correlation" paragraph no longer describes a body match — it states the id join. ## How it is verified RED first, on the new test, before the `src/tui.rs` change: ``` $ cargo test --test tui_spec identical_bodies_join_by_message_id_not_body test identical_bodies_join_by_message_id_not_body ... FAILED panicked at tests/tui_spec.rs:517:5: queued marker must land on the queued row (id 7): "you: same text ✓" ``` That is the bug in one line: the queued row claimed delivery. After the change: ``` $ cargo test SUITES=26 PASSED=204 FAILED=0 IGNORED=3 (3 ignored = network/Tor tests, unchanged) tui_spec: 21 passed (was 20) $ cargo clippy --all-targets -- -D warnings Finished `dev` profile [unoptimized + debuginfo] target(s) in 21.87s (exit 0) ``` New test `identical_bodies_join_by_message_id_not_body`: two outbound messages with identical text, only the **older** one queued (the ordering the body match got wrong) → row 0 carries `◷ queued` and no `✓`, row 1 keeps `✓`, footer says `1 queued`. `renders_a_queued_row_from_a_real_outbox_send` still passes unchanged: it reads real `Outbox::pending()` rows (`message_id` set by the store) against real `list_messages()` rows, so the id join is exercised against a real sqlite store, not only against fixtures. ## Honest finding, out of scope here — `crates/onionwire-sdk` does not compile `onionwire-sdk` is a **separate cargo workspace**, and root CI only runs `cargo test` / `cargo clippy` at the root, so neither #45 nor #48 caught this: ``` $ (cd crates/onionwire-sdk && cargo build) error[E0308]: mismatched types --> src/lib.rs:195:9 self.inner.send(&pk, body.as_bytes()).await.map_err(WireError::new) expected `Result<(), WireError>`, found `Result<OutboxStatus, WireError>` ``` Pre-existing on this stack, not caused by this commit — proven by stashing this diff and rebuilding the SDK on `ebd3a30` alone (same E0308). It is PR #45's `Node::send() -> Result<OutboxStatus, String>` change; the SDK still expects `Result<()>`. `crates/onionwire-sdk/**` is out of scope for this card, so it is left alone and filed as a follow-up task rather than smuggled in here. ## Scope Changed files: `src/store.rs`, `src/tui.rs`, `tests/tui_spec.rs`, `docs/TUI.md`. No new crate, no wire change, no new wire prefix, no server, no README change. `rustfmt` was not run repo-wide (the tree is not rustfmt-clean and a plain `cargo fmt` would add drive-by churn to parent-owned files).
feat(outbox): local retry queue for chat sends
All checks were successful
ci / test (pull_request) Successful in 3m22s
068b655c19
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.
Merge remote-tracking branch 'origin/feat/local-outbox' into feat/tui-outbox-state
All checks were successful
ci / test (pull_request) Successful in 3m16s
7c6de696a1
feat(tui): per-message outbox delivery state + N queued footer
All checks were successful
ci / test (pull_request) Successful in 3m20s
ebd3a306e8
Chat rows now carry the state the local outbox actually holds: `✓` delivered,
`◷ queued (try n/8, retry 45s)` while the retry worker still has it, `» sending`
mid-attempt and `✗ failed: <short reason>` once attempts are exhausted. The
footer replaces the flat `sent` / `send failed` copy with the live count
(`2 queued`), and keeps a fail-closed `send failed: …` statement as long as any
row is terminally failed.

States come from the outbox API (`Node::outbox_pending` → `Queued` / `Sending` /
`Failed`; a delivered row is deleted, so absence is `Sent`). No parallel state
model, no new wire prefix. Every new glyph has an ASCII fallback (`ok` plus the
state word) exercised by a test.

- `chat_with_delivery()` / `delivery_tag()` / `retry_in_text()` /
  `short_send_reason()` / `OutboxSummary::note()` are pure and unit-tested.
- `draw_chat()` is now the real chat-pane renderer (extracted from
  `App::draw_main`) so width/wrap is testable without a `Node`.
- docs/TUI.md: delivery markers, copy, and the 80x24 floor / 120x40 target.

Verified: cargo test 26/26 suites ok (tui_spec 20/20, incl. a real Store +
Outbox::send -> pending() -> render path); clippy --all-targets -D warnings clean.
feat(tui): join outbox rows to chat rows by message id
All checks were successful
ci / test (pull_request) Successful in 3m27s
afff5f8dff
`chat_with_delivery` matched pending outbox rows to chat rows by body
because `store::Message` carried no id, so an older send that was still
queued showed a delivered mark whenever a newer send of the same text had
already crossed the circuit.

`store::Message` now carries its `messages.id`, and the TUI joins
`OutboxEntry::message_id` == `Message::id`. The body match and its
newest-first fallback are gone.

`list_messages()` keeps its signature; callers that do not need the id
are untouched.
sirius force-pushed feat/tui-msgid-join from afff5f8dff
All checks were successful
ci / test (pull_request) Successful in 3m27s
to 2cbe7d41e5
All checks were successful
ci / test (pull_request) Successful in 4m12s
2026-09-12 21:10:43 +00:00
Compare
Merge branch 'main' into feat/tui-msgid-join
All checks were successful
ci / test (pull_request) Successful in 4m10s
18ccab5464
sirius merged commit 46cff770ab into main 2026-09-12 22:11:27 +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!50
No description provided.