Skip to content

Commit 52771b6

Browse files
authored
Stop preserving stale whole-agent Codex runtime pins
This removes stale whole-agent Codex runtime pins from the remaining doctor/Crestodian paths and teaches doctor cron repair to normalize old openai-codex payload model refs to canonical openai refs. Runtime policy stays provider/model-scoped and cron execution stays strict.
1 parent 34d275c commit 52771b6

9 files changed

Lines changed: 142 additions & 12 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Docs: https://docs.openclaw.ai
235235
- macOS/config: reject stale or destructive app fallback config writes before direct replacement and keep rejected payloads as private audit artifacts, so `gateway.mode`, metadata, and auth are not silently clobbered. Fixes #64973 and #74890. Thanks @BunsDev.
236236
- Gateway/macOS: include Apple Silicon Homebrew bin and sbin directories in generated LaunchAgent service PATHs and service-audit expectations so `openclaw gateway restart` keeps Homebrew Node installs reachable. Fixes #79232. Thanks @BunsDev and @TurboTheTurtle.
237237
- Doctor/OpenAI: stop pinning migrated `openai-codex/*` routes to the Codex runtime so mixed-provider agents keep automatic PI routing for MiniMax, Anthropic, and other non-OpenAI model switches.
238+
- Doctor/OpenAI: remove stale whole-agent Codex runtime pins while repairing legacy OpenAI-Codex routes, so upgraded agents do not force an unregistered Codex harness before provider/model routing can choose the right runtime.
238239
- Gateway/macOS: `openclaw gateway stop` now uses `launchctl bootout` by default instead of unconditionally calling `launchctl disable`, so KeepAlive auto-recovery still works after unexpected crashes; use the new `--disable` flag to opt into the persistent-disable behavior when a manual stop should survive reboots. Fixes #77934. Thanks @bmoran1022.
239240
- Gateway/macOS: `repairLaunchAgentBootstrap` no longer kickstarts an already-running LaunchAgent, preventing unnecessary service restarts and session disconnects when repair runs against a healthy gateway. Fixes #77428. Thanks @ramitrkar-hash.
240241
- Gateway/macOS: `openclaw gateway stop --disable` now persists the LaunchAgent disable bit even after a previous bootout left the service not loaded, keeping the explicit stay-down path reliable. (#78412) Thanks @wdeveloper16.
@@ -334,7 +335,7 @@ Docs: https://docs.openclaw.ai
334335
- Codex harness: honor `models.providers.openai-codex.models[].contextTokens` for native `openai/*` Codex runtime runs and `/status` context reporting, so subscription-backed Codex agents use the configured OAuth context cap without inflating past the runtime model window. Fixes #77858. Thanks @lilesjtu.
335336
- Sessions cleanup: add `openclaw sessions cleanup --fix-dm-scope` so operators who return `session.dmScope` to `main` can dry-run and retire stale direct-DM session rows while preserving transcripts as deleted archives. Fixes #47561 and #45554. Thanks @BunsDev.
336337

337-
- Doctor/Codex: repair legacy `openai-codex/*` routes to canonical `openai/*`, keep OpenAI agent turns on Codex by default, ignore stale whole-agent/session runtime pins, preserve explicit provider/model runtime policy, and migrate legacy runtime model refs to model-scoped runtime entries. Thanks @vincentkoc.
338+
- Doctor/Codex: repair legacy `openai-codex/*` routes and cron payload model refs to canonical `openai/*`, keep OpenAI agent turns on Codex by default, ignore stale whole-agent/session runtime pins, preserve explicit provider/model runtime policy, and migrate legacy runtime model refs to model-scoped runtime entries. Thanks @vincentkoc.
338339
- Video generation: wait up to 20 minutes for slow fal/MiniMax queue-backed jobs, stop forwarding unsupported Google Veo generated-audio options, and normalize MiniMax `720P` requests to its supported `768P` resolution with the usual override warning/details instead of failing fallback.
339340
- Channels/durable delivery: preserve channel-specific final reply semantics when using durable sends, including Telegram selected quotes and silent error replies plus WhatsApp message-sending cancellations.
340341
- Channels/message lifecycle: build legacy channel delivery results from message receipts and add receipts to BlueBubbles, Feishu, Google Chat, iMessage, IRC, LINE, Nextcloud Talk, QQ Bot, Signal, Synology Chat, Tlon, Twitch, WhatsApp, Zalo, and Zalo Personal send results and owner-path reply delivery plus Discord, Matrix, Mattermost, Slack, and Teams send results while preserving existing message id compatibility.

‎src/commands/doctor-cron-payload-migration.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,59 @@ import {
55

66
type UnknownRecord = Record<string, unknown>;
77

8+
function toCanonicalOpenAIModelRef(value: unknown): string | undefined {
9+
const raw = readString(value);
10+
if (typeof raw !== "string") {
11+
return undefined;
12+
}
13+
const trimmed = raw.trim();
14+
const slash = trimmed.indexOf("/");
15+
if (slash <= 0) {
16+
return undefined;
17+
}
18+
const provider = trimmed.slice(0, slash).trim().toLowerCase();
19+
if (provider !== "openai-codex") {
20+
return undefined;
21+
}
22+
const model = trimmed.slice(slash + 1).trim();
23+
return model ? `openai/${model}` : undefined;
24+
}
25+
826
function normalizeChannel(value: string): string {
927
return normalizeOptionalLowercaseString(value) ?? "";
1028
}
1129

30+
export function hasLegacyOpenAICodexCronModelRef(payload: UnknownRecord): boolean {
31+
if (toCanonicalOpenAIModelRef(payload.model)) {
32+
return true;
33+
}
34+
const fallbacks = payload.fallbacks;
35+
return (
36+
Array.isArray(fallbacks) && fallbacks.some((fallback) => toCanonicalOpenAIModelRef(fallback))
37+
);
38+
}
39+
40+
function migrateLegacyOpenAICodexModelRefs(payload: UnknownRecord): boolean {
41+
let mutated = false;
42+
43+
const model = toCanonicalOpenAIModelRef(payload.model);
44+
if (model && payload.model !== model) {
45+
payload.model = model;
46+
mutated = true;
47+
}
48+
49+
const fallbacks = payload.fallbacks;
50+
if (Array.isArray(fallbacks)) {
51+
const next = fallbacks.map((fallback) => toCanonicalOpenAIModelRef(fallback) ?? fallback);
52+
if (next.some((fallback, index) => fallback !== fallbacks[index])) {
53+
payload.fallbacks = next;
54+
mutated = true;
55+
}
56+
}
57+
58+
return mutated;
59+
}
60+
1261
export function migrateLegacyCronPayload(payload: UnknownRecord): boolean {
1362
let mutated = false;
1463

@@ -34,5 +83,9 @@ export function migrateLegacyCronPayload(payload: UnknownRecord): boolean {
3483
mutated = true;
3584
}
3685

86+
if (migrateLegacyOpenAICodexModelRefs(payload)) {
87+
mutated = true;
88+
}
89+
3790
return mutated;
3891
}

‎src/commands/doctor-cron-store-migration.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ describe("normalizeStoredCronJobs", () => {
106106
});
107107
});
108108

109+
it("rewrites legacy OpenAI Codex model refs in cron payloads", () => {
110+
const { job, result } = normalizeOneJob(
111+
makeLegacyJob({
112+
id: "legacy-codex-cron-model",
113+
schedule: { kind: "every", everyMs: 60_000 },
114+
payload: {
115+
kind: "agentTurn",
116+
message: "ping",
117+
model: " openai-codex/gpt-5.5 ",
118+
fallbacks: ["anthropic/claude-opus-4.6", "openai-codex/gpt-5.4-mini"],
119+
},
120+
}),
121+
);
122+
123+
expect(result.mutated).toBe(true);
124+
expect(result.issues.legacyPayloadCodexModel).toBe(1);
125+
expect(job.payload).toMatchObject({
126+
kind: "agentTurn",
127+
message: "ping",
128+
model: "openai/gpt-5.5",
129+
fallbacks: ["anthropic/claude-opus-4.6", "openai/gpt-5.4-mini"],
130+
});
131+
});
132+
109133
it("does not report legacyPayloadKind for already-normalized payload kinds", () => {
110134
const jobs = [
111135
{

‎src/commands/doctor-cron-store-migration.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
normalizeOptionalStringifiedId,
1111
} from "../shared/string-coerce.js";
1212
import { normalizeLegacyDeliveryInput } from "./doctor-cron-legacy-delivery.js";
13-
import { migrateLegacyCronPayload } from "./doctor-cron-payload-migration.js";
13+
import {
14+
hasLegacyOpenAICodexCronModelRef,
15+
migrateLegacyCronPayload,
16+
} from "./doctor-cron-payload-migration.js";
1417

1518
type CronStoreIssueKey =
1619
| "jobId"
@@ -19,6 +22,7 @@ type CronStoreIssueKey =
1922
| "legacyScheduleString"
2023
| "legacyScheduleCron"
2124
| "legacyPayloadKind"
25+
| "legacyPayloadCodexModel"
2226
| "legacyPayloadProvider"
2327
| "legacyTopLevelPayloadFields"
2428
| "legacyTopLevelDeliveryFields"
@@ -380,8 +384,12 @@ export function normalizeStoredCronJobs(
380384

381385
if (payloadRecord) {
382386
const hadLegacyPayloadProvider = Boolean(normalizeOptionalString(payloadRecord.provider));
387+
const hadLegacyPayloadCodexModel = hasLegacyOpenAICodexCronModelRef(payloadRecord);
383388
if (migrateLegacyCronPayload(payloadRecord)) {
384389
mutated = true;
390+
if (hadLegacyPayloadCodexModel) {
391+
trackIssue("legacyPayloadCodexModel");
392+
}
385393
if (hadLegacyPayloadProvider) {
386394
trackIssue("legacyPayloadProvider");
387395
}

‎src/commands/doctor-cron.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ function formatLegacyIssuePreview(issues: Partial<Record<string, number>>): stri
5454
if (issues.legacyPayloadKind) {
5555
lines.push(`- ${pluralize(issues.legacyPayloadKind, "job")} needs payload kind normalization`);
5656
}
57+
if (issues.legacyPayloadCodexModel) {
58+
lines.push(
59+
`- ${pluralize(issues.legacyPayloadCodexModel, "job")} still uses legacy \`openai-codex/*\` cron model refs`,
60+
);
61+
}
5762
if (issues.legacyPayloadProvider) {
5863
lines.push(
5964
`- ${pluralize(issues.legacyPayloadProvider, "job")} still uses payload \`provider\` as a delivery alias`,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ describe("collectCodexRouteWarnings", () => {
124124
cfg: {
125125
agents: {
126126
defaults: {
127+
agentRuntime: { id: "codex" },
127128
model: {
128129
primary: "openai-codex/gpt-5.5",
129130
fallbacks: ["openai-codex/gpt-5.4", "anthropic/claude-sonnet-4-6"],
@@ -191,7 +192,11 @@ describe("collectCodexRouteWarnings", () => {
191192
});
192193

193194
expect(result.warnings).toStrictEqual([]);
194-
expect(result.changes).toEqual([expect.stringContaining("Repaired Codex model routes")]);
195+
expect(result.changes).toEqual([
196+
expect.stringContaining("Repaired Codex model routes"),
197+
"Removed agents.defaults.agentRuntime; runtime is now provider/model scoped.",
198+
"Removed agents.list.worker.agentRuntime; runtime is now provider/model scoped.",
199+
]);
195200
expect(result.cfg.agents?.defaults?.model).toEqual({
196201
primary: "openai/gpt-5.5",
197202
fallbacks: ["openai/gpt-5.4", "anthropic/claude-sonnet-4-6"],
@@ -210,8 +215,8 @@ describe("collectCodexRouteWarnings", () => {
210215
expect(result.cfg.agents?.list?.[0]).toMatchObject({
211216
id: "worker",
212217
model: "openai/gpt-5.4",
213-
agentRuntime: { id: "codex" },
214218
});
219+
expect(result.cfg.agents?.list?.[0]?.agentRuntime).toBeUndefined();
215220
expect(result.cfg.channels?.modelByChannel?.telegram?.default).toBe("openai/gpt-5.4");
216221
expect(result.cfg.hooks?.mappings?.[0]?.model).toBe("openai/gpt-5.4-mini");
217222
expect(result.cfg.hooks?.gmail?.model).toBe("openai/gpt-5.4");

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ type SessionRouteRepairResult = {
1818
changed: boolean;
1919
sessionKeys: string[];
2020
};
21+
type ConfigRouteRepairResult = {
22+
cfg: OpenClawConfig;
23+
changes: CodexRouteHit[];
24+
runtimePinChanges: string[];
25+
};
2126
type CodexSessionRouteRepairSummary = {
2227
scannedStores: number;
2328
repairedStores: number;
@@ -442,10 +447,38 @@ function rewriteAgentModelRefs(params: {
442447
}
443448
}
444449

445-
function rewriteConfigModelRefs(params: { cfg: OpenClawConfig; env?: NodeJS.ProcessEnv }): {
450+
function clearLegacyAgentRuntimePolicy(
451+
container: MutableRecord | undefined,
452+
pathLabel: string,
453+
changes: string[],
454+
): void {
455+
if (!container) {
456+
return;
457+
}
458+
if (asMutableRecord(container.embeddedHarness)) {
459+
delete container.embeddedHarness;
460+
changes.push(`Removed ${pathLabel}.embeddedHarness; runtime is now provider/model scoped.`);
461+
}
462+
if (asMutableRecord(container.agentRuntime)) {
463+
delete container.agentRuntime;
464+
changes.push(`Removed ${pathLabel}.agentRuntime; runtime is now provider/model scoped.`);
465+
}
466+
}
467+
468+
function clearConfigLegacyAgentRuntimePolicies(cfg: OpenClawConfig): string[] {
469+
const changes: string[] = [];
470+
clearLegacyAgentRuntimePolicy(asMutableRecord(cfg.agents?.defaults), "agents.defaults", changes);
471+
for (const [index, agent] of (cfg.agents?.list ?? []).entries()) {
472+
const id = typeof agent.id === "string" && agent.id.trim() ? agent.id.trim() : String(index);
473+
clearLegacyAgentRuntimePolicy(agent as MutableRecord, `agents.list.${id}`, changes);
474+
}
475+
return changes;
476+
}
477+
478+
function rewriteConfigModelRefs(params: {
446479
cfg: OpenClawConfig;
447-
changes: CodexRouteHit[];
448-
} {
480+
env?: NodeJS.ProcessEnv;
481+
}): ConfigRouteRepairResult {
449482
const nextConfig = structuredClone(params.cfg);
450483
const hits: CodexRouteHit[] = [];
451484
const defaultsRuntime = nextConfig.agents?.defaults?.agentRuntime;
@@ -518,9 +551,12 @@ function rewriteConfigModelRefs(params: { cfg: OpenClawConfig; env?: NodeJS.Proc
518551
key: "model",
519552
path: "channels.discord.voice.model",
520553
});
554+
const runtimePinChanges =
555+
hits.length > 0 ? clearConfigLegacyAgentRuntimePolicies(nextConfig) : [];
521556
return {
522-
cfg: hits.length > 0 ? nextConfig : params.cfg,
557+
cfg: hits.length > 0 || runtimePinChanges.length > 0 ? nextConfig : params.cfg,
523558
changes: hits,
559+
runtimePinChanges,
524560
};
525561
}
526562

@@ -545,7 +581,7 @@ export function collectCodexRouteWarnings(params: {
545581
hit.runtime ? `; current runtime is "${hit.runtime}"` : ""
546582
}.`,
547583
),
548-
"- Run `openclaw doctor --fix`: it rewrites configured model refs and stale sessions to `openai/*` without changing explicit runtime policy.",
584+
"- Run `openclaw doctor --fix`: it rewrites configured model refs and stale sessions to `openai/*`, clears old whole-agent runtime pins, and keeps provider/model runtime policy.",
549585
].join("\n"),
550586
];
551587
}
@@ -578,6 +614,7 @@ export function maybeRepairCodexRoutes(params: {
578614
`Repaired Codex model routes:\n${repaired.changes
579615
.map((hit) => `- ${formatCodexRouteChange(hit)}`)
580616
.join("\n")}`,
617+
...repaired.runtimePinChanges,
581618
],
582619
};
583620
}

‎src/crestodian/assistant-backends.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function buildCodexAppServerPlannerConfig(workspaceDir: string): OpenClawConfig
7171
agents: {
7272
defaults: {
7373
workspace: workspaceDir,
74-
agentRuntime: { id: "codex" },
7574
model: { primary: `openai/${CRESTODIAN_CODEX_MODEL}` },
7675
},
7776
},

‎src/crestodian/assistant.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ describe("Crestodian assistant", () => {
159159
agents: {
160160
defaults: {
161161
workspace: "/tmp/workspace",
162-
agentRuntime: { id: "codex" },
163162
model: { primary: "openai/gpt-5.5" },
164163
},
165164
},
@@ -220,7 +219,6 @@ describe("Crestodian assistant", () => {
220219
expect(firstEmbeddedCall.config).toMatchObject({
221220
agents: {
222221
defaults: {
223-
agentRuntime: { id: "codex" },
224222
model: { primary: "openai/gpt-5.5" },
225223
},
226224
},

0 commit comments

Comments
 (0)