Overview
The Lifecycle Manager is the core orchestration engine that polls sessions, detects state transitions, emits events, and triggers automated reactions. It implements a state machine that tracks sessions through their entire lifecycle from spawning to completion. Key responsibilities:- Periodically poll all active sessions
- Detect state transitions (spawning → working → pr_open → etc.)
- Emit events on transitions
- Execute automated reactions (auto-fix CI failures, review comments, etc.)
- Escalate to human notification when auto-handling fails
The Lifecycle Manager runs as a background polling loop, typically checking sessions every 30 seconds. It’s the primary automation layer between agents and humans.
Architecture
Methods
start
Start the lifecycle polling loop.number
default:"30000"
Polling interval in milliseconds. Default is 30 seconds.
The polling loop includes a re-entrancy guard - if a previous poll is still running, subsequent polls are skipped until it completes.
stop
Stop the lifecycle polling loop.check
Force an immediate state check for a specific session, bypassing the polling schedule.string
required
The session ID to check (e.g., “my-app-1”).
- After manually updating session metadata
- When you need immediate reaction to state changes
- For testing and debugging
getStates
Get a snapshot of all tracked session states.Map<SessionId, SessionStatus>
Map of session IDs to their current status.
State Machine
The lifecycle manager implements a state machine with the following transitions:Session Statuses
All Session Statuses
All Session Statuses
Status Detection
The lifecycle manager determines session status by polling multiple sources:1. Runtime Liveness
2. Agent Activity
Prefers JSONL-based detection (reads agent’s session files directly):3. PR Detection
4. CI Status
5. Review State
Reaction System
Reactions are automated responses to state transitions. They can send messages to agents, notify humans, or trigger actions like auto-merge.Reaction Configuration
Reaction Actions
Available Actions
Available Actions
Escalation
Reactions can escalate to human notification after:number
Maximum number of retry attempts before escalating.
number | string
Escalate after N attempts (number) or duration (string like “30m”).
Reaction Tracking
The lifecycle manager tracks attempts per session:- Reset when session transitions to a new state
- Persists across polling cycles
- Cleaned up when session is killed/merged
Events
The lifecycle manager emits events on state transitions. Events are routed to notifiers based on priority.Event Types
Session Lifecycle Events
Session Lifecycle Events
PR Lifecycle Events
PR Lifecycle Events
CI Events
CI Events
Review Events
Review Events
Merge Events
Merge Events
Event Structure
Notification Routing
Events are routed to notifiers based on priority:EventPriority
Critical issues requiring immediate attention (stuck, needs_input, exited).
EventPriority
Actionable events (approved, ready to merge, merged).
EventPriority
Issues that may need attention (CI failed, changes requested).
EventPriority
Informational updates (session spawned, working).
Error Handling
Graceful Degradation
The lifecycle manager continues operating even when individual checks fail:Re-entrancy Guard
Prevents overlapping poll cycles:State Cleanup
Prunes stale entries when sessions are deleted:Complete Example
See Also
- Session Manager - Create and manage sessions
- Config Loader - Configure reactions and notification routing
- Plugin: Runtime - Runtime liveness checks
- Plugin: Agent - Activity detection
- Plugin: SCM - PR and CI status
