Repository navigation
fix(heartbeat): let a conversation's chained command completions skip the interval wait - #164756
Conversation
|
🦞👀 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 October 5, 2026, 5:49 PM ET / 21:49 UTC (Revision 4). ClawSweeper reviewWhat this changesThe heartbeat scheduler lets conversation-owned background command completions skip the periodic interval while preserving event spacing and flood limits. Merge readiness✅ Ready for maintainer review The PR remains necessary: current main still delays these completions until the heartbeat interval. No actionable patch defect remains, and the prior review’s test-cost documentation request is satisfied. Priority: P2 Review scores
Verification
How this fits togetherBackground command exits queue completion events that wake OpenClaw’s heartbeat runner. The scheduler decides when those events may start an agent turn, whose existing delivery path returns useful results to the conversation. flowchart TD
A[Background command exits] --> B[Session event queue]
B --> C[Completion ownership check]
C --> D[Heartbeat scheduler]
D --> E[Spacing and flood guards]
E --> F[Agent continuation turn]
F --> G[Conversation reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +34, Tests +78, Docs 0. Total +112 across 6 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep conversation completions responsive through the existing runner while preserving periodic-work cooldowns and shared rate guards. Do we have a high-confidence way to reproduce the issue? Yes: current-main source exposes the interval deferral after a preceding completion turn when the next command takes more than 30 seconds; the captured before/after live run corroborates it. This review did not execute a reproduction. Is this the best way to solve the issue? Yes: the patch repairs the existing scheduler decision and shares the completion classifier without adding another wake owner, setting, or delivery path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1b7dd0b2ac92. 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
History |
4dbc218 to
70bad65
Compare
70bad65 to
8b1e99b
Compare
… the interval wait
c2c5f3b to
3e5ab66
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed as the merge commit above. Checked on the exact head 3e5ab66: two gpt-6-astra reviewers LAND (general + loop safety), ClawSweeper ready, live Telegram (every=1h: step 2 arrived ~5 s after exit; main: nothing in 8+ min). Admin merge past one inherited red: |
… the interval wait (openclaw#164756) A background command completion started by the conversation (user turn or conversation continuation) now skips the heartbeat not-due wait, so a chained step reports within the existing 30 s spacing instead of waiting up to the heartbeat interval. The flood guard and 30 s spacing still apply; heartbeat-owned and other event wakes keep the full cooldown.
Related: #164719, #17797, #75436
What Problem This Solves
Fixes: step 2 of a chained background request ("run A; when it finishes, tell me and run B") reaches the chat up to one heartbeat interval late when a heartbeat ran less than
everyago.#164719 (merged as f0b38ed) made a command started inside a conversation's completion turn belong to that conversation, so its result goes back to that chat or topic. Its completion wake still goes through the heartbeat event cooldown, though (
shouldDeferWakeinsrc/infra/heartbeat-cooldown.ts). The completion turn for step 1 counts as a heartbeat run, so when step 2 finishes more than 30 s later, its wake is deferrednot-dueuntillastRun + every. Measured live on origin/main: withevery: 3m, step 2 arrived about 2m22s after the command exited. Withevery: 1h, no wake came in 5+ minutes; the before run below waited 8+ minutes.User Impact
User impact: when the agent starts a background command while answering a previous command's result, the new result comes back about as soon as the command exits, instead of waiting up to the heartbeat interval (an hour on a typical quiet setup). Periodic heartbeats, heartbeat-started commands, automation-started commands and other event wakes keep the full cooldown. No new settings, messages or warnings.
Why This Change Was Made
Provenance
nextDueMscooldown gate was only enforced on theintervalbranch. That let event-driven wakes (especiallyexec-event) fire heartbeat runs back-to-back when a heartbeat agent's tools triggered more wakes." Heartbeat exec-event interval-bypass regression (re: #17797): runaway runs every ~10s instead of configured every:30m #75436 reported runs "every ~10s instead of configured every:30m". The invariant to keep: a heartbeat's own tool exits must not re-trigger heartbeat runs faster thanevery.not-duegate: a wake deferred for spacing is retained and runs at the 30 s mark. So on origin/main, a command that finishes less than 30 s after the previous heartbeat turn already chains every 30 s, whoever started it. Only commands that run longer than 30 s get pushed out toevery.fromConversationTurnon the queued completion. It is set only when the exec started in a user turn or in a conversation continuation (bash-tools.exec-request-preparation.ts,continuesConversation). Heartbeat-owned, periodic-poll and cron turns never set it.Fix
startHeartbeatRunnerpeeks the targeted session's pending events for anexec-eventwake, excluding heartbeat delivery-awareness notices (the same view the prompt builder uses). When every pending event is a conversation-owned exec completion (isConversationExecCompletion, now shared withheartbeat-runner-prompt.ts),shouldDeferWakeskips only thenot-duegate. The other guards still apply:DEFAULT_FLOOD_THRESHOLD/DEFAULT_FLOOD_WINDOW_MS), which is checked firstDEFAULT_MIN_WAKE_SPACING_MS)Heartbeat-owned, automation, mixed and unflagged queues keep the full #17797 / #75436 cooldown.
No chain cap (maintainer decision)
An earlier draft of this PR proposed a chain-depth cap. It was dropped. On origin/main, short commands already chain every 30 s through retained wakes, with no total bound. Letting conversation-owned completions skip the
not-duegate adds no new unbounded case; it only stops penalizing commands that run longer than 30 s. The rate guards stay as they are, and each turn is model-gated.Bounded cost
tools.exec.notifyOnExit: falseturns completion turns off.Evidence
Regressions (real scheduler,
src/infra/heartbeat-runner.scheduler.test.ts)These drive
startHeartbeatRunnerthroughrequestHeartbeatwith real system-event queue entries. Fake time, 10 simulated minutes, and each turn starts the next command:"holds a conversation's completion turn behind the flood guard": after 5 manual runs, a conversation completion at 40 s does not run until the flood window clears at 60 s.
Mutation checks: moving the exemption ahead of the flood guard fails 2 rows;
every→somefails the reminder row; dropping the delivery-awareness filter fails the awareness row.Checks:
tsgo:coreandtsgo:core:testpass. Scheduler, cooldown, event-routing and broadcast-outcome suites pass (4 files, 85 tests).Test cost:
pnpm test src/infra/heartbeat-runner.scheduler.test.ts --maxWorkers=1takes 20.2 s wall time locally on a cold transform cache (Vitest duration 17.7 s, 96% of it transform; 31 tests). The six added tests run in 1–5 ms each on fake timers, with no real timers or process boots. In CI (checks-node-changed-6, run 37367320373) the file took 2.84 s (Vitest duration), and its shard finished in 3.99 s.CI: everything passes except
check-lint-core-2, which is inherited. It fails onsrc/state/openclaw-agent-execution-incognito.compute.test.ts(max-lines, 1024 > 1000). That file isn't touched here, andoxlintreproduces the same error on clean origin/main 0ac81cf. Earlier cancellations ("job was not acquired by Runner of type hosted") were runner capacity and passed on rerun.Live: Telegram Test Server forum topic, real
gpt-6-astraConfig in our setup's shape: heartbeat
every: 1h,target: "none",isolatedSession: true,lightContext: true,directPolicy: "allow", active hours set. The prompt asks for two chainedsleep 40; echo RESULT-<nonce>-A|Bbackground steps.Step 2 printed: RESULT-C340395F-Bposted at 19:53:52.9Z (~5 s after exit, 64 s after "Step 2 started")Before (origin/main): the topic got "Step 1 started." and "Step 2 started." The step 2 command ran on the topic session (#164719), but because step 1's completion turn had started about 45 s earlier, its wake was deferred
not-dueuntillastRun + 1h.After: the topic got "Step 1 started and is running in the background.", "Step 2 started and is running in the background.", then
Step 2 printed: RESULT-C340395F-B. Step 2's completion turn ran 45 s after step 1's: past the 30 s spacing, well insideevery. The first periodic heartbeat poll ran later in its isolated:heartbeatsession and posted nothing (target: "none"). No warnings and no other messages.Unchanged and out of scope: step 1's "Step 1 printed: …" line is commentary text before a tool call, and heartbeat delivery posts only the final payload of a completion turn (existing behavior, noted on #164719).
An earlier after run on the same head
Step 2's command exited at 19:41:18Z. The completion turn started at 19:41:18.1Z, and⚠️ Agent couldn't generate a response…" at 19:40:12Z, before any completion or heartbeat turn had run, so the scheduler wasn't involved. I reran for a clean timeline (above).
Step 2 printed: RESULT-639E6818-Bwas posted at 19:41:22.9Z. In that run, the first user turn ended with an empty final answer from the model. The existing incomplete-turn path posted "Proof directories (local):
events.ndjson(Telegram timeline),gateway.log, the transcript snapshot androot-patch.jsonfor each run.Reviews
gpt-6-astrareviewer, round 1 on 3e5ab66: LAND, no findings. It confirmed that the queue peek matches preflight for targeted and global keys, isolation and the awareness filter; that retained and merged wakes are unchanged; and that dropping the scheduled-tick and task exclusions is safe, because scheduled ticks already setnextDueMs = nowand task intent already skipsnot-due.LOC vs origin/main: production +38/-5, tests +78, docs +1/-1.