Repository navigation
fix(heartbeat): cron jobs for one agent starve heartbeats for all other agents - #167845
Conversation
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.
…-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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs real behavior proof before merge. What this changesScope heartbeat automation guards to recorded agent and session targets while retaining conservative handling of unattributed work. Example: Agent alpha has a scheduled heartbeat while agent beta has active and queued cron turns.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR addresses source-confirmed cross-agent heartbeat starvation that remains on current main, and the revised patch has no actionable code findings. Priority: P1 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway heartbeat runner reads cron activity and command-queue ownership before preparing a background agent turn, then either skips the wake or admits it for execution. flowchart TD
A[Scheduled heartbeat] --> B[Heartbeat admission]
C[Cron execution markers] --> B
D[Active and queued command targets] --> B
B --> E[Busy skip]
B --> F[Agent turn and delivery]
Technical reviewBest possible solution: Use queue-owned execution targets to admit independent agents’ heartbeats while preserving same-agent exclusion, exact waiting-owner exemptions, and conservative unattributed-work guards. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically returns cron-in-progress for an otherwise eligible alpha heartbeat while beta owns non-waiting cron activity or automation lane work; no target code was executed during this read-only review. Is this the best way to solve the issue? The revised approach fixes attribution at the existing queue owner instead of subtracting unrelated marker counts, and preserves cleanup and capacity semantics without another state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a5a279840425. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +31, Tests +90, Docs 0. Total +121 across 12 files. Added test files: 0. View PR surface stats
Review metrics
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 (3 earlier review cycles)
Reviewed October 15, 2026, 9:11 AM ET / 13:11 UTC (Revision 4). |
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.
Merge current main and complete the contributor's marker-scoping fix with queue-owned target facts for active and queued cron/nested/hook work. Preserve same-agent/session exclusion, exact heartbeat-wait exemptions, and conservative unbound-target behavior. Consolidate regressions into existing owner suites. Related: openclaw#167844 Original fix: openclaw#167845 by @yozakura-ava. Validation: changed-file lint/format and static Codex autoreview. Unit tests, typechecks, and live proof are delegated to PR CI per maintainer policy. Co-authored-by: yozakura-ava <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…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]>
Related: #167844
What Problem This Solves
Cron work for one agent can continuously suppress scheduled heartbeats for every other agent on the same Gateway.
User Impact
Heartbeats can run while another agent has active or queued automation work. Work targeting the heartbeat's own agent or session still defers it, and exact cron executions waiting for heartbeat settlement remain exempt. Legacy or unbound work without a recorded target stays conservative and blocks all agents. No configuration change or migration is required.
Why This Change Was Made
The original fix scoped active cron markers but left actual cron model turns blocked by global queue counts. The command queue now retains its existing execution target when an entry becomes active, replacing the task-ID Set with one Map. Heartbeat uses the same target predicate for current markers and active/queued Cron, CronNested, and HookDispatch entries. It never infers lane ownership by subtracting unrelated marker counts. Unfiltered queue counts retain their constant-time path.
Cron receipt publication also records an explicit target session because the job owner and an agent-qualified execution key can differ. Targets describe the admitted operation, not later job edits. Current queue membership and generation fences own cleanup; marker generation and exact identity own the heartbeat-wait exemption. No new deferred external effect or permission is introduced.
Main's ambient channel-readiness backoff (#173003) and self-removal owner guard (#167857) are preserved. The original review's lane-level concern is addressed; this retains a Related reference because legacy/unattributed work and the main command lane remain conservative global guards.
Original fix by @yozakura-ava; maintainer cleanup completes queue targeting, removes the duplicate private-predicate tests and 208-line synthetic-depth suite, and adds smaller coverage in the existing heartbeat and queue tests.
Evidence
c66b651210ab2efa74c5670a31d43e4dfc27106eused process-global marker queries and all three cron-related lane depths. Current cron receipt publication supplies agent ownership, and embedded execution/compaction already enqueue with session targets.4794818c99d20623157fe0d17881c60a114c87a7, including openclaw/ci-gate. The selected tests, production and test types, lint, format, source/architecture guards, and UI integration checks passed. No inherited failure exception is needed for this final CI run.scopes scheduled heartbeats to cron targets (owner=$owner, session=$sessionKey);ignores foreign active and queued %s work but protects the target session; the existing heartbeat-wait settlement test now includes foreign active work;counts matching targets with lane concurrency %s; the existing queue-reset replacement test now checks retained target identity.--mode branch, through P2) returned scoped-clean with no actionable findings; it statically checked target scoping, exact waiting-owner exemptions, and queue generation/reset behavior. Pre-commit review also found no actionable findings.ClawSweeper review
6084047604reported no code findings on the contributor head, requested removal of redundant predicate coverage, and asked for live proof. Redundant coverage is removed. The proof-only request is superseded by maintainer policy: PR CI is the proof.