Repository navigation
fix(heartbeat): skip poll when active session lane is busy - #14396
grunt3714-lgtm wants to merge 1 commit into
Conversation
- Check both main lane and active heartbeat session lane queue depth - Prevent heartbeat poll collisions with in-flight embedded session runs - Add regression test for busy session lane skip
| const { entry, sessionKey, storePath } = resolveHeartbeatSession(cfg, agentId, heartbeat); | ||
| const queueReader = opts.deps?.getQueueSize ?? getQueueSize; | ||
| const mainQueueSize = queueReader(CommandLane.Main); | ||
| const sessionQueueSize = queueReader(resolveEmbeddedSessionLane(sessionKey)); | ||
| if (mainQueueSize > 0 || sessionQueueSize > 0) { | ||
| return { status: "skipped", reason: "requests-in-flight" }; |
There was a problem hiding this comment.
Exec/cron events can stall
runHeartbeatOnce now returns { status: "skipped", reason: "requests-in-flight" } whenever either CommandLane.Main or the resolved session: lane has in-flight work (src/infra/heartbeat-runner.ts:424-430). This check runs before the exec/cron event handling (peekSystemEvents(sessionKey)), so if a long-running session lane is busy, heartbeat will never process pending exec completion / cron system events for that session, potentially blocking those notifications indefinitely.
If exec/cron events are intended to be delivered even while a session lane is busy, the busy-lane check needs to exempt opts.reason === "exec-event" and opts.reason?.startsWith("cron:") (or otherwise ensure pending events can still be relayed).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/heartbeat-runner.ts
Line: 424:429
Comment:
**Exec/cron events can stall**
`runHeartbeatOnce` now returns `{ status: "skipped", reason: "requests-in-flight" }` whenever either `CommandLane.Main` *or* the resolved `session:` lane has in-flight work (`src/infra/heartbeat-runner.ts:424-430`). This check runs *before* the exec/cron event handling (`peekSystemEvents(sessionKey)`), so if a long-running session lane is busy, heartbeat will never process pending exec completion / cron system events for that session, potentially blocking those notifications indefinitely.
If exec/cron events are intended to be delivered even while a session lane is busy, the busy-lane check needs to exempt `opts.reason === "exec-event"` and `opts.reason?.startsWith("cron:")` (or otherwise ensure pending events can still be relayed).
How can I resolve this? If you propose a fix, please make it concise.|
Closing — heartbeat scheduler reliability was addressed in #14901 (2026.2.12). No longer needed. |
…upstream 22 comment-edits across 13 files. All bare `#N` references that point to karmaterminal/openclaw or karmaterminal/openclaw-bootstrap fork issues now use the prefixed `karmaterminal/openclaw#N` (or `karmaterminal/openclaw-bootstrap#N`) form so they cannot be silently auto-linked to unrelated upstream openclaw/openclaw issues. Citations changed: - bug #639 -> #639 (8 sites: compact-reasons.{ts,test.ts}, followup-runner.ts ×3, agent-runner-execution.ts ×3, request-compaction-tool.ts ×2) - (#580) / See #580 -> (#580) / See #580 (4 sites: context-pressure.{ts,test.ts}) - (#531) -> (#531) (2 sites: scheduler.test.ts) - issue #475 -> #475 (1 site: session-cost-usage.ts) - bootstrap#475 -> karmaterminal/openclaw-bootstrap#475 (1 site: discoverAllSessions.test.ts; the line above already used the prefixed form, this was the laggard) - Bug #473 fix / issue #473 -> #473 (3 sites: subagent-announce.continuation.runtime.{ts,test.ts}) - review gap on #188 -> review gap on #188 (1 site: status.test.ts; also dropped a named-prince prefix in the same test label, which separately satisfies part of #200) Left alone (out of scope per issue): - Pre-existing upstream openclaw/openclaw citations (openclaw#26905, openclaw#36142, openclaw#60552, openclaw#28491, openclaw#41981, openclaw#18264, openclaw#59428, openclaw#31311, openclaw#14869, openclaw#17971, openclaw#29683, openclaw#58409, openclaw#35481, openclaw#30115, openclaw#14396, openclaw#19537, #1205, #1435, openclaw#26881, openclaw#32228, openclaw#35074, openclaw#26881) -- these were present at v2026.4.14 and resolve correctly. - delegate-dispatch.ts:62 (`openclaw#189.`) -- already in the canonical prefixed form per the issue's exception note. Refs #199
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
A backgrounded exec that exits while its requester session is busy relied on the idle heartbeat wake to surface its completion. That wake is skipped as requests-in-flight whenever the session's command lane is non-empty and retries every second without an attempt cap (see openclaw#14396, closed without merge), so it never gets admitted and the completion starves for as long as the session stays active. Add an exec-completion steering queue that mirrors the subagent steering path: every embedded run turn leases any pending exec completions for its session and prepends them to the turn, so a busy session picks them up on its next turn regardless of lane contention. The durable system event and idle heartbeat wake remain the fallback for a fully idle session.
Fixes #13573
Summary
Heartbeat polling previously only checked the global main queue lane before running. Embedded Pi runs are queued in per-session lanes (
session:<key>), so a session could be actively busy while heartbeat still fired and collided with that run.This change makes heartbeat skip when either:
Changes
runHeartbeatOncemainandsession:<heartbeatSessionKey>lanesskipped: requests-in-flightwhen either lane is busyheartbeat-runner.skips-session-busy.test.tsValidation
pnpm -s vitest run src/infra/heartbeat-runner.skips-session-busy.test.tsGreptile Overview
Greptile Summary
This PR updates
runHeartbeatOnceto resolve the heartbeat session key earlier and skip heartbeat execution when either the globalCommandLane.Mainqueue or the resolved per-sessionsession:lane has in-flight work, preventing heartbeat from colliding with active embedded Pi runs. It also adds a regression test that asserts heartbeats are skipped when the active session lane reports queued work via the injectedgetQueueSizedependency.Confidence Score: 3/5
(4/5) You can add custom instructions or style guidelines for the agent here!