Skip to content

Commit b28a254

Browse files
committed
fix(cron): increase watchdog timeouts and make them configurable
The hardcoded 60-second setup and pre-execution watchdog timeouts are too aggressive for environments where the Codex app-server startup takes longer (OAuth resolution, sandbox provisioning, model prewarm on modest hardware). Changes: - Increase default CRON_AGENT_SETUP_WATCHDOG_MS from 60s to 180s - Increase default CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS from 60s to 180s - Make both configurable via cronConfig.setupWatchdogMs and cronConfig.preExecutionWatchdogMs This fixes all isolated-session cron jobs failing with: 'cron: isolated agent setup timed out before runner start' or silently aborting at 60s before the first model call. Tested on OpenClaw 2026.5.12 running on Raspberry Pi 5 where Codex app-server startup consistently takes 70-90s.
1 parent 9e03865 commit b28a254

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎src/config/types.cron.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ export type CronConfig = {
5858
failureAlert?: CronFailureAlertConfig;
5959
/** Default destination for failure notifications across all cron jobs. */
6060
failureDestination?: CronFailureDestinationConfig;
61+
/**
62+
* Max milliseconds to wait for the agent runner to start before aborting
63+
* an isolated cron job. Default: 180_000 (3 minutes).
64+
*/
65+
setupWatchdogMs?: number;
66+
/**
67+
* Max milliseconds to wait for the execution phase (first model call) after
68+
* the runner starts. Capped at `jobTimeoutMs / 2`. Default: 180_000 (3 minutes).
69+
*/
70+
preExecutionWatchdogMs?: number;
6171
};

‎src/cron/service/timer.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export { DEFAULT_JOB_TIMEOUT_MS } from "./timeout-policy.js";
5656

5757
const MAX_TIMER_DELAY_MS = 60_000;
5858
const CRON_TIMEOUT_CLEANUP_GUARD_MS = 20_000;
59-
const CRON_AGENT_SETUP_WATCHDOG_MS = 60_000;
60-
const CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS = 60_000;
59+
const DEFAULT_CRON_AGENT_SETUP_WATCHDOG_MS = 180_000;
60+
const DEFAULT_CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS = 180_000;
6161
const CRON_AGENT_PRE_EXECUTION_MIN_WATCHDOG_MS = 1_000;
6262

6363
/**
@@ -176,6 +176,7 @@ export async function executeJobCoreWithTimeout(
176176
deferUntilRunner: deferTimeoutUntilExecutionStart,
177177
jobTimeoutMs,
178178
triggerTimeout,
179+
cronConfig: state.deps.cronConfig,
179180
});
180181
const corePromise = executeJobCore(state, job, runAbortController.signal, {
181182
onExecutionStarted: deferTimeoutUntilExecutionStart ? watchdog.noteRunnerStarted : undefined,
@@ -214,6 +215,7 @@ function createCronAgentWatchdog(params: {
214215
deferUntilRunner: boolean;
215216
jobTimeoutMs: number;
216217
triggerTimeout: (reason: string) => void;
218+
cronConfig?: CronConfig;
217219
}): CronAgentWatchdog {
218220
let state: CronAgentWatchdogState = params.deferUntilRunner ? "waiting_for_runner" : "executing";
219221
let timeoutId: NodeJS.Timeout | undefined;
@@ -258,7 +260,7 @@ function createCronAgentWatchdog(params: {
258260
if (state === "waiting_for_execution") {
259261
setTimedOut(preExecutionTimeoutErrorMessage(activeExecution));
260262
}
261-
}, resolveCronAgentPreExecutionWatchdogMs(params.jobTimeoutMs));
263+
}, resolveCronAgentPreExecutionWatchdogMs(params.jobTimeoutMs, params.cronConfig));
262264
};
263265
const noteExecutionProgress = (info?: CronAgentExecutionStarted) => {
264266
if (!info) {
@@ -289,7 +291,7 @@ function createCronAgentWatchdog(params: {
289291
if (state === "waiting_for_runner") {
290292
setTimedOut(setupTimeoutErrorMessage(activeExecution));
291293
}
292-
}, CRON_AGENT_SETUP_WATCHDOG_MS);
294+
}, resolveCronAgentSetupWatchdogMs(params.cronConfig));
293295
return;
294296
}
295297
startTimeout();
@@ -387,10 +389,23 @@ function formatCronAgentExecutionPhase(execution?: CronAgentExecutionStarted): s
387389
return formatEmbeddedAgentExecutionPhase(execution?.phase);
388390
}
389391

390-
function resolveCronAgentPreExecutionWatchdogMs(jobTimeoutMs: number): number {
392+
function resolveCronAgentSetupWatchdogMs(cronConfig?: CronConfig): number {
393+
const raw = cronConfig?.setupWatchdogMs;
394+
if (typeof raw === "number" && Number.isFinite(raw) && raw > 0) {
395+
return Math.floor(raw);
396+
}
397+
return DEFAULT_CRON_AGENT_SETUP_WATCHDOG_MS;
398+
}
399+
400+
function resolveCronAgentPreExecutionWatchdogMs(jobTimeoutMs: number, cronConfig?: CronConfig): number {
401+
const cap = typeof cronConfig?.preExecutionWatchdogMs === "number"
402+
&& Number.isFinite(cronConfig.preExecutionWatchdogMs)
403+
&& cronConfig.preExecutionWatchdogMs > 0
404+
? Math.floor(cronConfig.preExecutionWatchdogMs)
405+
: DEFAULT_CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS;
391406
return Math.max(
392407
CRON_AGENT_PRE_EXECUTION_MIN_WATCHDOG_MS,
393-
Math.min(CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS, Math.floor(jobTimeoutMs / 2)),
408+
Math.min(cap, Math.floor(jobTimeoutMs / 2)),
394409
);
395410
}
396411

0 commit comments

Comments
 (0)