Repository navigation
fix(codex): build the plugin environment during setup - #2626
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
hidb4ai
left a comment
There was a problem hiding this comment.
One integration regression remains: the new doctor field causes Desktop to reject the entire integration diagnostic report.
hireview001
left a comment
There was a problem hiding this comment.
- CI failed: CI result (failure).
- CI failed: windows-unit-portability (failure).
- CI failed: Main (failure). Failed steps: windows-unit-portability / Verify Codex resolves and launches cmd shims on Windows; CI result / Require successful selected checks.
Desktop's diagnostics projection accepts only the check names it knows and rejects the whole doctor report otherwise, so the plugin_runtime check that `powercontext doctor codex` now reports made Desktop show the Integrations report as an invalid response. Add plugin_runtime to the projection's allowlist. A Codex doctor fixture now links the two sides: the Desktop test projects every check in it, and a Python test fails when Codex doctor emits a check the fixture lacks.
Setup now refuses to run without uv on PATH. The Windows cmd shim fixture sets PATH to its own bin directory only, so every setup test built on it failed at that check. Put a placeholder uv.exe there; the environment build itself stays stubbed by the autouse fixture.
hidb4ai
left a comment
There was a problem hiding this comment.
Re-reviewed 38efa8b. The Desktop projection regression is fixed: the original CLI-output counterexample now passes, runtime statuses remain visible, and private details remain excluded. The shared fixture covers the CLI-to-Desktop contract, and the Windows test fixture now satisfies the uv prerequisite. No remaining correctness findings, new database tables, or new public operations; the existing doctor JSON gains a diagnostic field. Latest-head CI is still running, including validation needed for the Windows fixture change, and must complete before merge.
Which issue or RFC does this PR close?
No tracking issue. The real-host Codex E2E in #2624 found it: the first session after
powercontext setup codexoften started without PowerContext's MCP tools.Rationale for this change
Setup installs the plugin but leaves its Python environment unbuilt. Codex's first session then builds it from two places at once:
http_headers_helper,uv run ... mcp_headers.py), which Codex runs with a filtered environment (HOME,PATH,USER,SHELL,TMPDIR, ...; noUV_*);SessionStarthook (uv run ... session_binding.py), which runs with the session's full environment.Observed with Codex CLI 0.167.2, by wrapping the helper to record its environment, stderr and exit status:
.venvwith the interpreter uv finds (3.11 here). The hook starts during that build withUV_PYTHONset (3.13), and uv replaces the environment. The helper fails mid-import (ModuleNotFoundError: No module named 'annotated_types', or a dylib rejected withcode signature ... not valid). It exits 1 on all three of Codex's attempts (250 ms and 1 s apart), and the session has no PowerContext MCP at all.mcp_optional_startup_grace_ms, 1000 ms by default; the server isrequired: false. Codex then lists the first turn's tools without PowerContext.Same-environment concurrent
uv runcalls are safe: uv locks the environment, and eight hand-run races never failed. The damage comes from the build happening at session start, under two different environments. Building it once during setup removes both effects. The helper and the hooks then accept the existing environment whatever interpreter they would have picked.What changes are included in this PR?
CodexInstaller.installchecks foruvbefore it runs any Codex command that changes state, so a machine without uv is refused with nothing installed.codex plugin add,CodexInstaller.installrunsuv sync --frozen --quiet --project <installed plugin>. It does this also when it keeps an already-installed disabled plugin.UV_PROJECT_ENVIRONMENTandVIRTUAL_ENV, so it builds the plugin's own.venv(the one the helper uses) and never syncs into another project's environment.SetupErrorwith uv's message and says the plugin is installed and setup can be rerun.powercontext doctor codexreports a newplugin_runtimecheck, run withuv sync --frozen --checkbefore the MCP probe (whose helper run would otherwise build the environment itself):okwhen the environment is ready;degraded, with a hint to rerun setup, when a plugin was installed or updated without setup;failedwhenuvis missing._codex_plugin_rootholds the plugin cache location shared by the endpoint update, setup and doctor.uvand, on a first install, the package index; doctor flags a plugin installed without setup.mcp_optional_startup_grace_msfor optional MCP servers. Forcodex exec, setting this top-level key to0makes the first turn wait up tostartup_timeout_sec.Are there any user-facing changes?
Yes.
powercontext setup codexnow builds the plugin environment, so it needsuvonPATHand can take a few seconds longer on first install.uv, setup fails before changing Codex.doctor codex --jsonhas a newplugin_runtimeentry.mcp_optional_startup_grace_ms; the docs describe it.How was this change tested?
New tests in
tests/test_system_cli.py; each fails on master and passes here:test_setup_codex_prepares_the_plugin_runtime_before_codex_starts_itUV_NO_SYNC=1so uv must find the environment ready; doctor then reportsplugin_runtimeok.ModuleNotFoundError: No module named 'pydantic'test_doctor_codex_reports_a_plugin_environment_that_setup_did_not_builddegradedand builds nothing.KeyError: 'plugin_runtime'test_setup_codex_requires_uv_before_changing_codexThe first two tests run a real
uv syncof the plugin's lock, astests/test_hook_characterization.pyalready does, so on a cold uv cache they need the package index.uv run pytest tests/test_system_cli.py tests/test_setup_transport.py tests/test_cli_minimax.py tests/codex_plugin tests/test_cli*.py: 929 passed, 46 skipped.make checkpasses.Real Codex CLI 0.167.2 on macOS arm64. I ran the test(e2e): run real Codex with the PowerContext plugin against a Server in CI #2624 E2E cases plus five first-session
search_memorycases, with the E2E's own prebuild step removed, underpytest -n 5:mcp_optional_startup_grace_ms.venv)Not verified: Windows (the new test is POSIX-only; the setup step uses the same
uvcall), and a real first install with an empty uv cache (it would need downloads).After this merges, test(e2e): run real Codex with the PowerContext plugin against a Server in CI #2624's E2E can drop its own prebuild step.
AI usage statement
Claude Code (Claude Opus 5.5) investigated the failure with the real Codex CLI, wrote the change, the test and this description, and ran the verification above.