Skip to content

fix(cron): per-attempt AbortControllers and deferred execution timeout#392

Open
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-42482-fix-cron-abort-timeout-42464
Open

fix(cron): per-attempt AbortControllers and deferred execution timeout#392
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-42482-fix-cron-abort-timeout-42464

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Summary

Fix two root causes of isolated cron agentTurn jobs hanging until timeout (openclaw#42464):

  • Per-attempt AbortControllers (Cron job timeout aborts entire model fallback chain via shared AbortController openclaw/openclaw#37505): The cron timeout fires a shared AbortController signal that propagates to all subsequent model fallback attempts, killing them instantly (~100ms) without making a network request. Each fallback attempt in runCronIsolatedAgentTurn now gets its own AbortController linked to the parent signal, so when one attempt is aborted the next attempt starts with a fresh (non-aborted) controller.

  • Deferred execution timeout (bug(cron): job timeout includes cron-lane queue wait time openclaw/openclaw#41783): The timeout timer in executeJobCoreWithTimeout started immediately via Promise.race, but the job may wait in the lane queue (inside runEmbeddedPiAgent) before doing real work. executeJobCore now accepts an onExecutionStart callback and calls it right before runIsolatedAgentJob, deferring the timeout clock until actual execution begins. A 2× safety backstop prevents indefinite hangs if the callback is never called.

Files changed

  • src/cron/isolated-agent/run.ts — per-attempt AbortController in the runWithModelFallback run callback
  • src/cron/service/timer.ts — deferred timeout arming via onExecutionStart callback
  • src/cron/service.cron-timeout-abort.test.ts — 5 new tests covering both fixes

Test plan

  • All 502 existing cron tests pass (64 test files)
  • All 60 model-fallback tests pass
  • 5 new tests covering:
    • Deferred timeout does not fire during queue wait
    • executeJobCore calls onExecutionStart before running isolated jobs
    • executeJobCore calls onExecutionStart for main session jobs
    • Abort signal fires correctly on timeout
    • executeJobCoreWithTimeout still times out correctly with deferred start

Closes openclaw#37505
Closes openclaw#41783
Fixes openclaw#42632
Refs openclaw#42464 openclaw#40237

Related

Fix two root causes of cron agentTurn jobs hanging until timeout:

1. Shared AbortController kills fallback chain (openclaw#37505): When the cron
   timeout fires, it aborts a shared signal that propagates to all
   subsequent model fallback attempts, killing them instantly (~100ms).
   Now each fallback attempt in runCronIsolatedAgentTurn gets its own
   AbortController linked to the parent signal, so new attempts start
   with a fresh (non-aborted) controller.

2. Queue wait consumes execution timeout (openclaw#41783): The timeout timer
   started immediately in executeJobCoreWithTimeout, but the job may
   wait in the lane queue (inside runEmbeddedPiAgent) before doing real
   work. Now executeJobCore accepts an onExecutionStart callback and
   calls it right before runIsolatedAgentJob, deferring the timeout
   clock until actual execution begins. A 2x safety backstop prevents
   indefinite hangs if the callback is never called.

Closes openclaw#37505
Closes openclaw#41783
Refs openclaw#42464 openclaw#40237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants