Retain Codex interaction callbacks across server restarts

This commit is contained in:
2026-11-05 14:32:59 +00:00
parent c7e57973a0
commit c2a8f5ff16
20 changed files with 1356 additions and 18 deletions
+35 -4
View File
@@ -36,10 +36,12 @@ chat_close; see `internal/server/chat_manager.go` and `chat_detach.go`):
`<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.
- **Codex**: threads and turns live in the App Server. The installed server
connects through `pipelines-codex-host`, which retains the original App Server
connection and unanswered approvals/questions while Pipelines detaches. A new
server receives those same callbacks and reconciles ordinary turn state through
readback. Direct mode (hosting disabled or helper absent) still loses pending
connection-bound interactions on restart.
- **Claude Code**: its detachable hosts keep the CLI running (see the Claude
Code section).
@@ -72,6 +74,35 @@ not a fake empty success or silent auto-approval. App Server socket loss does
not provide durable callback recovery; a disconnected transport is reported as
an error rather than claiming old requests are still actionable.
### Pending interactions across restarts
The installed `pipelines-codex-host` helper owns one WebSocket connection to the
existing Codex App Server Unix socket. It never starts a second Codex daemon or
changes Codex settings. Helpers are scoped by database path and upstream socket,
with mode-0600 Unix sockets and singleton locks under the mode-0700 directory
`<user cache dir>/pipelines/codex-hosts/<database hash>/`.
On reconnect the helper returns its cached initialization handshake and replays
only unanswered server requests, preserving exact callback IDs and parameters.
Responses and `serverRequest/resolved` remove pending entries. Old/new client RPC
IDs are remapped so a delayed response for an old Pipelines process cannot answer
a new process's call. A new attach closes the obsolete downstream connection.
Ordinary notifications are not spooled; the existing thread readback repairs gaps.
State is bounded to 128 callbacks / 8 MiB and 256 in-flight client calls, with a
16 MiB frame limit. Exceeding pending bounds closes the bridge without granting,
declining or otherwise auto-answering an interaction. A detached bridge expires
after 20 minutes with no pending interactions, or after 24 hours even if pending.
An upstream App Server restart, a bridge crash, or expiry loses its connection-
bound callbacks: no disk JSON can recreate them on a new connection. The initial
deployment cannot recover requests already owned by the old direct connection.
`PIPELINES_CODEX_HOST` overrides the helper executable; `off` disables hosting.
The server otherwise finds it beside `pipelines-server`, then on PATH. Without
hosting, direct-mode fixtures and intentional direct connections retain their
previous behaviour and limitation. Installing a new helper binary does not kill
an existing helper or its pending requests.
## Claude Code
The adapter in `internal/claude` owns one Claude Code CLI process per active