Run several live sessions in one `clai2` process with `LiveRuntimes`: `open`, `new`, `close`, and idle closing
Part 5 of the clai2 multi-session stack (#10468 → #10469 → #10477 → #10485 → this PR → #10495 → #10504 → #10541 → #10549). Based on #10485. No linked issue: requested by the CLAI maintainer.
Why. The web UI (next PR) drives several live sessions in one CLAI process, each in its own folder. This PR adds the process's registry of live sessions and the operations on it. Behaviour stays the same with one session: the terminal keeps exactly one, and the web plugin still talks to its default session.
New public surface (in pydantic_clai2.plugins, read as host.live)
LiveSessions.open(conversation_id, /),new(*, workspace=None),close(live_id, /),subscribe(listener) -> unsubscribe.LiveSession.queued,watchers,watch() -> unwatch.- Internal:
runtime/live_runtimes.py :: LiveRuntimes, held asClaiProcess.live;SessionRuntime.close(reason),serve(*, resume, ready).
Behaviour
- One conversation is live in one session. Concurrent
opencalls return one session./resume,host.conversation.resume, delete, and archive refuse a conversation another live session holds, opens, or resumes. A conversation another process runs opens once, in one copy. - Opened sessions run in their own folder, project settings, and plugins, with
Interrupts(signals=False)and a discarded console. They refuse/reloadand/update. A failure while opening reaches the caller. A failure afterwards is logged, and the other sessions keep running. - A session closes after an hour idle. It stays open while it is running, has queued input, a fork or task, a watcher, or terminal focus. Its plugins end with
'exit'. /setof anything exceptmodelandrun.*reaches every live session, unless that session's project file sets the key.- There is no turn cap and no new setting.
plugin code :: await host.live.open(conversation_id)
└─ runtime/live_runtimes.py :: LiveRuntimes.open()
- └─ RuntimeError('This CLAI opens no other live sessions.')
+ ├─ the session already holding it, or its copy (concurrent calls get one)
+ └─ LiveRuntimes._start()
+ └─ cli/web.py :: _web_session(workspace) (own folder, project, plugins; no signals)
+ └─ runtime/session_runtime.py :: SessionRuntime.serve(resume=conversation_id)
+ └─ Session.resume() under LiveRuntimes.claim() -> a LiveSession, listed once loaded
Verification
tests/clai2/test_live_runtimes.py:test_sessions_stream_at_once_and_an_interrupt_stops_only_its_own,test_a_conversation_is_live_in_one_session(concurrent opens, resume/delete/archive refusals, closing and switching holders),test_a_conversation_another_process_runs_opens_one_copy,test_a_session_that_fails_leaves_the_others_running,test_idle_sessions_close_after_the_timeout,test_settings_other_than_the_model_and_run_reach_every_live_session,test_run_web_opens_more_sessions_in_their_own_folders.tests/clai2/reload_script.pychecks the terminal's session stays the only live one through each reload.- The full
tests/clai2suite passes. Pyright and ruff are clean, and changed lines have 100% branch coverage. - Manual check with
clai2 --web: two sessions streamed at once with per-folder skills andAGENTS.md. Interrupting one left the other running. Idle closing and watching worked, and so did terminal/costand/exit.
What changes for existing users. Nothing.
For the lead (lower-PR changes made here): the LiveSession/LiveSessions protocol additions, PR 4's _Live made public as JoinedSessions (failing listeners logged), LiveRuntime queued/changed/watch, and SessionPlugins(queued=).
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.