fix(observer): project each run into its channel and scope the link to it
Problem
The Observer: link flows run printed opened an arbitrary workspace channel with nothing about the flow:
- No run published anything to Relaycast — only agent communication was projected.
- The token was workspace-wide, so the dashboard opened whichever channel listed first.
- The link was minted and printed only after the run finished.
Reproduced before the change: flows run testdata/hello-deterministic.flow.yaml completed and printed a link; listing the workspace's channels afterwards showed no channel for the run.
Change
- kernel —
run.start {watch: true}streams the new run's entries on the starting connection fromrun.spawnedon. The watcher is registered before the first append (Engine::start_observed), so every entry arrives once and there is nothing to replay. This is the only way to observe a run whose id the caller does not yet know (YAML runs block inrun.start). Opt-in; unchanged without the flag.kernel/DESIGN.mdupdated. - sdk —
run-projection.tspublishes run start, every step transition and the terminal outcome intowf-<runId>(the channel agent communication already uses). Each message carries the run snapshot undermetadata.relayflow(version 1) for AgentWorkforce/relaycast#450 to draw.journal-projection.tsfolds the journal stream for YAML runs; authored runs use the executor's progress events plus a newonRunStartedhook. Resume usesrun.watch, and replayed history updates the snapshot without re-posting. - cli —
cli/observer-session.tsscopes the observer token to the run's channel (channel_names, no DMs) and printsObserver:on stderr as soon as the run exists, then on stdout afterRUNas before. - Fails open (RFC-0001 decision 7 — a projection, not the record). A projection or mint failure produces one
[observer]line and never touches the run. A daemon that predateswatchrefuses the field while decoding, before any run exists, so the CLI starts again without it and says the run was not projected. A refusedrun.watchon resume is ignored. - tests —
tests/isolate-workspace.ts(vitest setup) pointsAGENT_RELAY_HOMEat an empty dir and clearsRELAYCAST_WORKSPACE_KEY. Without it, any developer logged in withagent-relayhad SDK tests minting real tokens — and, with this change, publishing into their real workspace. That also pushed two live-CLI test files past vitest's 5s timeout.
Evidence
Live run against production cast.agentrelay.com. The channel afterwards (GET /v1/channels/wf-01m37ws2v3pbxb7y4zc4qx7hv1/messages):
▶ hello-deterministic started · 2 steps · run 01M37WS2V3PBXB7Y4ZC4QX7HV1 | running [('greet','pending'),('shout','pending')]
○ greet (deterministic) 0.00s | running [('greet','running'),('shout','pending')]
✓ greet (deterministic) 0.01s completionReason: success | running [('greet','completed'),('shout','pending')]
○ shout (deterministic) 0.00s | ...
✓ shout (deterministic) 0.00s completionReason: success | ...
■ hello-deterministic completed · completionReason: success | completed [...]
(Start lines now read started.) The minted token lists exactly one channel: ['wf-01m37ws2v3pbxb7y4zc4qx7hv1'].
Link timing. A roughly 15s fan-out/fan-in flow printed Observer: on stderr at 1.78s.
Live dashboard. Local engine and dashboard from relaycast#450, plus this branch: one page session went 0/4 → 1/4 → 2/4 → 3/4 → 4/4 steps.
Mutation checks (each: revert the change, run the test, capture the failure, restore byte-identically with cmp, re-run):
watchsent asfalse→streams the run into wf-<runId>…:AssertionError: expected undefined to be true/ restored:1 passed- old-daemon fallback removed →
starts again without watch…:AssertionError: expected 1 to be +0/ restored:1 passed - kernel
if false && params.watch→run_start_with_watch_streams_every_entry_once_before_the_result:test result: FAILED. 0 passed; 1 failed/ restored:2 passed
Suites
sh ../ops/cargo.sh test --workspace --no-fail-fast→cargo_exit=0, 26 test binaries allok.- SDK
npx vitest run:Tests 34 failed | 2928 passed | 64 skipped. All 34 are inauthored-node-runtime,babysitter-native-extension,hosted-base-snapshot,hosted-extension-isolationandhosted-extension-protocol. Those same files fail on a cleanmainworktree on this machine (Tests 35 failed | 61 passedacross the set), so they predate this PR.live-kernelanddirect-inputpass with the isolation fix. - Cost:
hello-deterministicexits in 1.32s with the observer on vs 0.52s withFLOWS_NO_OBSERVER=1, while the last messages are sent (bounded at 5s).
Found, not fixed here
- Kernel: the independent steps
lintandtestran serially (testrouted at 18.06s, afterlintcompleted).test'sstep.attempt.startedis stamped 8.03s, so itswallclock_msis 24055 for asleep 14. scripts/run-workflow.shdrives the v1relayflowsrunner and still prints a workspace-wide link.
🤖 Generated with Claude Code
[!NOTE]
Medium Risk
Adds an opt-in kernel protocol field and best-effort external Relaycast publication, but execution and admission remain unchanged when observation fails or is disabled.
Overview
flows run / flows resume now push a live run snapshot into Relaycast channel wf-<runId> and mint an ot_live_ link scoped to that channel (not the whole workspace). The link can appear on stderr as soon as the run id exists; --no-observer-link / FLOWS_NO_OBSERVER=1 still disable projection and minting.
Kernel: run.start accepts optional watch: true, streaming journal entry events on the starting connection from run.spawned onward. Engine::start_observed registers a pre-append hook so new runs need no replay; idempotent admission replays then watches the same run. Failed starts unwind the watcher; observation errors do not affect admission or execution.
SDK / CLI: run-projection and journal-projection publish step transitions and terminal status under metadata.relayflow (v1). YAML runs use run.start {watch} (with a fallback when an old daemon rejects watch); resume attaches run.watch and folds replayed history without re-posting stale terminal facts. Authored roots use onRunStarted plus executor progress. createObserverSession replaces the pre-run workspace-wide mint with channel-scoped tokens and bounded drain/cleanup of the session publisher agent.
Tests / docs: Vitest isolate-workspace prevents tests from hitting real Relaycast workspaces; new kernel and projection tests cover watch ordering, admission replay, and fail-open behavior. docs/OBSERVER-RUN-PROJECTION.md documents the producer contract.
Reviewed by Cursor Bugbot for commit 63c71cc481d4dd2edab560a92645550394cb71e4. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes the observer link flows run printed, which opened an arbitrary workspace channel with nothing about the flow: the token was workspace-wide, nothing projected the run, and the link only appeared after the run finished. Now each run projects its lifecycle into its wf-<runId> channel and the link is scoped to that channel, printed on stderr as soon as the run exists.
- Kernel:
run.start {watch: true}streams the new run's entries on the starting connection fromrun.spawned, registered before the first append so there is nothing to replay. This is the only way to observe a run whose id the caller does not yet know. - SDK: a run projection publishes run start, step transitions, and terminal outcome into
wf-<runId>, each message carrying the run snapshot undermetadata.relayflow(v1). YAML runs fold the journal stream (epoch summaries reset step state); authored runs use the executor's progress events plus a newonRunStartedhook. Publication goes through a per-session publisher agent, retired history-preserving after its queue drains — including when the create response was lost. - CLI: the observer token is scoped to the run's channel (no DMs) and the link prints on stderr as soon as the run exists, then on stdout after
RUNas before. - Resume keeps the watcher attached through a parked initial response; replayed history folds into the snapshot without re-publishing, and an old terminal fact cannot close the resumed projection.
- Fails open: a projection or mint failure produces one
[observer]line and never touches the run. A daemon that predateswatchrefuses the field while decoding, before any run exists, so the CLI starts again without it and prints that the run was not projected. A refusedrun.watchon resume is ignored. - Tests:
tests/isolate-workspace.tspointsAGENT_RELAY_HOMEat an empty dir and clearsRELAYCAST_WORKSPACE_KEY, so SDK tests never mint real tokens or publish into a developer's real workspace.docs/OBSERVER-RUN-PROJECTION.mdrecords the design and its fail-open boundaries.
Agent Relay sessions