Skip to content

Move code mode into standalone host process - #27648

Closed
cconger wants to merge 16 commits into
mainfrom
cconger/code-mode-host-skeleton
Closed

Move code mode into standalone host process#27648
cconger wants to merge 16 commits into
mainfrom
cconger/code-mode-host-skeleton

Conversation

@cconger

@cconger cconger commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Why

Code mode currently runs V8 in the main Codex process, so a runtime crash can take down the entire session and forces Codex binaries to link V8 directly. This change isolates code mode in a dedicated process while preserving nested tool calls and session-local stored values.

What changed

  • Added protocol, client, and host crates for framed JSON IPC over stdio.
  • Moved V8 execution into codex-code-mode-host; core now communicates through CodeModeSession.
  • Lazily starts one host connection and creates isolated code-mode sessions within it.
  • Recovers from host failure: the failed call returns a generic runtime error, the concrete cause is logged, and the next exec starts a fresh host/session. wait and terminate do not silently recreate lost state.
  • Prefixes cell IDs with the host process ID to prevent collisions after restart.
  • Exits the host on request-handler panics rather than leaving requests hanging.
  • Raised the bounded IPC frame limit from 16 MiB to 256 MiB for inline image results.
  • Runs core-suite code-mode coverage through the IPC implementation instead of an in-process fallback.
  • Packages and signs the host alongside Codex across release targets and validates it during installation.
  • Added //codex-rs/cli:codex-with-code-mode; just bazel-codex incrementally builds both binaries and injects the host runfile path.

cconger added 10 commits June 10, 2026 14:38
Split the code-mode protocol and client from the V8-backed runtime so core and
app-server no longer link codex-code-mode in production. ThreadManager now
provisions durable code-mode sessions through a shared external host process,
while tests can still inject the in-process provider.

The IPC protocol uses a persistent stdin/stdout transport. Each frame is a
4-byte big-endian length followed by JSON, with a 16 MiB frame limit. Client
requests carry u64 request IDs so create, execute, wait, terminate, and shutdown
operations can be multiplexed over one process. Session IDs isolate durable
stored values. Execute returns an ExecutionStarted response immediately and an
asynchronous InitialResponse when the initial yield or completion is available.

Nested tool calls and notifications travel from the host back to the client as
delegate requests with their own IDs. Delegate responses, cancellation, and
cell-closed lifecycle messages use the same framed channel. Wire operations
encode errors as Result values. A dead connection fails pending operations,
cancels outstanding delegates, and lets the provider spawn a new host for later
sessions.

Build codex-code-mode-host with V8 pointer-compression sandbox support and add
it to canonical primary and app-server packages, legacy Linux and Windows
bundles, signing verification, installers, Python runtime packages, and release
CI for macOS, Linux, and Windows. The host is discovered next to the current
executable, through CODEX_CODE_MODE_HOST_PATH, or on PATH. OS-level seccomp or
seatbelt restrictions remain a follow-up to this cross-platform process split.

Benchmarks were run from release builds on Linux x86_64 with the V8 sandbox
profile and a text('ok') workload. Cold measurements used 30 samples, warm
session provisioning used 200, and warm command execution used 500. Values are
mean/p50/p95 in milliseconds:

- session startup: in-process 0.002/0.002/0.005, IPC 2.623/2.599/2.894
- fresh-session command: in-process 1.831/1.758/1.915, IPC 7.428/7.252/8.306
- warm session provisioning: in-process 0.002/0.002/0.003,
  IPC 0.471/0.463/0.581
- warm command: in-process 1.759/1.757/1.940, IPC 2.005/2.001/2.166

The steady-state median command overhead is approximately 0.244 ms. The median
fresh host plus first command cost is 7.252 ms.

Validation:

- 62/62 core code-mode integration tests passed against the external host
- focused protocol, client, runtime, host, tools, and trace tests passed
- Cargo and Bazel real-process host IPC tests passed
- 11/11 package builder tests passed
- Bazel lock verification, scoped Clippy fixes, and repository formatting passed
@cconger
cconger requested a review from a team as a code owner June 11, 2026 18:27
@cconger

cconger commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing this in favor of a stacked approach:
#27724
#27725
#27726
#27727

@cconger cconger closed this Jun 12, 2026
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