Terminal State¶
Terminals transition through several states during their lifecycle. Understanding these states is crucial for managing terminals effectively.
Terminal States¶
Initializing¶
The terminal is being created and onInit hooks are executing. Input is disabled during this state.
Characteristics:
- Terminal process is running
onInithooks are executing- No input accepted yet
- Supervisor waits for Ready state
Ready¶
The terminal has completed initialization and is ready for input. This state is reached after all onInit hooks complete successfully.
Characteristics:
- Terminal is fully initialized
- Ready to accept input
- Can be attached to
postAttachhooks will run on attach
Attached¶
A supervisor is currently connected to the terminal and forwarding I/O.
Characteristics:
- Supervisor is connected
- I/O is being forwarded
- User can interact with terminal
- Multiple supervisors can attach (multi-attach)
Detached¶
The terminal is running but no supervisor is currently attached.
Characteristics:
- Terminal continues running
- No active supervisor connection
- Can be reattached anytime
- Terminal process is independent
Exited¶
The terminal process has terminated.
Characteristics:
- Terminal process is dead
- Cannot be attached to
- Metadata preserved for inspection
- May be restarted depending on
restartPolicy
State Transitions¶
Normal Flow¶
- Created: Terminal process spawned
- Initializing:
onInithooks running - Ready: Initialization complete
- Attached: Supervisor connects
- Detached: Supervisor disconnects (terminal continues)
- Exited: Terminal process terminates
With Restart Policy¶
If restartPolicy is set to restart-on-error or restart-unlimited:
Querying Terminal State¶
# List terminals with state
sb get terminals
# Get specific terminal info
sb get terminal my-terminal
State Persistence¶
Terminal state is persisted in ~/.sbsh/run/terminals/<id>/meta.json, including:
- Current state
- State transitions
- Timestamps
- Attacher information
Related Concepts¶
- Terminals - Terminal lifecycle
- Supervisor - State management
- Event Log - State history