Keep OpenCode/Codex chat and stage sessions running across server restarts
A stopping server no longer interrupts harness sessions. Runs are canceled with a shutdown cause, so stage clients leave admitted sessions running and owned; start-up recovery re-adopts live OpenCode V2 stage sessions (wait, read back the result, continue the graph), restarts unadmitted visits, continues runs between stages, and falls back to interrupted with a reason when the harness is gone. Chats with live work are recorded on shutdown and reattached on start; turns that ended during the downtime are folded in from history. The server-spawned V2 chat serve is now a detached owned service. PIPELINES_SHUTDOWN_SESSIONS=stop restores the old behaviour.
This commit is contained in:
@@ -6,6 +6,45 @@ when the `claude` CLI is installed. The selected backend is stored on the
|
||||
operator-session row and returned as `backend` on every `chat_sessions` row, so a
|
||||
restart does not have to guess from the session id.
|
||||
|
||||
## Restarts keep sessions running
|
||||
|
||||
A server restart or stop does not stop chat sessions. Only an operator action
|
||||
stops one: closing the chat, or Stop on its turn. On shutdown the server records
|
||||
each chat that still has work on its harness (a turn in flight, a pending
|
||||
question or approval, or running background tasks) in `chat_live_sessions`.
|
||||
It then detaches each backend instead of closing it, and never sends an
|
||||
interrupt.
|
||||
|
||||
On the next start each recorded chat is reattached. The server asks the harness
|
||||
whether the turn is still running, re-subscribes to its event stream with no
|
||||
client attached, re-reads pending approvals/questions and background shells,
|
||||
and holds queued prompts behind the turn. If a turn ended while the server was
|
||||
down, or its end event was lost with the old stream, the end is folded in from
|
||||
the harness's history. Clients get a `resync`, the reply notifies once (with
|
||||
the text the harness recorded), and queued prompts are delivered in order. The
|
||||
older start-up probe of recently used chats still runs for anything not
|
||||
recorded, for example after a crash.
|
||||
|
||||
Per backend (the contract is `chatSessionDetacher` in
|
||||
`internal/server/chat_detach.go`):
|
||||
|
||||
- **OpenCode**: sessions live in the OpenCode service. An attached endpoint
|
||||
(the operator's CLI-managed service) already outlives the server. Without
|
||||
one, a V2 server now uses a detached Pipelines-owned chat service
|
||||
(`opencode serve` in its own session, registered in
|
||||
`<cache>/pipelines/private/opencode-chat-service.json`). The next server
|
||||
reuses it at the same address and password, and it is not stopped on
|
||||
shutdown. A V1 serve child still ends with the server.
|
||||
- **Codex**: threads and turns live in the App Server. Detaching closes the
|
||||
control connection, and the next server reconciles through `thread/read`.
|
||||
An approval or question the App Server sent to the old connection is bound to
|
||||
it, so one still pending at shutdown cannot be answered after the restart.
|
||||
- **Claude Code**: closed as before until its host implements
|
||||
`DetachSessions`.
|
||||
|
||||
`PIPELINES_SHUTDOWN_SESSIONS=stop` restores the old shutdown, which closes the
|
||||
chat clients and records nothing. See [Installation](install.md#restarts-keep-sessions-running).
|
||||
|
||||
## Codex
|
||||
|
||||
The adapter in `internal/codex` connects to the Codex App Server's Unix
|
||||
|
||||
Reference in New Issue
Block a user