flows status --cloud / flows logs: show running steps, add --watch and --follow

Merged
AG
1mo ago
+2135-323

flows status --cloud --watch and flows logs --follow

Closes the ticket's three items: live step rows on the hosted status page, a
watched page, and a followed runner log.

What changed

Live step rows (flows status --cloud, one-shot and watched).
running and backoff render ↻, waiting and needs_human render ⏸,
matching cli/status.ts's glyphs. A row in flight shows the number of the
attempt now running and the time since its startTime:

  ↻ agent-5  agent          running      attempt 1  6m50s

Only what Cloud's snapshot establishes is printed:

  • The attempt number comes from retryCount + 1, not attempts.length —
    those entries are completion records, so during a second attempt the array
    still holds one and would print attempt 1. It is printed only when the row
    also carries a startTime; a row with no dispatch evidence shows no attempt
    at all rather than attempt 1.
  • No /max denominator, no awaiting <kind>: <id>, no backoff until …:
    Cloud's step rows carry no maximum, no wait id and no backoff deadline.
  • Elapsed is derived only for a step that is in flight and has not ended. A
    finished step whose endTime is missing keeps the duration Cloud reported
    instead of being advanced to now. A start in the future clamps to zero.
  • A running run whose snapshot has no rows prints steps 0 then
    No step snapshot available yet. — a fact about the snapshot, where a bare
    steps 0 would be a claim about the run.

flows status --cloud --watch. Polls every two seconds; each tick reads
the run record, then the step rows, renders the whole page, checks the abort,
and emits it in one io.stdout call. ANSI clear only for a TTY (threaded
through CliIo.tty); redirected output appends complete pages. A failed poll
leaves the previous page untouched. The terminal page is printed once and no
further tick is scheduled.

flows logs <run> --follow. Reads the run record, then the log, each tick;
prints only whole lines, holding a partial line across polls so a secret split
on a chunk boundary is redacted as one line. Stops only when the run is
terminal and the envelope says done and the served bytes cover
totalSize; done with an active run keeps following, and a terminal run with
done: false keeps draining. Prints the header once and the run's footer once
(COMPLETED <run> completionReason: success).

Exit codes are the run's, not the read's. The raw-record validator behind
getCloudFlowRun moved to cloud-run-record.ts and is now shared, so
--watch/--follow block on exactly what flows run --cloud --wait blocks
on: 0 only on an attested completed/success, 1 on an attested failure or
cancellation, and cloud_invalid_response (exit 1) on a terminal record that
attests neither, or on a run status this client does not know.
getCloudRunDetailLive validates and maps the same response, so no second
GET per poll. Ctrl-C is observation_aborted, exit 1, and says the hosted run
was not cancelled. Existing read refusals keep their codes and exits.

Deliberate decisions

  • No offset paging. The route's offset is a byte count and content is a
    JavaScript string; subtracting one from the other silently loses text the
    moment the log contains a non-ASCII character — which the runner's own
    transition lines do (▶, ✓, ·). The Cloud-side contract could not be
    checked from this repo, so --follow re-reads the log whole each poll and
    prints the new suffix, refusing with cloud_log_rewritten if what was
    printed is no longer a prefix. Cost: a full read per poll, and the log held
    in memory. Benefit: no line can be duplicated or skipped. Documented in
    docs/CLOUD.md.
  • --follow --step is refused (invalid_invocation, before any request).
    A retry replaces a transcript and the rendered form is built from the whole
    JSONL; following it is a separate feature.
  • --json emits one final document, not a frame stream — the one the
    one-shot form would have printed, with --follow carrying the whole redacted
    log. Deliberately unlike check --watch's report-per-check. ok: true means
    the read succeeded; the run's outcome is the exit code. Called out in the
    docs as a choice, not a repository rule.
  • The page is two reads, not a snapshot. Detail then steps, against two
    projections; a step row can lag its header by a poll. Documented rather than
    papered over.
  • A terminal run whose log never reports done keeps draining. Stopping
    after N identical polls would be an arbitrary truncation; Ctrl-C ends it.
    Documented.

Module layout

cli/cloud-read.ts was 518 lines, past the AGENTS §1 threshold. The shared
pieces moved to dependency-only modules, so the one-shot and live entry points
import them without depending on each other (cli.ts dispatches both):

filelinescontents
cli/cloud-format.ts82safe, thousands, dollars, instant, ago, errorLines
cli/cloud-refusal.ts113refusalFor, fail, RUN_ID_REQUIRED, isTransientRead
cli/cloud-status-view.ts208the status page, live rows, the scrubbers
cli/cloud-live.ts310the two live entry points
cli/cloud-read.ts249argv and the three one-shot commands
cloud-run-record.ts64cloudRunState, isCloudRunActive

Verification

All commands run from packages/sdk.

npm run typecheck && npm run build && npm run typecheck:tests — clean:

> @relayflows/sdk@2.0.25 typecheck
> tsc --noEmit && tsc -p tsconfig.type-tests.json

> @relayflows/sdk@2.0.25 build
> tsc && node scripts/make-cli-executable.mjs

> @relayflows/sdk@2.0.25 typecheck:tests
> tsc -p tsconfig.tests.json

npx vitest run tests/cloud-live.test.ts tests/cloud-read.test.ts tests/cloud-run.test.ts tests/cli-status.test.ts tests/relay-cli-surface.test.ts tests/cli.test.ts:

 Test Files  6 passed (6)
      Tests  308 passed (308)
   Duration  3.62s

tests/cloud-live.test.ts is new: 43 cases over live rows (all four states,
retry in progress, unknown attempt, absent/invalid/future timestamps, elapsed
growing across frames, empty snapshot), watch lifecycle (running → completed,
already terminal, failed, cancelled, exactly one final frame and no extra poll,
TTY vs redirected), outcome integrity (completed with no valid result,
contradictory reason, unknown status, mismatched run id, needs_human step on
an active run), follow content (growth, no-op poll, blank and repeated lines,
CRLF, partial lines, unterminated final line, empty log, multibyte log),
draining (done + active, terminal + not done, transient failure on the final
read, finished failed run), security (secret split across polls), cancellation
(pre-aborted, between the two reads, during the sleep, aborted fetch, no
process handler installed), refusals and retries (404/401, 503 backoff growth,
cap and reset, zero requests on the refused combination), --json for both
verbs, and the argv/runCli wiring.

Mutation verification

Two behaviours, each reverted, failed, restored byte-for-byte (md5 compared),
and re-passed.

1. Attempt number from retryCount + 1, not attempts.length. Changed
cli/cloud-status-view.ts:85 to `attempt ${step.attempts.length}`:

 FAIL  tests/cloud-live.test.ts > live step rows > counts the attempt now running, not the completed attempt records
AssertionError: expected 'RUN 20d04c99-3fa8-48c9-9286-92d364a5b…' to contain 'running      attempt 2'

- Expected
+ Received

- running      attempt 2
+   ↻ agent-5  agent          running      attempt 1  6m50s

Restored (md5sum of the file and the backup both
c736206b848f19d523c4353d2c8cd071) and re-run:

 ✓ tests/cloud-live.test.ts (43 tests | 42 skipped) 7ms
 Test Files  1 passed (1)
      Tests  1 passed | 42 skipped (43)

2. The abort check before a frame is emitted. Deleted the
if (isAborted(signal)) return aborted(...) line between rendering and writing
the page in cli/cloud-live.ts:

 FAIL  tests/cloud-live.test.ts > cancellation > prints no partial frame when the abort lands between the two reads
AssertionError: expected [ Array(1) ] to deeply equal []

- Array []
+ Array [
+   "RUN 20d04c99-3fa8-48c9-9286-92d364a5bc2e   insight-proof-2022   running   started 7m01s ago   spend 0 in / 0 out / $0
+ steps 1: 1 running
+
+   ↻ agent-5  agent          running      attempt 1  6m50s",
+ ]

Restored (both 53d54ee5994b3ecfb687eb9ceb638c42) and re-run:

 ✓ tests/cloud-live.test.ts (43 tests | 42 skipped) 7ms
 Test Files  1 passed (1)
      Tests  1 passed | 42 skipped (43)

Full package suite: 7 files fail, for environment reasons, before this change

npm test in packages/sdk:

 Test Files  7 failed | 155 passed | 3 skipped (165)
      Tests  39 failed | 2558 passed | 25 skipped (2622)

The failures are tests/live-kernel.test.ts, tests/webhook-live.test.ts,
tests/mcp.test.ts, tests/provider-trigger-executor.test.ts,
tests/authored-node-runtime.test.ts,
tests/canonical-software-factory.test.ts and
tests/stuck-run-triage.test.ts, with two causes, neither touched by this
change:

  • spawn …/kernel/target/debug/relayflowd ENOENT — ops/cargo.sh puts build
    output under $HOME/.relayflows-toolchain/target/<hash>/, not
    kernel/target/, so the live-kernel suites find no binary in this sandbox.
  • expected an @relayflows/surface flow handle — this sandbox had no
    node_modules at all; installing pulled the published @relayflows/surface
    rather than linking packages/surface, so two copies of the surface are
    loaded.

Confirmed pre-existing by stashing the change (git stash push -- docs packages) and re-running exactly those seven files on the unmodified tree:

 Test Files  7 failed (7)
      Tests  39 failed | 50 passed | 18 skipped (107)

Same seven files, same 39 tests. The stash was popped and the working tree
restored before committing.

No kernel code was touched and no kernel test was run. The change is
TypeScript CLI and transport only.

Not done

  • Cloud-side live step snapshots (cloud#3921) and the transition lines
    (cloud#3918) could not be verified from this repo — both issue URLs were
    unreachable. Item 1 is therefore exercised against fixtures shaped like the
    documented step-row contract, not against a live hosted run.
  • --follow --step (rendered or raw) is refused rather than implemented.
  • No --watch for the local flows status; it stays a one-file offline read.

[!NOTE]
Medium Risk
Changes CLI exit semantics, streaming log redaction, and shared Cloud run attestation—security- and automation-sensitive—but behavior is heavily specified and tested; no server or kernel changes.

Overview
Adds live hosted-run observation via flows status --cloud --watch (2s redraw until terminal) and flows logs <run-id> --follow (append runner output until the log drains). Both use the same outcome rules as flows run --cloud --wait: exit 0 only on attested completed/success, 1 on failure/cancel or Ctrl-C (observation_aborted), with shared validation in new cloud-run-record.ts and getCloudRunDetailLive.

flows status --cloud now renders in-flight steps like the local view (↻/⏸, attempt from retryCount + 1, elapsed from startTime) without inventing max attempts or wait metadata; empty snapshots on active runs get an explicit message.

--follow re-reads the full log each poll (no byte offset paging), refuses --step and cloud_log_rewritten if the prefix changes, and releases lines only after block-wise redaction (openSecretStart / openCredentialStart) so secrets and split credential headers cannot leak across polls.

Refactors oversized cloud-read.ts into shared format/refusal/status modules plus cloud-live.ts; CliIo.tty controls ANSI clear on watch. Docs (CLOUD.md, SURFACE.md) and tests/cloud-live.test.ts cover the new behavior.

Reviewed by Cursor Bugbot for commit be836baf3d5b0eef14fd7728cafff28f037a4058. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Adds live reads for hosted runs: flows status --cloud now renders running steps with elapsed time, --watch redraws the page every two seconds until the run ends, and flows logs <run> --follow appends new runner output until the run is terminal.

  • Both live commands exit with the run's outcome, not the read's, through the validator flows run --cloud --wait already uses (extracted to cloud-run-record.ts and shared): 0 only on an attested completed/success, 1 on failure or cancellation, cloud_invalid_response on a terminal record that attests neither.
  • Ctrl-C ends the observation (observation_aborted, exit 1) without cancelling the hosted run.
  • Elapsed time is derived from startTime for in-flight rows and is never overridden by a stale duration_ms, so a watched frame's clock keeps running.
  • --follow re-reads the whole log each poll and prints only the new suffix, redacting the un-released remainder as one block rather than line by line, so a multi-line secret such as a PEM key cannot leak; a snapshot that no longer extends printed output refuses with cloud_log_rewritten. A trailing named-credential header (authorization:, Bearer, x-callback-token:, x-nightcto-evidence-token:) split across polls is held rather than printed in clear: the release cut shrinks until the header is inside the held remainder and never grows over it, so the header and its value leave together once the line completes — which also prevents the hold from bouncing forever between a header and a blank line, or releasing a header plus the first line of a still-arriving multiline secret. A done snapshot drains only after a post-terminal log read, so a stale upload marker cannot truncate the run's last bytes. Offset paging was avoided because the route's offset is a byte count and the content is a string, which would lose text on the first non-ASCII character.
  • --follow --step is refused before any request.

Refactors

  • cli/cloud-read.ts (518 lines, past the project's threshold) was split into dependency-only modules — cloud-format.ts, cloud-refusal.ts, cloud-status-view.ts, cloud-live.ts — so the one-shot and live entry points share formatting, refusals, and the status view without import cycles. Adds cloud-run-record.ts (cloudRunState, isCloudRunActive), now the single source of truth for what a run record attests.
  • New tests/cloud-live.test.ts covers 43 cases across live rows, watch lifecycle, draining, follow content, redaction, cancellation, and refusals.

Fixes #540


Agent Relay sessions

  • devin session bead-mac · contributor · ran gh pr commands · last active 2026-09-23