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:
2026-11-04 16:17:08 +00:00
parent 9351cd7d74
commit aa8eddd686
26 changed files with 2318 additions and 99 deletions
+22
View File
@@ -183,6 +183,28 @@ func (m *chatManager) Close() {
closeHarness(claudeClient)
}
// DetachSessions is the shutdown counterpart of Close for a server that keeps
// chat sessions running across a restart (see chat_detach.go). Each harness
// that implements chatSessionDetacher releases its handles without stopping a
// session; one that does not is closed as before. The OpenCode connection's
// lifetime belongs to the caller (cmd/pipelines-server), so it is only detached.
func (m *chatManager) DetachSessions() {
m.mu.Lock()
m.closed = true
codexClient, claudeClient := m.codex, m.claude
m.mu.Unlock()
if detacher, ok := m.opencode.(chatSessionDetacher); ok {
detacher.DetachSessions()
}
for _, client := range []chatBroker{codexClient, claudeClient} {
if detacher, ok := client.(chatSessionDetacher); ok {
detacher.DetachSessions()
continue
}
closeHarness(client)
}
}
// Backends lists the harnesses available for a new session.
func (m *chatManager) Backends() []string {
backends := []string{}