Skip to main content

Overview

The Session interface represents a running agent session in the orchestrator. Each session encapsulates an AI coding agent working on a specific task, tracking its lifecycle state, activity, workspace, and associated resources.

Interface Definition

Properties

SessionId
required
Unique session identifier (e.g. "my-app-3", "backend-12"). Used for all session operations.
string
required
Which project this session belongs to. References a project ID from the orchestrator config.
SessionStatus
required
Current lifecycle status of the session. One of:
  • "spawning" - Session is being created
  • "working" - Agent is actively working
  • "pr_open" - PR has been created
  • "ci_failed" - CI checks failed
  • "review_pending" - Awaiting code review
  • "changes_requested" - Reviewer requested changes
  • "approved" - PR approved
  • "mergeable" - Ready to merge
  • "merged" - PR merged (terminal state)
  • "cleanup" - Cleaning up resources (terminal state)
  • "needs_input" - Waiting for human input
  • "stuck" - Agent is stuck/blocked
  • "errored" - Session encountered an error (terminal state)
  • "killed" - Session was manually killed (terminal state)
  • "done" - Session completed successfully (terminal state)
  • "terminated" - Session terminated (terminal state)
ActivityState | null
required
Activity state from agent plugin (null = not yet determined). One of:
  • "active" - Agent is processing (thinking, writing code)
  • "ready" - Agent finished its turn, alive and waiting for input
  • "idle" - Agent has been inactive for a while (stale)
  • "waiting_input" - Agent is asking a question / permission prompt
  • "blocked" - Agent hit an error or is stuck
  • "exited" - Agent process is no longer running (terminal state)
string | null
required
Git branch name for this session. Null if branch not yet created.
string | null
required
Issue identifier if working on a specific issue (e.g. GitHub issue number, Linear issue ID). Null if not issue-based.
PRInfo | null
required
Pull request information once PR is created. Null if PR not yet opened.
string | null
required
Absolute path to the workspace directory on disk. Null if workspace not yet created.
RuntimeHandle | null
required
Runtime handle for communicating with the session environment (tmux, docker, etc.). Null if runtime not yet initialized.
AgentSessionInfo | null
required
Agent session metadata (summary, cost estimates, internal session ID). Null if not yet available.
Date
required
Timestamp when the session was created.
Date
required
Timestamp of last detected activity. Updated by lifecycle manager during activity checks.
Date
When this session was last restored from a terminal state. Undefined if never restored.
Record<string, string>
required
Key-value pairs for arbitrary metadata. Used for custom tags, labels, or plugin-specific data.

SessionId

Unique session identifier string (e.g. "my-app-1", "backend-12").

SessionStatus

ActivityState

SessionSpawnConfig

Configuration for creating a new session via SessionManager.spawn().

Usage Examples

Creating a Session

Checking Session State

Monitoring Activity

Implementation Notes

Terminal States

Sessions in terminal states (defined by TERMINAL_STATUSES and TERMINAL_ACTIVITIES) have finished executing and their resources can be cleaned up:

Restorable Sessions

Some terminal sessions can be restored (e.g. errored, killed) while others cannot (e.g. merged):

Activity Detection

The activity field is populated by the agent plugin’s getActivityState() method, which uses agent-native mechanisms (JSONL logs, SQLite, etc.) rather than terminal output parsing.

Metadata Persistence

Session state is persisted to flat key-value files in the data directory. The metadata format is backwards-compatible with the original bash implementation.

See Also

  • Runtime - Runtime execution environment interface
  • Agent - Agent plugin interface for activity detection
  • Workspace - Workspace isolation interface
  • SCM - Source control and PR lifecycle interface