Skip to main content
Show test progress while a command is running. This recipe uses the SDK to start and check each operation and its underlying client to open an SSE transport subscription. It deliberately closes the first connection, commits a cursor, and opens another connection for the same operation.

Prerequisites

Complete Set up access. In a fresh project, run uv init --python 3.12 and uv add "contree-sdk[async]==0.5.1" "contree-client==0.6.0". The SDK reads the connection from your environment or saved profile; credentials stay in the local client and are not passed to guest code. The available tag:alpine:latest image supplies the POSIX shell, test, grep, and sleep. The example is synchronous, so uv add "contree-sdk==0.5.1" "contree-client==0.6.0" is sufficient if async support is not needed. Start with main() and run_variant(). The first run passes; the second deliberately fails a test and returns process exit code 1. consume_events() displays complete events before committing their IDs. It closes the first connection after five events, then passes that cursor as last_event_id on a new request if completion has not already arrived. For ordinary application streaming, prefer operation.events(), which shares one reader and supports buffered replay with since=N. The direct client subscription here demonstrates an actual network disconnect and Last-Event-Id resumption. A second events() subscription on the same handle would replay its memory buffer without closing the transport.

Complete source

Save as stream_tests.py and run uv run python stream_tests.py. Representative output follows; IDs and chunk boundaries vary:
The client decodes SSE and handles transport reconnection, including in-band SSE errors, using its last received ID. The application’s committed cursor advances only after an event is decoded and displayed; the forced new subscription starts from that cursor. Persist the cursor with any durable consumer side effects when adapting this pattern. Reconnection failure, malformed output, missing completion, truncation, or an unexpected final result fails the program and triggers operation shutdown. The final wait() retrieves the typed process result; it may open its own reader after the direct transport subscription has closed. A nonzero test exit remains a successful API operation. Both runs are disposable and have 30-second guest execution limits. Each event subscription and final wait has a 45-second local limit; synchronous network reads and cleanup can extend those waits. The finally block stops work still owned by this program after local failure. See Stream output and events and the SSE endpoint reference.