android: poll the live wallet-child probe so the wallet sync line moves #134

Merged
sirius merged 1 commit from wt/t_07542df0 into main 2026-09-20 04:48:15 +00:00
Owner

What

The wallet screen's refresh loop now polls a real probe, so the sync h/t segment moves on its own.

On main the 2s loop called Wire::wallet_status, which is a cached read (Node::wallet_child_status — "cheap: no dial"): it re-reads the record the last probe left in the store, and that record is only written by Node::wallet_child_refresh, reachable over UniFFI today only inside start_wallet_child. That is why tapping a chain-mode button looked like a refresh — it was the only thing that probed.

How

  • WireViewModel.openWalletChild() now runs walletChildRefreshLoop(tickMs = 2_000, cached = ::paintWalletChildCached, live = ::refreshWalletChild).
    • paintWalletChildCached() → Wire::wallet_status. Runs once, before the first tick: never dials, so the screen has a record to render immediately.
    • refreshWalletChild() → Wire::wallet_child_refresh(). Runs on every tick (t = 2s, 4s, …).
  • Both reads go through one readWalletChild() that keeps the previous behaviour exactly: Dispatchers.IO, requireWire() called inside the runCatching (a locked node must land in walletChildError, not crash the tick), and the sticky walletChildError fold.
  • Ticks stay strictly serialized and the loop stays a plain while (isActive) { delay; read } — the loop suspends on the read before it sleeps, so a probe slower than the tick delays the next tick instead of overlapping it. No Flow, no collectLatest, no launch per tick: two concurrent wallet_child_refresh calls against one child is a racing probe.
  • Tick cadence (2s), the one-poller guarantee on re-entry, ui/WalletChildStatusText.kt's copy and the sync h/t format are untouched. No new field, no percent, no progress bar, no "last updated". ui/WalletScreen.kt is not touched at all.

The post-action call sites that already called refreshWalletChild() after set_chain_source / stop_wallet_child now hit the live probe too. That is the same call, one hop more honest: stop_wallet_child leaves no live child, so the core short-circuits with the cached snapshot and the call is as cheap as it was.

Tests

android/app/src/test/java/com/siriusdevops/onionwire/WalletChildRefreshLoopTest.kt (new, 3 tests).

The loop's two reads are parameters for one reason: there is no seam to fake Wire from a JVM unit test. requireWire() is NodeHost.requireOpen(), a process-global that only openWire() — a real Arti bootstrap — populates, and NodeHost.wire is private. Wire itself is the generated UniFFI interface (≈40 methods), so "implement a fake" means a hand-written stub of the whole surface. Rather than invent a mock framework, the loop takes cached / live lambdas and the new test drives those for real. The binding of live to WireViewModel.refreshWalletChild() (and of cached to paintWalletChildCached()) is the two lines in WireViewModel.openWalletChild(), and the only honest evidence for it is the committed source:

android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt
    suspend fun paintWalletChildCached() = readWalletChild { requireWire().walletStatus() }
    suspend fun refreshWalletChild() = readWalletChild { requireWire().walletChildRefresh() }

What the tests pin (virtual time, so the 2s cadence is asserted exactly):

  • the cached read paints exactly once and every tick after it is the live probe (4 ticks of virtual time → cached == 1, live == 3, currentTime == 8000);
  • a probe that takes 5 ticks is never overlapped — maxInFlight == 1, three probes, the tick pushed out by the probe's own length;
  • cancelling the loop (leaving the wallet screen) stops the dialing.

They have teeth: with live() mutated to cached() in the loop, all three fail —

WalletChildRefreshLoopTest > the_first_paint_is_the_cached_read_and_every_tick_after_it_is_live FAILED
    java.lang.AssertionError: the cheap read paints once, and only once expected:<1> but was:<4>
WalletChildRefreshLoopTest > a_probe_slower_than_the_tick_is_never_overlapped FAILED
    java.lang.AssertionError: two concurrent wallet_child_refresh probes is a race expected:<1> but was:<0>
WalletChildRefreshLoopTest > cancelling_the_loop_stops_the_probes FAILED
    java.lang.AssertionError: two ticks have gone by expected:<2> but was:<0>

Full suite green on this branch's tree (commit 4d2528351b6df2c54ce5506797722f37317047e5, the head that was pushed):

$ ./gradlew :app:testDebugUnitTest --no-build-cache \
    -x :sdk:cargoBuildAndroid -x :sdk:cargoHostLib -x :sdk:uniffiBindgen -x :sdk:verifyDynamicLibc
> Task :app:testDebugUnitTest
BUILD SUCCESSFUL in 1s
WalletChildRefreshLoopTest                 tests=3  failures=0 errors=0
crypto.StoreSecretTest                     tests=11 failures=0 errors=0
crypto.StoredPassphraseStoreTest           tests=9  failures=0 errors=0
keepalive.KeepAlivePolicyTest              tests=3  failures=0 errors=0
keepalive.NodeLifetimeTest                 tests=9  failures=0 errors=0
ui.InviteAddFlowTest                       tests=5  failures=0 errors=0
ui.MessageDeliveryTest                     tests=10 failures=0 errors=0
ui.OutboxDetailTest                        tests=17 failures=0 errors=0
ui.UnlockSubmitTest                        tests=3  failures=0 errors=0
ui.WalletChildStatusTextTest               tests=47 failures=0 errors=0

(117 tests, 0 failures. --no-build-cache so a FROM-CACHE is not reported as a pass. The -xs skip the Rust tasks; :sdk:uniffiBindgen was run first against this checkout to regenerate android/sdk/build/generated/uniffi/, which carries suspend fun walletChildRefresh(): WalletChildStatus on the Wire interface. Note the recipe needs -x :sdk:verifyDynamicLibc as well — it depends on cargoBuildAndroid, so excluding the latter alone leaves the verifier to fail on a missing .so.)

Base

base = main. The parent card t_0a355a62 (rust-dev: export Wire::wallet_child_refresh over UniFFI, PR #132) is merged into main as fa0e4b2 — git merge-base --is-ancestor origin/wt/t_0a355a62 origin/main exits 0 and git rev-list --count origin/main..origin/wt/t_0a355a62 is 0 — so this branch is cut from origin/main, not stacked. crates/onionwire-sdk/** is untouched by this PR.

Scope

Only android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt and the new test. ui/WalletChildStatusText.kt, ui/WalletScreen.kt, .forgejo/**, every build.gradle.kts and everything under src/** / crates/** are untouched. android/README.md and android/CUPRATE_DAEMON.md were checked and neither describes the refresh cadence as a cached read (CUPRATE_DAEMON.md says "the blocks the chain daemon had at the last probe", which is now true rather than aspirational), so no doc change.

android-ci / android will run on this PR (android/** is in its pull_request path filter) and builds the release APK path through scripts/build-android-local.sh; it does not run these JVM tests, which is why the output above is pasted here.

## What The wallet screen's refresh loop now polls a real probe, so the `sync h/t` segment moves on its own. On `main` the 2s loop called `Wire::wallet_status`, which is a cached read (`Node::wallet_child_status` — "cheap: no dial"): it re-reads the record the *last* probe left in the store, and that record is only written by `Node::wallet_child_refresh`, reachable over UniFFI today only inside `start_wallet_child`. That is why tapping a chain-mode button looked like a refresh — it was the only thing that probed. ## How - `WireViewModel.openWalletChild()` now runs `walletChildRefreshLoop(tickMs = 2_000, cached = ::paintWalletChildCached, live = ::refreshWalletChild)`. - `paintWalletChildCached()` → `Wire::wallet_status`. Runs **once**, before the first tick: never dials, so the screen has a record to render immediately. - `refreshWalletChild()` → `Wire::wallet_child_refresh()`. Runs on **every tick** (t = 2s, 4s, …). - Both reads go through one `readWalletChild()` that keeps the previous behaviour exactly: `Dispatchers.IO`, `requireWire()` called *inside* the `runCatching` (a locked node must land in `walletChildError`, not crash the tick), and the sticky `walletChildError` fold. - Ticks stay strictly serialized and the loop stays a plain `while (isActive) { delay; read }` — the loop suspends on the read *before* it sleeps, so a probe slower than the tick delays the next tick instead of overlapping it. No `Flow`, no `collectLatest`, no `launch` per tick: two concurrent `wallet_child_refresh` calls against one child is a racing probe. - Tick cadence (2s), the one-poller guarantee on re-entry, `ui/WalletChildStatusText.kt`'s copy and the `sync h/t` format are untouched. No new field, no percent, no progress bar, no "last updated". `ui/WalletScreen.kt` is not touched at all. The post-action call sites that already called `refreshWalletChild()` after `set_chain_source` / `stop_wallet_child` now hit the live probe too. That is the same call, one hop more honest: `stop_wallet_child` leaves no live child, so the core short-circuits with the cached snapshot and the call is as cheap as it was. ## Tests `android/app/src/test/java/com/siriusdevops/onionwire/WalletChildRefreshLoopTest.kt` (new, 3 tests). The loop's two reads are parameters for one reason: **there is no seam to fake `Wire` from a JVM unit test.** `requireWire()` is `NodeHost.requireOpen()`, a process-global that only `openWire()` — a real Arti bootstrap — populates, and `NodeHost.wire` is private. `Wire` itself is the generated UniFFI interface (≈40 methods), so "implement a fake" means a hand-written stub of the whole surface. Rather than invent a mock framework, the loop takes `cached` / `live` lambdas and the new test drives those for real. The binding of `live` to `WireViewModel.refreshWalletChild()` (and of `cached` to `paintWalletChildCached()`) is the two lines in `WireViewModel.openWalletChild()`, and the only honest evidence for it is the committed source: ``` android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt suspend fun paintWalletChildCached() = readWalletChild { requireWire().walletStatus() } suspend fun refreshWalletChild() = readWalletChild { requireWire().walletChildRefresh() } ``` What the tests pin (virtual time, so the 2s cadence is asserted exactly): - the cached read paints exactly once and every tick after it is the live probe (4 ticks of virtual time → `cached == 1`, `live == 3`, `currentTime == 8000`); - a probe that takes 5 ticks is never overlapped — `maxInFlight == 1`, three probes, the tick pushed out by the probe's own length; - cancelling the loop (leaving the wallet screen) stops the dialing. They have teeth: with `live()` mutated to `cached()` in the loop, all three fail — ``` WalletChildRefreshLoopTest > the_first_paint_is_the_cached_read_and_every_tick_after_it_is_live FAILED java.lang.AssertionError: the cheap read paints once, and only once expected:<1> but was:<4> WalletChildRefreshLoopTest > a_probe_slower_than_the_tick_is_never_overlapped FAILED java.lang.AssertionError: two concurrent wallet_child_refresh probes is a race expected:<1> but was:<0> WalletChildRefreshLoopTest > cancelling_the_loop_stops_the_probes FAILED java.lang.AssertionError: two ticks have gone by expected:<2> but was:<0> ``` Full suite green on this branch's tree (commit `4d2528351b6df2c54ce5506797722f37317047e5`, the head that was pushed): ``` $ ./gradlew :app:testDebugUnitTest --no-build-cache \ -x :sdk:cargoBuildAndroid -x :sdk:cargoHostLib -x :sdk:uniffiBindgen -x :sdk:verifyDynamicLibc > Task :app:testDebugUnitTest BUILD SUCCESSFUL in 1s WalletChildRefreshLoopTest tests=3 failures=0 errors=0 crypto.StoreSecretTest tests=11 failures=0 errors=0 crypto.StoredPassphraseStoreTest tests=9 failures=0 errors=0 keepalive.KeepAlivePolicyTest tests=3 failures=0 errors=0 keepalive.NodeLifetimeTest tests=9 failures=0 errors=0 ui.InviteAddFlowTest tests=5 failures=0 errors=0 ui.MessageDeliveryTest tests=10 failures=0 errors=0 ui.OutboxDetailTest tests=17 failures=0 errors=0 ui.UnlockSubmitTest tests=3 failures=0 errors=0 ui.WalletChildStatusTextTest tests=47 failures=0 errors=0 ``` (117 tests, 0 failures. `--no-build-cache` so a `FROM-CACHE` is not reported as a pass. The `-x`s skip the Rust tasks; `:sdk:uniffiBindgen` was run first against this checkout to regenerate `android/sdk/build/generated/uniffi/`, which carries `suspend fun walletChildRefresh(): WalletChildStatus` on the `Wire` interface. Note the recipe needs `-x :sdk:verifyDynamicLibc` as well — it depends on `cargoBuildAndroid`, so excluding the latter alone leaves the verifier to fail on a missing `.so`.) ## Base `base = main`. The parent card `t_0a355a62` (rust-dev: export `Wire::wallet_child_refresh` over UniFFI, PR #132) is **merged** into `main` as `fa0e4b2` — `git merge-base --is-ancestor origin/wt/t_0a355a62 origin/main` exits 0 and `git rev-list --count origin/main..origin/wt/t_0a355a62` is 0 — so this branch is cut from `origin/main`, not stacked. `crates/onionwire-sdk/**` is untouched by this PR. ## Scope Only `android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt` and the new test. `ui/WalletChildStatusText.kt`, `ui/WalletScreen.kt`, `.forgejo/**`, every `build.gradle.kts` and everything under `src/**` / `crates/**` are untouched. `android/README.md` and `android/CUPRATE_DAEMON.md` were checked and neither describes the refresh cadence as a cached read (CUPRATE_DAEMON.md says "the blocks the chain daemon had at the last probe", which is now true rather than aspirational), so no doc change. `android-ci / android` will run on this PR (`android/**` is in its `pull_request` path filter) and builds the release APK path through `scripts/build-android-local.sh`; it does **not** run these JVM tests, which is why the output above is pasted here.
android: poll the live wallet-child probe so the sync line moves
All checks were successful
android-ci / android (pull_request) Successful in 10m51s
4d2528351b
The wallet screen's 2s loop read Wire::wallet_status, which only re-reads the
snapshot the last probe left in the store — so the `sync h/t` segment sat frozen
until a chain-mode tap ran start_wallet_child (which probes on its way out).

The loop now paints once from the cached read (non-dialing, so the screen has a
record immediately) and then calls Wire::wallet_child_refresh for every tick:
one live probe of the child's loopback wallet RPC, and of the configured local
daemon's get_info when that RPC does not answer. Same 2s cadence, same
Dispatchers.IO, same sticky walletChildError, same one-poller guarantee.

The loop is a top-level function taking its two reads as parameters, which is
the only seam a JVM test has — requireWire() is NodeHost.requireOpen(), a
process-global only a real Arti bootstrap sets. WalletChildRefreshLoopTest pins
that the cached read paints exactly once and every tick after it is the live
probe, that a probe slower than the tick is never overlapped, and that
cancelling the loop (leaving the screen) stops the dialing.
sirius merged commit d2d49d27c5 into main 2026-09-20 04:48:15 +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!134
No description provided.