mirror of
https://github.com/openai/codex.git
synced 2026-09-04 15:08:45 +00:00
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
124 lines
4.4 KiB
Python
124 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from codex_package.cargo import build_source_binaries
|
|
from codex_package.cargo import source_binaries_for_target
|
|
from codex_package.targets import PACKAGE_VARIANTS
|
|
from codex_package.targets import TARGET_SPECS
|
|
|
|
|
|
class SourceBinariesForTargetTest(unittest.TestCase):
|
|
def test_macos_package_with_prebuilt_entrypoint_builds_nothing(self) -> None:
|
|
self.assertEqual(
|
|
source_binaries_for_target(
|
|
TARGET_SPECS["aarch64-apple-darwin"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
build_entrypoint=False,
|
|
build_code_mode_host=False,
|
|
build_bwrap=False,
|
|
build_codex_command_runner=False,
|
|
build_codex_windows_sandbox_setup=False,
|
|
),
|
|
[],
|
|
)
|
|
|
|
def test_linux_package_with_prebuilt_entrypoint_and_bwrap_builds_nothing(
|
|
self,
|
|
) -> None:
|
|
self.assertEqual(
|
|
source_binaries_for_target(
|
|
TARGET_SPECS["x86_64-unknown-linux-musl"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
build_entrypoint=False,
|
|
build_code_mode_host=False,
|
|
build_bwrap=False,
|
|
build_codex_command_runner=False,
|
|
build_codex_windows_sandbox_setup=False,
|
|
),
|
|
[],
|
|
)
|
|
|
|
def test_windows_package_with_prebuilt_entrypoint_and_helpers_builds_nothing(
|
|
self,
|
|
) -> None:
|
|
self.assertEqual(
|
|
source_binaries_for_target(
|
|
TARGET_SPECS["x86_64-pc-windows-msvc"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
build_entrypoint=False,
|
|
build_code_mode_host=False,
|
|
build_bwrap=False,
|
|
build_codex_command_runner=False,
|
|
build_codex_windows_sandbox_setup=False,
|
|
),
|
|
[],
|
|
)
|
|
|
|
def test_missing_windows_helpers_are_built(self) -> None:
|
|
self.assertEqual(
|
|
source_binaries_for_target(
|
|
TARGET_SPECS["x86_64-pc-windows-msvc"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
build_entrypoint=False,
|
|
build_code_mode_host=False,
|
|
build_bwrap=False,
|
|
build_codex_command_runner=True,
|
|
build_codex_windows_sandbox_setup=True,
|
|
),
|
|
["codex-command-runner", "codex-windows-sandbox-setup"],
|
|
)
|
|
|
|
def test_missing_code_mode_host_is_built(self) -> None:
|
|
self.assertEqual(
|
|
source_binaries_for_target(
|
|
TARGET_SPECS["x86_64-unknown-linux-musl"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
build_entrypoint=False,
|
|
build_code_mode_host=True,
|
|
build_bwrap=False,
|
|
build_codex_command_runner=False,
|
|
build_codex_windows_sandbox_setup=False,
|
|
),
|
|
["codex-code-mode-host"],
|
|
)
|
|
|
|
def test_build_uses_prebuilt_windows_helpers_without_running_cargo(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
root = Path(temp_dir)
|
|
entrypoint = touch_file(root / "codex.exe")
|
|
code_mode_host = touch_file(root / "codex-code-mode-host.exe")
|
|
command_runner = touch_file(root / "codex-command-runner.exe")
|
|
sandbox_setup = touch_file(root / "codex-windows-sandbox-setup.exe")
|
|
|
|
outputs = build_source_binaries(
|
|
TARGET_SPECS["x86_64-pc-windows-msvc"],
|
|
PACKAGE_VARIANTS["codex"],
|
|
cargo=str(root / "cargo-that-should-not-run"),
|
|
profile="release",
|
|
entrypoint_bin=entrypoint,
|
|
code_mode_host_bin=code_mode_host,
|
|
bwrap_bin=None,
|
|
codex_command_runner_bin=command_runner,
|
|
codex_windows_sandbox_setup_bin=sandbox_setup,
|
|
)
|
|
|
|
self.assertEqual(outputs.entrypoint_bin, entrypoint)
|
|
self.assertEqual(outputs.code_mode_host_bin, code_mode_host)
|
|
self.assertEqual(outputs.codex_command_runner_bin, command_runner)
|
|
self.assertEqual(outputs.codex_windows_sandbox_setup_bin, sandbox_setup)
|
|
|
|
|
|
def touch_file(path: Path) -> Path:
|
|
path.write_text("", encoding="utf-8")
|
|
return path.resolve()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|