A request retry is not a session restore
A conventional gateway can route a new request to a healthy upstream. When an upstream connection disappears mid-stream, however, the client may already have consumed part of the response and the agent may have moved on to tool execution. Replaying the original request can duplicate work or produce a different continuation.
An agent session spans more than one HTTP exchange: it can include partial server-sent events, acknowledged output, tool-call chunks, and application state. A stateless proxy generally has no authoritative record of that full execution context.
It is useful to distinguish a TCP acknowledgement from an application acknowledgement. TCP confirms delivery to the peer's network stack; it does not prove that the agent persisted a token, displayed it to a user, or committed a tool result. A recovery design should define which layer owns each checkpoint and what the client can safely replay.
Checkpoint the boundary you can recover
A transport-aware design observes connection transitions and maintains explicit recovery state. It can identify a failed path, choose a healthy standby, and resume only from a checkpoint the system considers safe. The exact boundary depends on the protocol and on what the client and upstream have acknowledged.
A ring buffer can provide a bounded place to retain recent frames or offsets, but it is not automatically a durable workflow database. Define what happens when the buffer wraps, when a process exits before data is committed, and when the replacement worker has a different model or tool context. The recovery contract should state which state is retained and which state must be rebuilt by the application.
- Track stream offsets or frame sequence identifiers.
- Distinguish generated, transmitted, and client-acknowledged data.
- Avoid replaying side effects unless the operation is idempotent.
- Expose a clear policy for stale or incomplete checkpoints.
Why the operating-system boundary matters
Application-level retry libraries know the requests their SDK sends. An OS-boundary runtime can observe socket and worker health beneath a particular agent framework, which can reduce the need to rewrite each application around a new workflow abstraction.
That placement does not remove the need for application semantics. Authentication, tool idempotency, provider behavior, and the correctness of a restored checkpoint remain important and must be tested for each deployment.
The operating system can report that a connection closed or stalled, but it cannot infer every business-level commit from packet state alone. An application still needs to decide whether an operation is repeatable and how to reconcile an external side effect. Keep transport recovery and task orchestration as cooperating layers with a documented boundary.
Validate, do not assume
Use a failure lab or staging environment to break an upstream connection during a real stream. Record the last acknowledged event, confirm how the replacement is selected, and compare the resumed task with a clean control run. A handoff-latency measurement alone is not proof of end-to-end token continuity.
Test more than one cut point: before the first event, between events, during a tool call, and after the tool succeeds but before its result is persisted. For each case, verify the client-visible transcript, side effects, and final task state. Keep a negative test where recovery is deliberately refused because the checkpoint is ambiguous; safe failure is preferable to silently replaying work.
Check the local daemon health route
from urllib.request import urlopen
with urlopen("http://localhost:8080/health") as response:
print(response.read().decode())Use this request to verify that the local daemon is responding. Review the API reference for available management and telemetry paths.