Skip to content

Commit a5d1d9e

Browse files
authored
fix(openai): harden codex catalog, routing opt-out, and WHAM half-open reprobe (#108683)
- Align OAuth model-discovery client_version with the pinned @openai/codex package (contract test ties it to extensions/codex/package.json). - Static OAuth fallback advertises only the proven GPT-5.6 subscription route (Sol); Terra/Luna come from live discovery when entitled. (#105445) - Honor the deprecated whole-agent agentRuntime openclaw opt-out for implicit Codex plugin installation; explicit model policy still wins. (#95131) - Half-open reprobe for long WHAM subscription blocks: bounded 45-minute background probes with durable claims, generation checks, and process dedupe so restored capacity unblocks profiles early. (#107262)
1 parent 6c11d26 commit a5d1d9e

14 files changed

Lines changed: 544 additions & 62 deletions

‎extensions/openai/openai-provider.test.ts‎

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Openai tests cover openai provider plugin behavior.
2+
import fs from "node:fs";
23
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
34
import type { Context, Model, SimpleStreamOptions } from "openclaw/plugin-sdk/llm";
45
import {
@@ -165,6 +166,19 @@ vi.mock("openclaw/plugin-sdk/provider-stream-family", async (importOriginal) =>
165166
};
166167
});
167168

169+
const OPENAI_CODEX_MODELS_URL = `${OPENAI_CODEX_RESPONSES_BASE_URL}/models?client_version=${readPinnedCodexClientVersion()}`;
170+
171+
function readPinnedCodexClientVersion(): string {
172+
const packageJson = JSON.parse(
173+
fs.readFileSync(new URL("../codex/package.json", import.meta.url), "utf8"),
174+
) as { dependencies?: Record<string, unknown> };
175+
const version = packageJson.dependencies?.["@openai/codex"];
176+
if (typeof version !== "string") {
177+
throw new Error("expected an exact @openai/codex dependency");
178+
}
179+
return version;
180+
}
181+
168182
function runWrappedPayloadCase(params: {
169183
wrap: NonNullable<ReturnType<typeof buildOpenAIProvider>["wrapStreamFn"]>;
170184
provider: string;
@@ -676,9 +690,7 @@ describe("buildOpenAIProvider", () => {
676690
maxTokens: 64_000,
677691
});
678692
expect(fetchSpy).toHaveBeenCalledOnce();
679-
expect(fetchSpy.mock.calls[0]?.[0]).toBe(
680-
"https://chatgpt.com/backend-api/codex/models?client_version=1.0.0",
681-
);
693+
expect(fetchSpy.mock.calls[0]?.[0]).toBe(OPENAI_CODEX_MODELS_URL);
682694
const headers = fetchSpy.mock.calls[0]?.[1]?.headers;
683695
expect(headers).toBeInstanceOf(Headers);
684696
if (!(headers instanceof Headers)) {
@@ -691,6 +703,25 @@ describe("buildOpenAIProvider", () => {
691703
}
692704
});
693705

706+
it("uses the managed Codex package version for OAuth model discovery", async () => {
707+
const pinnedVersion = readPinnedCodexClientVersion();
708+
const fetchGuard: LiveModelCatalogFetchGuard = vi.fn(async (params) => ({
709+
response: Response.json({ models: [{ slug: "gpt-5.5", visibility: "list" }] }),
710+
finalUrl: params.url,
711+
release: async () => undefined,
712+
}));
713+
714+
await buildOpenAICodexLiveProviderConfig({
715+
discoveryApiKey: "placeholder",
716+
fetchGuard,
717+
});
718+
719+
const requestUrl = vi.mocked(fetchGuard).mock.calls[0]?.[0].url;
720+
expect(new URL(requestUrl ?? "https://placeholder").searchParams.get("client_version")).toBe(
721+
pinnedVersion,
722+
);
723+
});
724+
694725
it("uses runtime OAuth profiles when catalog auth resolution is empty", async () => {
695726
mocks.resolveApiKeyForProvider.mockResolvedValue({
696727
mode: "oauth",
@@ -797,9 +828,7 @@ describe("buildOpenAIProvider", () => {
797828
maxTokens: 128_000,
798829
});
799830
const fetchParams = vi.mocked(fetchGuard).mock.calls[0]?.[0];
800-
expect(fetchParams?.url).toBe(
801-
"https://chatgpt.com/backend-api/codex/models?client_version=1.0.0",
802-
);
831+
expect(fetchParams?.url).toBe(OPENAI_CODEX_MODELS_URL);
803832
const init = fetchParams?.init;
804833
const headers = init?.headers;
805834
expect(headers).toBeInstanceOf(Headers);
@@ -876,52 +905,9 @@ describe("buildOpenAIProvider", () => {
876905
supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max", "ultra"],
877906
},
878907
});
879-
expect(provider.models.find((model) => model.id === "gpt-5.6-terra")).toMatchObject({
880-
contextWindow: 372_000,
881-
contextTokens: 372_000,
882-
compat: {
883-
supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max", "ultra"],
884-
},
885-
});
886-
expect(provider.models.find((model) => model.id === "gpt-5.6-luna")).toMatchObject({
887-
contextWindow: 372_000,
888-
contextTokens: 372_000,
889-
compat: { supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"] },
890-
});
908+
expect(provider.models.map((model) => model.id)).not.toContain("gpt-5.6-terra");
909+
expect(provider.models.map((model) => model.id)).not.toContain("gpt-5.6-luna");
891910
expect(provider.models.map((model) => model.id)).toContain("gpt-5.5");
892-
const gpt56Models = Object.fromEntries(
893-
provider.models
894-
.filter((model) => model.id.startsWith("gpt-5.6-"))
895-
.map((model) => [model.id, model]),
896-
);
897-
for (const modelId of ["gpt-5.6-sol", "gpt-5.6-terra"]) {
898-
const model = gpt56Models[modelId];
899-
expect(model?.compat?.supportedReasoningEfforts).toContain("ultra");
900-
expect(
901-
buildOpenAIProvider()
902-
.resolveThinkingProfile?.({
903-
provider: "openai",
904-
modelId,
905-
agentRuntime: "codex",
906-
api: "openai-chatgpt-responses",
907-
compat: model?.compat,
908-
} as never)
909-
?.levels.map((level) => level.id),
910-
).toContain("ultra");
911-
}
912-
const luna = gpt56Models["gpt-5.6-luna"];
913-
expect(luna?.compat?.supportedReasoningEfforts).not.toContain("ultra");
914-
const lunaLevels = buildOpenAIProvider()
915-
.resolveThinkingProfile?.({
916-
provider: "openai",
917-
modelId: "gpt-5.6-luna",
918-
agentRuntime: "codex",
919-
api: "openai-chatgpt-responses",
920-
compat: luna?.compat,
921-
} as never)
922-
?.levels.map((level) => level.id);
923-
expect(lunaLevels).toContain("max");
924-
expect(lunaLevels).not.toContain("ultra");
925911
expect(release).toHaveBeenCalledOnce();
926912
});
927913

‎extensions/openai/openai-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ function classifyOpenAiFailoverCode(code: string | undefined) {
8181
}
8282
}
8383
const OPENAI_MODELS_ENDPOINT = "https://api.openai.com/v1/models";
84-
const OPENAI_CODEX_MODELS_ENDPOINT = `${OPENAI_CODEX_RESPONSES_BASE_URL}/models?client_version=1.0.0`;
84+
// Keep synchronized with extensions/codex's exact @openai/codex dependency;
85+
// the provider contract test fails when that managed-runtime pin changes.
86+
const OPENAI_CODEX_CLIENT_VERSION = "0.144.4";
87+
const OPENAI_CODEX_MODELS_ENDPOINT = `${OPENAI_CODEX_RESPONSES_BASE_URL}/models?client_version=${OPENAI_CODEX_CLIENT_VERSION}`;
8588
const OPENAI_MODELS_CACHE_TTL_MS = 60_000;
8689
const OPENAI_CODEX_MODELS_CACHE_TTL_MS = 60_000;
8790
const OPENAI_GPT_56_DIRECT_CONTEXT_TOKENS = 1_050_000;
@@ -440,6 +443,12 @@ function buildOpenAICodexStaticProviderConfig(): ModelProviderConfig {
440443
api: "openai-chatgpt-responses",
441444
auth: "oauth",
442445
models: OPENAI_MANIFEST_PROVIDER.models.flatMap((model) => {
446+
const modelId = normalizeLowercaseStringOrEmpty(model.id);
447+
// Static OAuth rows are offline hints, not entitlement claims. Keep only
448+
// the proven GPT-5.6 subscription route; live discovery may add others.
449+
if (modelId.startsWith("gpt-5.6") && modelId !== OPENAI_GPT_56_SOL_MODEL_ID) {
450+
return [];
451+
}
443452
const normalized = normalizeOpenAICodexCatalogModel(model);
444453
return normalized ? [normalized] : [];
445454
}),

‎src/agents/agent-runtime-id.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/** Agent runtime id normalization and retired runtime-selection compatibility helpers. */
2+
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import { normalizeAgentId } from "../routing/session-key.js";
4+
25
export type EmbeddedAgentRuntime = "openclaw" | "auto" | (string & {});
36

47
export const OPENCLAW_AGENT_RUNTIME_ID = "openclaw";
@@ -31,6 +34,21 @@ export function normalizeOptionalAgentRuntimeId(raw: unknown): EmbeddedAgentRunt
3134
return value ? normalizeEmbeddedAgentRuntime(value) : undefined;
3235
}
3336

37+
/** Resolves the deprecated explicit whole-agent runtime override, when present. */
38+
export function resolveAgentScopedRuntimeOverride(params: {
39+
config?: OpenClawConfig;
40+
agentId?: string;
41+
}): EmbeddedAgentRuntime | undefined {
42+
const agentId = params.agentId ? normalizeAgentId(params.agentId) : undefined;
43+
const agentRuntime = agentId
44+
? params.config?.agents?.list?.find((entry) => normalizeAgentId(entry.id) === agentId)
45+
?.agentRuntime?.id
46+
: undefined;
47+
return normalizeOptionalAgentRuntimeId(
48+
agentRuntime ?? params.config?.agents?.defaults?.agentRuntime?.id,
49+
);
50+
}
51+
3452
/**
3553
* @deprecated Whole-agent runtime environment selection is retired. Use
3654
* provider/model runtime policy or a registered agent harness instead.

‎src/agents/auth-profiles/state.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function normalizeUsageStatsEntry(raw: unknown): ProfileUsageStats | undefined {
127127
errorCount: normalizeFiniteNumber(raw.errorCount),
128128
failureCounts: normalizeFailureCounts(raw.failureCounts),
129129
lastFailureAt: normalizeFiniteNumber(raw.lastFailureAt),
130+
lastProbeAt: normalizeFiniteNumber(raw.lastProbeAt),
130131
};
131132
for (const key of Object.keys(stats) as Array<keyof ProfileUsageStats>) {
132133
if (stats[key] === undefined) {

‎src/agents/auth-profiles/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export type ProfileUsageStats = {
115115
errorCount?: number;
116116
failureCounts?: Partial<Record<AuthProfileFailureReason, number>>;
117117
lastFailureAt?: number;
118+
lastProbeAt?: number;
118119
};
119120

120121
/** Durable, non-secret auth profile selection state. */

‎src/agents/auth-profiles/usage.test-support.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type UsageDeps = {
66

77
type AuthProfileUsageTestApi = {
88
setDepsForTest(overrides: Partial<UsageDeps> | null): void;
9+
resetWhamReprobeStateForTest(): void;
910
};
1011

1112
function getTestApi(): AuthProfileUsageTestApi {
@@ -16,4 +17,5 @@ function getTestApi(): AuthProfileUsageTestApi {
1617

1718
export const testing: AuthProfileUsageTestApi = {
1819
setDepsForTest: (overrides) => getTestApi().setDepsForTest(overrides),
20+
resetWhamReprobeStateForTest: () => getTestApi().resetWhamReprobeStateForTest(),
1921
};

0 commit comments

Comments
 (0)