Skip to main content
A session represents an active connection between T3 Code and a provider (currently Codex). Sessions manage conversation threads, turn execution, and maintain stateful connections to the underlying agent infrastructure.

Session Lifecycle

Sessions progress through distinct states during their lifetime:
1

Connecting

The server spawns a codex app-server process and establishes JSON-RPC communication over stdio.
2

Ready

The session is idle and ready to accept new turns. No active agent execution is in progress.
3

Running

A turn is actively executing. The agent is processing user input, running tools, or generating responses.
4

Error

A recoverable error occurred. The session may be able to continue with intervention.
5

Closed

The session has been terminated and can no longer accept commands.

Session Schema

Sessions are represented by the ProviderSession type:
packages/contracts/src/provider.ts
The resumeCursor field stores provider-specific state needed to resume a thread after restart. For Codex, this contains the provider’s internal thread ID.

Starting a Session

Sessions are started via the ProviderService.startSession method:

Session Resume Behavior

When a resumeCursor is provided, T3 Code attempts to resume the existing Codex thread:
1

Resume Attempt

Send thread/resume JSON-RPC request to Codex app-server with the provider thread ID
2

Success Path

If resume succeeds, the session reconnects to the existing thread state
3

Fallback Path

If resume fails with a recoverable error (thread not found, missing thread), automatically fall back to starting a fresh thread
4

Error Path

If resume fails with an unrecoverable error, the session transitions to error state
apps/server/src/codexAppServerManager.ts
Recoverable Resume Errors: Errors containing snippets like “not found”, “missing thread”, “no such thread”, “unknown thread”, or “does not exist” trigger automatic fallback to a fresh thread start.

Session Events

Sessions emit lifecycle events through the provider event stream:
Emitted when the session begins connecting to the provider.
Emitted when attempting to open or resume a thread.
Emitted when resume fails and falls back to fresh start.
Emitted when the session is ready to accept turns.
Emitted when the session has been closed.

Sending Turns

Once a session is ready, you can send turns to the agent:
When a turn starts, the session transitions from ready to running state and sets activeTurnId to the new turn’s ID.

Turn Lifecycle

Turns represent discrete agent execution cycles:

Turn Events

Turns emit various events during execution:

turn/started

Turn execution has begun

turn/completed

Turn finished (success or error)

item/agentMessage/delta

Streaming text from agent response

item/tool/started

Tool execution started

Interrupting Turns

Active turns can be interrupted:
When interrupted:
  1. Session status changes to “ready”
  2. activeTurnId is cleared
  3. Partial work may be retained depending on provider behavior

Stopping Sessions

Sessions can be explicitly stopped:
Stopping a session:
  1. Cancels any active turns
  2. Rejects pending approval requests
  3. Kills the codex app-server process
  4. Removes the session from the active session directory
  5. Emits session/closed event
Stopped sessions cannot be restarted. You must create a new session, optionally with a resumeCursor to continue the conversation.

Session Directory

The ProviderSessionDirectory tracks active sessions:

Provider-Specific Session Features

Codex Sessions

Codex sessions support additional capabilities:
Read the full conversation history:
Rewind conversation state by N turns:
Codex sessions detect account type and plan:

Best Practices

Always Store Resume Cursor

Save resumeCursor after each successful operation to enable seamless restarts

Handle Resume Failures

Be prepared for resume to fall back to fresh thread start

Monitor Session Status

Watch for status transitions to handle errors and completion

Clean Up Sessions

Explicitly stop sessions when done to free resources

Next Steps

Runtime Modes

Configure approval policies and sandbox modes

Providers

Learn about provider adapter architecture

Architecture

Understand the overall system design