Replace codex-agent-driver with the official openai-codex SDK - #53
Merged
Conversation
nabinpkl
force-pushed
the
refactor/codex-sdk-migration
branch
2 times, most recently
from
June 6, 2026 20:24
5012e3c to
20a172e
Compare
Swap the codex agent runtime off the hand-written codex-agent-driver path-dependency (sibling second-brain repo) and onto OpenAI's official openai-codex Python SDK. The SDK is the harness the driver emulated: it spawns and drives `codex app-server`, exposes native threads, streams typed notifications, supports read-only sandbox and server-enforced output_schema, and bundles the codex binary. ADR 17 records the decision and supersedes ADR 15's mechanism. Agent plane (agent-service/): - One shared AsyncCodex app-server built at lifespan; each chat thread is one native codex thread (thread_start / thread_resume). Drops the per-thread codex_home machinery (CODEX_HOME_ROOT), the state sqlite model-read hack, and the worker-thread/queue bridge in favour of `async for` over the SDK turn stream. - codex_config.py: the per-thread config overlay that mounts the data-plane MCP server (four-tool allow-list) and disables every codex built-in tool (lockdown), plus the writable-CODEX_HOME builder. - codex_events.py: parses the SDK's typed notifications back to their camelCase wire dict so the driver is insulated from beta SDK attribute churn. - Helper calls (constitution gate, eval judge, repeat detector) run on a separate codex helper app-server (own CODEX_HOME, ephemeral threads, no MCP), preserving the no-bleed separation. - codex_profile.py removed; tests, smoke script, env, Docker, and compose updated. The SDK is Beta, pinned exactly with the accepted risk recorded in docs/dependency-exceptions.md. Data plane (backend/src/mcp.rs): - The bundled codex (0.137) forwards MCP tool input schemas to the OpenAI API verbatim, which rejects a root $ref schema in strict mode. The three transparent-newtype args (wallet_profile, community_summary, get_token_info) now implement JsonSchema manually to inline the object at the root instead of emitting a root $ref. Regenerated the tools/list snapshot consumed by the hermetic-eval mock. Evals: - model_assertions_codex.yaml asserted the constitution gate uses the pydantic-ai policy model, which contradicts the all-or-nothing helper routing: under codex runtime the gate runs via codex and emits no gen_ai model span. Replaced that probe with a functional check that the gate fires, and re-minted the baseline. CI: - This commit introduces the CI workflow (.github/workflows/ci.yml was previously untracked), so its first run had to be made green. The backend job installs the librdkafka build deps (libcurl/sasl/zlib) the Dockerfile uses; frontend and wire-drift use pnpm 10 (pnpm 9 rejects the settings-only pnpm-workspace.yaml); wire-drift pins protoc 34.1 for the buf python plugin; the re-enabled agent-service job runs the documented <5s unit baseline (the integration suite has pre-existing pytest_httpx mock drift, excluded until repaired separately). - Regenerated the switches wire types (Rust + TS): the .proto doc comment had been edited without re-running codegen, so the committed generated files were stale. Doc-comment-only delta, no schema change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nabinpkl
force-pushed
the
refactor/codex-sdk-migration
branch
from
June 6, 2026 20:27
20a172e to
c502e46
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Migrates the codex agent runtime off the hand-written
codex-agent-driverpath-dependency (siblingsecond-brainrepo) and onto OpenAI's officialopenai-codexPython SDK. The SDK is the harness the driver emulated — it drivescodex app-server, exposes native threads, streams typed notifications, supports read-only sandbox + server-enforcedoutput_schema, and bundles the codex binary. Recorded in ADR 17 (supersedes ADR 15's mechanism).Agent plane (
agent-service/)AsyncCodexapp-server at lifespan; each chat thread is one native codex thread (thread_start/thread_resume). Drops the per-threadcodex_homemachinery (CODEX_HOME_ROOT), the state-sqlite model-read hack, and the worker-thread/queue bridge in favour ofasync forover the SDK turn stream.codex_config.py— per-threadconfigoverlay mounting the data-plane MCP server (four-tool allow-list) + the built-in-tool lockdown, plus the writable-CODEX_HOMEbuilder.codex_events.py— parses the SDK's typed notifications back to their camelCase wire dict, insulating the driver from beta SDK attribute churn.CODEX_HOME, ephemeral threads, no MCP) — preserves the no-bleed separation.codex_profile.pyremoved; tests, smoke script, env, Docker, compose, and CI (agent-service job re-enabled) updated. SDK is Beta, pinned exactly with the accepted risk indocs/dependency-exceptions.md.Data plane (
backend/src/mcp.rs)The bundled codex (0.137) forwards MCP tool input schemas to the OpenAI API verbatim, which rejects a root
$refschema in strict mode. The three transparent-newtype args (wallet_profile,community_summary,get_token_info) now implementJsonSchemamanually to inline the object at the root. Regenerated thetools/listsnapshot consumed by the hermetic-eval mock.Evals
model_assertions_codex.yamlasserted the constitution gate uses the pydantic-ai policy model, contradicting the all-or-nothing helper routing (under codex runtime the gate runs via codex and emits nogen_aimodel span). Replaced that probe with a functional "gate fired" check; re-minted the baseline.Verification
mcp::tests pass (incl. schema snapshot drift test).docker compose up -d --build; live codex turns confirmed: token streaming,wallet_profileMCP dispatch, lockdown, model stamping, constitution gate fires + approves.turn-root,codex-primary-model-used,no-error,no-builtin-tool-call,constitution-gate-fired).🤖 Generated with Claude Code