Repository navigation
fix: report settled heartbeat cron outcomes - #134464
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 31, 2026, 5:28 PM ET / 21:28 UTC. ClawSweeper reviewWhat this changesThe PR makes heartbeat-monitor and heartbeat-task cron runs wait for the coalesced heartbeat turn’s terminal result and records that result in cron history. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessThe central cron-history bug remains unfixed on current main, and this PR addresses it at the right lifecycle boundary. A handler-replacement race can drop an awaited cron settlement and turn a completed heartbeat into a ten-minute cron timeout, so the PR needs one focused repair before merge. Priority: P2 Review scores
Verification
How this fits togetherThe Automations scheduler runs system-owned heartbeat cron jobs, which enqueue work through the shared heartbeat wake queue. That queue coalesces work into a heartbeat agent turn and must return its settled result to every waiting cron parent. flowchart LR
A[Cron monitor or task] --> B[Cron execution]
B --> C[Heartbeat wake queue]
C --> D[Coalesced heartbeat turn]
D --> E[Wake settlement]
E --> F[Cron run history]
G[Handler replacement] --> C
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +170, Tests +453. Total +623 across 14 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve every awaited settlement across a handler-generation change by either resolving it with the already-observed terminal result or requeuing the current wake, and add a focused replacement-race regression. Do we have a high-confidence way to reproduce the issue? Yes: current main’s source completes heartbeat cron work immediately after dispatch, while the PR’s new awaitable settlement path makes the reported outcome mismatch directly reproducible in a focused cron/heartbeat harness. Is this the best way to solve the issue? No: awaiting the coalesced child is the right owner-boundary repair, but the proposed handoff logic must retain or settle the current waiter when the heartbeat handler changes generation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6334c317eb1d. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
3fbe17d to
20a7916
Compare
|
ClawSweeper rank-up move resolved: I accept the +160 net production-line lifecycle cost because this repair needs one bounded many-parent-to-one-child settlement path plus exact active-owner exclusion. The logic remains concentrated in |
20a7916 to
dc1c560
Compare
dc1c560 to
a2aa35f
Compare
|
Merged via squash.
|
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]>
Drop the cron lane-depth discount. It subtracted a count of foreign cron markers from a count of Cron lane entries, but those are different populations with different lifecycles: a scheduled run publishes its marker without entering the lane (src/cron/service/run-admission.ts), while a queued manual run holds a lane slot before its marker exists (src/cron/service/ops-run-preparation.ts). An equal-count mismatch therefore escaped the fail-closed guard and could let a heartbeat fire into its own queued automation. The marker term is now agent-scoped via hasActiveCronJobsForAgent and hasActiveCronJobsForAgentExceptMarkers, so another agent's running cron job no longer blocks this agent's heartbeat. listCronHeartbeatWaitOwners stays process-wide as in openclaw#134464: its owners carry the exact lane task they occupy, which makes the exemption an exact identity match rather than a count-based guess. CronNested and HookDispatch remain global by design because they are entered with no owning cron marker; both residuals are pinned by tests and need agentId on CommandLaneTaskMarker, which is out of scope here.
…er agents (#167845) * fix(heartbeat): scope cron busy-gate to the target agent Cron work for one agent starved heartbeats for every other agent on a multi-agent gateway: the busy-gate used process-global hasActiveCronJobs() plus process-wide Cron/CronNested/HookDispatch lane depths, while the reply-run gate beside it was already agent-scoped via hasActiveRunForAgent. Scope the cron gate the same way: - add hasActiveCronJobsForAgentExceptMarkers(), countActiveCronJobsForOtherAgents() and listCronHeartbeatWaitOwnersForAgent() to src/cron/active-jobs.ts - use them in src/infra/heartbeat-runner-execution.ts, preserving the ownsCronLaneTask exemption per agent CommandLaneTaskMarker carries no agentId, so the Cron-lane depth is corrected by discounting runs this process can attribute to other agents. Markers with no recorded agent stay in the global count, keeping the documented safe default: unattributed work keeps suppressing every agent rather than letting a heartbeat fire into cron work it cannot name. CronNested/HookDispatch have no run attribution at all today and so keep counting process-wide. A cron run against agent X still suppresses agent X's heartbeats; only cross-agent suppression is removed. Single-agent gateways are unchanged. * fix(heartbeat): fail closed on the cron lane discount; pin the nested-lane residual Rin REWORK round 1 on 9a779b6f. R3: the foreign-run discount clamped with Math.max(0, ...), which silently reports a busy lane as idle whenever the foreign-marker count exceeds observed lane depth. Markers are created at admission while a lane slot is held only while the task is queued or running, so the two views can disagree. Fail closed instead: when they disagree, keep counting the lane globally. Also drop the comment's unproven "one admitted cron run holds exactly one Cron lane slot" claim. R1: CronNested and HookDispatch stay process-global, but not because they are cron-only -- gateway hook dispatch and the reply-runner fallback enqueue into them with no owning cron marker, so "every cron run belongs to another agent" would not prove the work is foreign and relaxing on that basis would be unsound. Kept fail-closed, documented in place, and pinned by two new tests that name the residual and will flip to "ready" once per-agent attribution lands on CommandLaneTaskMarker. NOT TEST-VERIFIED: the infra shard could not be scoped to run in this environment (see card 9a779b6f). Lint clean; cron shard unaffected. * fix(heartbeat): scope the cron marker gate to the target agent Drop the cron lane-depth discount. It subtracted a count of foreign cron markers from a count of Cron lane entries, but those are different populations with different lifecycles: a scheduled run publishes its marker without entering the lane (src/cron/service/run-admission.ts), while a queued manual run holds a lane slot before its marker exists (src/cron/service/ops-run-preparation.ts). An equal-count mismatch therefore escaped the fail-closed guard and could let a heartbeat fire into its own queued automation. The marker term is now agent-scoped via hasActiveCronJobsForAgent and hasActiveCronJobsForAgentExceptMarkers, so another agent's running cron job no longer blocks this agent's heartbeat. listCronHeartbeatWaitOwners stays process-wide as in #134464: its owners carry the exact lane task they occupy, which makes the exemption an exact identity match rather than a count-based guess. CronNested and HookDispatch remain global by design because they are entered with no owning cron marker; both residuals are pinned by tests and need agentId on CommandLaneTaskMarker, which is out of scope here. * test(heartbeat): use inferred deferred types --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: yozakura-ava <[email protected]>
…er agents (openclaw#167845) * fix(heartbeat): scope cron busy-gate to the target agent Cron work for one agent starved heartbeats for every other agent on a multi-agent gateway: the busy-gate used process-global hasActiveCronJobs() plus process-wide Cron/CronNested/HookDispatch lane depths, while the reply-run gate beside it was already agent-scoped via hasActiveRunForAgent. Scope the cron gate the same way: - add hasActiveCronJobsForAgentExceptMarkers(), countActiveCronJobsForOtherAgents() and listCronHeartbeatWaitOwnersForAgent() to src/cron/active-jobs.ts - use them in src/infra/heartbeat-runner-execution.ts, preserving the ownsCronLaneTask exemption per agent CommandLaneTaskMarker carries no agentId, so the Cron-lane depth is corrected by discounting runs this process can attribute to other agents. Markers with no recorded agent stay in the global count, keeping the documented safe default: unattributed work keeps suppressing every agent rather than letting a heartbeat fire into cron work it cannot name. CronNested/HookDispatch have no run attribution at all today and so keep counting process-wide. A cron run against agent X still suppresses agent X's heartbeats; only cross-agent suppression is removed. Single-agent gateways are unchanged. * fix(heartbeat): fail closed on the cron lane discount; pin the nested-lane residual Rin REWORK round 1 on 9a779b6f. R3: the foreign-run discount clamped with Math.max(0, ...), which silently reports a busy lane as idle whenever the foreign-marker count exceeds observed lane depth. Markers are created at admission while a lane slot is held only while the task is queued or running, so the two views can disagree. Fail closed instead: when they disagree, keep counting the lane globally. Also drop the comment's unproven "one admitted cron run holds exactly one Cron lane slot" claim. R1: CronNested and HookDispatch stay process-global, but not because they are cron-only -- gateway hook dispatch and the reply-runner fallback enqueue into them with no owning cron marker, so "every cron run belongs to another agent" would not prove the work is foreign and relaxing on that basis would be unsound. Kept fail-closed, documented in place, and pinned by two new tests that name the residual and will flip to "ready" once per-agent attribution lands on CommandLaneTaskMarker. NOT TEST-VERIFIED: the infra shard could not be scoped to run in this environment (see card 9a779b6f). Lint clean; cron shard unaffected. * fix(heartbeat): scope the cron marker gate to the target agent Drop the cron lane-depth discount. It subtracted a count of foreign cron markers from a count of Cron lane entries, but those are different populations with different lifecycles: a scheduled run publishes its marker without entering the lane (src/cron/service/run-admission.ts), while a queued manual run holds a lane slot before its marker exists (src/cron/service/ops-run-preparation.ts). An equal-count mismatch therefore escaped the fail-closed guard and could let a heartbeat fire into its own queued automation. The marker term is now agent-scoped via hasActiveCronJobsForAgent and hasActiveCronJobsForAgentExceptMarkers, so another agent's running cron job no longer blocks this agent's heartbeat. listCronHeartbeatWaitOwners stays process-wide as in openclaw#134464: its owners carry the exact lane task they occupy, which makes the exemption an exact identity match rather than a count-based guess. CronNested and HookDispatch remain global by design because they are entered with no owning cron marker; both residuals are pinned by tests and need agentId on CommandLaneTaskMarker, which is out of scope here. * test(heartbeat): use inferred deferred types --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: yozakura-ava <[email protected]>
Fixes #134327
Refs #134373
What Problem This Solves
Fixes an issue where heartbeat cron runs were recorded as successful as soon as their wake was accepted, even when the delayed heartbeat agent turn later failed. Operators could therefore see
ok/succeededhistory for model work that never completed.Why This Change Was Made
Cron task completion accounting is the lifecycle owner. Heartbeat cron work now stays open until the coalesced wake reaches a terminal result, and that result is mapped through the existing cron outcome vocabulary.
The wake queue fans one child result out to every represented cron parent, retains waiters across retryable skips and handler replacement, and detaches only the exact waiter on cancellation. Exact waiting cron and lane owners are excluded from the child's busy check so they cannot block their own work; unrelated cron work remains a blocker.
This uses the existing ten-minute cron watchdog and durable running-receipt recovery. It does not add a protocol status, persistence schema, polling loop, retry that hides failures, or unbounded scheduler wait.
#134373 concerns deletion of completed isolated cron sessions. It does not share this completion transition, so this PR does not change session cleanup.
User Impact
Heartbeat cron history now reports the eventual heartbeat outcome:
error/failedok/succeededskipped/failedCoalescing still produces one child turn, manual heartbeat runs use the same contract, and ordinary system-event cron remains dispatch-only.
Evidence
1363c4744796e7e18ace354efb70ebbdd00bef2c: a failed child followed an already-persistedok/succeededparent with summaryheartbeat wake requested.3fbe17d78ba5c43837bd84f8edbfcfeb76dc4cb2: the same parent waits and recordserror/failedwithheartbeat failed: agent-runner-failure.1363c474…): https://github.com/user-attachments/assets/be972314-fb81-4542-961e-14a8cb31afb23fbe17d7…): https://github.com/user-attachments/assets/74b80368-c3f7-4af8-8114-9cec068eee58node scripts/check-changed.mjs: passed.$autoreview: no findings, confidence 0.91.An expanded local
pnpm test:changedrun completed twelve projects before a Vitest worker exited while another full OpenClaw campaign saturated the host. It produced no assertion failure; exact-head hosted CI remains required before landing.Scope and Review Notes
Production LOC: +231/-71 (net +160) | Tests: +473/-20 | Test support: +12/-2
The production growth is the bounded many-parent-to-one-child settlement bridge and exact lifecycle ownership needed to preserve coalescing. Shared settlement and Gateway adapter logic were extracted to avoid duplicate branches.
Related open PRs are not superseded: #133747 covers cancelled-run retry settlement, #132464 covers orphaned heartbeat transcripts, #72677 covers handoff warnings, and #131590 covers one-shot disable visibility. None owns heartbeat child-to-parent completion.
Release-note context: Cron heartbeat jobs now report the settled heartbeat child outcome instead of treating accepted wake dispatch as completed work.