Skip to content

Commit 6aafdf1

Browse files
authored
fix(cron): repair bad persisted model sentinels (#78641)
* fix(cron): repair bad persisted model sentinels * test(cron): relax model preservation assertion
1 parent 5572ee1 commit 6aafdf1

8 files changed

Lines changed: 137 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Docs: https://docs.openclaw.ai
122122

123123
### Fixes
124124

125+
- Cron/doctor: repair persisted cron jobs whose `payload.model` was stored as `"default"`, `"null"`, blank, or JSON `null` by removing the bad override during `openclaw doctor --fix` while keeping cron runtime model validation strict. Fixes #78549. Thanks @bizzle12368239.
125126
- Doctor/OpenAI Codex: revert the 2026.5.5 `doctor --fix` repair that rewrote valid `openai-codex/*` ChatGPT/Codex OAuth routes to `openai/*`, which could break OAuth-only GPT-5.5 setups or accidentally move users onto the OpenAI API-key route. If 2026.5.5 already changed your default model, run `openclaw models set openai-codex/gpt-5.5 && openclaw config validate` to switch the default agent back to the Codex OAuth PI route. Fixes #78407.
126127
- Discord/groups: instruct group-chat agents to stay silent when a message is addressed to someone else, replying only when invited or correcting key facts. (#78615)
127128
- Discord/groups: tell Discord-channel agents to wrap bare URLs as `<https://example.com>` so link previews do not expand into uninvited embeds. (#78614)

‎docs/automation/cron-jobs.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ This fires ~5–6 times per month instead of 0–1 times per month. OpenClaw use
134134

135135
`--model` uses the selected allowed model as that job's primary model. It is not the same as a chat-session `/model` override: configured fallback chains still apply when the job primary fails. If the requested model is not allowed or cannot be resolved, cron fails the run with an explicit validation error instead of silently falling back to the job's agent/default model selection.
136136

137+
If older or hand-edited `jobs.json` entries store `payload.model` as `"default"`, `"null"`, a blank string, or JSON `null`, run `openclaw doctor --fix`. Doctor removes those invalid persisted override sentinels; runtime does not support them as fallback aliases. Omit the model field to use the normal agent/default model selection.
138+
137139
Cron jobs can also carry payload-level `fallbacks`. When present, that list replaces the configured fallback chain for the job. Use `fallbacks: []` in the job payload/API when you want a strict cron run that tries only the selected model. If a job has `--model` but neither payload nor configured fallbacks, OpenClaw passes an explicit empty fallback override so the agent primary is not appended as a hidden extra retry target.
138140

139141
Model-selection precedence for isolated jobs is:

‎docs/cli/cron.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Retention and pruning are controlled in config:
157157

158158
<Note>
159159
If you have cron jobs from before the current delivery and store format, run `openclaw doctor --fix`. Doctor normalizes legacy cron fields (`jobId`, `schedule.cron`, top-level delivery fields including legacy `threadId`, payload `provider` delivery aliases) and migrates simple `notify: true` webhook fallback jobs to explicit webhook delivery when `cron.webhook` is configured.
160+
161+
Doctor also removes persisted cron `payload.model` sentinels such as `"default"`, `"null"`, blank strings, and JSON `null`. Cron runtime still treats any non-empty `payload.model` string as an explicit model override and validates it against `agents.defaults.models`; omit the model key when a job should use the agent/default model selection.
160162
</Note>
161163

162164
## Common edits

‎docs/gateway/doctor.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ That stages grounded durable candidates into the short-term dreaming store while
309309
- top-level payload fields (`message`, `model`, `thinking`, ...) → `payload`
310310
- top-level delivery fields (`deliver`, `channel`, `to`, `provider`, ...) → `delivery`
311311
- payload `provider` delivery aliases → explicit `delivery.channel`
312+
- invalid persisted cron `payload.model` sentinels (`"default"`, `"null"`, blank strings, JSON `null`) → removed model override
312313
- simple legacy `notify: true` webhook fallback jobs → explicit `delivery.mode="webhook"` with `delivery.to=cron.webhook`
313314

314315
Doctor only auto-migrates `notify: true` jobs when it can do so without changing behavior. If a job combines legacy notify fallback with an existing non-webhook delivery mode, doctor warns and leaves that job for manual review.

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

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

109+
it("removes invalid persisted cron model inheritance sentinels", () => {
110+
const sentinelValues: unknown[] = ["default", " null ", "", null];
111+
const jobs = sentinelValues.map((model, index) =>
112+
makeLegacyJob({
113+
id: `bad-model-${index}`,
114+
sessionTarget: "isolated",
115+
payload: {
116+
kind: "agentTurn",
117+
message: "ping",
118+
model,
119+
},
120+
delivery: { mode: "announce" },
121+
}),
122+
);
123+
124+
const result = normalizeStoredCronJobs(jobs);
125+
126+
expect(result.mutated).toBe(true);
127+
expect(result.issues.invalidCronPayloadModel).toBe(4);
128+
for (const job of jobs) {
129+
const payload = job.payload as Record<string, unknown>;
130+
expect(payload.model).toBeUndefined();
131+
}
132+
});
133+
134+
it("preserves real persisted cron model refs", () => {
135+
const { job, result } = normalizeOneJob(
136+
makeLegacyJob({
137+
id: "real-model",
138+
sessionTarget: "isolated",
139+
payload: {
140+
kind: "agentTurn",
141+
message: "ping",
142+
model: "minimax-portal/MiniMax-M2.7",
143+
},
144+
delivery: { mode: "announce" },
145+
}),
146+
);
147+
148+
expect(result.issues.invalidCronPayloadModel).toBeUndefined();
149+
expect((job.payload as Record<string, unknown>).model).toBe("minimax-portal/MiniMax-M2.7");
150+
});
151+
109152
it("does not report legacyPayloadKind for already-normalized payload kinds", () => {
110153
const jobs = [
111154
{

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type CronStoreIssueKey =
2020
| "legacyScheduleCron"
2121
| "legacyPayloadKind"
2222
| "legacyPayloadProvider"
23+
| "invalidCronPayloadModel"
2324
| "legacyTopLevelPayloadFields"
2425
| "legacyTopLevelDeliveryFields"
2526
| "legacyDeliveryMode";
@@ -226,6 +227,17 @@ function stripLegacyTopLevelFields(raw: Record<string, unknown>) {
226227
}
227228
}
228229

230+
function isInvalidCronPayloadModelSentinel(value: unknown): boolean {
231+
if (value === null) {
232+
return true;
233+
}
234+
if (typeof value !== "string") {
235+
return false;
236+
}
237+
const normalized = normalizeLowercaseStringOrEmpty(value);
238+
return normalized === "" || normalized === "default" || normalized === "null";
239+
}
240+
229241
export function normalizeStoredCronJobs(
230242
jobs: Array<Record<string, unknown>>,
231243
): NormalizeCronStoreJobsResult {
@@ -379,6 +391,15 @@ export function normalizeStoredCronJobs(
379391
}
380392

381393
if (payloadRecord) {
394+
if (
395+
payloadRecord.kind === "agentTurn" &&
396+
"model" in payloadRecord &&
397+
isInvalidCronPayloadModelSentinel(payloadRecord.model)
398+
) {
399+
delete payloadRecord.model;
400+
mutated = true;
401+
trackIssue("invalidCronPayloadModel");
402+
}
382403
const hadLegacyPayloadProvider = Boolean(normalizeOptionalString(payloadRecord.provider));
383404
if (migrateLegacyCronPayload(payloadRecord)) {
384405
mutated = true;

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,67 @@ describe("maybeRepairLegacyCronStore", () => {
159159
);
160160
});
161161

162+
it("repairs invalid persisted cron payload model sentinels", async () => {
163+
const storePath = await makeTempStorePath();
164+
await writeCronStore(storePath, [
165+
{
166+
id: "bad-model-default",
167+
name: "Bad model default",
168+
enabled: true,
169+
createdAtMs: Date.parse("2026-02-01T00:00:00.000Z"),
170+
updatedAtMs: Date.parse("2026-02-02T00:00:00.000Z"),
171+
schedule: { kind: "every", everyMs: 60_000, anchorMs: 1 },
172+
sessionTarget: "isolated",
173+
wakeMode: "now",
174+
payload: {
175+
kind: "agentTurn",
176+
message: "Status",
177+
model: "default",
178+
},
179+
delivery: { mode: "announce" },
180+
state: {},
181+
},
182+
{
183+
id: "bad-model-null",
184+
name: "Bad model null",
185+
enabled: true,
186+
createdAtMs: Date.parse("2026-02-01T00:00:00.000Z"),
187+
updatedAtMs: Date.parse("2026-02-02T00:00:00.000Z"),
188+
schedule: { kind: "every", everyMs: 60_000, anchorMs: 1 },
189+
sessionTarget: "isolated",
190+
wakeMode: "now",
191+
payload: {
192+
kind: "agentTurn",
193+
message: "Status",
194+
model: "null",
195+
},
196+
delivery: { mode: "announce" },
197+
state: {},
198+
},
199+
]);
200+
201+
await maybeRepairLegacyCronStore({
202+
cfg: createCronConfig(storePath),
203+
options: {},
204+
prompter: makePrompter(true),
205+
});
206+
207+
const persisted = JSON.parse(await fs.readFile(storePath, "utf-8")) as {
208+
jobs: Array<Record<string, unknown>>;
209+
};
210+
for (const job of persisted.jobs) {
211+
expect((job.payload as Record<string, unknown>).model).toBeUndefined();
212+
}
213+
expect(noteMock).toHaveBeenCalledWith(
214+
expect.stringContaining("2 jobs store an invalid cron payload model inheritance sentinel"),
215+
"Cron",
216+
);
217+
expect(noteMock).toHaveBeenCalledWith(
218+
expect.stringContaining("Cron store normalized"),
219+
"Doctor changes",
220+
);
221+
});
222+
162223
it("warns instead of replacing announce delivery for notify fallback jobs", async () => {
163224
const storePath = await makeTempStorePath();
164225
await fs.mkdir(path.dirname(storePath), { recursive: true });

‎src/commands/doctor-cron.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ function formatLegacyIssuePreview(issues: Partial<Record<string, number>>): stri
5959
`- ${pluralize(issues.legacyPayloadProvider, "job")} still uses payload \`provider\` as a delivery alias`,
6060
);
6161
}
62+
if (issues.invalidCronPayloadModel) {
63+
const verb = issues.invalidCronPayloadModel === 1 ? "stores" : "store";
64+
lines.push(
65+
`- ${pluralize(issues.invalidCronPayloadModel, "job")} ${verb} an invalid cron payload model inheritance sentinel`,
66+
);
67+
}
6268
if (issues.legacyTopLevelPayloadFields) {
6369
lines.push(
6470
`- ${pluralize(issues.legacyTopLevelPayloadFields, "job")} still uses top-level payload fields`,

0 commit comments

Comments
 (0)