Skip to main content
The REST event endpoint exposes a server-sent events (SSE) stream for one operation. It carries primary-process and child-process events, including stdout, stderr, spawn, exit, and completion. The subscription observes execution; disconnecting it does not cancel the operation or extend its lifetime. Complete access setup, create an operation, and keep its UUID. The end-to-end streaming recipe runs a small test suite and follows its events with the SDK.

Stream with the Python SDK

Use an explicit ContreeSession when an operation handle is needed. The default lazy session returns a subprocess handle from spawn(). Configure credentials and install SDK 0.5.1 as shown in the Python quickstart.
The command prints streamed output followed by Exit code: 0. wait() checks the terminal operation and returns the primary process result. A failed operation raises FailedOperationError; cancellation raises InterruptedError. Check output truncation when complete logs are required. One operation handle shares a single event reader across events(), wait(), and subprocess consumers. Each iterator has an independent cursor; operation.events(since=42) replays buffered events whose IDs exceed 42, then follows new events. spid=... filters a process. Events remain in memory for the lifetime of the handle. Release completed handles when replay is no longer needed. The client reconnects the transport stream. Closing one iterator or letting events(timeout=...) expire stops that subscription; it does not cancel the operation. A failed or cancelled wait() attempts remote cancellation. Call cancel() deliberately to stop remote work, and inspect its terminal state before repeating it. In async code, select ContreeAsyncSession, await spawn() and wait(), use async for, and await shutdown().

Choose live or historical reading

Use follow=1 to send available events and continue following an active operation. Use follow=0 to read only the events currently available. Following requires the operation’s spawn permission in addition to baseline list permission because the server keeps subscription state. Every normal frame has an id, an event name, and JSON data. Keepalive comments start with : and contain no application event. An sse_error frame reports an in-band stream failure after HTTP 200 has already been sent. The JSON object identifies the process with spid. The primary process is spid=1; additional subprocesses use spid values of 2 or greater. Add spid=<id> to the query when only one process is relevant.

Decode output as it arrives

For stdout and stderr events, inspect data.encoding before displaying data.value. Decode base64 values to bytes. An ascii value can be displayed as text. Preserve the channel label: stderr is useful even when the process ultimately succeeds. Output chunks reflect process writes and buffering. They are not guaranteed to align with application lines. Ordering is represented by the event IDs in the combined stream; do not infer a stronger ordering guarantee between the operating system’s stdout and stderr streams.

Commit a resumable cursor

Parse a complete SSE frame, validate its JSON, perform the application’s side effect, and only then save its event ID. The saved ID means “fully processed,” not merely “received from the socket.” If the connection breaks halfway through a frame, leave the cursor unchanged. Reconnect with the last successfully processed ID:
The service sends events after that ID. Consumers should still deduplicate by event ID so a crash between an external side effect and cursor persistence does not display or apply an event twice. The cursor belongs to your event consumer. Reconnecting continues observation of the same operation; it does not submit the command again.

Separate stream completion from execution success

An exit event reports that a process ended. A completion event describes operation completion. Neither replaces the final status query. After the stream closes, query GET /operations/{operationId} and check the terminal operation status, primary process exit code, signal, timeout flag, truncation flags, and any operation error. If recorded output is truncated, the stream is not an unlimited log store. Use the final result and a retained file artifact when the workload requires complete output, subject to the documented retention rules.

Recover observation failures

The SSE endpoint reference defines the wire format, query parameters, permissions, event schemas, and errors. The streaming recipe demonstrates progressive output, deliberate disconnect and resume, a successful test run, and a test run whose process exits nonzero.