Repository navigation
Description
Bug
When isolatedSession: true is configured for heartbeat, two issues occur:
1. No overlap protection — concurrent heartbeats overwrite each other
runHeartbeatOnce calls resolveCronSession with forceNew: true every time it fires. If a previous heartbeat is still running (e.g., LLM is mid-execution), the next scheduled heartbeat:
- Creates a brand-new
sessionId, overwriting the store entry - Starts a second concurrent execution against the same agent workspace
- The previous run's session is silently orphaned
There is no guard preventing a second heartbeat from starting while the first is still in flight.
2. session + isolatedSession causes nested session keys
When both "session": "heartbeat" and "isolatedSession": true are configured:
resolveHeartbeatSessionreads"session": "heartbeat"→ returnsagent:<id>:heartbeatrunHeartbeatOnceappends:heartbeatsuffix → createsagent:<id>:heartbeat:heartbeat- Next cycle repeats →
agent:<id>:heartbeat:heartbeat:heartbeat - Session keys grow unboundedly
Without "session", the key becomes agent:<id>:main:heartbeat — which works but is a sub-session of main, not a truly independent heartbeat session.
Expected behavior
- If a heartbeat run is still executing, the next scheduled trigger should be skipped (not start a parallel run)
"session": "heartbeat"+"isolatedSession": trueshould produceagent:<id>:heartbeat— a single independent session key that gets a freshsessionIdeach run, without suffix nesting
Reproduction
// openclaw.json
{
"heartbeat": {
"every": "15m",
"session": "heartbeat",
"isolatedSession": true,
"target": "feishu",
// ...
}
}After a few cycles, sessions.json shows:
agent:<id>:heartbeat:heartbeat
agent:<id>:heartbeat:heartbeat:heartbeat
...
Suggested fix
-
Overlap guard: Track active heartbeat runs per agent in a module-level
Map. Skip if the agent already has a run in progress. -
Session key nesting: When
isolatedSessionis true and an explicitheartbeat.sessionis configured, use the resolved session key directly (it's already a dedicated heartbeat key) instead of appending:heartbeatagain.
const hasExplicitSession = Boolean(heartbeat?.session?.trim());
const isolatedKey = hasExplicitSession ? sessionKey : `${sessionKey}:heartbeat`;Environment
- openclaw 2026.3.14
- macOS, gateway mode
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Hollychou924 commentedon Mar 22, 2026
GMTekAI commentedon Mar 22, 2026
I checked this against current
main, and the specific root-cause theory in the issue/comments does not line up with the current runner.A few source-backed points:
runHeartbeatOnce(...)checksgetQueueSize(CommandLane.Main)and returnsrequests-in-flightinsrc/infra/heartbeat-runner.ts:639-641.src/infra/heartbeat-runner.ts:1200-1205, and there is regression coverage for both retry behavior and preserving cadence insrc/infra/heartbeat-runner.scheduler.test.ts:137-210.:heartbeatsuffix append path.resolveHeartbeatSession(...)insrc/infra/heartbeat-runner.ts:278-330canonicalizes forced/explicit heartbeat session keys and returns them directly.So my read is:
If this still reproduces on a current build, I’d look next at a narrower seam: targeted wake routing or an older release behavior, not unconditional suffix growth in the current heartbeat runner.
ha7rock commentedon Mar 27, 2026
Same issue here on 2026.3.24 with
isolatedSession: trueandtarget: "none".My observation aligns with the overlap problem: gateway logs confirm heartbeat fires at the scheduled tick (e.g. :54 past each hour), but ~60-70% of runs silently produce no session transcript. Also seeing 2-hour gaps where the scheduler doesn't fire at all, which may be the orphaned-session issue cascading.
The runs that do land work fine — it's just that most get swallowed. Overlap guard + proper session key handling would likely fix both symptoms.
meinnamehier commentedon Mar 29, 2026
Can confirm this is still happening on 2026.3.28 (Linux, gateway mode). With isolatedSession: true and heartbeat every 30m, I accumulated 145 zombie entries in sessions.json in ~2.5 days, with keys up to agent:main:main:heartbeat:heartbeat:heartbeat... (119 levels deep). Running a periodic cleanup script as a workaround until this is fixed.
GMTekAI commentedon Mar 30, 2026
I re-checked this against current
mainafter the newer 2026.3.28 confirmations, and my read is:src/infra/heartbeat-runner.tsitself.Source-backed notes:
getQueueSize(CommandLane.Main)/requests-in-flightinsrc/infra/heartbeat-runner.ts:639-641.src/infra/heartbeat-runner.ts:1200-1205, and there is regression coverage for that behavior insrc/infra/heartbeat-runner.scheduler.test.ts:137-210.:heartbeatappend path inresolveHeartbeatSession(...); current session resolution is insrc/infra/heartbeat-runner.ts:256-330.The strongest current seam I found is the isolated cron session stack:
src/cron/isolated-agent/run.ts:339-362callsresolveCronSession(...)withforceNew: params.job.sessionTarget === "isolated", then persists bothagentSessionKeyand a derivedrunSessionKey.src/cron/isolated-agent/session.ts:31-77rolls a freshsessionIdwhenforceNewis set, while preserving parts of the prior session entry.So if users are still seeing zombie / repeatedly nested keys like
agent:main:main:heartbeat:heartbeat:...on 2026.3.28, I think the best next step is to reproduce that shape through the isolated-session persistence path and add a failing regression there before changing heartbeat runner logic.At minimum, I’m not seeing evidence in the current tree for the earlier proposed fix of adding another overlap map inside the runner itself.
Megarushing commentedon Mar 30, 2026
Can confirm issue is still happening on current version:
My
openclaw doctor:yubingjiaocn commentedon Apr 1, 2026
Still reproducing on 2026.3.31 (latest as of today).
Setup: Agent with
isolatedSession: true+every: "30m"heartbeat.Observed: Heartbeat sessions recursively spawn new heartbeat sessions. The session key keeps appending
:heartbeatsuffixes:Each nested session runs a full model invocation (~$0.15–0.50 each), so the cost adds up quickly. Had to disable heartbeat entirely as a workaround.
The isolated heartbeat session should be excluded from heartbeat scheduling — its key already contains
:heartbeat, so filtering on that suffix would prevent recursion.GMTekAI commentedon Apr 2, 2026
I re-checked this against the current tree, and my read is that the bug still looks real, but the original root-cause theory in this issue no longer matches current
maincleanly.Current source already has runner-level backpressure:
src/infra/heartbeat-runner.ts:641returnsrequests-in-flightwhen the main lane is busy.src/infra/heartbeat-runner.ts:1200explicitly preserves scheduler cadence on that skip path.src/infra/heartbeat-runner.ts:256is where heartbeat session resolution now lives, and the broadrunner always appends another :heartbeatexplanation does not line up cleanly with the current file.That said, the repeated confirmations here through 2026.3.31 make the bug itself hard to dismiss.
The strongest current seam I found is the isolated-session persistence path rather than the top-level heartbeat wake guard:
src/cron/isolated-agent/run.ts:339callsresolveCronSession(...)src/cron/isolated-agent/run.ts:345setsforceNew: params.job.sessionTarget === "isolated"So my current read is:
heartbeat-runner.tsfirst.Smallest sensible next step:
heartbeat.isolatedSession: trueon currentmain.:heartbeatsession keys.agentSessionKeyandrunSessionKeyplus fresh-session rollover behavior throughsrc/cron/isolated-agent/run.tsandsrc/cron/isolated-agent/session.tsbefore changing runner scheduling logic.steipete commentedon Apr 25, 2026
Closing this as implemented after Codex review.
Current
mainalready handles the reported heartbeat session-key accumulation and overlap/backpressure paths: isolated heartbeat keys are canonicalized back to a single:heartbeatsibling, stale accumulated keys are removed, and the runner skips when the main queue or resolved session lane is busy. The changelog shows the session-key cleanup shipped inv2026.4.10.What I checked:
runHeartbeatOncereturnsrequests-in-flightwhen the main lane is busy before starting a heartbeat run. (src/infra/heartbeat-runner.ts:759, 60f7a59f5ed5)src/infra/heartbeat-runner.ts:782, 60f7a59f5ed5)resolveIsolatedHeartbeatSessionKeycollapses repeated trailing:heartbeatsuffixes back to one canonical isolated key instead of appending unbounded nested suffixes. (src/infra/heartbeat-runner.ts:375, 60f7a59f5ed5)heartbeatIsolatedBaseSessionKeyfor future stabilization. (src/infra/heartbeat-runner.ts:885, 60f7a59f5ed5):heartbeatsuffixes, and legacy isolated entries converging back to a single canonical key; separate tests cover skipping when the target session lane is busy. (src/infra/heartbeat-runner.isolated-key-stability.test.ts:102, 60f7a59f5ed5)## 2026.4.10says isolated heartbeat session cleanup shipped: stale accumulated:heartbeat:heartbeatvariants are removed when the next tick converges them to the canonical sibling. (CHANGELOG.md:949, 60f7a59f5ed5)So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review notes: reviewed against 60f7a59f5ed5; fix evidence: release v2026.4.10.