Eai. PTY. Session
(eai v1.0.2)
Copy Markdown
Per-session GenServer owning a single PTY process.
Each PTY.Session holds the state previously scattered as one map entry
inside Eai.Sandbox.PTYPool. Moving to a dedicated process means:
- Slow PTY init (
pty_init_sleep_ms,pty_ready_sleep_ms) runs inside this process and no longer blocks other sessions. - PTY crash →
:pty_exitedarrives in this process only; orphaned tasks are cleaned up immediately viaResultCollector.force_complete/1. :transientrestart: on abnormal exit, the supervisor restarts the session with a fresh PTY.init/1force-completes any in-flight task left over from the previous incarnation.
Graph
<<{Eai.PTY.Registry, required_by, Eai.PTY.Session}. <<{Eai.PTY.Supervisor, spawned_by, Eai.PTY.Session}. <<{Eai.Hub, required_by, Eai.PTY.Session}. <<{Eai.ResultCollector, required_by, Eai.PTY.Session}. <<{Eai.Naming, required_by, Eai.PTY.Session}. <<{Eai.PTY.Session, required_by, Eai.PTY}.
Lifecycle
start_link(pty_session_id)
└─ init/1
├─ mkdir work_dir, setup symlinks
├─ ExPTY.spawn (shell, on_data → self, on_exit → self)
└─ flush init noise
handle_call :exec / :force_reset / :write_raw / :interrupt_task / :clear_task / :info
handle_info {:pty_data, data} / :pty_exited
terminate/2 → Hub.run_post_only(__MODULE__, :terminate, [reason, state])Naming / addressing
Registered via Eai.Naming.pty_session(pty_session_id) on start.
Look up by Eai.PTY.Registry.lookup(pty_session_id).
Summary
Functions
Returns a specification to start this module under a supervisor.
Clear completed task state. Called by Eai.PTY via Hub.run.
Execute command async. Called by Eai.PTY via Hub.run.
Force-reset session PTY. Called by Eai.PTY via Hub.run.
Inject Ctrl+C interrupt. Called by Eai.PTY via Hub.run.
Start a PTY.Session for pty_session_id.
Send raw input. Called by Eai.PTY via Hub.run.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Clear completed task state. Called by Eai.PTY via Hub.run.
Execute command async. Called by Eai.PTY via Hub.run.
Force-reset session PTY. Called by Eai.PTY via Hub.run.
Inject Ctrl+C interrupt. Called by Eai.PTY via Hub.run.
Start a PTY.Session for pty_session_id.
Send raw input. Called by Eai.PTY via Hub.run.