Hosted Lifecycle And Recovery
Hosted clients use one server-authoritative lifecycle for control state, committed history, live observation, semantic input, and responses.
The runtime scope is:
agentId + sessionId + threadIdThe Lifecycle
Opening or recovering a thread uses two independent reads:
GET /state
-> restore activeExecution and pendingRequests immediately
-> capture observedCursor = N
GET /events?after={appliedCursor}
-> catch up canonical events after the client's cursor
-> remain attached for future commits
-> advance appliedCursor only after projection succeedsSubmitting work remains a separate command:
POST /inputs
-> 202 { disposition, threadExecutionId?, startedAt?, result? }The backend owns execution. Disconnecting an observer does not cancel the execution.
Read Control State
GET /sessions/{sessionId}/threads/{threadId}/stateExample:
{
"observedCursor": {
"sequenceNumber": 42
},
"activeExecution": {
"threadExecutionId": "execution-123",
"agentId": "assistant",
"sessionId": "session-1",
"threadId": "main",
"status": "active"
},
"pendingRequests": []
}/state is deliberately metadata-only. It does not return event history.
observedCursoris the coherent journal boundary observed with the control state.activeExecutionrestores running and cancellation controls before history finishes loading.pendingRequestsrestores permission, clarification, continuation, and client-tool interactions.
observedCursor is not an applied cursor. A client must not skip to it without projecting the intervening events.
Catch Up And Remain Live
GET /sessions/{sessionId}/threads/{threadId}/events?after=17
Accept: text/event-streamThe stream sends committed catch-up events and then waits for new commits on the same connection.
id: 18
event: agent-event
data: {"event":{"version":"1.0","type":"TEXT_DELTA","threadSequenceNumber":18,"text":"hello","messageId":"message-1"},"route":{"origin":{"sessionId":"session-1","threadId":"main"},"path":[{"sessionId":"session-1","threadId":"main"}],"threadExecutionId":"execution-123"}}Historical catch-up uses event: agent-event; newly committed live deliveries use event: live-agent-event. Both carry the same { "event": ..., "route": ... } data envelope, so project data.event and retain data.route for hierarchy and cursor attribution.
The server also accepts Last-Event-ID when the after query parameter is absent. It sends comment heartbeats while idle:
: heartbeatClients must maintain separate notions of received and applied progress. Reconnect only from the greatest contiguous ThreadJournalCursor whose handlers completed successfully.
- Decode events in order.
- Parse the SSE id as the journal sequence number and verify it equals
threadSequenceNumber. - Apply the event through the same handler used for live delivery.
- Advance the applied cursor only after successful application.
- On EOF or transport failure, reconnect from the applied cursor.
If projection fails, stop applying later events. Reconnection redelivers the failing canonical fact.
Submit And Track An Execution
Accepted input returns:
{
"disposition": "started",
"threadExecutionId": "execution-123",
"startedAt": "2026-07-15T10:15:30Z"
}Only one execution can own a thread at a time. Hosting reserves ownership, commits THREAD_EXECUTION_STARTED, exposes activeExecution, executes the input, commits THREAD_EXECUTION_FINISHED, and only then clears active ownership. A conflicting work submission, such as compaction, returns 409 with the ThreadExecutionActive error.
Send While A Turn Runs
A user message is never refused because the thread is busy. Send it to /inputs as usual, with no threadExecutionId:
{
"version": "1.0",
"type": "USER_MESSAGES_INPUT",
"messages": [
{
"role": "user",
"contents": [
{
"$type": "text",
"text": "Focus on the failing tests first."
}
]
}
]
}When the running turn can take it, the response is {"disposition": "steered", "threadExecutionId": "execution-123"} and the turn reads the message before its next model request. Otherwise the message starts the next turn as soon as the running work finishes, and the response is started.
Interrupt Safely
Read /state, then cancel that exact execution with its dedicated route:
POST /sessions/{sessionId}/threads/{threadId}/executions/execution-123/cancelThe successful response is a ThreadExecutionCancellationDto with the terminal status and whether cancellation was applied. An execution that is no longer the thread's active one returns 409 ThreadExecutionNotActive. Never automatically retry against a mismatched execution; it may be newer work started by another client.
Messages that joined the cancelled turn before it read them are answered in one follow-up turn, which starts on its own.
Interactive Responses
Pending request events are canonical journal facts and are also included in /state while answerable. Send the matching response envelope through:
POST /sessions/{sessionId}/threads/{threadId}/responsesThe request must already be answerable before its committed notification can reach observers. Reopening a client can therefore restore pending interaction UI without replaying the whole thread first.
Long Disconnects
For a laptop sleep, proxy timeout, or UI closed for hours:
- Preserve the last successfully applied cursor when possible.
- Read
/stateto restore control state and capture the current journal boundary. - Open
/events?after={sequence}. - Apply catch-up events through the same projector.
- Continue on the same stream as commits become live.
A client with no local projection starts at sequence zero, after=0, and reconstructs the complete conversation incrementally. It retains semantic UI state, not the raw event graph.
Transport Responsibilities
HTTP owns commands and control state. SSE owns ordered committed observation. Each transport therefore has one lifecycle responsibility.