Repository navigation
fix(cron): keep timeout retries behind the run-receipt settlement fence - #137274
xydigitLybnnnn wants to merge 17 commits into
Conversation
…law#137215) This fixes an issue where cron would retry a timed-out job even though the original execution was still running. This could cause duplicate non-idempotent work when the abort signal is ignored by the underlying execution. Changes: - Add `jobId` parameter to `resolveTransientCronRetryDecision` to check for active executions - Block retry when `isCronJobActive(jobId)` returns true, returning "active execution in progress" - Add detailed logging in timeout cleanup to help diagnose abort-ignoring executions - Log timeout events with execution metadata (phase, provider, model) The fix is defensive: when a timeout fires but the original execution continues, the retry decision now checks if that job is still marked as active and declines to schedule a retry. This prevents overlapping executions that could duplicate webhook deliveries, API calls, or other side effects. Test plan: - Unit test for `resolveTransientCronRetryDecision` with mocked active job - Existing `run-receipt-settlement.test.ts` proves the timeout fence works 🤖 AI-assisted: This PR was developed with AI assistance (co-mind) Closes openclaw#137215
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Dependency graph guard clearedThis PR no longer has dependency changes awaiting review. A future dependency graph change from an external contributor requires a maintainer's
|
|
Codex review: needs maintainer review before merge. What this changesThis PR adds contextual timeout logging and tests that preserve retries behind the existing run-receipt settlement fence. Example: A one-shot agent job exceeds its 1-second timeout while cleanup rejects.
Review scores
ProductKind: Maintenance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR open for its useful timeout diagnostics and schedule-level coverage; it preserves existing retry behavior and only partially addresses the linked report. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe cron scheduler admits jobs through durable run receipts, executes their payloads, and records outcomes; watchdog cleanup bounds waiting while receipt settlement controls successor admission. flowchart TD
A[Scheduled job] --> B[Receipt admission]
B --> C[Payload execution]
C --> D[Timeout watchdog]
D --> E[Bounded cleanup and logging]
E --> F[Retry scheduling]
C --> G[Receipt settlement]
G --> B
F --> B
Technical reviewBest possible solution: Retain the useful diagnostics and schedule-boundary tests while leaving broader timeout-result policy with the linked issue. Do we have a high-confidence way to reproduce the issue? No current-main overlap failure was reproduced; inspected source already fences pending execution, and the supplied Gateway trace demonstrates that contract. Is this the best way to solve the issue? The narrow diagnostics and schedule-level coverage are useful, but this patch does not settle the linked report's broader late-success policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d5c246249673. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +19, Tests +278. Total +297 across 3 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (20 earlier review cycles; latest 8 shown)
Reviewed October 11, 2026, 11:15 PM ET / October 12, 2026, 03:15 UTC (Revision 21). |
Replace the isCronJobActive(jobId) retry gate with a timeout-cleanup confirmation signal. cleanupTimedOutCronAgentRun now reports whether the original execution was confirmed terminated; when it cannot (abort ignored, cleanup rejected, or guard timeout exceeded), the run result carries timeoutCleanupUnconfirmed and resolveTransientCronRetryDecision returns retryable:false with reason "original execution may still be running". The previous gate evaluated during outcome finalization while the completing run's own active marker was still registered, blocking every retry and breaking one-shot retry regression tests (openclaw#24355, openclaw#106875). Also: - remove the unrelated @pnpm/exe pnpm-lock.yaml change (dependency guard) - raise the flaky child-cache-retention test child-process timeout Fixes openclaw#137215
The visible-spawn rollback cases exercise the real in-process gateway and SQLite store and can exceed the default 120s per-case timeout on loaded CI runners (they pass locally in ~110s for the whole file). Raise the per-case budget to 300s. Unrelated pre-existing robustness fix unblocking CI; the PR itself only changes cron retry behavior.
…eout-retry-during-active-execution
Timeout cleanup is not a termination fact: its contract is Promise<void>, and the Gateway callback resolves both when there is no session to clean up and when the drain reports drained=false. Treating a resolved cleanup as "the original stopped" therefore suppressed the retry for exactly the unconfirmed cases, and a rejected or guard-expired cleanup permanently disabled an enabled one-shot job -- removing documented timeout retry behavior even though the run receipt already prevents an overlapping execution. The retry decision no longer takes a cleanup-derived flag; overlap prevention stays with the settlement owner (run receipt), which defers terminalization while the underlying execution is pending. The cleanup helper keeps its guard so a stuck cleanup cannot block the lane, and now logs factually what happened (request sent, request finished, guard elapsed, cleanup failed) instead of claiming confirmed termination. Adds schedule-level regression coverage in src/cron/service/timer-timeout-retry-settlement.test.ts: a timed-out one-shot keeps its retry and still runs it once the original settles (both when cleanup rejects and when it outlives its guard), and a timed-out recurring job keeps its normal schedule; the successor stays fenced throughout. Drops the two unrelated test-timeout bumps from this PR.
|
Revision 14 pushed ( Findings addressed
Also dropped the two unrelated test-timeout bumps from the previous revision. Real behavior proof (after fix) Real
Transcript and harness: Regression coverage: Note: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…eout-retry-during-active-execution # Conflicts: # src/cron/service/agent-watchdog.ts
…eout-retry-during-active-execution
) Keep the worker-owned receipt active until the underlying execution settles, while recording its timeout once and preserving retry eligibility. Finish only the receipt after settlement and let startup recovery reuse recorded outcomes. Remove obsolete host mixed-batch handling and unused finalizer options. Supersedes #137274, thanks @xydigitLybnnnn. Co-authored-by: 林意斌0668000448 <[email protected]> Co-authored-by: xydigitLybnnnn <[email protected]>
|
Thanks @xydigitLybnnnn for identifying the timeout/retry settlement problem and contributing the earlier work. The cron worker architecture has since changed, so I reimplemented the fix at the current receipt owner in #189469, now merged, with your commit-author credit preserved. The fake-timer regressions failed on the pre-fix main baseline and pass with the repair, including retry eligibility and single outcome accounting. Closing this PR as superseded by #189469. |
…claw#189469) Keep the worker-owned receipt active until the underlying execution settles, while recording its timeout once and preserving retry eligibility. Finish only the receipt after settlement and let startup recovery reuse recorded outcomes. Remove obsolete host mixed-batch handling and unused finalizer options. Supersedes openclaw#137274, thanks @xydigitLybnnnn. Co-authored-by: 林意斌0668000448 <[email protected]> Co-authored-by: xydigitLybnnnn <[email protected]>
Refs #137215. Takes the review's recommended route: preserve retries through settlement — the run receipt stays the single overlap fence, and this revision stops deriving a retry hold from a cleanup promise that cannot prove termination.
What Problem This Solves
The previous revision of this PR gated retries on whether timeout cleanup could "confirm" the original execution stopped.
cleanupTimedOutAgentRunisPromise<void>, and the Gateway callback resolves both when there is no session to clean up and when the drain reportsdrained: false, so a resolved cleanup is not a termination fact. Two consequences:resolveTransientCronRetryDecisionreturnedretryable: false;applyJobResultthen disabled an enabled one-shot job and clearednextRunAtMs, permanently removing documented timeout retry behavior;nextRunAtMsafterwards.Both were raised as blocking findings. Current main already prevents the overlap the issue describes: the run receipt defers terminalization while the underlying execution is pending, so a successor cannot start (
src/cron/service/run-receipt-settlement.test.ts). Overlap prevention therefore does not need a retry-suppression rule, and adding one costs the documented retry.Why This Change Was Made
timeoutCleanupUnconfirmedend to end (CronRunOutcome,resolveTransientCronRetryDecision, bothapplyJobResultcall sites) and the"original execution may still be running"decision reason. Timeouts keep the retry they had before this PR.cleanupTimedOutCronAgentRunreturnsvoidagain and no longer interprets "the cleanup request finished" as confirmed termination. It keeps the guard so a stuck cleanup cannot block the cron lane, attaches the rejection handler immediately (no unhandled rejection when the guard wins the race), and logs what actually happened: request sent, request finished, guard elapsed, or cleanup failed — with job/execution context for operators debugging stuck runs.AGENTS.mdexplicitly forbids hiding failures with longer timeouts.Evidence
Real Gateway run through the reported boundary
Harness:
.artifacts/evidence-137274/cron-timeout-trace.mts(kept atlogs/real_behavior/issue-137215-evidence/harness/). It boots a realopenclaw gatewayfrom this checkout, creates a one-shot isolated cron agent turn (job timeout 3s) over the real WebSocket API, and points the model provider at a stub that never answers, so the job times out while its execution is still running. Only product surfaces are observed:cron.add/cron.run/cron.listresponses, the gateway log, and the cron events on the operator event stream.cron.run {mode:"force"}→{"ok":true,"ran":false,"reason":"already-running"}, 0 extra model requests[model-fetch] error … message=cron: job execution timed out (last phase: model-call-started)[agent/embedded] run cleanup: … aborted=true timedOut=true, agent lifecyclephase=error aborted=true,message processed … outcome=errorstatus=skipped(cron event), 0 extra model requestsenabled: true,lastStatus: "error",nextRunAtMsmoved past the run (retry scheduled),consecutiveErrors: 1; cron eventsjobEnabled=true lastStatus=error nextRunAtMs=… status=errorembedded run agent start→model-fetch … start→outcome=completed duration=1329ms,embedded run done … aborted=false) and cron reportsstatus=ok/lastStatus=okFull transcript:
trace-after-fix.mdin the same directory.Schedule-level regression coverage (fails on the previous revision)
node scripts/run-vitest.mjs run src/cron/service/timer-timeout-retry-settlement.test.tskeeps a timed-out one-shot retry eligible when cleanup rejects and runs it after settlementkeeps a timed-out one-shot retry eligible when cleanup outlives its guard and runs it after settlement→ with the previous revision's retry-suppression restored on top of current main, both fail at
expect(afterTimeout.enabled).toBe(true)(expected false to be true): the one-shot was disabled andnextRunAtMscleared. Each case also asserts the retry stays fenced while the original is unsettled and then runs after settlement.keeps a recurring job scheduled after a timeout whose original is still running— documents that no hold is claimed and the receipt performs the fencing.src/cron/service/timer-trigger.test.tsreplaces the old "holds the retry" case with the preserved contract: a timeout error staystransient retry, including when execution already started.Tests and validation
timer.timeout-watchdog,timer-trigger,timer-outcome-finalization.receipts,run-receipt-settlement,service.runs-one-shot-main-job-disables-it,timer-timeout-retry-settlement— passpnpm tsgo:core— cleanpnpm check:assertion-safety,pnpm check:max-lines-ratchet, oxfmt and oxlint on the changed files — cleansrc/cron/service/timer.regression.test.tshas 3 failures (keeps user cancellation disabled after main payload handoff (condition=false/true),keeps main-session cron wrappers visible across restart generation advance) that reproduce identically with this PR's cron changes removed, i.e. they come from currentmain, not from this revision.Risk checklist
mainis limited to logging: the retry decision no longer has the cleanup-derived branch, so previously suppressed retries retry again as documented.already-running/skippedin the real Gateway run).timeoutCleanupUnconfirmedfield was never persisted (Transient internal detailsibling comment applies).pnpm-lock.yamluntouched.🤖 AI-assisted: developed with AI assistance (Trae).