Skip to content

Commit 50a30b7

Browse files
authored
fix(codex): migrate redundant native service tiers (#118738)
1 parent cdd0856 commit 50a30b7

7 files changed

Lines changed: 388 additions & 48 deletions

File tree

‎src/agents/model-extra-params.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const FAST_MODE_CUTOFF_MODEL_PARAM_KEYS = new Set([
1919

2020
// Native harnesses receive recognized values as typed run controls. Other value
2121
// shapes with the same keys remain authored provider request parameters.
22-
function isAgentRuntimeModelParam(key: string, value: unknown): boolean {
22+
export function isAgentRuntimeModelParam(key: string, value: unknown): boolean {
2323
if (key === "thinking") {
2424
return (
2525
value === false ||

‎src/commands/doctor/shared/codex-route-config-scan.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "./codex-route-model-slots.js";
2525
import type {
2626
CodexRouteHit,
27-
DisabledCodexPluginRouteHit,
27+
CodexRuntimeRouteHit,
2828
DisabledCodexPluginRouteIssue,
2929
} from "./codex-route-types.js";
3030

@@ -216,10 +216,18 @@ export function collectConfigModelRefs(
216216
export function collectDisabledCodexPluginRouteHits(
217217
cfg: OpenClawConfig,
218218
env?: NodeJS.ProcessEnv,
219-
): DisabledCodexPluginRouteHit[] {
219+
): CodexRuntimeRouteHit[] {
220220
if (!isCodexPluginUnavailableByConfig(cfg)) {
221221
return [];
222222
}
223+
return collectCodexRuntimeRouteHits(cfg, env);
224+
}
225+
226+
/** Find effective configured model routes that select the Codex runtime. */
227+
export function collectCodexRuntimeRouteHits(
228+
cfg: OpenClawConfig,
229+
env?: NodeJS.ProcessEnv,
230+
): CodexRuntimeRouteHit[] {
223231
const defaults = cfg.agents?.defaults;
224232
const defaultRefs = collectAgentRuntimeModelRefs({
225233
agent: defaults,
@@ -280,7 +288,7 @@ export function collectDisabledCodexPluginRouteHits(
280288
}
281289
}
282290

283-
const hits: DisabledCodexPluginRouteHit[] = [];
291+
const hits: CodexRuntimeRouteHit[] = [];
284292
const seen = new Set<string>();
285293
for (const ref of candidateRefs) {
286294
const canonicalModel = resolveRuntimeModelRef({
@@ -303,7 +311,12 @@ export function collectDisabledCodexPluginRouteHits(
303311
continue;
304312
}
305313
seen.add(key);
306-
hits.push({ path: ref.path, modelRef: ref.modelRef, canonicalModel });
314+
hits.push({
315+
path: ref.path,
316+
modelRef: ref.modelRef,
317+
canonicalModel,
318+
...(ref.agentId ? { agentId: ref.agentId } : {}),
319+
});
307320
}
308321
return hits;
309322
}
@@ -324,7 +337,7 @@ export function collectDisabledCodexPluginRouteIssues(
324337

325338
export function enableCodexPluginForRequiredRoutes(params: {
326339
cfg: OpenClawConfig;
327-
routeHits: DisabledCodexPluginRouteHit[];
340+
routeHits: CodexRuntimeRouteHit[];
328341
}): { cfg: OpenClawConfig; changes: string[] } {
329342
// Explicit user opt-out wins over managed-harness repair; doctor warns instead.
330343
if (params.routeHits.length === 0 || codexPluginRepairIsBlocked(params.cfg)) {

‎src/commands/doctor/shared/codex-route-types.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export type LegacyLosslessCompactionConfig = {
2626
modelValue?: string;
2727
};
2828

29-
export type DisabledCodexPluginRouteHit = {
29+
export type CodexRuntimeRouteHit = {
3030
path: string;
3131
modelRef: string;
3232
canonicalModel: string;
33+
agentId?: string;
3334
};
3435

3536
export type DisabledCodexPluginRouteIssue = {

‎src/commands/doctor/shared/codex-route-warnings.test.ts‎

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe("collectCodexRouteWarnings", () => {
348348
expect(result.cfg.agents?.list?.[0]?.models?.["openai-codex/gpt-5.4"]).toBeUndefined();
349349
});
350350

351-
it("warns when Codex app-server command includes inline arguments", () => {
351+
it("warns without executing a custom Codex app-server command", () => {
352352
const warnings = collectCodexRouteWarnings({
353353
plugins: {
354354
entries: {
@@ -371,7 +371,140 @@ describe("collectCodexRouteWarnings", () => {
371371
'- plugins.entries.codex.config.appServer.command: "node C:\\Users\\me\\.openclaw\\npm\\node_modules\\@openai\\codex\\bin\\codex.js" starts with "node" and embeds "C:\\Users\\me\\.openclaw\\npm\\node_modules\\@openai\\codex\\bin\\codex.js". The command field must be only the executable path.',
372372
"- Remove the override to use managed Codex startup, or move script/options to plugins.entries.codex.config.appServer.args.",
373373
].join("\n"),
374+
[
375+
"- Custom Codex app-server command bypasses OpenClaw's managed exact-version binary.",
376+
"- plugins.entries.codex.config.appServer.command: Doctor did not execute, inspect, or rewrite this command.",
377+
"- Remove the override to use managed Codex startup, or verify the custom binary matches the Codex version bundled with this OpenClaw release.",
378+
].join("\n"),
379+
]);
380+
});
381+
382+
it("repairs only redundant native Codex service tiers and is idempotent", () => {
383+
const command = "node -e process.exit(99)";
384+
const original = {
385+
plugins: { entries: { codex: { enabled: true, config: { appServer: { command } } } } },
386+
agents: {
387+
defaults: {
388+
params: { temperature: 0.7 },
389+
models: {
390+
"openai/gpt-5.6-sol": {
391+
params: { fastMode: true, serviceTier: "priority", temperature: 0.2 },
392+
agentRuntime: { id: "codex" },
393+
},
394+
"openai/gpt-5.6-terra": {
395+
params: { fast_mode: "on", service_tier: "PRIORITY" },
396+
agentRuntime: { id: "codex" },
397+
},
398+
},
399+
},
400+
},
401+
};
402+
403+
const repaired = maybeRepairCodexRoutes(original);
404+
405+
expect(repaired.changes).toStrictEqual([
406+
"Removed redundant agents.defaults.models.openai/gpt-5.6-sol.params.serviceTier; fastMode already selects native priority.",
407+
"Removed redundant agents.defaults.models.openai/gpt-5.6-terra.params.service_tier; fastMode already selects native priority.",
374408
]);
409+
expect(repaired.cfg.agents?.defaults?.models).toEqual({
410+
"openai/gpt-5.6-sol": {
411+
params: { fastMode: true, temperature: 0.2 },
412+
agentRuntime: { id: "codex" },
413+
},
414+
"openai/gpt-5.6-terra": {
415+
params: { fast_mode: "on" },
416+
agentRuntime: { id: "codex" },
417+
},
418+
});
419+
expect(repaired.cfg.plugins?.entries?.codex?.config).toEqual({
420+
appServer: { command },
421+
});
422+
expect(repaired.warnings.join("\n")).toContain(
423+
"Custom Codex app-server command bypasses OpenClaw's managed exact-version binary.",
424+
);
425+
expect(repaired.warnings.join("\n")).toContain("agents.defaults.params.temperature");
426+
expect(repaired.warnings.join("\n")).toContain(
427+
"agents.defaults.models.openai/gpt-5.6-sol.params.temperature",
428+
);
429+
expect(original.agents.defaults.models["openai/gpt-5.6-sol"].params).toHaveProperty(
430+
"serviceTier",
431+
);
432+
433+
const second = maybeRepairCodexRoutes(repaired.cfg);
434+
expect(second.cfg).toBe(repaired.cfg);
435+
expect(second.changes).toStrictEqual([]);
436+
expect(second.warnings).toStrictEqual(repaired.warnings);
437+
});
438+
439+
it("preserves and reports authored params across effective Codex sources", () => {
440+
const original = {
441+
agents: {
442+
defaults: {
443+
model: "openai/gpt-5.6-sol",
444+
params: { temperature: 0.7 },
445+
models: {
446+
"openai/gpt-5.6-sol": {
447+
params: {
448+
fastMode: true,
449+
fast_mode: false,
450+
serviceTier: "priority",
451+
temperature: 0.2,
452+
},
453+
agentRuntime: { id: "codex" },
454+
},
455+
"openai/gpt-5.6-openclaw": {
456+
params: { fastMode: true, serviceTier: "priority" },
457+
agentRuntime: { id: "openclaw" },
458+
},
459+
},
460+
},
461+
entries: {
462+
coder: { params: { topP: 0.8 } },
463+
worker: {
464+
models: {
465+
"openai/gpt-5.6-sol": { agentRuntime: { id: "openclaw" } },
466+
},
467+
},
468+
},
469+
},
470+
};
471+
472+
const result = maybeRepairCodexRoutes(original);
473+
474+
expect(result.cfg).toBe(original);
475+
expect(result.changes).toStrictEqual([]);
476+
expect(result.warnings.join("\n")).toContain(
477+
"agents.defaults.models.openai/gpt-5.6-sol.params.serviceTier",
478+
);
479+
expect(result.warnings.join("\n")).toContain(
480+
"agents.defaults.models.openai/gpt-5.6-sol.params.temperature",
481+
);
482+
expect(result.warnings.join("\n")).toContain("agents.defaults.params.temperature");
483+
expect(result.warnings.join("\n")).toContain("agents.entries.coder.params.topP");
484+
expect(result.warnings.join("\n")).not.toContain("gpt-5.6-openclaw.params.serviceTier");
485+
});
486+
487+
it("canonicalizes and repairs a redundant legacy tier in one pass", () => {
488+
const result = maybeRepairCodexRoutes({
489+
agents: {
490+
defaults: {
491+
models: {
492+
"openai-codex/gpt-5.6-sol": {
493+
params: { fastMode: true, serviceTier: "priority" },
494+
agentRuntime: { id: "codex" },
495+
},
496+
},
497+
},
498+
},
499+
});
500+
501+
expect(result.cfg.agents?.defaults?.models?.["openai-codex/gpt-5.6-sol"]).toBeUndefined();
502+
expect(result.cfg.agents?.defaults?.models?.["openai/gpt-5.6-sol"]?.params).toEqual({
503+
fastMode: true,
504+
});
505+
expect(result.changes).toContain(
506+
"Removed redundant agents.defaults.models.openai/gpt-5.6-sol.params.serviceTier; fastMode already selects native priority.",
507+
);
375508
});
376509

377510
it("warns when Codex runtime routes are configured while the Codex plugin is disabled", () => {

0 commit comments

Comments
 (0)