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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pingdotgg/t3code/llms.txt
Use this file to discover all available pages before exploring further.
Session Lifecycle
Sessions progress through distinct states during their lifetime:Connecting
The server spawns a
codex app-server process and establishes JSON-RPC communication over stdio.Running
A turn is actively executing. The agent is processing user input, running tools, or generating responses.
Session Schema
Sessions are represented by theProviderSession 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 theProviderService.startSession method:
Session Resume Behavior
When aresumeCursor is provided, T3 Code attempts to resume the existing Codex thread:
Fallback Path
If resume fails with a recoverable error (thread not found, missing thread), automatically fall back to starting a fresh thread
apps/server/src/codexAppServerManager.ts
Session Events
Sessions emit lifecycle events through the provider event stream:session/connecting
session/connecting
Emitted when the session begins connecting to the provider.
session/threadOpenRequested
session/threadOpenRequested
Emitted when attempting to open or resume a thread.
session/threadResumeFallback
session/threadResumeFallback
Emitted when resume fails and falls back to fresh start.
session/ready
session/ready
Emitted when the session is ready to accept turns.
session/closed
session/closed
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:- Session status changes to “ready”
activeTurnIdis cleared- Partial work may be retained depending on provider behavior
Stopping Sessions
Sessions can be explicitly stopped:- Cancels any active turns
- Rejects pending approval requests
- Kills the
codex app-serverprocess - Removes the session from the active session directory
- Emits
session/closedevent
Session Directory
TheProviderSessionDirectory tracks active sessions:
Provider-Specific Session Features
Codex Sessions
Codex sessions support additional capabilities:Thread Snapshots
Thread Snapshots
Read the full conversation history:
Thread Rollback
Thread Rollback
Rewind conversation state by N turns:
Account Detection
Account Detection
Codex sessions detect account type and plan:
Best Practices
Always Store Resume Cursor
Save
resumeCursor after each successful operation to enable seamless restartsHandle 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
