android: drive the runs list and run detail from server pushes

Replace the Android app's one-second run poll with the server's
workspace-scoped run_event pushes. The runs list, each pipeline row's
last-run line, the run header and the run detail (status, timeline,
stages, artifacts) now advance from the socket instead of polling or a
manual refresh.

- Wire: Message.kt mirrors internal/protocol/runevents.go (subscribe,
  unsubscribe, run_event; RunEventFrame/RunStepDelta). The frames are
  unsolicited and already arrive on the client's events stream;
  PipelinesRepository.subscribeRuns/unsubscribeRuns add the typed
  command, sent via a new PipelinesClient.sendOnly that does not hold the
  send lock waiting for the running server's unreliable subscribe ack.
- One pure fold: ui/RunEvents.kt folds a frame into the list (in place,
  order preserved) and the open detail with one shared status ladder and
  one shared run-field merge. It is monotonic (a stale or duplicate
  delta is dropped whole), reports needsResync for a run the list does
  not hold instead of inventing a row, and only requests a full get_run
  for a settled step or terminal run.
- Wiring: AppViewModel subscribes once per (re)connect and workspace;
  every (re)subscribe re-reads the list and open detail once, because the
  deployed server's subscribe snapshot is partial, then folds the pushes
  on top. Re-reads are push-driven, coalesced and keyed so no push is
  dropped and no timer remains. LiveBadge (RunStream.kt RunStreamState)
  shows honestly live/reconnecting/not live, confirmed by the ack, a
  push or a successful read and dropped when a read fails.
- ui/RunEventsTest.kt pins the delta sequence as pure cases: created run
  not in the list, step started, step finished, run finished, unknown
  run, duplicate/out-of-order deltas, and a reconnect resync.
- android/README.md records the change, the wire mapping and the
  observed limitation of the running server (partial snapshot, no ack
  within 30s), which the client tolerates without inventing a stream.

Checked where the change belongs: android/README.md gained this entry;
docs/cli.md described the Android app as still polling, which this makes
stale, so that sentence now says the app consumes the pushes while the
TUI still polls. The packaged TUI pipeline templates (internal/tui) do
not touch run-state refresh and need no change, and the packaged
authoring skill references (internal/author/skill/references) document
the authoring workflow, not the Android client's run updates, so none of
them needs updating.

Reviewed and approved by the run's review stage (build, unit tests,
Kotlin compile and lint in android/README.md); no merge/rebase/cherry-pick
was in progress and no conflict was present.
This commit is contained in:
2026-10-17 11:15:21 +01:00
parent 7875762b9a
commit 6a6c1d65fa
12 changed files with 1151 additions and 16 deletions
+85
View File
@@ -5268,3 +5268,88 @@ measured grid at `wm size 2000x2244` — and that each card opens a Summary / Gr
language. The empty, loading, error and unparseable-source states were built from
the app's shared state components but could not be produced live without mutating
the operator's server.
### Live run updates from the socket (17 Oct 2026)
`android/` only. The runs list, each pipeline row's last-run line, the run header
and the run detail (status, timeline, stages, artifacts) now advance from the
server's pushes; the one-second poll is gone.
- **Wire.** `data/protocol/Message.kt` mirrors `internal/protocol/runevents.go`:
the `subscribe`/`unsubscribe`/`run_event` types, the optional `run_ids` scope
and the `run_event` payload (`RunEventFrame`/`RunStepDelta`). The frames are
unsolicited (no request id), so they already flowed through the client's
`events` stream; `PipelinesRepository.subscribeRuns`/`unsubscribeRuns` add the
typed command. `subscribe` is sent with `PipelinesClient.sendOnly` (it does not
hold the send lock waiting for the ack) because the running server does not
reliably ack it; any ack/error still lands on `events` with the request id.
- **One pure fold.** `ui/RunEvents.kt` folds one frame into the runs list (in
place, order preserved) and into the open run detail (status, timestamps,
current stage, completed count, and at most one step by sequence). It is
monotonic: a stale `running` delta after a settled run, or a late step delta,
is dropped whole, so an out-of-order or duplicate frame never regresses or
duplicates a visit. A frame for a run the list does not hold reports
`needsResync` rather than inventing a row the compact delta cannot describe.
The row and the detail share one run-field merge and one status ladder
(`RunStateFields`/`advanceStatus`), so their monotonic rules cannot drift.
- **Wiring.** `AppViewModel` subscribes once per (re)connect and per workspace
(a reconnect clears the watch and re-subscribes). Every (re)subscribe then
re-reads the list — and the open run, if any — *once*, because the running
server's subscribe snapshot is not guaranteed complete; the pushes that follow
fold on top of that authoritative read. `applyRunEvent` folds the frame into
`runs` and `runDetail`; an unknown run or a terminal transition triggers one
coalesced `list_runs` re-read, and a settled step or terminal run triggers one
coalesced full `get_run` so the artifacts/output the compact delta omits fill
in. Both re-reads are push/connect-driven, coalesced and loop only if a newer
frame arrives while the read is in flight (the open detail discards and retries
a fetch that a newer frame overtook, keyed by run id so switching runs mid-fetch
is not dropped), so nothing is stale and no timer polls.
- **Honest status.** `RunStreamState` (live/reconnecting/not live) is confirmed
by the subscribe ack, the first push, or a successful (re)connect read (the
running server's ack is unreliable, so a push and the connect read also confirm
it) and shown by the small `LiveBadge` in the runs list and the run detail. A
failed list/detail read is *not* swallowed: it drops the badge to
reconnecting and retries with a bounded backoff, so the badge never keeps
saying "live" over state that failed to update. A manual refresh stays but is
never required.
- **No fighting the operator.** Rows update in place under stable LazyColumn
keys, so scroll, the selected row and an open pane do not jump and the list
does not reshuffle while it is read.
Evidence (macOS, JDK 17, Gradle 9.7.1 `--no-daemon --offline`,
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
- `gradle --no-daemon --offline :app:assembleDebug :app:testDebugUnitTest` →
`BUILD SUCCESSFUL`; the JUnit XML totals **446 tests, 0 failures, 0 errors, 0
skipped**. New `RunEventsTest` (16 cases) pins the delta sequence: a created run
not in the list (resync), a step started, a step finished (with completed
count), a run finished, a delta for an unknown run (resync), a
duplicate/out-of-order list and step delta (no regression, no duplicate visit),
a settled step keeping its word against a later terminal delta, a reconnect
resync that ignores a later older delta, and the full-sync heuristic.
- **The push path was confirmed on the running server** (`ws://10.0.0.75:8080`,
build `v0.0.0-20261017013542-7875762b9a2c`, i.e. this tree's `7875762`) by
dialling `/connect`, sending `list_runs` (241 runs) then
`subscribe {workspace:/Users/alan/repos/pipelines}`, and reading back
`run_event` frames (`run_id=239 … status=failed finished=…`,
`run_id=230 … succeeded`). Server-side push is a separate lane and is present;
no client-side stream was invented. **Observed limitation of that running
(dirty) server:** its subscribe snapshot was partial and its `subscribe` ack
did not arrive within 30s. The client therefore does not depend on the ack to
read live or to update: pushes confirm the stream and a delta for a run the
list does not hold re-reads `list_runs`. This is the server lane's to fix; the
client is correct against both the acked snapshot defined in
`internal/protocol/runevents.go` and the deployed behaviour.
- **APK publish.** `app-debug.apk` (18,754,221 bytes, sha256
`dbddf756b5eb26f87ba4e2083fb979829b5d349d9cf1b114941e9ceeb137ddf1`) copied to
`~/.local/share/pipelines/data/artifacts/240/3/pipelines-debug-wip-7875762.apk`;
`curl -I` (to `http://10.0.0.75:8080/artifacts/240/3/pipelines-debug-wip-7875762.apk`)
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18754221`. This republishes the artifact with its actual hash:
the earlier `240/1` copy's recorded sha256 did not reproduce from this tree.
Not verified in this pass (device work belongs to the visual-review stage, which
owns the operator's Pixel 9 Pro XL): the on-device status change with no refresh
and the live/reconnecting badge rendering. The captures and the phone's
main-revision restore are that stage's evidence.