Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(coding-agent): report a supported Codex client version for model discovery (#1375)

bilelrais324298a27e90
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index bfd4abb604..73509ff390 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed `openai-codex` models being invisible to `rlm` subagents and `find_models` because model discovery reported Prime Agent's own version as the Codex client version ([#1375](https://github.com/PrimeIntellect-ai/prime-agent/pull/1375) by [@bilelrais](https://github.com/bilelrais)).
- Fixed URLs not opening on click in fullscreen mode on terminals such as Ghostty; clicking a link in the transcript, dock, or overlays now opens it in the browser.
## [0.7.2] - 2026-08-11
diff --git a/packages/coding-agent/src/core/model-registry.ts b/packages/coding-agent/src/core/model-registry.ts
index 8644ff5ad2..89885d4350 100644
--- a/packages/coding-agent/src/core/model-registry.ts
+++ b/packages/coding-agent/src/core/model-registry.ts
@@ -27,7 +27,7 @@ import { dirname, join } from "path";
import { type Static, type TProperties, Type } from "typebox";
import type { Validator } from "typebox/compile";
import type { TLocalizedValidationError } from "typebox/error";
-import { getAgentDir, VERSION } from "../config.js";
+import { getAgentDir } from "../config.js";
import type { AuthSourceToken, AuthStatus, AuthStorage } from "./auth-storage.js";
import { PRIME_INFERENCE_PROVIDER_ID } from "./prime-inference-auth.js";
import {
@@ -372,6 +372,27 @@ function readOpenAICodexAccountId(token: string): string | undefined {
}
}
+/**
+ * The Codex backend gates its model catalog on the reported client version: it answers HTTP 200 with a
+ * catalog that grows as the version rises, so a low version yields a silently empty or partial list rather
+ * than an error. Prime Agent's own package version is far below the Codex CLI's version line, so it must
+ * report a supported Codex client version here instead.
+ *
+ * Shipping a new Codex model takes two edits, and both are required:
+ * 1. Add the model to `codexModels` in `packages/ai/scripts/generate-models.ts` and regenerate. That list is
+ * explicit, not fetched, so an unlisted model does not exist for Prime Agent at all.
+ * 2. Raise this constant to a Codex CLI release whose catalog includes that model. `getExecutableModels()`
+ * below intersects the registry with the discovered catalog, so a listed model the catalog omits is
+ * dropped.
+ *
+ * Skipping step 2 fails silently and asymmetrically: `rlm` subagent delegation and `find_models()` resolve
+ * through `getExecutableModels()` and lose the model, while `/model` reads the unfiltered `getAvailable()`
+ * and keeps offering it.
+ *
+ * Catalog behaviour measured 2026-08-13; see #702.
+ */
+const OPENAI_CODEX_CLIENT_VERSION = "0.147.0";
+
function openAICodexModelsUrl(baseUrl: string): string {
const normalized = baseUrl.replace(/\/+$/, "");
let path: string;
@@ -383,7 +404,7 @@ function openAICodexModelsUrl(baseUrl: string): string {
path = `${normalized}/codex/models`;
}
const url = new URL(path);
- url.searchParams.set("client_version", VERSION);
+ url.searchParams.set("client_version", OPENAI_CODEX_CLIENT_VERSION);
return url.toString();
}
diff --git a/packages/coding-agent/test/suite/regressions/702-codex-client-version.test.ts b/packages/coding-agent/test/suite/regressions/702-codex-client-version.test.ts
new file mode 100644
index 0000000000..93d113e0ac
--- /dev/null
+++ b/packages/coding-agent/test/suite/regressions/702-codex-client-version.test.ts
@@ -0,0 +1,73 @@
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+import { AuthStorage } from "../../../src/core/auth-storage.js";
+import { ModelRegistry } from "../../../src/core/model-registry.js";
+
+function codexAccessToken(accountId: string): string {
+ const payload = Buffer.from(
+ JSON.stringify({ "https://api.openai.com/auth": { chatgpt_account_id: accountId } }),
+ ).toString("base64url");
+ return `header.${payload}.signature`;
+}
+
+describe("issue #702 codex model discovery client version", () => {
+ const tempDirs: string[] = [];
+ const originalFetch = globalThis.fetch;
+
+ afterEach(() => {
+ globalThis.fetch = originalFetch;
+ while (tempDirs.length > 0) {
+ const dir = tempDirs.pop();
+ if (dir) {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ }
+ });
+
+ it("reports a Codex CLI client version on the discovery request instead of the package version", async () => {
+ const tempDir = mkdtempSync(join(tmpdir(), "codex-client-version-"));
+ tempDirs.push(tempDir);
+ const authPath = join(tempDir, "auth.json");
+ writeFileSync(
+ authPath,
+ JSON.stringify({
+ "openai-codex": {
+ type: "oauth",
+ access: codexAccessToken("account-123"),
+ refresh: "refresh-token",
+ expires: Date.now() + 60 * 60 * 1000,
+ accountId: "account-123",
+ },
+ }),
+ );
+
+ const registry = ModelRegistry.create(AuthStorage.create(authPath), join(tempDir, "models.json"));
+ const codexModels = registry.getAvailable().filter((model) => model.provider === "openai-codex");
+ expect(codexModels.length).toBeGreaterThan(0);
+
+ const requestedUrls: string[] = [];
+ globalThis.fetch = (async (input: Parameters<typeof globalThis.fetch>[0]) => {
+ requestedUrls.push(input instanceof Request ? input.url : input.toString());
+ return new Response(JSON.stringify({ models: codexModels.map((model) => ({ slug: model.id })) }), {
+ status: 200,
+ headers: { "content-type": "application/json" },
+ });
+ }) as typeof globalThis.fetch;
+
+ const executable = await registry.getExecutableModels();
+
+ const discoveryUrl = requestedUrls.find((url) => url.includes("/codex/models"));
+ expect(discoveryUrl).toBeDefined();
+ const clientVersion = new URL(discoveryUrl ?? "").searchParams.get("client_version");
+ // Prime Agent's own version is 0.x well below this floor, so this assertion fails on the
+ // unfixed source. Comparing against VERSION directly would pass today and break silently
+ // once the lockstep package version reaches the pinned constant.
+ expect(clientVersion).toMatch(/^\d+\.\d+\.\d+$/);
+ const [major, minor] = (clientVersion ?? "0.0.0").split(".").map(Number);
+ expect((major ?? 0) > 0 || (minor ?? 0) >= 144).toBe(true);
+
+ expect(executable.some((model) => model.provider === "openai-codex")).toBe(true);
+ });
+});