Repository navigation
codex-proxy: warm app-server daemon transport as lead route (#480) - #773
Conversation
First turn of a conversation runs codex exec without --ephemeral and captures the session id from the thread.started JSON event; later turns run codex exec resume <id> with only the new non-assistant tail. Key = sha256(resolved model/effort + system prompt + first user message). Session map persisted to sessions.json in the proxy state dir (LRU 64, 2h TTL). Any resume failure falls back to a full-history fresh run and re-keys. syncCodexTokensToOpenCode, endpoint.json, port parsing and SSE behaviour unchanged. Tests: 4 new warm-session tests (resume tail-only, resume-failure fallback, system-prompt change bypass, restart persistence) alongside the existing #676/#680 failure tests — 10/10 pass.
…x-cli 0.160.0) Passing --color to 'codex exec resume' is a clap usage error (exit 2). Probe on amd: resume with the shared option set minus --color succeeds, re-emits thread.started with the same thread_id, and answers from the resumed session.
One persistent WebSocket-over-Unix-socket connection to the managed codex app-server daemon (~/.codex/app-server-control/*.sock): initialize handshake once at first use, conversations map to daemon threads with the same keying/prefix-validation/persisted-LRU discipline as the exec resume build, keyed turns send only the new tail via turn/start, deltas stream as SSE, usage maps from thread/tokenUsage/updated (last). Raw floor on the laptop daemon (0.164.0), gpt-5.6-luna: thread/start 5.1s, turn 1 14.4s, turn 2 2.15s — vs 46s/56s for the exec-resume build on the same model and script. The stdio bridge (codex app-server proxy) never answered an initialize against this daemon; the direct control socket (WebSocket over UDS) answers instantly and needs no child. CODEX_PROXY_TRANSPORT=app-server (default) | exec-resume | exec. Any app-server failure before response commit — daemon down, thread lost, RPC error, daemon death mid-turn — falls back to exec-resume, then exec; one reconnect attempt precedes the fallback. sync of Codex tokens to OpenCode preserved unchanged.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 29 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77d462ae2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| client.turnStates.set(threadId, state); | ||
| client.rpc('turn/start', { |
There was a problem hiding this comment.
Serialize concurrent turns on the same daemon thread
When two requests concurrently extend the same warm conversation, both reuse its thread ID and the second call overwrites the first call's state here. Notifications are dispatched only by thread ID, so the second request can receive the first turn's answer while the first request never resolves. If the daemon rejects the overlapping turn instead, its failure handler deletes the shared state and still strands the first request. Serialize turns per thread and associate notifications with the accepted turn ID.
Useful? React with 👍 / 👎.
| // The session already holds its own assistant replies, so the tail fed | ||
| // to `exec resume` is only the new non-assistant turns. | ||
| const tailMessages = messages.slice(entry.fedCount).filter(m => m.role !== 'assistant'); |
There was a problem hiding this comment.
Validate the assistant reply before reusing a session
When a caller edits the latest assistant response or submits a different conversation with the same system prompt and first user message, prefix validation still accepts the request: fedHashes contains only the previous request's input, not the reply generated afterward. This filter then discards the supplied assistant response, causing the next answer to use the cached session's different history. Record and validate the generated reply as part of the reusable prefix, falling back to full history when it differs.
Useful? React with 👍 / 👎.
| sessionId: sessionId || threadId || prev.sessionId, | ||
| threadId: threadId || prev.threadId, | ||
| fedCount: messages.length, | ||
| fedHashes: messages.map(messageHash), |
There was a problem hiding this comment.
Clear the old daemon thread when recording a fresh exec session
If the daemon is unavailable and an edited or truncated history retains the same conversation key but fails planResume, the request takes the fresh exec path. Recording that successful run assigns its new sessionId but preserves the previous daemon threadId, while advancing the stored message hashes. Once the daemon becomes available, a subsequent extension passes prefix validation and sends only its new tail to the old thread, which has a different history. Invalidate the old thread ID when a new exec session replaces it.
Useful? React with 👍 / 👎.
| res.on('close', () => { | ||
| if (!res.writableEnded && currentChild) { | ||
| try { currentChild.kill('SIGTERM'); } catch (_) {} | ||
| } |
There was a problem hiding this comment.
Cancel the daemon turn when the HTTP client disconnects
When a client aborts a request using the default app-server transport, currentChild is null, so this close handler does nothing and the daemon continues generating an answer nobody will receive. Unlike the previous child-process path, abandoned requests keep consuming inference resources and can subsequently be recorded as successful warm sessions. This was reproduced by aborting after turn/start: no interruption RPC was sent, and the abandoned turn was persisted after completion. Track the active daemon turn and interrupt it on disconnect, without proceeding into fallback execution.
Useful? React with 👍 / 👎.
| if (typeof params.tokenUsage.last.outputTokens === 'number') state.completionTokens = params.tokenUsage.last.outputTokens; | ||
| } else if (method === 'turn/completed' && params.turn) { | ||
| client.turnStates.delete(threadId); | ||
| if (params.turn.status === 'failed') { |
There was a problem hiding this comment.
Treat interrupted daemon turns as unsuccessful
When a daemon turn is interrupted, this condition falls through to the success branch, returning any partial content with finish_reason: 'stop' and recording the session as successful. The protocol generated by the locally installed Codex explicitly includes interrupted in TurnStatus and permits an error on interrupted turns; passing such a completion through the actual handler reproduced ok: true with an unfinished answer and no error detail. Require a completed status for success and route interruptions through the existing failure or pre-output fallback handling.
Useful? React with 👍 / 👎.
| }, 60000).catch((err) => state.fail(err)); | ||
| }); | ||
|
|
||
| const threadConfig = (effort) => ({ model_reasoning_effort: effort }); |
There was a problem hiding this comment.
Preserve the shell-tool restriction in daemon thread configuration
When the daemon has shell tools enabled, the new default transport no longer applies the --disable shell_tool restriction retained in the exec path's commonArgs. Both daemon thread creation and resumption use this config alongside approvalPolicy: 'never' and sandbox: 'danger-full-access', so chat requests can now execute host shell commands without approval. The installed Codex reports shell_tool enabled with an empty configuration, and its --help documents --disable <FEATURE> as “Equivalent to -c features.<name>=false”. Add the equivalent features.shell_tool=false override to the daemon thread configuration.
Useful? React with 👍 / 👎.
Stacks on #766 (branch base is
warm/codex-proxy-sessionstip 6f0a33c; merge #766 first or this PR's diff against main includes it).What
codex-proxy gains an app-server transport as the default lead route: one persistent WebSocket-over-Unix-socket connection to the managed codex app-server daemon (
~/.codex/app-server-control/app-server-control.sock). Conversations map to daemon threads with the same keying (sha256 model/effort + system + first user msg), prefix validation, persisted map (sessions.json, LRU 64 / 2h TTL) as the #766 resume build; keyed turns send only the new tail viaturn/start; deltas stream as SSE; usage maps fromthread/tokenUsage/updated(last).CODEX_PROXY_TRANSPORT=app-server(default) |exec-resume|exec. Any app-server failure before response commit (daemon down, thread lost, RPC error, daemon death mid-turn) falls back to exec-resume → exec, with one reconnect attempt first. A request never fails because the warm route failed.syncCodexTokensToOpenCode()preserved.Connection mechanics, evidenced on the laptop daemon (0.164.0, ChatGPT login): control socket is WebSocket-over-UDS — HTTP Upgrade handshake (101) then JSON-RPC text frames (client frames masked). The stdio bridge
codex app-server proxywas tried first and never answered aninitializein 180s against this daemon; the direct socket answers instantly and needs no per-request (or any) child process.Measurements — all gpt-5.6-luna, same two-turn script (WARM1/WARM2)
Full proxy timings (3 turns) and the daemon-blocked fallback proof are in the #480 worker report after live deploy verification.
Tests
node --test bin/codex-proxy.test.mjs— 18/18 pass (10 pre-existing + 8 new: app-server two-turn mapping/tail-only, SSE deltas, thread resume after proxy restart, turn-failure/RPC-failure/daemon-death/unreachable-socket fallback to exec, exec-resume transport bypass). New tests use a fake WS-over-UDS app-server in the suite's existing stub style.Need help on this PR? Tag
@codesmith-botwith what you need.