Skip to content

feat(codex): prefer newer installed Codex for ChatGPT discovery - #168228

Merged
roboclaw-bot merged 19 commits into
mainfrom
feat/codex-prefer-newer-installed
Oct 10, 2026
Merged

roboclaw-bot merged 19 commits into
mainfrom
feat/codex-prefer-newer-installed

Conversation

@obviyus

@obviyus obviyus commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

ChatGPT can offer models to a newer installed Codex before OpenClaw updates its bundled Codex, but managed turns and discovery currently remain pinned to the bundled version.

User Impact

Managed Codex turns can use a newer stable same-major Codex already on PATH, and ChatGPT discovery sends that selection as client_version. No installation is performed and the selected OpenClaw agent runtime does not change.

Explicit commands, environment overrides, remote app-servers, and macOS desktop-first Computer Use keep their existing precedence. Login-status probes, node exec-servers, and the Doctor package check continue using the bundled package.

Why This Change Was Made

The Codex plugin remains the single selection owner. It accepts native executables and the official npm launcher, requires a parseable stable version newer than the bundle and in the same major, and proves a real initialize handshake against an isolated throwaway CODEX_HOME. It otherwise uses bundled @openai/[email protected]. Version and handshake checks share a four-second cold-selection budget; requests with less time spend at most half their remaining deadline on selection. A timeout selects the bundled pin and ignores late success, preserving time for bundled startup. A selected binary that later fails startup or changes version yields to the bundle before any thread or turn, and remains rejected until Gateway restart.

Desktop-owned macOS binaries are not adopted through PATH aliases. The selection probe forces its SQLite location as well as its Codex home into temporary storage, and skips probing when system/managed requirements can override that location. Explicit and desktop-first connections retain their existing ownership rules.

The private-local plugin-sdk/codex-client-version-runtime facade exposes resolveCodexClientVersion({ config, env, agentDir }). Catalog requests that can reach OpenAI carry the parent Gateway's captured decision into their worker, rather than allowing the worker to select a different binary. Unrelated-provider and auth-only requests do not probe Codex. The version is included in the existing catalog cache key.

This deliberately revises the PATH-independent default in #71808 while retaining its safeguards: an older CLI below the protocol floor is not selected; a failing handshake falls back; the plugin-owned dependency remains staged and available; and selecting a binary does not change the auth-home policy. Related behavior in #71842, #100973, #127394, #149647, #150255, #152181, #156187, #156671, and #158703 remains unchanged outside the documented binary-selection change.

The automatic-selection direction and residual same-major protocol risk have explicit maintainer approval.

Known, accepted limitations: a model-list request captured before a first-use rejection can finish with the previous version, including when capture precedes worker-pool admission. Already-cached ChatGPT model rows can remain for about 60 seconds. A standalone CLI selects in its own process and can disagree with a Gateway started later. More importantly, a newer same-major Codex can pass initialize and still change later protocol semantics; compatibility beyond that handshake is not proven. These windows and the protocol risk are documented, not hidden by automatically changing the OpenClaw runtime.

Evidence

  • Focused coverage: 233 tests passed across ten suites, including 164 shared-client tests, 31 binary-selection tests, and eight probe-isolation cases. Core and extension typechecks and the line-cap ratchet passed.
  • Regression coverage includes missing/older/equal/prerelease/different-major installations, launch and handshake errors, removed native artifacts, version changes, concurrent rejection, shared fallback reuse, deadline reservation, desktop-first agents, and Gateway-to-worker version handoff.
  • Both original review regressions fail on prior head 11093c3: cold selection does not settle within the caller budget, and unrelated/auth-only worker requests call the Codex resolver twice. The repaired tests pass; config/env overrides and rejected concurrent-start fallback also pass.
  • Concurrent fallback is covered while the bundled process is still initializing, both when this startup rejects the installed binary and when another startup rejects it. Both callers share one bundled process and retain/release its leases correctly.
  • Update behavior: the candidate's opt-in Doctor managed-package check explicitly disables installed-binary selection (preferInstalled: false), so a newer PATH Codex cannot attest a missing or mismatched bundled dependency.
  • A real authenticated ChatGPT turn and the production backend model list for the newer client_version remain unproven. Synthetic provider responses establish the emitted request parameter, not model availability or later protocol compatibility.

Runtime matrix

The Linux cells run the installed candidate package through Gateway models.list, with a synthetic HTTPS ChatGPT endpoint and synthetic token. TLS verification and the normal SSRF guard remain enabled. All 18 cells passed, including readiness, the selection log, emitted client_version, authorization, and hung-probe cleanup checks.

Cases Result
No PATH Codex, older 0.159.0, equal 0.160.0 Bundled 0.160.0; discovery reports 0.160.0
Newer npm install, path with spaces/chained symlinks, Bun global install Installed 0.162.1; discovery reports 0.162.1
Exit during handshake, hung version check, hung handshake, unparseable version Bundled 0.160.0; discovery reports 0.160.0
Prerelease and different-major installation Bundled 0.160.0; discovery reports 0.160.0
Explicit environment and configured command No automatic selection; existing override behavior retained
pnpm-generated shell shim Skipped; bundled 0.160.0
Node 24 and Bun runtime, with/without newer Codex Selected and reported versions agree
Native macOS arm64: absent, actual standalone 0.162.1 install, failing native handshake 3/3; selection, discovery version, and real initialize version agree
Published npm OpenClaw 2026.9.8 + published Codex plugin → candidate Update status ok; Gateway ready before/after; client_version changes from 0.158.0 to 0.162.1; Doctor managed-package check passes

The update retained the same synthetic auth profile and used it successfully after cutover. These package/runtime cells were executed on ea2e956; the subsequent main merge did not alter the Codex or OpenAI implementation. The current integrated head is checked separately by CI.

CI context

Integrated-head CI completed with inherited failures in unchanged areas; no required lane remains unrun. The corresponding main evidence is:

No unrelated source or failing assertion was changed to make this PR pass.

Merge Danger

Two-way door: reverting restores the bundled-only managed default; this change adds no config, dependency bump, durable state, or data migration. Blast radius is managed Codex stdio turns and ChatGPT model discovery on hosts with a newer accepted PATH Codex. A later same-major protocol incompatibility can still break such turns; operators can pin appServer.command or remove that executable from the Gateway PATH. Existing explicit/remote/desktop-first behavior is not broadened.

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling extensions: openai extensions: codex extensions: xai size: XL labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR prefers a qualified newer installed Codex for managed turns and reports its version during ChatGPT model discovery.

Example: The Gateway has bundled Codex 0.160.0 and installed Codex 0.162.1 on PATH.

  • Before: Managed turns use 0.160.0, and discovery sends client_version=0.160.0.
  • After: If 0.162.1 passes selection checks, managed turns use it and discovery sends client_version=0.162.1; failed selection retains the bundle.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Coherent approved implementation with useful regression coverage and reported runtime/upgrade exercises; direct authenticated backend evidence remains limited, and CI retains attributed inherited failures.
Proof confidence 🦐 gold shrimp (3/6) Verified maintainer authorship places this PR outside the ordinary contributor proof gate; the body reports packaged Gateway selection, discovery, native initialization, and upgrade exercises, while expressly leaving authenticated ChatGPT behavior unproven.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: ChatGPT models available to a newer installed Codex remain unavailable through the bundled managed runtime.
Reason: Verified maintainer direction accepts automatic qualification and its residual compatibility limits, while the implementation retains existing explicit and desktop ownership.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it implements an approved, useful runtime-selection change that current main does not provide, with no actionable introduced defect found.

Priority: P2
Reviewed head: 7d5b0dd7d757b66fdf8f13150c317dd61ace2ae1

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported packaged Gateway matrix uses a synthetic ChatGPT endpoint; an authenticated production discovery-and-turn scenario remains unproven.
Agent review details

How this fits together

The Codex plugin selects the executable for managed stdio startup; the Gateway carries that selection's version into catalog workers, which construct OpenAI discovery requests.

flowchart TD
  A[Gateway request] --> B[Codex selection owner]
  B --> C[Installed executable probe]
  B --> D[Bundled fallback]
  B --> E[Managed app server]
  B --> F[Catalog worker handoff]
  F --> G[ChatGPT model discovery]
Loading

Technical review

Best possible solution:

Land the approved selection policy with bundled fallback and parent-owned discovery handoff through the native CI exception workflow.

Do we have a high-confidence way to reproduce the issue?

This is an intentional capability change: current-main source confirms managed startup and ChatGPT discovery remain tied to the bundle.

Is this the best way to solve the issue?

The approach keeps selection in the Codex owner, preserves override precedence, and carries one decision into workers; its remaining protocol and catalog timing limits are documented and accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e3415ea8c554.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 629593b adds extensions/openai/base-url.ts:6 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 629593b029d8; files: extensions/openai/base-url.ts)
  • Peter Steinberger: Raw commit 2640154 adds src/agents/prepared-model-catalog-worker.ts:290 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2640154bcf80; files: src/agents/prepared-model-catalog-worker.ts)
  • pash-openai: Raw commit edb618c adds extensions/codex/src/app-server/managed-binary.ts:3 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: edb618c6c4a9; files: extensions/codex/src/app-server/managed-binary.ts)

PR surface

Source +933, Tests +1001, Docs +77, Config +7, Other +2. Total +2020 across 48 files. Added test files: 5.

View PR surface stats
Area Files Added Removed Net
Source 23 1168 235 +933
Tests 16 1044 43 +1001
Docs 5 103 26 +77
Config 2 8 1 +7
Generated 0 0 0 0
Other 2 2 0 +2
Total 48 2325 305 +2020

Review metrics

Metric Value Why it matters
Managed startup default One default selection policy changes; no new user configuration option or dependency pin. Eligible PATH installations can now replace the bundle automatically, while the bundle remains available for fallback.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Useful model-discovery and runtime improvement limited to hosts with a qualifying newer installed Codex.
  • merge-risk: 🚨 compatibility: Automatic selection can run newer same-major protocol behavior beyond initialize validation; the verified direction approver explicitly accepted this residual risk.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-10T07:16:56.772Z sha 5a2059e :: blocked before merge. :: none
  • reviewed 2026-10-10T07:26:43.264Z sha e82d84f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T07:44:01.995Z sha 276156e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T08:42:48.244Z sha 196348d :: blocked before merge. :: [P1] [P1] Contain configured SQLite homes before launching the probe
  • reviewed 2026-10-10T09:11:01.851Z sha 3c0ebd6 :: blocked before merge. :: [P1] [P1] Exclude enforced storage requirements before launching the probe
  • reviewed 2026-10-10T09:25:40.199Z sha 47688b8 :: blocked before merge. :: [P2] Share the bundled startup before publishing installed rejection
  • reviewed 2026-10-10T11:27:49.620Z sha ea2e956 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T11:46:26.649Z sha 7d5b0dd :: needs changes before merge. :: none

Reviewed October 10, 2026, 8:05 AM ET / 12:05 UTC (Revision 10).

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Approved direction for this PR: prefer an installed Codex only when it is strictly newer than the bundled one, same major version, and passes a real startup handshake; otherwise use the bundled Codex. Explicit appServer.command / OPENCLAW_CODEX_APP_SERVER_BIN still wins. Runtime selection is unchanged (no automatic switch to the OpenClaw runtime). Accepted residual risk: a same-major newer Codex that passes the handshake but changes later protocol behavior; documented, no extra safeguard.

@obviyus
obviyus force-pushed the feat/codex-prefer-newer-installed branch from 11093c3 to 5a2059e Compare October 10, 2026 07:10
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

The two newly exposed non-Codex failures reproduce on this PR's exact clean main parent, 45c7bc9e9ca9a838115d560ec13b67d287c3d2b4, without the PR changes.

After pnpm install --frozen-lockfile, the same owning Vitest configuration was used:

OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 OPENCLAW_VITEST_MAX_WORKERS=2 \
node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.extension-database-workers.config.ts \
  --configLoader runner --maxWorkers 2 \
  extensions/memory-core/src/memory/manager-search-reindex-backoff.test.ts \
  extensions/agentsapi/agentsapi-attempt.test.ts

Result: 2 files failed; 5 tests failed and 13 passed.

  • manager-search-reindex-backoff.test.ts:173: both force=false and force=true expect one embedding call but receive zero.
  • agentsapi-attempt.test.ts:530: the new-run, reset-binding, and new-budget retry cases expect { kind: "failed", source: "prompt" } with the transcript-admission-identity error, but receive { kind: "ok" }.

These are the same assertions reported by integrated-head CI run 38049166366. They are inherited main failures, not effects of the Codex client-version handoff. No assertions were changed, retried, or suppressed, and no unrelated source fixes were made.

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@roboclaw-bot
roboclaw-bot merged commit cbaa9ab into main Oct 10, 2026
264 of 276 checks passed
@roboclaw-bot
roboclaw-bot deleted the feat/codex-prefer-newer-installed branch October 10, 2026 18:07
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

steipete added a commit that referenced this pull request Oct 10, 2026
#168228 (cbaa9ab) exported InstalledCodexAppServer, but only managed-binary.ts uses it, so the CI deadcode:exports scan fails on main.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…claw#168228)

Prefer a validated newer stable same-major Codex CLI on PATH for managed turns, and carry the selected client version into ChatGPT model discovery. Return to the bundled runtime when it catches up or the installed candidate fails qualification/startup.

Bound cold selection, retain shared fallback ownership and explicit/desktop precedence, isolate probe storage, and skip selection for unrelated catalog and auth-only requests.

Production-authenticated ChatGPT discovery and turns remain unproven; same-major post-initialize protocol compatibility is an accepted residual risk.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
openclaw#168228 (1120acc) exported InstalledCodexAppServer, but only managed-binary.ts uses it, so the CI deadcode:exports scan fails on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex extensions: openai extensions: xai merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants