Run Events SSE API
The /runs/events endpoint streams real-time updates about evaluation runs using Server-Sent Events (SSE). Clients subscribe once and receive run status transitions, progress counters, item-level updates, and log records.
Endpoint Summary
Authentication & CORS
- The stream respects the same authentication (cookies/session headers) as other API calls. Clients should set
withCredentials: truewhen constructing theEventSourceso cookies are forwarded. - CORS is enabled by default; the backend returns the appropriate
Access-Control-Allow-Originheader so long as the request originates from a trusted frontend.
Query Parameters
Stream Lifecycle
- The server immediately sends a comment
: readyto signal the connection is live. - If no events occur for 15 seconds, a keep-alive comment
: pingis emitted; clients can ignore these. - The connection stays open until the client closes it, the limit is reached, or Redis/back-end errors occur.
Event Types
Each data message is a JSON object with a type property. Four event types are currently supported.
run_status
Emitted whenever a run transitions state (for example pending → running → completed, a retry window is scheduled, a cancellation is requested, or a worker resume is recorded).
statusmatches the REST schema (pending,running,completed,failed,canceled).startedAt/finishedAtare ISO-8601 timestamps in UTC and may benullif not yet known.retryCountreports how many automatic retries have been attempted (0 when never retried).retryAfteris the next scheduled retry timestamp (UTC). It isnullonce the run is dispatched or finishes.retryRequestedAtandretryReasoncapture the moment and reason the scheduler enqueued the latest retry.resumedCountandlastResumedAtare present when the worker resumed an existing run after an interruption.cancelRequestedAtis present when a user asked to cancel an in-flight run. During that phase the UI should keep the current item visible until the provider request settles.
run_progress
Reports coarse-grained execution counts so the UI can show progress indicators.
completedrepresents the number of dataset items processed so far.totalis the expected item count for the run (inclusive of variations).
run_item
Emitted when an individual dataset item starts, emits activity snapshots, completes, or fails. This is the event used by the active runs board to keep the current card and recent-history stack in sync.
phaseis one ofstarted,activity,completed, orfailed.sequenceis the 1-based item order within the run.itemcontains the stage snapshot for the current question card.responseis the current textual response snapshot and may benulluntil the request finishes.scoreandlatencyMsmay benullwhile the item is still running.activityis optional and carries the persisted per-request observability snapshot:requestStartedAt,firstChunkAt,lastChunkAt,requestFinishedAttransport(streamingorbuffered)streamingRequested,streamingFallback,fallbackReasonchunkCount,textChunkCount,reasoningChunkCountresponsePreview,responsePreviewTruncatedreasoningPreview,reasoningPreviewTruncated
- Activity snapshots may be repeated as the request progresses and may also be echoed on the terminal
completed/failedsnapshot so the client can settle the final card without an extra REST fetch.
run_log
Streams log lines generated by the pipeline (queue events, errors, scoring summaries, etc.).
levelis one ofdebug,info,warn, orerror.datacontains structured metadata (JSON) when available and may benull.
Client Guidelines
- Instantiate once: Create the
EventSourcewhen the app shell mounts and share updates via state management (TanStack Query in our SPA). - Handle recoverable SSE failures: Redis/back-end interruptions may close the stream. Retry with backoff when
source.onerrorfires, but keep the last hydrated/runs/activesnapshot so the UI remains coherent during reconnect. - Cache updates: Use status and progress events to update run lists, and use
run_itemfor card-level UI updates; the SPA invalidates stale queries for affected runs and items when necessary. - Preserve in-flight cancellation semantics: If
cancelRequestedAtis present but the current item still has an unfinished request, keep that card visible and show a cancellation-requested state instead of collapsing immediately to terminal history. - Cleanup: Always call
source.close()when unmounting or when navigating away to avoid leaking sockets.
Migration Notes
- 2025-11-05:
run_statusgained retry metadata (retryCount,retryAfter,retryRequestedAt,retryReason). Clients should ignore unknown keys if unused. - 2026-03-12:
run_statusmay also includeresumedCount,lastResumedAt, andcancelRequestedAt, andrun_item.phasenow includesactivity. Clients that assumed only terminal item phases should update their parsers and reducers accordingly. - When upgrading, confirm any SSE parsers that assume a fixed key order or shape (for example zod schemas) are updated to mark the newer keys optional.
- The SPA stores the latest retry/resume/cancel snapshot alongside the run list and active board.
Custom consumers can follow the same pattern: hydrate from
/runs/active, mergerun_statusandrun_itemevents, and fall back to a fresh read-model fetch after reconnect.
Example (React)
Troubleshooting
- CORS errors: Ensure the frontend origin is allowed and that credentials are enabled in both the client (
withCredentials) and the server middleware. - Flooded logs: Filter
run_logevents bylevelbefore displaying in the UI. - Missing updates: Confirm Redis is reachable by the API process; broadcasts fall back silently if Redis is unavailable (logged server-side).
