feat(android): chat row renders queued (try 3/8, retry 45s) from the SDK outbox rows #59

Merged
sirius merged 2 commits from wt/t_f8658427 into feat/sdk-outbox-rows 2026-09-12 23:09:44 +00:00
Owner

What

An Android chat row can now say why it is still queued: ◷ queued (try 3/8, retry 45s), read from the SDK's outbox rows instead of a flat queued.

Consumes PR #58's surface (Wire.outbox(pubkeyHex) -> OutboxRow { messageId, status, attempts, nextAttemptAt, lastError }, outboxMaxAttempts()). android/** only — no Rust changes.

How

  • ui/OutboxDetail.kt (new)
    • retryInText mirrors src/tui.rs::retry_in_text: <= 0 -> retry now; < 60 -> retry {n}s; else retry {ceil-minutes}m ((n + 59) / 60, so the app never promises an attempt sooner than the store will make one).
    • outboxDetails(...) pairs the SDK's rows with the chat rows and returns QueuedRowDetail { attempts, maxAttempts, nextInSecs } -> queued (try 3/8, retry 45s), plus the numbers alone for the a11y announcement.
    • The denominator is outboxMaxAttempts() fetched once at chat open — the app never hardcodes 8. With the budget unknown, rows stay flat.
  • ui/ChatScreen.kt — polls loadOutbox() on the same 2s cadence as the bodies and computes the countdown against an injectable nowSeconds (the store holds an absolute instant; the age belongs to the client). DeliveryMarker now renders deliveryMarkerText(d, detail) and announces deliveryAnnouncement(d, detail).
  • WireViewModel — two thin passthroughs: outbox(pubkeyHex) and outboxMaxAttempts(). Kept minimal: this file is a hotspot with open PR #49.

Terminal failed rows get no countdown

A failed row keeps the last time it was scheduled for, so a countdown there would promise an attempt that never happens. Failed rows keep the marker's own failed: <reason> (the sanitized short reason MessageDelivery already produces from ChatMessage.delivery), and sending stays bare — both matching the TUI. The chat-level N queued footer from t_f46a9863 is unchanged.

The join is positional, and fail-closed

OutboxRow.message_id is messages.id, but the SDK's ChatMessage does not carry that id yet, so the join cannot be done on it from Kotlin. messages() is ORDER BY m.id and the outbox holds one row per pending send, so the nth pending chat row owns the nth outbox row (sorted by messageId). That is only allowed to speak when it can prove itself: mismatched counts, an unknown status, or a status contradicting the one the SDK resolved for that message drop every detail and fall back to the flat markers. Wrong numbers are worse than none.

Adding id to ChatMessage would delete the positional assumption entirely; filed as a follow-up card for rust-dev.

Evidence

./gradlew --no-daemon :app:assembleDebug :app:testDebugUnitTest -> BUILD SUCCESSFUL

  • 32 unit tests, 0 failures (OutboxDetailTest 17, MessageDeliveryTest 10, InviteAddFlowTest 5).
  • OutboxDetailTest covers the three retry_in_text buckets (0/-45 -> retry now, 1/45/59 -> Ns, 60/61/600/1500/1800 -> Nm), the target wording queued (try 3/8, retry 45s), queued (try 3/12, ...) when the caller passes a different budget, that a failed row yields null detail (no countdown) while its marker stays failed: connection timed out, that sending is bare, and the three fail-closed cases (row-count mismatch, contradicting status, unknown status).
  • Debug APK: 42,086,800 bytes, sha256 44402cf6e896dabb3061fb5326e25d0528eccb79be508c1923c1c88a15967007, contains lib/arm64-v8a/libonionwire_sdk.so.

Bases — read before merging

  • Android base: PR #56 (feat/android-outbox-state, t_f46a9863) — the Android half of the #52/#56 duplicate pair. Do not merge #52; its ui/Delivery.kt is the older duplicate and would collide with ui/MessageDelivery.kt.
  • SDK/Rust base: PR #58 -> PR #51. This PR is stacked on #58's branch (feat/sdk-outbox-rows), so its diff is android-only. Retarget to main once #51 -> #58 land.
  • WireViewModel.kt stays a hotspot with open PR #49 (Tor lifecycle); the additions here are two passthrough functions.
## What An Android chat row can now say *why* it is still queued: `◷ queued (try 3/8, retry 45s)`, read from the SDK's outbox rows instead of a flat `queued`. Consumes PR #58's surface (`Wire.outbox(pubkeyHex)` -> `OutboxRow { messageId, status, attempts, nextAttemptAt, lastError }`, `outboxMaxAttempts()`). `android/**` only — no Rust changes. ## How * `ui/OutboxDetail.kt` (new) * `retryInText` mirrors `src/tui.rs::retry_in_text`: `<= 0` -> `retry now`; `< 60` -> `retry {n}s`; else `retry {ceil-minutes}m` (`(n + 59) / 60`, so the app never promises an attempt sooner than the store will make one). * `outboxDetails(...)` pairs the SDK's rows with the chat rows and returns `QueuedRowDetail { attempts, maxAttempts, nextInSecs }` -> `queued (try 3/8, retry 45s)`, plus the numbers alone for the a11y announcement. * The denominator is `outboxMaxAttempts()` fetched once at chat open — the app never hardcodes 8. With the budget unknown, rows stay flat. * `ui/ChatScreen.kt` — polls `loadOutbox()` on the same 2s cadence as the bodies and computes the countdown against an injectable `nowSeconds` (the store holds an absolute instant; the age belongs to the client). `DeliveryMarker` now renders `deliveryMarkerText(d, detail)` and announces `deliveryAnnouncement(d, detail)`. * `WireViewModel` — two thin passthroughs: `outbox(pubkeyHex)` and `outboxMaxAttempts()`. Kept minimal: this file is a hotspot with open PR #49. ### Terminal `failed` rows get no countdown A `failed` row keeps the last time it was *scheduled* for, so a countdown there would promise an attempt that never happens. Failed rows keep the marker's own `failed: <reason>` (the sanitized short reason `MessageDelivery` already produces from `ChatMessage.delivery`), and `sending` stays bare — both matching the TUI. The chat-level `N queued` footer from t_f46a9863 is unchanged. ### The join is positional, and fail-closed `OutboxRow.message_id` is `messages.id`, but the SDK's `ChatMessage` does not carry that id yet, so the join cannot be done on it from Kotlin. `messages()` is `ORDER BY m.id` and the outbox holds one row per pending send, so the *n*th pending chat row owns the *n*th outbox row (sorted by `messageId`). That is only allowed to speak when it can prove itself: mismatched counts, an unknown status, or a status contradicting the one the SDK resolved for that message drop **every** detail and fall back to the flat markers. Wrong numbers are worse than none. Adding `id` to `ChatMessage` would delete the positional assumption entirely; filed as a follow-up card for rust-dev. ## Evidence `./gradlew --no-daemon :app:assembleDebug :app:testDebugUnitTest` -> BUILD SUCCESSFUL * 32 unit tests, 0 failures (`OutboxDetailTest` 17, `MessageDeliveryTest` 10, `InviteAddFlowTest` 5). * `OutboxDetailTest` covers the three `retry_in_text` buckets (`0`/`-45` -> `retry now`, `1`/`45`/`59` -> `Ns`, `60`/`61`/`600`/`1500`/`1800` -> `Nm`), the target wording `queued (try 3/8, retry 45s)`, `queued (try 3/12, ...)` when the caller passes a different budget, that a `failed` row yields `null` detail (no countdown) while its marker stays `failed: connection timed out`, that `sending` is bare, and the three fail-closed cases (row-count mismatch, contradicting status, unknown status). * Debug APK: 42,086,800 bytes, sha256 `44402cf6e896dabb3061fb5326e25d0528eccb79be508c1923c1c88a15967007`, contains `lib/arm64-v8a/libonionwire_sdk.so`. ## Bases — read before merging * Android base: **PR #56** (`feat/android-outbox-state`, t_f46a9863) — the Android half of the #52/#56 duplicate pair. **Do not merge #52**; its `ui/Delivery.kt` is the older duplicate and would collide with `ui/MessageDelivery.kt`. * SDK/Rust base: **PR #58** -> **PR #51**. This PR is stacked on #58's branch (`feat/sdk-outbox-rows`), so its diff is android-only. Retarget to `main` once #51 -> #58 land. * `WireViewModel.kt` stays a hotspot with open PR #49 (Tor lifecycle); the additions here are two passthrough functions.
Consumes the SDK surface from PR #58 (`Wire.outbox(pubkeyHex)` →
`OutboxRow { messageId, status, attempts, nextAttemptAt, lastError }` and
`outboxMaxAttempts()`): a queued chat row now says *why* it is still queued
instead of a flat `queued`.

* `OutboxDetail.kt` — `retryInText` mirrors `src/tui.rs::retry_in_text`
  (`<= 0` → `retry now`; `< 60` → `retry {n}s`; else `retry {ceil-minutes}m`),
  and `outboxDetails` joins the SDK's rows onto the chat rows. The denominator
  is the core's `outboxMaxAttempts()`/`Rust` budget, fetched once — never 8.
* A terminal `"failed"` row keeps the marker's own `failed: <reason>` and gets
  **no** countdown: `nextAttemptAt` on a failed row is the last time it was
  scheduled for, so a countdown there would promise an attempt that never comes.
  `"sending"` stays bare, matching the TUI.
* `ChatScreen` polls the outbox rows on the same 2s cadence as the bodies and
  renders the countdown against an injectable `nowSeconds` (the store holds an
  absolute instant, the app computes the age).
* The join is positional — `ChatMessage` carries no `messages.id` — and
  fail-closed: mismatched row counts, an unknown status, or a status that
  contradicts the one the SDK resolved for that message drops every detail and
  leaves the flat markers. `ChatMessage.id` would remove the positional part;
  filed as follow-up.
* `OutboxDetailTest` (17 tests) asserts the three `retry_in_text` buckets, the
  `queued (try 3/8, retry 45s)` wording, that a failed row shows no countdown,
  that the denominator comes from the caller, and the three fail-closed cases.
  32 unit tests, 0 failures.

Android base: PR #56 (`feat/android-outbox-state`, t_f46a9863) — the Android
half of the #52/#56 duplicate pair, which is not merged here. SDK base: PR #58
on PR #51.
Author
Owner

Bases (read before merging)

  • Android base: PR #56 feat/android-outbox-state (t_f46a9863) — the Android half of the #52/#56 duplicate pair. Do not merge #52: its ui/Delivery.kt is the older duplicate and collides with ui/MessageDelivery.kt.
  • Rust/SDK base: this PR is stacked on PR #58 -> PR #51, so the diff here is android-only. Retarget to main once #51 -> #58 land.
  • WireViewModel.kt is a hotspot with open PR #49; the additions here are two passthrough functions.

CI

No checks will appear on this PR: .forgejo/workflows/ci.yml allowlists src/**, crates/**, tests/**, Cargo.* — an android-only change cannot affect the Rust build, so the run is skipped by design rather than missing. The evidence for this change is local:

./gradlew --no-daemon :app:assembleDebug :app:testDebugUnitTest
BUILD SUCCESSFUL
32 unit tests, 0 failures (OutboxDetailTest 17, MessageDeliveryTest 10, InviteAddFlowTest 5)
## Bases (read before merging) * Android base: **PR #56** `feat/android-outbox-state` (t_f46a9863) — the Android half of the #52/#56 duplicate pair. Do **not** merge #52: its `ui/Delivery.kt` is the older duplicate and collides with `ui/MessageDelivery.kt`. * Rust/SDK base: this PR is stacked on **PR #58** -> **PR #51**, so the diff here is android-only. Retarget to `main` once #51 -> #58 land. * `WireViewModel.kt` is a hotspot with open PR #49; the additions here are two passthrough functions. ## CI No checks will appear on this PR: `.forgejo/workflows/ci.yml` allowlists `src/**`, `crates/**`, `tests/**`, `Cargo.*` — an android-only change cannot affect the Rust build, so the run is skipped by design rather than missing. The evidence for this change is local: ``` ./gradlew --no-daemon :app:assembleDebug :app:testDebugUnitTest BUILD SUCCESSFUL 32 unit tests, 0 failures (OutboxDetailTest 17, MessageDeliveryTest 10, InviteAddFlowTest 5) ```
sirius force-pushed wt/t_f8658427 from f2109a52b2 to e7976202d3 2026-09-12 21:11:09 +00:00 Compare
sirius force-pushed wt/t_f8658427 from e7976202d3 to a2c632f162 2026-09-12 21:12:04 +00:00 Compare
sirius force-pushed wt/t_f8658427 from a2c632f162 to 20bfe70288 2026-09-12 21:15:46 +00:00 Compare
sirius force-pushed wt/t_f8658427 from 20bfe70288 to ea27c1508e 2026-09-12 21:17:43 +00:00 Compare
sirius force-pushed wt/t_f8658427 from ea27c1508e to 0999601e6a 2026-09-12 22:15:15 +00:00 Compare
sirius merged commit 563388d18d into feat/sdk-outbox-rows 2026-09-12 23:09:44 +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!59
No description provided.