Skip to content

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

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
@greptile-apps

greptile-apps Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a premature timeout for systemEvent cron jobs that target the main session with wakeMode: "now". When such a job fires, executeJobCore awaits runHeartbeatOnce() synchronously — blocking the cron lane for the full duration of the agent turn. Previously, resolveCronJobTimeoutMs applied the generic DEFAULT_JOB_TIMEOUT_MS (10 min) to all non-agentTurn payloads, cutting off legitimately long-running turns (~16 min observed). The fix adds a narrow branch that returns AGENT_TURN_SAFETY_TIMEOUT_MS (60 min) exclusively for the main + wakeMode=now combination, matching the ceiling already applied to agentTurn jobs.

Key points:

  • The logic branch is correctly scoped: assertSupportedJobSpec enforces main → systemEvent and isolated → agentTurn, so the new condition (main + now) is mutually exclusive with the existing agentTurn check — no overlap is possible.
  • Two new tests cover the happy path (60-min ceiling for main+now) and the regression path (10-min default preserved for main+next-heartbeat).
  • The fallback when state.deps.runHeartbeatOnce is absent (the job completes instantly via requestHeartbeatNow) is safe with the more generous timeout — a fast job is never harmed by a ceiling it can't reach.
  • No mechanism exists to override the timeout for systemEvent jobs (since timeoutSeconds is an agentTurn-only field), but this is a pre-existing limitation not introduced by this PR.

Confidence Score: 5/5

  • This PR is safe to merge — the change is narrowly scoped, logically sound, and backed by two focused regression tests.
  • The root cause is clearly identified and verified against the actual execution path in timer.ts (lines 979–1020). The new condition is mutually exclusive with existing conditions due to the type-system invariant enforced by assertSupportedJobSpec. The change is a pure timeout policy adjustment with no side effects on scheduling, persistence, or delivery logic. Tests correctly cover both the new behavior and the preserved default.
  • No files require special attention.

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

@BryanTegomoh

BryanTegomoh commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor Author

CI failures (secrets/loader/memory tests) are pre-existing — also hitting unrelated PRs like #50743. Fix only touches src/cron/timer.ts + its test, all passing.

@BryanTegomoh

Copy link
Copy Markdown
Contributor Author

closing — 21 CI failures, likely stale against main. will resubmit with a fresh branch if needed.

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

Labels

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