Skip to content

fix(cron): use agent-turn timeout for main systemEvent jobs with wakeMode=now - #50670

Closed
BryanTegomoh wants to merge 1 commit into
openclaw:mainfrom
BryanTegomoh:fix/cron-systemevent-wake-now-timeout
Closed

BryanTegomoh wants to merge 1 commit into
openclaw:mainfrom
BryanTegomoh:fix/cron-systemevent-wake-now-timeout

Conversation

@BryanTegomoh

Copy link
Copy Markdown
Contributor

Problem

When a systemEvent cron job targets the main session with wakeMode: "now", the scheduler calls runHeartbeatOnce() and blocks while the agent turn runs. The outer timeout applied by resolveCronJobTimeoutMs() is DEFAULT_JOB_TIMEOUT_MS (10 minutes) for all non-agentTurn payloads.

Long-running agent turns (transcriptions, web searches, multi-step tasks) get killed with "cron: job execution timed out" even though the agent is actively working. The reporter saw ~960s (16 min) runs getting cut.

The wakeMode: "next-heartbeat" path is not affected because it calls requestHeartbeatNow() and returns immediately.

Root cause

resolveCronJobTimeoutMs() treats all systemEvent jobs the same regardless of whether the scheduler actually blocks on the agent turn.

Fix

Apply AGENT_TURN_SAFETY_TIMEOUT_MS (60 min) when job.sessionTarget === "main" && job.wakeMode === "now", matching the ceiling already used for agentTurn jobs. All other systemEvent paths keep the 10-min default.

2 files changed, 1 logic branch + 2 tests added.

Fixes #50621

…Mode=now

When a systemEvent cron job targets the main session with wakeMode=now,
the scheduler blocks while runHeartbeatOnce() executes the agent turn.
The generic 10-minute timeout kills long-running turns even though the
agent is actively working.

Apply AGENT_TURN_SAFETY_TIMEOUT_MS (60 min) for this specific path,
matching the ceiling already used for agentTurn jobs.

Fixes openclaw#50621
@openclaw-barnacle openclaw-barnacle Bot added size: XS r: too-many-prs Auto-close: author has more than twenty active PRs. labels Mar 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@greptile-apps

greptile-apps Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a real timeout bug where systemEvent cron jobs targeting the main session with wakeMode: "now" were being killed by the 10-minute generic safety cap, even though they legitimately block while an agent turn runs. The fix surgically adds a single new branch in resolveCronJobTimeoutMs to apply the 60-minute AGENT_TURN_SAFETY_TIMEOUT_MS ceiling for this specific combination, matching the existing treatment of agentTurn jobs.

Key observations:

  • The fix correctly mirrors the blocking code path in executeJobCore (timer.ts line 979–1021) where runHeartbeatOnce() is awaited synchronously only when sessionTarget === "main" && wakeMode === "now".
  • The ordering of the new if block is correct — the agentTurn guard returns first, so the new branch is only ever reached by systemEvent payloads.
  • systemEvent payloads have no timeoutSeconds field, so configuredTimeoutMs is always undefined for them. This means there is currently no way for users to override the new 60-minute ceiling for systemEvent/main/now jobs — but since the CronPayload type itself doesn't allow timeoutSeconds on systemEvent, this is expected and not a gap.
  • One minor untested edge case: a systemEvent job with sessionTarget: "isolated" and wakeMode: "now" (unusual; the execution path in timer.ts would skip it with an error at line 1043–1044) — no impact on correctness.
  • Two new tests cover the happy path and its inverse clearly and correctly.

Confidence Score: 5/5

  • This PR is safe to merge — the change is minimal, targeted, and directly addresses a confirmed production timeout regression.
  • The two-file change is a precise fix: one new conditional branch in the timeout-resolution function and two tests that cover both the new path and its inverse. The blocking behavior in executeJobCore (timer.ts) is confirmed in the existing code and aligns exactly with the condition being guarded. No existing tests are modified, and no other code paths are affected.
  • No files require special attention.

Last reviewed commit: "fix(cron): use agent..."

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4616532917

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +28 to +29
if (job.sessionTarget === "main" && job.wakeMode === "now") {
return AGENT_TURN_SAFETY_TIMEOUT_MS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't raise all default main-session wakes to a 60-minute stall window

Because wakeMode defaults to "now" for cron jobs (src/cron/normalize.ts:414-416), this branch silently changes most existing main-session systemEvent jobs from the 10-minute safety cap to a 60-minute cap. When runHeartbeatOnce() wedges on a provider/network stall, executeJobCoreWithTimeout() is the only thing that frees the worker (src/cron/service/timer.ts:53-73), and cron still runs with concurrency 1 by default (src/cron/service/timer.ts:81-85). In that scenario one stuck reminder now blocks unrelated scheduled jobs for up to 50 extra minutes, so the fix trades one false-timeout bug for a much larger scheduler-starvation window.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r: too-many-prs Auto-close: author has more than twenty active PRs. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron systemEvent job times out after ~960s even though agent runs in main session

1 participant