You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds an explicit settlement await to the factory API so a caller can block
on a run reaching a terminal status without hand-rolling a poll loop.
`waitForRun(runId, { signal? })` resolves with the terminal envelope once the
run settles into completed, error, halted, or cancelled, and resolves
immediately when it has already settled. It subscribes to the run's
`factory.run_updated` invalidation events and re-reads the durable envelope
rather than polling on a timer. The subscription is installed before the first
read so a transition landing between the two cannot be missed, and re-reads are
serialized so a burst of events collapses into one in-flight read — the run's
revision advances once per operation, so bursts are the normal case. The
subscription is released on settle, abort, and read failure. Aborting rejects
the wait and leaves the run executing; cancel() remains the way to stop it.
Also exports `isFactoryRunTerminal(status)` and the `FactoryRunStatus` type so
callers driving their own loop share one definition of terminal.
This is additive and carries no wire change: it is built entirely on the
existing `getRun` method and `factory.run_updated` session event, so it is
correct against the current foreground runtime, where it resolves on the first
read. It becomes load-bearing under background execution, where `run()` resolves
with a running envelope and `result` is only readable after settlement.
Verification: 94 factory unit tests pass (81 existing, 13 new). The runtime's
Agent Factories E2E suite passes 19/19 under STRICT_CAPTURES against a build of
this branch. The coalescing and unsubscribe tests were mutation-tested — each
goes red with its guard removed.
`getRun(runId)` reads the latest run envelope, and `cancel(runId)` cancels a run and returns its terminal envelope.
212
212
213
+
`waitForRun(runId, options?)` resolves with the terminal envelope once the run settles into `completed`, `error`, `halted`, or `cancelled`, and resolves immediately when it has already settled:
It watches `factory.run_updated` and re-reads the durable envelope rather than polling on a timer, and it collapses a burst of invalidation events into a single in-flight read. Pass a `signal` to stop waiting:
Aborting rejects the wait and has no effect on the run, which keeps executing — use `cancel(runId)` to actually stop it. Because a terminal envelope is final, the resolved value never changes afterwards. `isFactoryRunTerminal(status)` exposes the same terminal-status test for callers driving their own loop.
231
+
213
232
Listen for the ephemeral `factory.run_updated`event. Its`{ runId, revision }` payload is an invalidation signal. Re-read the desired API when a newer monotonic revision arrives.
214
233
215
234
Revisions cover durable lifecycle, accounting, phase, agent, and progress changes. Continuous read-time fields can change without a newrevision. These include `observedAt`, active-time calculations, live counts, and a live agent's status or prompt-safe activity text. Factory prompts are never exposed by these APIs. A run is visible only through the session that owns it.
0 commit comments