Release native chat runtimes on lifecycle changes

Ensure /new and chat close stop native foreground and background work before changing registry state. Preserve transcripts while surfacing release and recovery cleanup failures instead of reporting false success, with focused adapter and server regressions.
This commit is contained in:
2026-11-11 17:11:40 +00:00
parent a5912d9a1e
commit 2307d45417
11 changed files with 197 additions and 14 deletions
+8 -1
View File
@@ -162,6 +162,10 @@ The host stops the CLI (EOF, then SIGINT, then SIGKILL to its process group) and
removes its files only when one of these happens:
- The operator closes the chat (`chat_close`).
An explicit close releases the backend runtime before recording `closed_at`; a
release failure is returned to the client and does not report a successful
close. The registry row and native transcript are retained in either case.
- A genuinely idle unhosted CLI is released. For hosted sessions, server cache
eviction only detaches; the host owns authoritative background-task liveness.
- The CLI exits; the server then gets its stderr.
@@ -228,7 +232,10 @@ and Claude Code a new session UUID. The server then re-keys the
`operator_sessions` row in one transaction. The new row keeps the title,
directory, tag, backend, colour, star, creation time, model override and mode.
The old row is not deleted: it records `replaced_by`, is no longer listed, and
its native session can still be resumed in a terminal.
its native session can still be resumed in a terminal. Before the row is moved,
the server releases the old native runtime; this stops active/background work
without deleting the native transcript. If release fails, `/new` reports an
error and leaves the registry row on the old session.
The row is re-keyed rather than mapped from a stable id because every other
layer is keyed by the native id: rooms, queues, transcripts, shells, exports and