Skip to content

codex-proxy: warm app-server daemon transport as lead route (#480) - #773

Merged
dezren39 merged 3 commits into
mainfrom
warm/codex-proxy-app-server
Oct 25, 2026
Merged

dezren39 merged 3 commits into
mainfrom
warm/codex-proxy-app-server

Conversation

@dezren39

@dezren39 dezren39 commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Stacks on #766 (branch base is warm/codex-proxy-sessions tip 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 via turn/start; deltas stream as SSE; usage maps from thread/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 proxy was tried first and never answered an initialize in 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)

route turn 1 turn 2
raw app-server floor (direct WS client) 14.44s (+5.09s thread/start) 2.15s
exec-resume proxy (#766, re-measured) 46.07s 56.07s
native reference (Drew) ~22s class —

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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Muse (sandbox agent) and others added 3 commits October 24, 2026 16:08
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.
@dezren39
dezren39 requested a review from a team as a code owner October 24, 2026 16:39
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 071a01ca-4bc8-493e-84f5-2a9d3c850796
Commits

Reviewing files that changed from the base of the PR and between 3184df6 and 77d462a.

Files selected for processing: 2
  • bin/codex-proxy.mjs
  • bin/codex-proxy.test.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T16:44:00.734408Z 77d462a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread bin/codex-proxy.mjs
Comment on lines +637 to +638
client.turnStates.set(threadId, state);
client.rpc('turn/start', {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread bin/codex-proxy.mjs
Comment on lines +323 to +325
// 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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread bin/codex-proxy.mjs
Comment on lines +337 to +340
sessionId: sessionId || threadId || prev.sessionId,
threadId: threadId || prev.threadId,
fedCount: messages.length,
fedHashes: messages.map(messageHash),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread bin/codex-proxy.mjs
Comment on lines +1081 to +1084
res.on('close', () => {
if (!res.writableEnded && currentChild) {
try { currentChild.kill('SIGTERM'); } catch (_) {}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread bin/codex-proxy.mjs
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') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread bin/codex-proxy.mjs
}, 60000).catch((err) => state.fail(err));
});

const threadConfig = (effort) => ({ model_reasoning_effort: effort });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@dezren39
dezren39 merged commit 447f7ae into main Oct 25, 2026
4 checks passed
@dezren39
dezren39 deleted the warm/codex-proxy-app-server branch October 25, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant