Repository navigation
fix(heartbeat): avoid timeouts for busy scheduled polls - #148333
Conversation
Settle untouched, event-free native polls at pre-execution busy guards without retaining an unowned child. Preserve queued tasks/events, admitted work, and genuine execution deadlines. Co-authored-by: vincentkoc <[email protected]>
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 5:50 AM ET / 09:50 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR makes untouched, event-free scheduled heartbeat polls finish as skipped when busy, with regression coverage and documentation for waiting until the next scheduled tick. Merge readiness✅ Ready for maintainer review This PR remains useful: current main pauses queue-wait deadlines but still retains untouched busy monitor occurrences. The proposed settlement change preserves payload-bearing and started work, and no actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherCron schedules heartbeat monitors and waits for the heartbeat wake queue to report their outcome. The heartbeat runner checks pending work and activity before preparation; its result determines automation completion and the next scheduled opportunity. flowchart TD
A[Scheduled monitor tick] --> B[Heartbeat wake queue]
C[Events and scheduled tasks] --> B
B --> D[Runner checks pending work and activity]
D --> E{Untouched plain poll and busy?}
E -->|Yes| F[Record skipped and await next tick]
E -->|No| G[Retain retry or execute work]
G --> H[Report eventual outcome to cron]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +85, Tests +1238, Docs 0. Total +1323 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep settlement in the existing wake owner, retiring only untouched plain monitor occurrences while preserving eventual outcomes for events, tasks, and prepared work. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that a scheduled poll behind held foreground work remains queued on current main; the supplied regression exercises that boundary. The original queue-wait timeout is already mitigated, and this review did not execute a reproduction. Is this the best way to solve the issue? Yes, the change extends the existing settlement owner without changing public result types, SDK contracts, configuration, or stored formats, and conservatively preserves work that must retry. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 41f119f66004. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Closes #148874 ## What Problem This Solves Heartbeat cron jobs report execution timeouts while queued behind foreground work. ## Why This Change Was Made Queue entry pauses the cron watchdog; attempt start arms it. This state has one writer. Retries retain their final outcome, including after handler replacement. Growth: `timer-job-runner.ts` +7 (deadline), `timer-execution.ts` +1 (handoff), `timer-execution-timeout.ts` +5 (type), `session-event-wake.ts` +18 (notifications). Growth accepted under the owner's standing acceptance (2026-09-15). ## User Impact Queue waits no longer create false errors. Actual failures and execution deadlines remain effective. ## Evidence Real Gateway: hold a `chat.send` response for five seconds; call `cron.run` with a two-second heartbeat timeout; read `cron.runs`/`cron.get`. Main expired at 2,010 ms before any heartbeat request, with one consecutive error. The fix stayed pending, then recorded the retained retry's success at 60.4 seconds. Separate controls recorded a failed retry and an executing timeout, each with one consecutive error. ## Compatibility Preserves #134464 outcome accounting. No config, schema, protocol or SDK change. #148333's next-cadence policy remains separate. ## Consumers Scheduled monitors, heartbeat tasks and immediate cron events. ## Invalidation Enqueue pauses the deadline; attempts restart it; completion disposes it. ## Tests 196 tests passed on a fresh merge with main; 27 focused tests also cover unlimited heartbeats. Original-code negative controls fail. Type-aware checks passed. ## Contention Immediate handoff, coalescing and cancellation remain unchanged and covered. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes openclaw#148874 ## What Problem This Solves Heartbeat cron jobs report execution timeouts while queued behind foreground work. ## Why This Change Was Made Queue entry pauses the cron watchdog; attempt start arms it. This state has one writer. Retries retain their final outcome, including after handler replacement. Growth: `timer-job-runner.ts` +7 (deadline), `timer-execution.ts` +1 (handoff), `timer-execution-timeout.ts` +5 (type), `session-event-wake.ts` +18 (notifications). Growth accepted under the owner's standing acceptance (2026-09-15). ## User Impact Queue waits no longer create false errors. Actual failures and execution deadlines remain effective. ## Evidence Real Gateway: hold a `chat.send` response for five seconds; call `cron.run` with a two-second heartbeat timeout; read `cron.runs`/`cron.get`. Main expired at 2,010 ms before any heartbeat request, with one consecutive error. The fix stayed pending, then recorded the retained retry's success at 60.4 seconds. Separate controls recorded a failed retry and an executing timeout, each with one consecutive error. ## Compatibility Preserves openclaw#134464 outcome accounting. No config, schema, protocol or SDK change. openclaw#148333's next-cadence policy remains separate. ## Consumers Scheduled monitors, heartbeat tasks and immediate cron events. ## Invalidation Enqueue pauses the deadline; attempts restart it; completion disposes it. ## Tests 196 tests passed on a fresh merge with main; 27 focused tests also cover unlimited heartbeats. Original-code negative controls fail. Type-aware checks passed. ## Contention Immediate handoff, coalescing and cancellation remain unchanged and covered. Co-authored-by: Ayaan Zaidi <[email protected]>
* fix(cron): exclude queue waits from heartbeat timeouts (#148876) Closes #148874 Heartbeat cron jobs report execution timeouts while queued behind foreground work. Queue entry pauses the cron watchdog; attempt start arms it. This state has one writer. Retries retain their final outcome, including after handler replacement. Growth: `timer-job-runner.ts` +7 (deadline), `timer-execution.ts` +1 (handoff), `timer-execution-timeout.ts` +5 (type), `session-event-wake.ts` +18 (notifications). Growth accepted under the owner's standing acceptance (2026-09-15). Queue waits no longer create false errors. Actual failures and execution deadlines remain effective. Real Gateway: hold a `chat.send` response for five seconds; call `cron.run` with a two-second heartbeat timeout; read `cron.runs`/`cron.get`. Main expired at 2,010 ms before any heartbeat request, with one consecutive error. The fix stayed pending, then recorded the retained retry's success at 60.4 seconds. Separate controls recorded a failed retry and an executing timeout, each with one consecutive error. Preserves #134464 outcome accounting. No config, schema, protocol or SDK change. #148333's next-cadence policy remains separate. Scheduled monitors, heartbeat tasks and immediate cron events. Enqueue pauses the deadline; attempts restart it; completion disposes it. 196 tests passed on a fresh merge with main; 27 focused tests also cover unlimited heartbeats. Original-code negative controls fail. Type-aware checks passed. Immediate handoff, coalescing and cancellation remain unchanged and covered. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 4e88587) * fix: stop marking delivered scheduled reports as failed (#152165) * fix: preserve completed scheduled reports after tool read failures * fix: keep cron failures after progress-only messages (cherry picked from commit e731216) --------- Co-authored-by: Sriram Natarajan <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Merged via squash.
|
Closes #148332
What Problem This Solves
Fixes: periodic heartbeat monitors can stay running behind foreground work, delay shutdown, and be recorded as failed after an ordinary Gateway restart.
User Impact
User impact: a plain, event-free monitor poll that has not started preparation finishes as skipped and waits for its next scheduled tick. Busy foreground work no longer creates a false heartbeat failure.
Queued events, scheduled tasks, direct manual wakes, and work already prepared or admitted keep their retries and eventual success/failure accounting. Genuine execution deadlines remain errors. No configuration change, migration, permission change, or SDK contract change is required.
Why This Change Was Made
The existing wake owner settles a poll only when the heartbeat runner proves it carries no pending work. Eligibility is conservative across coalescing, and a sticky work-started fact prevents later busy attempts from discarding admitted work.
This refresh preserves RoboClaw's original implementation and commit ancestry, incorporates the current scheduler/recovery ownership, and adds real-flow coverage for skipped monitors across restart. It updates this canonical PR without replacing its author credit.
Evidence
2d3dd99f5642: idle/no-route settles, but a busy monitor fails to produce a finished event. The candidate proves prompt settlement, persisted next-tick cadence, unchanged restart state, zero error backoff, immediate cron drain, and no model/notification calls for skipped polls.process.hrtimein the parent was incompatible with real SQLite-worker admission deadlines. The fixture keeps native hrtime while still simulating heartbeat cadence and watchdog timers; no production guard or assertion was weakened.Tests use fake scheduling timers, isolated SQLite state, real command-lane blocking, and injected model/channel boundaries. This is deterministic scheduler/runner proof, not a live provider or deployed Gateway test. No Gateway restart, live schedule/configuration change, deployment, or merge is part of this update.
Regression cost
Earlier single-worker
pnpm test <file> --maxWorkers=1wall measurements: private disposition 4.56 s (67 tests), module identity 9.16 s (1 test), real heartbeat flow 29.05 s (19 tests). Their test-time portions were below 30 seconds per file. Final refreshed busy-poll suite: 43.22 s wall (9 tests), with test execution 63% of the 39.67 s Vitest duration, below the 30-second per-file test-time budget. The real-flow suites retain CronService, wake ownership, heartbeat preflight/admission, and SQLite composition because fabricated busy results miss the original defect. CI timing will be available on the pushed revision.