Skip to content

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:

text
agentId + sessionId + threadId

The Lifecycle ​

Opening or recovering a thread uses two independent reads:

text
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 succeeds

Submitting work remains a separate command:

text
POST /inputs
  -> 202 { disposition, threadExecutionId?, startedAt?, result? }

The backend owns execution. Disconnecting an observer does not cancel the execution.

Read Control State ​

http
GET /sessions/{sessionId}/threads/{threadId}/state

Example:

json
{
  "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.

  • observedCursor is the coherent journal boundary observed with the control state.
  • activeExecution restores running and cancellation controls before history finishes loading.
  • pendingRequests restores 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 ​

http
GET /sessions/{sessionId}/threads/{threadId}/events?after=17
Accept: text/event-stream

The stream sends committed catch-up events and then waits for new commits on the same connection.

text
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:

text
: heartbeat

Clients must maintain separate notions of received and applied progress. Reconnect only from the greatest contiguous ThreadJournalCursor whose handlers completed successfully.

  1. Decode events in order.
  2. Parse the SSE id as the journal sequence number and verify it equals threadSequenceNumber.
  3. Apply the event through the same handler used for live delivery.
  4. Advance the applied cursor only after successful application.
  5. 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:

json
{
  "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:

json
{
  "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:

http
POST /sessions/{sessionId}/threads/{threadId}/executions/execution-123/cancel

The 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:

http
POST /sessions/{sessionId}/threads/{threadId}/responses

The 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:

  1. Preserve the last successfully applied cursor when possible.
  2. Read /state to restore control state and capture the current journal boundary.
  3. Open /events?after={sequence}.
  4. Apply catch-up events through the same projector.
  5. 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.

Built for production .NET agent applications.