Repository navigation
Description
Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
runHeartbeatOnce writes lastHeartbeatText / lastHeartbeatSentAt after a successful send but never nulls the pendingFinalDelivery* fields, so any heartbeat-driven agent run that previously set pendingFinalDelivery: true leaves the session permanently stuck on the get-reply redelivery short-circuit.
Steps to reproduce
- Drive the heartbeat path until
getReplyFromConfigproduces a substantive (non-HEARTBEAT_OK) text payload. The reply-agent path (src/auto-reply/reply/agent-runner.ts:2169) setspendingFinalDelivery: trueon the session at the end of substantive runs regardless of trigger. - Let the heartbeat finish:
sendDurableMessageBatchsucceeds andrunHeartbeatOncewriteslastHeartbeatText/lastHeartbeatSentAt(src/infra/heartbeat-runner.ts:2011-2022). - Wait for the next heartbeat tick.
Expected behavior
After step 2, pendingFinalDelivery* is cleared (the same way the user-message dispatch path does it via clearPendingFinalDeliveryAfterSuccess at src/auto-reply/reply/dispatch-from-config.ts:365-391, called from :1671). Subsequent heartbeats observe a clean session and invoke the agent normally.
Actual behavior
pendingFinalDelivery remains true indefinitely. On the next heartbeat, the get-reply fast path treats the session as having an unresolved final delivery and short-circuits before invoking the agent. The user observes silent loss: no notifications, no model calls, no errors surfaced.
OpenClaw version
Verified affected: 2026.5.7 through 2026.5.16-beta.2. Diagnosis applies to current main (2026.5.17).
Operating system
Linux (Docker deployment).
Install method
docker
Model
NOT_ENOUGH_INFO (model-independent; bug is in core heartbeat send path).
Provider / routing chain
NOT_ENOUGH_INFO (provider-independent).
Additional provider/model setup details
NOT_ENOUGH_INFO
Logs, screenshots, and evidence
Code-level diagnosis (paths against openclaw/openclaw main):
src/auto-reply/reply/agent-runner.ts:2169
Sets `pendingFinalDelivery: true` at the end of every substantive agent run,
regardless of trigger source (user message vs heartbeat).
src/auto-reply/reply/dispatch-from-config.ts:365-391
Defines `clearPendingFinalDeliveryAfterSuccess` which nulls all seven
pendingFinalDelivery* fields plus refreshes updatedAt.
src/auto-reply/reply/dispatch-from-config.ts:1671
Calls `clearPendingFinalDeliveryAfterSuccess` after a successful
user-message-driven dispatch. The heartbeat path has no equivalent call.
src/infra/heartbeat-runner.ts:1979-2022
Heartbeat send path. On success it writes `lastHeartbeatText` and
`lastHeartbeatSentAt` via `updateSessionStore`, but never clears any of
the seven `pendingFinalDelivery*` fields. This is the entire bug.
Local out-of-band workaround in our deployment: a cron job at */10 minutes
that nulls the stuck fields when `pendingFinalDeliveryText` matches
`lastHeartbeatText`. The cron consistently fires after every active-hours
heartbeat that produces substantive text, confirming the bug is fully
deterministic on the affected versions.
Impact and severity
- Affected: any deployment whose heartbeat-driven agent runs ever produce substantive (non-
HEARTBEAT_OK) text. Heartbeat-only setups silently lose every subsequent heartbeat after the first substantive run. - Severity: High. No user-visible error path; the agent simply stops responding to heartbeats and no model calls are made.
- Frequency: Deterministic. Every heartbeat that produces substantive text leaves the session stuck.
- Consequence: Missed notifications, missed model invocations, no surfaced error. Detection requires inspecting the session store directly.
Additional information
Suggested fix: extend the existing updateSessionStore call at src/infra/heartbeat-runner.ts:2011-2022 to also null the seven pendingFinalDelivery* fields, mirroring clearPendingFinalDeliveryAfterSuccess. A regression test seeding pendingFinalDelivery: true + a heartbeat-ack pendingFinalDeliveryText (so the heartbeat-defer check at :1328 does not short-circuit), running runHeartbeatOnce with a substantive reply, and asserting all seven fields are undefined afterward reproduces the bug and pins the fix.
PR follow-up will be linked here.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 17, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 18, 2026, 7:35 PM ET / 23:35 UTC.
Summary
Keep open: current main and latest release still have the heartbeat send-success write without pending-final cleanup, and the linked closing PR remains open rather than merged.
Reproducibility: yes. at source level: current main stores substantive heartbeat output as pendingFinalDelivery, then records visible heartbeat send success without clearing those fields. I did not run a writable fixture because this review is read-only.
Root-cause cluster
Relationship:
canonicalCanonical: #83184
Summary: This issue is the canonical report for the heartbeat send-success pendingFinalDelivery cleanup gap; one open PR is the candidate fix, and broader retry-bound work is adjacent.
Members:
fixed_by_candidate: fix(heartbeat): clear pendingFinalDelivery* on send success #83187 - The PR uses closing syntax for this issue and implements heartbeat pending-final cleanup plus regression coverage.partial_overlap: pendingFinalDelivery heartbeat replay loops forever — no attempt cap or TTL on orphan sessions #85743 - That issue covers the broader orphan replay TTL/attempt-cap fail-safe after pendingFinalDelivery becomes stuck, not the send-success cleanup cause tracked here.superseded: Fix heartbeat pending final delivery cleanup #87583 - That closed sibling PR was explicitly closed as superseded by the canonical cleanup path in the linked open PR.adjacent_distinct: Race in dispatch-from-config: abort check before clearPendingFinalDeliveryAfterSuccess() leaves pendingFinalDelivery stuck after successful delivery #89115 - That closed issue involved the same clear-after-success family in interactive dispatch abort ordering, not heartbeat-runner send success.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Next step
No new ClawSweeper fix PR should be queued because the issue already has an open closing implementation lane at #83187.
Review details
Best possible solution:
Land #83187 or an equivalent heartbeat cleanup with full pending-final field parity and regression coverage, while leaving broader retry-bound work to #85743.
Do we have a high-confidence way to reproduce the issue?
Yes, at source level: current main stores substantive heartbeat output as pendingFinalDelivery, then records visible heartbeat send success without clearing those fields. I did not run a writable fixture because this review is read-only.
Is this the best way to solve the issue?
Yes, clearing pending-final state in the heartbeat send-success owner path is the narrow maintainable fix for this issue. The linked PR is the implementation lane, while stale orphan replay caps belong to the adjacent follow-up.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against a7b52ecad90b.
Label changes
Label justifications:
P1: A successful substantive heartbeat can deterministically leave session state stuck and stop later heartbeat-driven notifications or model calls.impact:message-loss: Subsequent heartbeat alerts or updates can be silently skipped, blocked, or replayed from stale pending-delivery state.impact:session-state: The central failure is durable pendingFinalDelivery session state remaining set after heartbeat delivery succeeds.Evidence reviewed
What I checked:
AGENTS.md:1, a7b52ecad90b)src/infra/heartbeat-runner.ts:2117, a7b52ecad90b)src/auto-reply/reply/agent-runner.ts:2553, a7b52ecad90b)src/auto-reply/reply/dispatch-from-config.ts:732, a7b52ecad90b)src/auto-reply/reply/get-reply.fast-path.test.ts:300, a7b52ecad90b)src/infra/heartbeat-runner.ts:2075, 844f405ac1be)Likely related people:
src/auto-reply/reply/agent-runner.ts,src/auto-reply/reply/dispatch-from-config.ts,src/auto-reply/reply/get-reply.ts)src/auto-reply/reply/get-reply.ts,src/auto-reply/reply/get-reply.fast-path.test.ts)src/auto-reply/reply/get-reply.ts,src/auto-reply/reply/get-reply.fast-path.test.ts,src/infra/heartbeat-runner.ts)src/infra/heartbeat-runner.ts,src/infra/heartbeat-runner.commitments.test.ts)src/infra/heartbeat-runner.ts,src/infra/heartbeat-runner.clears-pending-final-delivery.test.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.fanispoulinakisai-boop commentedon May 20, 2026
Confirming this bug is still active and reproducing on OpenClaw
2026.5.18(cleannpm install -g openclaw@2026.5.18, macOS 26.5, Node v25.6.0).Two production incidents (~24h apart, same machine, same agent)
Incident 1 — 2026-05-18 17:09 → 2026-05-19 01:40 Athens
gateway.log) but produced zero Telegram outbound.sessions.jsonshowedpendingFinalDelivery: true, pendingFinalDeliveryAttemptCount: 17, pendingFinalDeliveryLastError: null, pendingFinalDeliveryTextcontaining the exact text already delivered at 17:09.pendingFinalDelivery*keys fromagent:main:mainimmediately restored normal heartbeat behavior.Incident 2 — 2026-05-19 17:10 → 2026-05-20 04:46 Athens (~12h later, post-5.18 update)
openai-codex/gpt-5.5).sessions.jsonat 04:46 showedpendingFinalDelivery: true, pendingFinalDeliveryTextmatching priorlastHeartbeatText(same-text correlation as in the original report).Confirmation of file:line citations
Reading the v2026.5.18 source confirms the diagnosis as reported in the original issue:
src/auto-reply/reply/agent-runner.ts:2151-2162writes the 7pendingFinalDelivery*keys to the session store whenevergetReplyFromConfigproduces non-token reply text. ThestripHeartbeatTokenack-check at 2142-2150 only filters pureHEARTBEAT_OKtoken replies.src/infra/heartbeat-runner.ts:1979-2022— the heartbeat outbound path updateslastHeartbeatText,lastHeartbeatSentAt,updatedAt, then callsmarkCommitmentsStatus/updateTaskTimestamps. It never undefines thependingFinalDelivery*keys.src/agents/agent-command.ts:1538-1559clears the same keys afterdeliverAgentCommandResultreturnsdeliverySucceeded === true. Heartbeat-runner does not go throughdeliverAgentCommandResult— it callssendDurableMessageBatchdirectly — so the clear is unreachable from heartbeat ticks.On PR #83503 / changelog wording
The 2026.5.18 changelog includes:
For anyone landing here from that line: PR #83503's diff touched
src/agents/auth-profiles/oauth.ts,profiles.ts,model-auth.ts,commands/sessions*,commands/models/list.status*, andsrc/logging/diagnostic*. It does NOT touchheartbeat-runner.ts,agent-runner.ts, oragent-command.ts. The "stuck runs" scope in #83503 is OAuth-fallback / idle queued embedded-run recovery — separate from this issue. Confirming this issue (#83184) is still the correct open ticket on 2026.5.18.Suggested fix (matching the original reporter's pointer)
Extend the existing
updateSessionStoreblock inheartbeat-runner.ts:2011-2022to also undefined the 7pendingFinalDelivery*keys after a verified-successfulsendDurableMessageBatchsend, mirroringagent-command.ts:1548-1551:Happy to share full
sessions.jsonsnapshots or gateway log excerpts from either incident if useful for testing the fix.Staasy commentedon May 23, 2026
Hit this in production on
2026.5.12(hourly heartbeat,session: main, openai-codex/gpt-5.4). Two additions not yet in this thread: a second route that creates the stuckpendingFinalDelivery, and why nothing ever recovers it — both still present at latest.1. A second route: an interrupted/aborted run, not a successful send
The OP route is "successful send never clears". In our incident the run never succeeded. The model emitted a short non-
HEARTBEAT_OKpreamble, then the embedded run went silent (cf. #85251) and was force-aborted by stuck-session recovery:The abort left the in-flight preamble as
pendingFinalDelivery(pendingFinalDeliveryCreatedAt == endedAt == abort time) and the session endedstatus: "timeout". So besides the successful-send path, the abort/timeout path also produces the stuck state — and here the run never reachesclearPendingFinalDeliveryAfterSuccessat all.2. Why it never recovers, even across a gateway restart
The give-up / cleanup paths in
src/agents/main-session-restart-recovery.tsare gated onstatus === "running":markSessionFailedreturns early unlessentry.status === "running"(it would otherwise clear allpendingFinalDelivery*).recoverStoreonly processes entries withstatus === "running" && abortedLastRun === true.A session left in
status: "timeout"matches neither, so post-restart recovery skips it entirely. Combined with the unbounded heartbeat retry inget-reply.ts(no cap — see #85743) andstripHeartbeatTokenclassifying any non-HEARTBEAT_OKtext as deliverable content (shouldSkip: false), the orphan retries once per heartbeat tick forever.Our session while wedged:
{ "status": "timeout", "pendingFinalDelivery": true, "pendingFinalDeliveryAttemptCount": 110, "pendingFinalDeliveryLastAttemptAt": "<created + ~109.8h>", "pendingFinalDeliveryLastError": null }110 attempts over ~109.8h = exactly one retry per hourly heartbeat ⇒ 4.5 days of silently dead heartbeat across one gateway restart, until the fields were cleared manually.
Version confirmation
The relevant code is unchanged at
v2026.5.20(latest stable) andv2026.5.22-beta.1:markSessionFailed/recoverStorestill gate onstatus === "running", and theget-reply.tsheartbeat retry still has no attempt/age cap. #80357 (which closed #79258) only skips the durable write when output strips to an ack-onlyHEARTBEAT_OK, so a non-ack preamble from an interrupted run is not covered.Suggestion
The give-up logic should also handle terminal non-
runningstates (timeout,aborted), and/or the attempt cap / TTL proposed in #85743 should apply regardless of content classification — so a single transient interruption (e.g. #85251) can't wedge the heartbeat session indefinitely.pfrederiksen commentedon May 26, 2026
Additional field evidence: heartbeat warning after Codex timeout/client-close cascade
Observed on OpenClaw
2026.5.22 (a374c3a), Nodev22.22.2, Linux/systemd user gateway, Telegram group heartbeat target, Codex app-server runtime withopenai/gpt-5.5.User-visible symptom
Telegram showed the heartbeat failure banner twice:
The main chat session stayed available, but the heartbeat itself did not produce
HEARTBEAT_OKor an alert.Local log signature
The failures lined up with a long-running Codex app-server turn timing out, then the client being retired/closed and subsequent lanes failing immediately:
A second similar incident occurred shortly afterward:
Mitigation being tested
I changed the heartbeat config to reduce coupling with the busy main/group session:
{ "heartbeat": { "lightContext": true, "isolatedSession": true, "skipWhenBusy": true, "timeoutSeconds": 120 } }Hot reload accepted the config:
After restart, the gateway was active/running and logs only showed:
No immediate
LLM request timed out,client is closed, or heartbeat-failed lines after restart yet. I’ll update if the next scheduled heartbeat still fails.This seems related to this issue because the user-visible failure is heartbeat-specific, but the proximate cause looks like the Codex app-server timeout/client-close cascade described in #85251.
aw-stevens commentedon May 27, 2026
Confirming on 2026.5.26 — different trigger context (main-session heartbeat + small model)
Confirming this is still live on
2026.5.26(latest stable). Our setup differs from the Telegram/target-delivery reports above, which may help separate the corependingFinalDeliverybug from the delivery-specific symptoms:Config
gateway heartbeat,
isolatedSession: false(main session),target: slack,ackMaxChars: 0, modelclaude-haiku-4-5via OpenRouter. The agent runs several periodic "programs" per tick.Trigger (differs from above)
The heartbeat's final reply intermittently includes non-
HEARTBEAT_OKtext — a small model leaking a sentence of preamble (e.g. "Excellent. Program 1 complete. The heartbeat contract is to return HEARTBEAT_OK…") around the token. SincestripHeartbeatTokenonly treats a pureHEARTBEAT_OKas an ack — andackMaxChars: 0means no other short reply qualifies — that preamble counts as substantive → setspendingFinalDelivery*, which the send-success path then never clears (the gap this issue tracks).Failure (main-session)
Every subsequent tick logs
[heartbeat] using explicit accountIdthen silently dead-ends — no model turn, norun_started— while the replay path incrementspendingFinalDeliveryAttemptCount. The tick still advancesheartbeatTaskState(consistent with #79479's stamp-on-skip), so it looks like it ran. Observed in our session store:Clean isolation test (recoverable-but-not-durable)
Delete the
pendingFinalDelivery*keys + restart → the next main-session tick dispatches a real run. But that run emits non-ack text again → re-setspendingFinalDelivery→ the following tick dead-ends again. So one manual clear buys exactly one tick. This rules out scheduler/session-routing root causes: dispatch works the instant the stale state is gone.Workaround that avoids it entirely
heartbeat.isolatedSession: true— a fresh session per tick carries nopendingFinalDelivery, so the replay never fires (cost: loses main-session context injection). May be worth noting for others until #83187 lands.PR #83187's clear-on-success would fix our case directly. A complementary
ackMaxChars-aware ack check (so a short non-token reply also clears — per the #85743 discussion) would harden it against small models that don't reliably emit the bare token.fanispoulinakisai-boop commentedon May 29, 2026
Still reproducing on
2026.5.20(e510042), macOS, openai/gpt-5.5 on the main session (agent:main:main).Fresh data from a long-running instance, in case the elapsed scale helps:
pendingFinalDeliveryCreatedAt: 2026-05-27 10:10:04 (a successful morning heartbeat send)pendingFinalDeliveryLastAttemptAt: 2026-05-30 01:09:23 (still firing)pendingFinalDeliveryAttemptCount: 123pendingFinalDeliveryLastError: nullThat's ~126 elapsed 30-min ticks over ~3 days vs attemptCount 123 (the small gap = the handful of ticks that re-delivered then re-stuck). User-visible symptom: the agent re-pushes the same cached morning message once per day past the quiet-hours boundary, and never runs a fresh turn again — so midday/evening check-ins silently stopped on 2026-05-28 with zero error and zero new model sessions on disk. The ~1s send-after-trigger latency confirms it's a cached redelivery, not a real turn.
Can confirm @aw-stevens's note:
heartbeat.isolatedSession: truesidesteps it (fresh session per tick carries nopendingFinalDelivery), and a manual clear of thependingFinalDelivery*keys is recoverable-but-not-durable — the next successful send re-sets it. Still no auto-clear/TTL as of 2026.5.20.fix(infra): clear pendingFinalDelivery* after successful heartbeat send
aw-stevens commentedon Jun 9, 2026
Was ... there an older version of OC that didn't suffer from this I can pin? Genuinely confused how more of the community isn't popping off about this, given the standard heartbeat in main session config feels basically unusable for us.
Switching to gpt-5-mini did solve the initial issue of CoT leaking into final messages that should have been an
ack(planting thependingLastReplypoison). But for alerts during heartbeat runs, where the OC response contract literally says "for alerts, do not include HEARTBEAT_OK; return only the alert text." -- the agent honors that contract exactly, sends just the substantive text via--announcepath, then OC poisons the session. So it really doesn't seem like there's any sort of workaround on the behavioral harness engineering front ... but maybe I'm missing something?[Update] My new workaround: created a custom plugin to just clear the pendingFinalReply poison pill up on every send -- effectively just recreating the fix from #83187 but via hooks/utilities available in the SDK 🤷♂️
danashburn commentedon Jun 12, 2026
Cross-referencing from #89115: the same clear-after-success ordering family is still live on 2026.6.5 in the interactive reply path, and the relevant dispatch block is unchanged in the published 2026.6.6-beta.2 tarball. Fresh production trace and a new compaction-adjacent trigger datapoint here: #89115 (comment)
#83187 still looks like the right fix for this heartbeat path. A maintainer review of it (or #89130 / #90229 for the reply path) would be appreciated.
fix(heartbeat): clear pendingFinalDelivery* on send success (#83187)
fix(heartbeat): clear pendingFinalDelivery* on send success (openclaw…
fix(heartbeat): clear pendingFinalDelivery* on send success (openclaw…
fix(heartbeat): clear pendingFinalDelivery* on send success (openclaw…
fix(heartbeat): clear pendingFinalDelivery* on send success (openclaw…