Skip to content

fix(cron): remove /2 divisor from pre-execution watchdog formula - #83111

Closed
kip-claw wants to merge 1 commit into
openclaw:mainfrom
kip-claw:fix/cron-pre-execution-watchdog-formula
Closed

kip-claw wants to merge 1 commit into
openclaw:mainfrom
kip-claw:fix/cron-pre-execution-watchdog-formula

Conversation

@kip-claw

Copy link
Copy Markdown
Contributor

Problem

resolveCronAgentPreExecutionWatchdogMs() halves the job timeout when calculating the stale-progress watchdog ceiling:

Math.min(CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS, Math.floor(jobTimeoutMs / 2))

This means any cron job whose tool execution runs silently (no intermediate phase events) for more than half its configured timeoutSeconds is killed by the pre-execution watchdog — even though the job-level timeout has not been reached.

Root Cause

The /2 divisor was likely intended as a safety margin: if nothing has happened in half the job timeout, something is probably wrong. However, this assumption breaks for shell commands that legitimately run silently for their entire duration:

  • rclone sync (cloud backup transfers)
  • rsync (large file syncs)
  • pg_dump (database dumps)
  • Any long-running CLI tool invoked via the Codex shell

These tools produce a single tool_execution_started phase event, then silence until completion. The stale-progress watchdog interprets this silence as a stall and aborts.

Fix

Remove the /2 divisor:

Math.min(CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS, jobTimeoutMs)

The job-level timeout (startTimeout()) already provides the hard upper bound for total run duration. The stale-progress detector should catch genuinely stalled processes (where the cap constant applies), not penalize active-but-silent ones by halving their allowed time.

Production Evidence

Tested on OpenClaw 2026.5.12 (Raspberry Pi 5, ARM64):

Attempt Watchdog Cap Formula Job Timeout Result
1 180s jobTimeoutMs/2 600s ❌ aborted=true at 180s
2 600s jobTimeoutMs/2 600s ❌ aborted=true at 300s (600/2)
3 600s jobTimeoutMs/2 1800s ❌ aborted=true at 600s (cap)
4 1800s jobTimeoutMs 1800s ✅ aborted=false at 301s

The actual rclone sync only needs ~5 minutes, but attempts 2 and 3 show the /2 divisor killing it prematurely at exactly half the effective ceiling.

Related

Files Changed

  • src/cron/service/timer.ts — one-line change in resolveCronAgentPreExecutionWatchdogMs()

The pre-execution (stale-progress) watchdog uses
Math.min(CAP, Math.floor(jobTimeoutMs / 2)) to determine when to abort a
cron job that has not emitted a new execution phase event. The /2 divisor
means a job configured with timeoutSeconds: 600 is silently killed at 300s
if the tool execution produces no intermediate phase events.

This affects any shell command that runs silently for its entire duration:
rclone sync, rsync, pg_dump, large file transfers, etc. The Codex process
spawns the tool, the tool runs, and eventually returns output — but during
that window the stale-progress watchdog fires at half the job timeout.

Remove the /2 divisor so the pre-execution watchdog respects the full job
timeout. The job-level timeout already provides the hard upper bound; the
stale-progress detector should not impose a stricter one for silent but
active processes.

Before: rclone sync killed at 300s (half of 600s job timeout)
After:  rclone sync completes at ~301s (durationMs=300967 aborted=false)

Fixes openclaw#83110
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR changes resolveCronAgentPreExecutionWatchdogMs() to use the full job timeout instead of Math.floor(jobTimeoutMs / 2) when computing the pre-execution watchdog ceiling.

Reproducibility: yes. by source inspection: an isolated CLI-backed cron run can call onExecutionStarted() and then emit no execution-stage phase, leaving createCronAgentWatchdog() in waiting_for_execution until the pre-execution timer fires. I did not run a live cron job in this read-only review.

Real behavior proof
Needs stronger real behavior proof before merge: The PR body includes a summarized production table, but not inspectable after-fix logs, terminal output, or an artifact, and the successful case appears to depend on a watchdog cap not changed here; the contributor should add redacted real output or a linked artifact and update the PR body for re-review.

Next step before merge
Needs maintainer/contributor coordination because the PR is a plausible cron bug fix but incomplete against current main and overlaps the open watchdog configurability work.

Security
Cleared: The diff only changes an in-process cron timeout formula and does not add dependencies, scripts, permissions, secrets handling, or supply-chain surface.

Review findings

  • [P2] Fix the capped watchdog path too — src/cron/service/timer.ts:393
Review details

Best possible solution:

Land a focused cron fix that preserves fast pre-execution stall detection, clears the watchdog once CLI or embedded execution actually starts, and includes regression coverage for silent long-running commands.

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

Yes, by source inspection: an isolated CLI-backed cron run can call onExecutionStarted() and then emit no execution-stage phase, leaving createCronAgentWatchdog() in waiting_for_execution until the pre-execution timer fires. I did not run a live cron job in this read-only review.

Is this the best way to solve the issue?

No. Removing /2 may be one component, but current main still caps the reported 600s job at 60s, and the maintainable fix likely needs regression coverage plus either a CLI execution milestone or the linked cap/config change.

Full review comments:

  • [P2] Fix the capped watchdog path too — src/cron/service/timer.ts:393
    With CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS still set to 60,000ms, a timeoutSeconds: 600 cron job still computes a 60s pre-execution watchdog after this change, so the rclone/rsync repro in the PR body is not fixed on current main. Please include the cap/config or execution-phase change needed for that repro, or avoid closing the linked issue from this one-line patch.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • node scripts/run-vitest.mjs src/cron/service/timer.regression.test.ts

What I checked:

  • PR diff: The branch changes only the pre-execution watchdog formula from Math.floor(jobTimeoutMs / 2) to jobTimeoutMs. (src/cron/service/timer.ts:393, 2d10facf243a)
  • Current cap still dominates long repros: Current main keeps CRON_AGENT_PRE_EXECUTION_WATCHDOG_MS at 60,000ms, so a 600s job still computes a 60s pre-execution watchdog after this PR's one-line formula change. (src/cron/service/timer.ts:60, 395346fe57d5)
  • Watchdog state machine: The pre-execution timer fires only while state is waiting_for_execution; execution-stage phase events clear it and move the run to the outer job timeout. (src/cron/service/timer.ts:253, 395346fe57d5)
  • Execution milestones already clear embedded tool runs: tool_execution_started is classified as an execution milestone, and embedded tool start events emit that phase, so embedded silent tool execution should already clear the pre-execution watchdog. (src/cron/service/timer.ts:135, 395346fe57d5)
  • CLI path source repro: runCliAgent() calls onExecutionStarted() before preparing the CLI run, but the inspected CLI path only emits before_agent_reply/runtime_plugins phases around hooks, leaving a no-phase CLI run under the pre-execution watchdog. (src/agents/cli-runner.ts:167, 395346fe57d5)
  • Existing documented contract: Cron docs describe setup/pre-execution watchdogs as capped independently from long timeoutSeconds values so cold-start/auth/context failures surface quickly rather than waiting for the full job budget. Public docs: docs/automation/cron-jobs.md. (docs/automation/cron-jobs.md:57, 395346fe57d5)

Likely related people:

  • Rui Xu: git blame attributes the cron watchdog constants, phase map, timeout state machine, and formula to commit d41916b. (role: current implementation introducer; confidence: medium; commits: d41916b5c378; files: src/cron/service/timer.ts, src/cron/service/timer.regression.test.ts, docs/automation/cron-jobs.md)
  • Peter Steinberger: Peter committed the current cron watchdog implementation commit and appears in recent main history around adjacent runtime/test maintenance. (role: committer and recent adjacent contributor; confidence: medium; commits: d41916b5c378, 395346fe57d5; files: src/cron/service/timer.ts, src/cron/service/timer.regression.test.ts)

Remaining risk / open question:

  • The PR body's after-fix production evidence is a summarized table rather than inspectable terminal output, logs, or an artifact, and the successful row appears to rely on a watchdog cap outside this diff.
  • The related watchdog-config PR is still open/draft, so merging this one-line formula alone could close the linked issue before the reported long-running cron behavior is actually fixed on main.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 395346fe57d5.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:crash-loop Crash, hang, restart loop, or process-level availability failure. labels May 17, 2026
@kip-claw kip-claw closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:crash-loop Crash, hang, restart loop, or process-level availability failure. P2 Normal backlog priority with limited blast radius. size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant