GetAgentStream: start a stream, simulate a mid-stream crash by cancelling the Events context (subscriber only), then reconnect from the last saved offset to receive remaining events — including events emitted while the subscriber was gone.
Source: examples/agent_with_reconnect/
What it demonstrates
- The 5-step caller-side reconnect protocol
- Capturing
runIDfromstream.ID()before consuming events - Tracking the
Offset()on each event and saving it as the resume point - Calling
GetAgentStream(ctx, runID)thenEvents(ctx, WithOffset(lastOffset))from a fresh context - Discarding already-processed events (offset ≤ saved offset) after reconnect
- Handling
ErrRunAlreadyCompletedwhen the run finished while disconnected
Requirements
Requires a durable runtime — Temporal or Restate. Local runtime has no stream offsets. The same public API (GetAgentStream + WithOffset, GetAgentRun) works on both.
Single process: Temporal embeds a worker; Restate embeds the SDK endpoint.
Stream and Events when simulating a subscriber crash. The durable run continues server-side, and GetAgentStream resumes from the saved offset.
Key code
Expected output
kill -9. For a real process-kill story, see Durable Agent (Temporal) or Durable Agent (Restate).
Learn more
Durable Execution
Full protocol, API reference, and offset semantics
Durable Agent (Restate)
Real process kill + state file reconnect (single process)
Streaming
RunID, offsets, and the streaming API
Restate Runtime
Embedded endpoint and durable event delivery