android+server: make every view live from the pushed run events

The pipelines list (and every other run-state view) kept the row it had when
the screen was last fetched. Two class-level root causes, fixed here:

- The app subscribed to run events scoped to the one workspace the operator
  configured, so a run executing in another workspace (a lane worktree is its
  own workspace) never delivered a frame: the rows only changed on a manual
  refresh. The app now asks for the blank "any workspace" scope the server
  already treats as any (ALL_WORKSPACES in AppViewModel.subscribeRuns, blank
  default on PipelinesRepository.subscribeRuns). Workspace isolation on the
  server is unchanged: an explicit workspace scope still matches only that
  workspace (TestRunEventWorkspaceIsolation); the new
  TestRunEventAllWorkspacesSubscription pins the blank "any" scope.
- foldRunEvent refused to insert a run the list had never held, returning
  needsResync and leaving the list untouched, so a run started after the
  screen loaded appeared only after a fetch. The pushed frame now carries the
  pipeline identity a row needs (RunEventFrame.PipelineID/Name/Title/Version),
  so the fold inserts the new run at the head from the frame's own identity
  without a fetch and without reordering existing rows; a server that predates
  those fields still falls back to the one resync. Added fields and why each
  is needed: pipeline_id (row's pipeline join), name (row title), title (the
  stored operator-facing title a row shows), version (the row's pinned
  version) - everything a RunSummary row renders, so no per-event fetch and no
  guess from stale cache. The server stamps them on every emitted frame from a
  per-run identity remembered at create/decide/cancel/resume (runner.go
  runIdentity/rememberRunIdentity/stampRunIdentity), first-write-wins through
  the coalescer (mergeRunEventFrame) and on the subscribe snapshot, so every
  transition - created/queued, running, each stage start/finish, terminal -
  carries them. Reconnect still resyncs once then follows pushes; the
  pull-to-refresh path is untouched.

Checks run: go build ./..., go vet ./..., go test ./... (all packages ok),
go test -race -run 'RunEvent|RunEvents|Subscribe' ./internal/protocol/
./internal/server/, and gradle --no-daemon testDebugUnitTest assembleDebug
(558 tests, 0 failures, 0 skipped; BUILD SUCCESSFUL).

Packaged templates and the packaged authoring skill references were checked:
nothing there describes the run_event field list or the client's subscription
scope, so neither needs updating (references/notifications.md only says the
attention surface is derived from the pushed run events, which is unchanged).
Docs are a shared file owned by a single writer and were not edited:
docs/cli.md's description of the pushed `run_event` frame still enumerates
only the older fields (status, outcome, current stage, completed-step count,
timestamps, optional step) and is now incomplete - it should mention the
pipeline identity fields; docs/ntfy.md remains accurate.
This commit is contained in:
2026-10-17 20:20:05 +01:00
parent 50af9dbc62
commit 5e2aece1be
11 changed files with 433 additions and 51 deletions
@@ -161,6 +161,13 @@ func TestRunEventWebSocketPushesTransitions(t *testing.T) {
if stepStarted == nil || stepStarted.RunID != runID || stepStarted.Status != protocol.RunStatusRunning || stepStarted.CurrentStage != "one" || stepStarted.Step.Sequence != 1 || stepStarted.Step.Stage != "one" {
t.Fatalf("step-started frame = %+v", stepStarted)
}
// Every frame carries the run's pipeline identity and stored title, so a
// client that has never held the run can build its list row from the frame.
for name, frame := range map[string]*protocol.RunEventFrame{"created": created, "step-started": stepStarted} {
if frame.PipelineID != ids[0] || frame.Name == "" || frame.Title == "" || frame.Version != 1 {
t.Fatalf("%s frame identity = %+v, want pipeline %d with name/title and version 1", name, frame, ids[0])
}
}
if stepFinished == nil || stepFinished.RunID != runID || stepFinished.Step.Status != "completed" || stepFinished.Step.Outcome != "success" || stepFinished.Step.Target != protocol.SuccessEnd || stepFinished.CompletedSteps != 1 {
t.Fatalf("step-finished frame = %+v", stepFinished)
}
@@ -195,11 +202,27 @@ func TestRunEventSubscribeSendsSnapshot(t *testing.T) {
if first.RunEvent.RunID != run.ID || first.RunEvent.Status != "succeeded" || first.RunEvent.CompletedSteps != 1 || first.RunEvent.FinishedAt == "" {
t.Fatalf("snapshot frame = %+v", first.RunEvent)
}
// A snapshot for a run the client never saw also carries the identity its row
// needs, so a fresh subscribe renders it without a second read.
if first.RunEvent.PipelineID != ids[0] || first.RunEvent.Name == "" || first.RunEvent.Version != 1 {
t.Fatalf("snapshot identity = %+v, want pipeline %d version 1", first.RunEvent, ids[0])
}
if ack := client.read(); ack.Type != protocol.Subscribe || ack.ID != "snap" {
t.Fatalf("subscribe ack = %+v", ack)
}
}
// TestMergeRunEventFrameKeepsIdentity proves a coalesced frame keeps the run's
// identity from an earlier transition when a later delta omits it, so the merged
// frame a client actually receives still carries what its row needs.
func TestMergeRunEventFrameKeepsIdentity(t *testing.T) {
into := &protocol.RunEventFrame{RunID: 1, PipelineID: 4, Name: "release", Title: "Ship it", Version: 3, Status: protocol.RunStatusQueued}
mergeRunEventFrame(into, &protocol.RunEventFrame{RunID: 1, Status: protocol.RunStatusRunning, CurrentStage: "build"})
if into.PipelineID != 4 || into.Name != "release" || into.Title != "Ship it" || into.Version != 3 || into.Status != protocol.RunStatusRunning {
t.Fatalf("merged identity lost: %+v", into)
}
}
// assertNoRunEvent reads for d, ignoring responses, and fails if any run_event
// frame arrives.
func assertNoRunEvent(t *testing.T, client *runEventClient, d time.Duration) {
@@ -288,6 +311,49 @@ func TestRunEventWorkspaceIsolation(t *testing.T) {
assertNoRunEvent(t, client, 400*time.Millisecond)
}
// TestRunEventAllWorkspacesSubscription proves the blank ("any workspace")
// subscribe scope — the one the app now asks for because its runs list is
// server-wide — delivers a run from every workspace, while an explicit
// workspace scope stays isolated (TestRunEventWorkspaceIsolation). It is what
// lets the app see a run executing in a lane worktree, a different workspace
// from the one the operator configured.
func TestRunEventAllWorkspacesSubscription(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
_, handler, ids := eventStore(t, ctx, "one")
handler.runner.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
return stage.Result{Outcome: "success", Output: stage.Values{}}, nil
}
first := eventWorkspace(t)
second := eventWorkspace(t)
client := dialRunEvents(t, ctx, handler)
// The blank workspace is the "every workspace" scope; no run_ids narrows it.
client.send(protocol.Message{Type: protocol.Subscribe, ID: "all", Workspace: ""})
if ack := client.read(); ack.Type != protocol.Subscribe || ack.ID != "all" {
t.Fatalf("subscribe ack = %+v", ack)
}
// Subscribe first, then start a run in each workspace, so both are delivered
// as live deltas rather than only in the snapshot.
client.send(protocol.Message{Type: protocol.RunPipeline, ID: "a", PipelineID: ids[0], Version: 1, RequestKey: "all-ws-a", Workspace: first, Input: map[string]any{"prompt": "test"}})
client.send(protocol.Message{Type: protocol.RunPipeline, ID: "b", PipelineID: ids[0], Version: 1, RequestKey: "all-ws-b", Workspace: second, Input: map[string]any{"prompt": "test"}})
terminals := map[string]*protocol.RunEventFrame{}
deadline := time.Now().Add(8 * time.Second)
for len(terminals) < 2 && time.Now().Before(deadline) {
message := client.read()
if message.Type != protocol.RunEvent || message.RunEvent == nil {
continue
}
frame := message.RunEvent
if frame.Status == "succeeded" || frame.Status == "failed" || frame.Status == "canceled" {
terminals[frame.Workspace] = frame
}
}
if terminals[first] == nil || terminals[second] == nil {
t.Fatalf("blank-scope subscription missed a workspace: got %v", terminals)
}
}
// TestRunEventCoalescingBoundsFrameCount records how many run_event frames a
// typical multi-stage run produces and asserts the count stays bounded: rapid
// transitions coalesce, and the terminal frame is never dropped.