Problem
When starting codex-acp via startAcpServer(), the Codex CLI/process is spawned before the gateway wire_api configuration is injected into the session/thread config. This can cause the Codex binary to attempt a WebSocket connection using the pre-injection configuration, receive a 405, and fall back to HTTPS on the first message. Subsequent messages work once the wire_api (e.g. "responses") is injected during createSessionConfig()/newSession().
Reproduction
- Start codex-acp with a configured gateway (MODEL_PROVIDER / CODEX_CONFIG passed to the process) where the server expects websocket usage when wire_api is set to "responses".
- startAcpServer() calls startCodexConnection() and spawns the Codex process (wire_api not yet injected into session config).
- The Codex process attempts a WebSocket connection on first message → receives 405 → falls back to HTTPS.
- createSessionConfig()/newSession() later injects wire_api: "responses" so subsequent messages work normally.
Expected
Codex should not attempt a WebSocket connection (or should have the correct wire_api) before the gateway configuration is injected and available to the Codex process, so the first message does not fail with 405.
Proposed fixes
- Pass CODEX_CONFIG / MODEL_PROVIDER (or at least the model provider/gateway wiring) into the spawned Codex process env so it sees the correct configuration at startup.
- Or defer spawning the Codex process until after createSessionConfig()/newSession() has prepared and injected wire_api into the session/thread config.
- Or make the Codex client resilient: delay initial WebSocket attempts or retry appropriately when the first attempt gets 405 due to missing config.
Notes
Related PR that fixed session persistence / resume races but did not change the spawn/config ordering: #337
Problem
When starting codex-acp via startAcpServer(), the Codex CLI/process is spawned before the gateway wire_api configuration is injected into the session/thread config. This can cause the Codex binary to attempt a WebSocket connection using the pre-injection configuration, receive a 405, and fall back to HTTPS on the first message. Subsequent messages work once the wire_api (e.g. "responses") is injected during createSessionConfig()/newSession().
Reproduction
Expected
Codex should not attempt a WebSocket connection (or should have the correct wire_api) before the gateway configuration is injected and available to the Codex process, so the first message does not fail with 405.
Proposed fixes
Notes
Related PR that fixed session persistence / resume races but did not change the spawn/config ordering: #337