#13574: fix(heartbeat): skip when session has active run
stale
Cluster:
Heartbeat Management Improvements
Defer heartbeat polling when the session already has an active embedded Pi run to avoid lock contention that can surface as Agent failed during compaction or long runs. The heartbeat checks for active runs before polling and defers up to 5 times (2 minutes each). If the session is still busy after 10 minutes, the cycle is skipped.
Testing:
- npm run build
- npx vitest run src/infra/heartbeat-runner*.test.ts
References #13573
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change adds a guard in `runHeartbeatOnce` to skip running the heartbeat poll when the resolved session has an active embedded Pi run, intended to reduce lock contention during compaction/long runs.
The logic is inserted immediately after resolving the heartbeat session entry and before heartbeat delivery/prompt resolution.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but skip logic likely breaks exec/cron event delivery and reduces heartbeat telemetry visibility.
- Change is small and localized, but the new early return occurs before exec/cron pending-event handling and doesn’t emit a heartbeat event for the new skip reason, which can alter externally-visible behavior and observability.
- src/infra/heartbeat-runner.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12786: fix: drop heartbeat runs that arrive while another run is active
by mcaxtr · 2026-02-09
82.7%
#15193: fix(heartbeat): keep scheduler chain alive on requests-in-flight skip
by seilk · 2026-02-13
80.6%
#19745: fix(heartbeat): enforce interval check regardless of trigger source
by misterdas · 2026-02-18
77.2%
#22277: fix: prevent heartbeat model override from bleeding into main session
by zhangjunmengyang · 2026-02-21
76.1%
#14241: fix(heartbeat): propagate originating session key for exec event qu...
by aldoeliacim · 2026-02-11
75.7%
#17801: fix(heartbeat): enforce interval guard for non-interval wake reasons
by aldoeliacim · 2026-02-16
75.4%
#22340: fix(heartbeat): drain system events after event-driven heartbeat run
by AIflow-Labs · 2026-02-21
74.9%
#11752: fix(heartbeat): clamp setTimeout delay to 2^31-1 to prevent Timeout...
by kjaylee · 2026-02-08
74.7%
#13524: feat: conditional bootstrap file loading for heartbeat vs DM sessions
by tarun131313 · 2026-02-10
74.6%
#17812: fix: prune HEARTBEAT_OK turns from session transcript
by MisterGuy420 · 2026-02-16
74.5%