Skip to content

fix(cron): extend main system event timeout - #86733

Closed
ferminquant wants to merge 4 commits into
openclaw:mainfrom
ferminquant:codex/50621-cron-systemevent-timeout
Closed

ferminquant wants to merge 4 commits into
openclaw:mainfrom
ferminquant:codex/50621-cron-systemevent-timeout

Conversation

@ferminquant

@ferminquant ferminquant commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Linked context

Closes #50621.

Summary

  • Extend the cron outer watchdog only for main-session systemEvent jobs with wakeMode: "now".
  • Preserve the existing 10-minute default for other systemEvent jobs, including wakeMode: "next-heartbeat".
  • Preserve existing agentTurn.timeoutSeconds behavior and the existing 60-minute safety ceiling for agent-turn jobs without an explicit timeout.

AI assistance disclosure

I used Codex to inspect the issue, related closed PRs, existing cron source, tests, and validation output, then to draft and verify this patch. I reviewed and understand the affected path: cron resolves the job timeout in src/cron/service/timeout-policy.ts, executeJobCoreWithTimeout applies that watchdog in src/cron/service/timer.ts, and main-session wake-now system events block while awaiting runHeartbeatOnce.

Real behavior proof

Behavior addressed: A blocking main-session cron systemEvent with wakeMode: "now" no longer uses the generic 10-minute job timeout while cron is waiting for runHeartbeatOnce; the next-heartbeat systemEvent path remains on the generic timeout.

Real environment tested: Local OpenClaw workspace on the rebased branch using the real cron timeout resolver and executeJobCoreWithTimeout path with isolated fake cron dependencies and no live credentials.

Exact steps or command run after this patch:

pnpm exec tsx .artifacts/issue-50621/runtime-proof.ts

Evidence after fix:

issue_50621_runtime_proof
target_job=sessionTarget:main payload:systemEvent wakeMode:now
default_system_event_timeout_ms=600000
agent_turn_safety_timeout_ms=3600000
resolved_target_timeout_ms=3600000
resolved_next_heartbeat_timeout_ms=600000
watchdog_delay_ms=3600000
settled_after_default_window=false
run_heartbeat_once_calls=1
final_status=ok
final_summary=long main-session task
proof_passed=true
proof_status=0

Observed result after fix: The target main-session wake-now systemEvent resolved to the 60-minute safety ceiling, did not settle after the old 10-minute window, called runHeartbeatOnce once, and completed successfully after the heartbeat promise resolved. A main-session next-heartbeat systemEvent still resolved to the 10-minute default.

What was not tested: A live provider/model run was not exercised; the proof isolates the cron watchdog path rather than spending credentials or model time.

Root Cause

resolveCronJobTimeoutMs treated every systemEvent job as generic cron work, so it returned DEFAULT_JOB_TIMEOUT_MS even when the main-session wake-now path synchronously awaited runHeartbeatOnce. That made a long but valid main-session heartbeat run fail around the generic cron watchdog window even though the underlying work was running in the main session.

Dependency contract / source proof

No external dependency behavior is changed. The relevant internal contracts are:

  • src/cron/types.ts: timeoutSeconds belongs to agentTurn payloads, not systemEvent payloads.
  • src/cron/service/jobs.ts: main-session jobs are systemEvent payloads; isolated/current/session target jobs are agentTurn payloads.
  • src/cron/service/timer.ts: executeJobCoreWithTimeout wraps the actual run using resolveCronJobTimeoutMs, and the blocking main-session path awaits runHeartbeatOnce only for wakeMode: "now".

Regression Test Plan

  • src/cron/service/timeout-policy.test.ts covers the exact policy split:
    • main systemEvent + wakeMode: "now" uses AGENT_TURN_SAFETY_TIMEOUT_MS.
    • main systemEvent + wakeMode: "next-heartbeat" keeps DEFAULT_JOB_TIMEOUT_MS.
    • existing agent-turn explicit/no-timeout behavior remains unchanged.
  • src/cron/service/timer.regression.test.ts covers the real wrapper path by keeping runHeartbeatOnce pending past the old default timeout and confirming the job does not complete early.

Security Impact

No credential, network, auth, or permission behavior changes. The patch only adjusts a local cron watchdog ceiling for one already-supported blocking runtime path.

Human Verification

I reviewed the affected cron timeout path, the main-session wake-now execution path, the related issue discussion, and closed reference PRs before accepting the final patch shape.

CODEOWNERS / owner review

The touched files are not matched by .github/CODEOWNERS. Nearby cron owner rules exist for src/cron/stagger.ts and src/cron/service/jobs.ts, but this patch does not touch either file.

Changelog

Contributor PR: no CHANGELOG.md entry added.

Review conversations

Reference issue/PR review checked before implementation:

Risks

  • Main-session wake-now cron jobs can occupy the cron run slot longer than before, up to the existing 60-minute safety ceiling.

Behavior tradeoffs

  • This keeps bounded failure behavior instead of removing the timeout or making all systemEvent jobs unbounded.
  • It gives the blocking path the same ceiling already used for agent-turn-style long work while leaving enqueue-only systemEvent modes short.

Scope boundaries

  • Does not change wakeMode: "next-heartbeat" behavior.
  • Does not add configuration.
  • Does not make all systemEvent jobs unbounded or long-running.
  • Does not change agentTurn.timeoutSeconds, including timeoutSeconds <= 0.
  • Does not change heartbeat scheduling, delivery, or provider/model timeout behavior.

Validation

node scripts/run-vitest.mjs src/cron/service/timeout-policy.test.ts src/cron/service/timer.regression.test.ts src/cron/service.runs-one-shot-main-job-disables-it.test.ts

Passed: 3 files, 58 tests.

OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree pnpm check:changed

Passed: changed lanes core, coreTests.

codex review --base origin/main

Passed: "The timeout policy change is narrowly scoped to main-session wake-now systemEvent jobs and is covered by focused policy and regression tests. I did not identify a correctness regression in the changed code."

@openclaw-barnacle openclaw-barnacle Bot added size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 26, 2026
@clawsweeper

clawsweeper Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 15, 2026, 3:09 AM ET / 07:09 UTC.

Summary
The PR changes cron timeout resolution so main-session wake-now systemEvent jobs use the existing one-hour agent-turn safety ceiling, while preserving the default timeout for other systemEvent paths and existing agentTurn timeout handling.

PR surface: Source -3, Tests +16, Other +2. Total +15 across 26 files.

Reproducibility: yes. Current main maps non-agent systemEvent jobs to DEFAULT_JOB_TIMEOUT_MS while the main-session wake-now path awaits runHeartbeatOnce under executeJobCoreWithTimeout.

Review metrics: 1 noteworthy metric.

  • Unrelated non-cron files: 24 modified outside the cron timeout-policy surface. These formatting/import-order edits broaden conflict and ownership review without contributing to the scheduler fix.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Remove unrelated non-cron formatting/import-order edits.
  • Restore focused executeJobCoreWithTimeout regression coverage.
  • Rebase or rebuild so GitHub no longer reports the PR as dirty/conflicting.

Risk before merge

  • [P1] The intended behavior can keep a cron run slot occupied for up to the existing one-hour ceiling when main-session wake-now work blocks.
  • [P1] GitHub currently reports this PR as DIRTY/CONFLICTING, so it cannot land as-is.
  • [P2] The live net diff modifies 24 files outside the cron timeout-policy surface, widening conflict and owner-review scope for a narrow scheduler fix.
  • [P1] The current live file list does not include timer.regression.test.ts, so the wrapper path that times out executeJobCoreWithTimeout is not locked by the branch.

Maintainer options:

  1. Rebuild as a cron-only patch (recommended)
    Remove unrelated formatting/import-order churn, restore executeJobCoreWithTimeout regression coverage, and keep the intended one-hour ceiling limited to main-session wake-now systemEvent jobs.
  2. Accept the longer slot occupancy
    After cleanup, maintainers can intentionally accept that wake-now main-session cron work may occupy a cron run slot for up to the existing one-hour safety ceiling.
  3. Keep the shorter watchdog
    Pause or close this PR if maintainers prefer the scheduler to report timeout after the existing generic window even when the main-session heartbeat is still doing work.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove every change outside the focused cron timeout policy and valuable cron regression coverage; preserve the main-session wake-now one-hour behavior, preserve next-heartbeat and agent-turn semantics, and run the narrow cron validation.

Next step before merge

  • [P2] A repair worker can mechanically rebuild the branch as a narrow cron-only patch and restore wrapper coverage; maintainers still need to consciously accept the availability tradeoff before merge.

Security
Cleared: The intended cron timeout change has no dependency, workflow, credential, permission, network, or package-supply-chain change; the extra touched security-sensitive files are formatting-only diffs.

Review findings

  • [P2] Remove unrelated non-cron formatting changes — extensions/amazon-bedrock-mantle/mantle-anthropic.runtime.test.ts:169-176
  • [P2] Restore wrapper-path regression coverage — src/cron/service/timeout-policy.test.ts:43
Review details

Best possible solution:

Land a clean cron-only version that extends only the blocking main-session wake-now systemEvent timeout, preserves all other timeout behavior, restores wrapper-path regression coverage, and records maintainer acceptance of the longer cron slot occupancy tradeoff.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main maps non-agent systemEvent jobs to DEFAULT_JOB_TIMEOUT_MS while the main-session wake-now path awaits runHeartbeatOnce under executeJobCoreWithTimeout.

Is this the best way to solve the issue?

Yes, conditionally. Reusing the existing one-hour safety ceiling only for the blocking wake-now path is narrower than removing the watchdog or adding configuration, but the submitted branch is not the best merge shape until unrelated churn is removed and wrapper coverage is restored.

Full review comments:

  • [P2] Remove unrelated non-cron formatting changes — extensions/amazon-bedrock-mantle/mantle-anthropic.runtime.test.ts:169-176
    Revert the formatting/import-order edits outside the cron timeout surface. They do not contribute to the stated fix, broaden conflict and ownership exposure across plugins, agents, scripts, and UI, and make the small scheduler change harder to audit safely.
    Confidence: 0.99
  • [P2] Restore wrapper-path regression coverage — src/cron/service/timeout-policy.test.ts:43
    The current live file list only adds resolver-level timeout-policy tests, while the reported failure happens through executeJobCoreWithTimeout awaiting runHeartbeatOnce. Add focused timer regression coverage for that wrapper path so the branch proves the runtime behavior it changes.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against efbefceb0e2e.

Label changes

Label justifications:

  • P2: This is a real cron reliability bug with clear source evidence and limited blast radius, not a security emergency or core outage.
  • merge-risk: 🚨 availability: The changed timeout can keep a cron run slot occupied for up to one hour when main-session wake-now heartbeat work blocks.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes after-fix live output from a local OpenClaw workspace exercising the real timeout resolver and executeJobCoreWithTimeout seam with redaction-safe fake cron dependencies.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix live output from a local OpenClaw workspace exercising the real timeout resolver and executeJobCoreWithTimeout seam with redaction-safe fake cron dependencies.
Evidence reviewed

PR surface:

Source -3, Tests +16, Other +2. Total +15 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 15 43 46 -3
Tests 10 47 31 +16
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 3 +2
Total 26 95 80 +15

Acceptance criteria:

  • [P2] node scripts/run-vitest.mjs src/cron/service/timeout-policy.test.ts src/cron/service/timer.regression.test.ts src/cron/service.runs-one-shot-main-job-disables-it.test.ts.
  • [P1] git diff --check origin/main...HEAD.
  • [P1] gh pr view 86733 --repo openclaw/openclaw --json mergeable,mergeStateStatus,files.

What I checked:

  • Current-main timeout policy still uses the generic systemEvent timeout: Current main returns AGENT_TURN_SAFETY_TIMEOUT_MS only for agentTurn jobs; systemEvent jobs still fall through to DEFAULT_JOB_TIMEOUT_MS. (src/cron/service/timeout-policy.ts:26, efbefceb0e2e)
  • Current-main wrapper applies that timeout before running the job core: executeJobCoreWithTimeout resolves the job timeout before starting executeJobCore, so the systemEvent default is applied to the main-session wake-now path. (src/cron/service/timer.ts:195, efbefceb0e2e)
  • Current-main wake-now path blocks on runHeartbeatOnce: For main-session wakeMode now jobs, executeMainSessionCronJob awaits runHeartbeatOnce, making the outer cron watchdog observable for long-running main-session work. (src/cron/service/timer.ts:1955, efbefceb0e2e)
  • Latest shipped release has the same timeout policy: The latest release v2026.6.6 still returns the one-hour safety ceiling only for agentTurn jobs and the default timeout for systemEvent jobs. (src/cron/service/timeout-policy.ts:26, 8c802aa68351)
  • PR head implements the intended resolver branch: The PR head returns AGENT_TURN_SAFETY_TIMEOUT_MS for systemEvent jobs only when sessionTarget is main and wakeMode is now. (src/cron/service/timeout-policy.ts:29, d0131f293e7f)
  • Live PR state remains dirty and broad: GitHub reports the PR as DIRTY/CONFLICTING with 26 changed files; the live file list contains 24 files outside the cron timeout-policy surface. (d0131f293e7f)

Likely related people:

  • steipete: Recent commit history shows repeated cron timeout/timer work, including explicit timeout capping and timer helper refactors; the contributor also explicitly routed the scheduler tradeoff to him for review. (role: recent area contributor and product-review route; confidence: high; commits: 42b320ad654f, 9d31cbbd6ad8, 77f09f25751a; files: src/cron/service/timeout-policy.ts, src/cron/service/timer.ts, src/cron/service/timer.regression.test.ts)
  • vincentkoc: Current main is at his cron commit that touched timer and timer regression coverage, and prior cron concurrency work appears in the same timer history. (role: recent adjacent cron maintainer; confidence: medium; commits: efbefceb0e2e, e844d1d6e56b; files: src/cron/service/timer.ts, src/cron/service/timer.regression.test.ts)
  • shakkernerd: Recent timer.regression.test and cron cancellation commits changed the same wrapper/test surface that this PR needs to cover. (role: adjacent regression-test owner; confidence: medium; commits: 9082233a433c, 93313c95a503, 5b76436c452a; files: src/cron/service/timer.ts, src/cron/service/timer.regression.test.ts)
  • ferminquant: The PR author also appears in merged cron timer history for task progress summaries, so they are relevant beyond only opening this PR. (role: current fix author and prior cron contributor; confidence: medium; commits: 92afd8ba25c3, 9b7b4eeefdaf, d0131f293e7f; files: src/cron/service/timer.ts, src/cron/service/timeout-policy.ts, src/cron/service/timeout-policy.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels May 26, 2026
@clawsweeper

clawsweeper Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Neon Shellbean

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: watches the merge queue.
Image traits: location green-check meadow; accessory little merge flag; palette amber, ink, and glacier blue; mood sparkly; pose leaning over a miniature review desk; shell starlit enamel shell; lighting cool dashboard glow; background gentle dashboard dots.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Neon Shellbean in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@ferminquant
ferminquant marked this pull request as ready for review May 26, 2026 02:55
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels May 26, 2026
@BingqingLyu

This comment was marked as spam.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels May 29, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels May 29, 2026
@ferminquant

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 29, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@ferminquant

Copy link
Copy Markdown
Contributor Author

@steipete ready for review when you have a cycle. Routing to you since you're the BDFL; please reassign to a sub-owner if anyone else is closer to the area.

@ferminquant
ferminquant requested a review from a team as a code owner June 12, 2026 17:42
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web app: web-ui App: web-ui extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling labels Jun 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 12, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 12, 2026
@ferminquant

Copy link
Copy Markdown
Contributor Author

Closing this PR rather than letting it sit indefinitely.

@ferminquant
ferminquant deleted the codex/50621-cron-systemevent-timeout branch June 15, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web cli CLI command changes commands Command implementations extensions: memory-core Extension: memory-core merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

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

3 participants