Files
PaperClipAI/docs/adapters/codex-local.md
T
emme1t 32e80f80fe fix(codex-local): accept newer prerelease CLI versions (#18508)
## Thinking Path

> - Paperclip manages AI agents and checks their execution environment.
> - The Codex adapter checks the installed CLI against the selected
model's minimum version.
> - The parser rejects prerelease builds shipped with Codex Desktop,
including builds newer than that minimum.
> - This stops the hello probe and can leave an approved agent in
verification.
> - This change accepts valid prerelease versions and compares their
release numbers with the stable minimum.
> - A prerelease of the minimum release stays below the minimum.

## Linked Issues or Issue Description

Fixes: #18498

Refs #15399, which introduced the version check, and #15053, which
reports the original model compatibility problem. Related open #15534
adds model catalog discovery; this change addresses version parsing.

## What Changed

- Parse one stable or prerelease `codex-cli` version line. Keep
malformed and ambiguous output invalid.
- Accept `0.164.0-alpha.11.1` against `0.157.0`. Keep `0.157.0-alpha.1`
below `0.157.0`.
- Cover the parser, stable minimum comparison, CLI hello-probe
admission, and ACP environment check.
- Document this version rule in the Codex adapter guide. The change
stays in the adapter that owns this rule.

## Verification

Tested source commit `d8e2e2e` on Windows x64, Node 24.16.0 and pnpm
9.15.4, with isolated test homes.

- Seven affected assertions fail with the original production code and
pass with this change. The three affected test files report 58 passed
and one existing Windows path-separator failure. The same path failure
occurs on the original source.
- The real `checkCodexCliVersionForModel` launches the installed
`codex.exe --version`, which reports `0.165.0-alpha.1.2`. Checks for
`gpt-6-luna`, `gpt-6-sol`, and `gpt-6.1-sol` fail on the original source
and pass after this change. This probe makes no model request.
- `pnpm --filter @paperclipai/adapter-codex-local typecheck` passes. The
package build passes with Git Bash as the script shell.
- The complete Codex adapter suite reports 530 passed, 65 failed, and
one skipped. All 65 failure names also fail on the original production
source. That comparison reports 522 passed and 73 failed: seven failures
are this regression, and one independent auth-lock timing test changes
result between runs. Existing failures include Windows symlink
permissions, POSIX file modes/signals, and path expectations.
- Full workspace checks remain incomplete on this host. `pnpm -r
typecheck` stops at the unchanged Grok launcher digest check in the CRLF
checkout. `pnpm test:run` stops at `spawnSync pnpm ENOENT`. `pnpm build`
stops at the shared package's POSIX shell command under Windows cmd.
Initial install/preflight symlink errors were resolved for local
workspace links with directory junctions; those earlier failures remain
recorded.
- `git diff --check` passes. Greptile reports 5/5 on this commit, and
Codex code review completed with no findings. On November 20, GitHub
reported 55 passing checks and three skipped checks for this commit.

To run the focused tests:

```sh
pnpm exec vitest run --config packages/adapters/codex-local/vitest.config.ts packages/adapters/codex-local/src/index.test.ts packages/adapters/codex-local/src/server/test.remote.test.ts packages/adapters/codex-local/src/server/acp.cli-version.test.ts
```

The hello responses in the adapter tests use transport fixtures. Live
model execution, lifecycle completion, and native Runner qualification
were not exercised.

## Risks

The check now admits prereleases whose release numbers exceed a verified
stable floor. The hello probe still checks the selected model after
version admission. Equal-release prereleases, invalid versions, and
ambiguous output stay incompatible. The verified model floors are
unchanged.

## Model Used

OpenAI GPT-6 through Codex, with reasoning, tool use, and local code
execution. This session does not expose its exact deployment model ID or
context-window limit.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [ ] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

With assistance from Astra.
2026-12-05 03:05:52 -08:00

9.6 KiB

title, summary
title summary
Codex OpenAI Codex local adapter setup and configuration

The codex_local adapter runs OpenAI's Codex CLI locally. It supports session persistence via previous_response_id chaining and skills injection through the global Codex skills directory.

Prerequisites

  • Codex CLI installed (codex command available)
  • Either a host Codex login with ~/.codex/auth.json, or a per-agent OPENAI_API_KEY configured in adapter env (Paperclip materializes this into $CODEX_HOME/auth.json for managed homes; Codex CLI reads credentials from auth.json, not directly from the process environment — for a self-managed external CODEX_HOME, write auth.json there directly instead)

Configuration Fields

For models with a verified minimum CLI version, the environment test checks codex --version before the hello probe. A prerelease meets a stable minimum when its major, minor, and patch version is higher. For example, 0.164.0-alpha.11.1 meets 0.157.0, while 0.157.0-alpha.1 is below that minimum. Malformed or ambiguous version output fails the check.

Field Type Required Description
cwd string Yes Working directory for the agent process (absolute path; created automatically if missing when permissions allow)
model string No Model to use
promptTemplate string No Prompt used for all runs
env object No Environment variables (supports secret refs)
timeoutSec number No Process timeout (0 = no timeout)
graceSec number No Grace period before force-kill
fastMode boolean No Enables Codex Fast mode. Currently supported on gpt-5.4 only and burns credits faster
dangerouslyBypassApprovalsAndSandbox boolean No Skip safety checks (dev only)

Session Persistence

Codex uses previous_response_id for session continuity. The adapter serializes and restores this across heartbeats, allowing the agent to maintain conversation context.

Skills Injection

The adapter symlinks Paperclip skills into the global Codex skills directory (~/.codex/skills). Existing user skills are not overwritten.

Fast Mode

When fastMode is enabled, Paperclip adds Codex config overrides equivalent to:

-c 'service_tier="fast"' -c 'features.fast_mode=true'

Paperclip currently applies that only when the selected model is gpt-5.4. On other models, the toggle is preserved in config but ignored at execution time to avoid unsupported runs.

Managed CODEX_HOME

When Paperclip is running inside a managed worktree instance (PAPERCLIP_IN_WORKTREE=true), the adapter instead uses a worktree-isolated CODEX_HOME under the Paperclip instance so Codex skills, sessions, logs, and other runtime state do not leak across checkouts. It seeds that isolated home from the user's main Codex home for shared auth/config continuity.

Per-agent isolation and auth seeding

For codex_local agents the server isolation guard pins each agent to a per-agent home (<instance>/companies/<companyId>/agents/<agentId>/codex-home) and sets OPENAI_API_KEY="" so an agent can never spend against the host API key or share another agent's Codex state.

A managed home is created empty, so the adapter must provision auth into it before launching Codex — otherwise the agent runs with zero credentials and the provider returns 401 Missing bearer. The seeding contract:

  • Managed homes (the default home and any configured CODEX_HOME under the company tree) are always seeded: the ChatGPT-subscription auth.json is symlinked from the host Codex home, or, when a per-agent OPENAI_API_KEY is configured, an API-key auth.json is written instead.
  • Genuine external overrides (a CODEX_HOME outside the Paperclip-managed company tree) are treated as self-managed and are never seeded or overwritten.
  • Fail-fast guard: if a managed home ends up with no usable auth.json and no configured API key, the run fails with an explicit adapter_failed ("no Codex credentials provisioned for managed home …") rather than emitting an unauthenticated request.

Auth ownership and precedence

codex_local is host-owns-auth when Paperclip owns the effective CODEX_HOME. The winning credential file is:

  1. Per-agent API key: when adapter env contains a non-empty OPENAI_API_KEY, Paperclip writes $CODEX_HOME/auth.json with only { "OPENAI_API_KEY": "..." }. This overwrites any existing file or symlink at that path. Codex CLI versions that Paperclip supports read the key from auth.json, not directly from the process environment.
  2. Host ChatGPT-subscription login: when no per-agent key is configured, Paperclip symlinks auth.json from the shared host Codex home into the managed home. The symlink keeps rotating/single-use refresh tokens live instead of copying a stale token into the managed home.
  3. External CODEX_HOME: if adapter env points CODEX_HOME outside the Paperclip-managed company tree, that home is self-managed. Paperclip does not seed or overwrite it, so its own auth.json wins.

For sandbox or SSH execution, Paperclip uploads the effective managed CODEX_HOME and launches Codex with CODEX_HOME pointing at that uploaded directory. Any auth.json already baked into the sandbox image is shadowed in managed-home mode. If the host has no usable auth.json and no per-agent OPENAI_API_KEY, the managed run fails fast instead of falling back to an in-sandbox login.

Worked example: a worker runs in a sandbox image that already has $HOME/.codex/auth.json, and the Paperclip host is logged in with a ChatGPT subscription. For a managed codex_local agent, Paperclip symlinks the host auth.json into the agent's managed home, uploads that home to the sandbox, and sets CODEX_HOME to the uploaded path. Codex reads the host-owned uploaded file, so the sandbox image login does not win.

For high-concurrency sandbox fleets, prefer a per-agent OPENAI_API_KEY over a shared ChatGPT-subscription login. API-key mode produces a standalone auth.json for each managed home and avoids many concurrent sandboxes sharing one rotating subscription credential. The tradeoff is billing: API-key mode is metered per token through the OpenAI API, while ChatGPT-subscription auth uses the subscription's flat-plan economics and quota behavior. Pick the mode deliberately for the fleet's cost and concurrency profile.

Deferred config-validation warning spec

This section specifies a warning that is not implemented yet. The warning should help operators notice the host-owns-auth topology before they run a sandbox fleet with ChatGPT-subscription credentials.

  • Source fields: resolved Codex auth mode (api vs subscription) and execution target kind (local, remote:ssh, or remote:sandbox). Infer the auth mode from the final managed $CODEX_HOME/auth.json shape after seeding: { "OPENAI_API_KEY": ... } means API-key mode; subscription-token-shaped host auth, including the symlinked host file, means ChatGPT-subscription mode. Use top-level shape only; do not read credential values into the warning. The target kind comes from AdapterExecutionTarget.
  • Transformations: during config preparation or home seeding for a run, classify (subscription auth mode AND remote/sandbox execution target) as a warning condition. This is classification only. Do not read credential values into the warning.
  • Sink fields: emit a warning log line through onLog("stderr", ...) and, when the config-validation surface supports it, a surfaced validation warning. The sink may include only the auth-mode label and target type.
  • Retention: warning text may appear in ephemeral run logs or validation results. Do not persist auth material.
  • Attacker-observable IDs: none new. The warning must not print token values, email addresses, or auth.json contents.
  • Hook point: wire the check at the codex_local execute/config-prep path around managed-home seeding: execute.ts already has executionTarget / target transport in scope, calls seedManagedCodexHome, and calls evaluateCodexCredentialReadiness before uploading CODEX_HOME. If the warning is factored into codex-home.ts, pass the resolved target classification in rather than making codex-home.ts inspect execution targets on its own.

Because the warning touches authentication behavior, its implementation needs a maintainer security review before merge. Treat this docs section as the follow-up implementation spec, not as authorization to add the warning in a docs-only change.

Manual Local CLI

For manual local CLI usage outside heartbeat runs (for example running as codexcoder directly), use:

npx paperclipai agent local-cli codexcoder --company-id <company-id>

This installs any missing skills, creates an agent API key, and prints shell exports to run as that agent.

Instructions Resolution

If instructionsFilePath is configured, Paperclip reads that file and prepends it to the stdin prompt sent to codex exec on every run.

This is separate from any workspace-level instruction discovery that Codex itself performs in the run cwd. Paperclip does not disable Codex-native repo instruction files, so a repo-local AGENTS.md may still be loaded by Codex in addition to the Paperclip-managed agent instructions.

Environment Test

The environment test checks:

  • Codex CLI is installed and accessible
  • Working directory is absolute and available (auto-created if missing and permitted)
  • Authentication signal (OPENAI_API_KEY presence)
  • A live hello probe (codex exec --json - with prompt Respond with hello.) to verify the CLI can actually run