Skip to content

fix(heartbeat): keep failed work pending after alerts - #118488

Merged
steipete merged 7 commits into
openclaw:mainfrom
emma300es:fix/heartbeat-failure-finalization-2026-08-03
Aug 11, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
emma300es:fix/heartbeat-failure-finalization-2026-08-03

Conversation

@emma300es

@emma300es emma300es commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Related: #94536

What Problem This Solves

Fixes an issue where users could receive a heartbeat runner-failure alert while OpenClaw still finalized the underlying heartbeat as successful. Retryable cron or exec events could be consumed, prior successful-heartbeat dedupe state could be replaced, and due work could be treated as completed even though the agent turn failed.

Why This Change Was Made

The root cause was ownership: heartbeat delivery inferred runner failure from rendered reply text after the agent runner had already produced the authoritative terminal outcome. That let a host-authored failure notice continue through successful-heartbeat bookkeeping.

The maintainer rewrite records the terminal agent-turn fact at the reply-operation owner, carries it into heartbeat classification, and routes both runner failures and terminal tool failures through one failure-notice finalizer. A visible notice remains a failed heartbeat: retryable events and prior dedupe state stay intact, while a successfully delivered notice clears only the exact pending-final recovery record it satisfies. Source-suppressed failure payloads remain private, and generic foreground failure copy is rewritten for heartbeat delivery even when an earlier heartbeat response was captured.

This preserves Emma's generic invariant and contributor credit while replacing the original text-inference patch with the canonical status-owner repair. The credited commit retains Co-authored-by: Emma <[email protected]>.

User Impact

When a heartbeat agent turn fails, users can still receive a useful alert, but OpenClaw keeps the underlying work pending for a later successful heartbeat. Message-tool-only private replies remain private, and failure alerts no longer contain foreground-only recovery guidance.

Evidence

  • Final focused proof on d67c8e45b71b2724dc9e544555b7cf04098f4d21: 4 files, 211 tests passed (the initial rewrite proof was 209 tests; two review-driven privacy/selection regressions raised the final count to 211).
  • Targeted oxfmt --check, core Oxlint, git diff --check origin/main...HEAD, and changed-gate dry-run passed. The dry-run selected only core and coreTests.
  • Fresh branch autoreview with maximum reasoning and findings through P2 completed clean after two bounded repair cycles; the final internal terminal-state refactor also received a clean max-P2 review.
  • Blacksmith Testbox tbx_01kzrrfyte696grctmgkac22nf passed pnpm plugin-sdk:api:check without changing the generated baseline (run).
  • Exact upstream Codex contract checked at openai/codex@279b93242cfef379e65da97e87e44b83c5934fd7: turn/completed carries an explicit terminal status, TurnStatus includes Failed, and app-server maps a recorded terminal error to TurnStatus::Failed while withholding a successful final agent message (source).
  • Production LOC: +112/-80 (net +32). Tests: +253/-64 (net +189). The production increase is the explicit terminal-state owner, private WeakMap-backed handoff that preserves the public Plugin SDK declaration contract, and privacy-safe failure finalizer replacing text inference and the narrower terminal-tool-only helper.
  • No live channel proof was run. Evidence is deterministic owner-boundary and mocked Telegram send-boundary proof plus exact-head CI; it is not represented as live channel validation.

@emma300es
emma300es force-pushed the fix/heartbeat-failure-finalization-2026-08-03 branch from b5e6fa4 to 6cd640d Compare August 3, 2026 05:03
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 11, 2026, 12:08 PM ET / 16:08 UTC.

ClawSweeper review

What this changes

The PR carries the agent turn’s terminal result into heartbeat finalization so failure alerts do not acknowledge retryable work, dedupe state, or inspected events as successful.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 7 items remain

Keep open: the new terminal-status bridge maps cancelled agent turns to failures, so intentional restart/user aborts become runner-failure heartbeat outcomes. It also needs real production-boundary proof before merge.

Priority: P1
Reviewed head: d67c8e45b71b2724dc9e544555b7cf04098f4d21

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The owner-boundary direction is promising, but a P2 cancellation regression and mock-only proof prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Focused mocked tests are useful, but the PR lacks after-fix production-boundary evidence showing a failed heartbeat retains work and a later successful heartbeat consumes it; redact private data in any trace. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Focused mocked tests are useful, but the PR lacks after-fix production-boundary evidence showing a failed heartbeat retains work and a later successful heartbeat consumes it; redact private data in any trace. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main failure inference: Current main infers runner failure only from a recognized rendered failure string, then can continue successful delivery bookkeeping; this is the source-level behavior the PR intends to replace.
Proposed owner-boundary handoff: The branch records the closed result from the reply runner before heartbeat code reads the shared reply-operation state, which is the appropriate producer-to-consumer direction for failure facts.
Cancellation is a distinct terminal category: The existing runner returns distinct aborted outcomes for restart and user cancellation, while the new bridge converts every non-settled result to failed; the canonical terminal-outcome owner separately classifies cancellation and failure.
Findings 1 actionable finding [P2] Preserve cancellation separately from failure
Security None None.

How this fits together

Heartbeat invokes an embedded agent, classifies its reply, then either delivers an alert or updates retry and dedupe state. The PR adds a private handoff from the reply runner to heartbeat classification so an agent failure remains failed after a visible alert.

flowchart LR
  A[Heartbeat wake] --> B[Embedded agent turn]
  B --> C[Reply operation state]
  C --> D[Heartbeat classification]
  D --> E[Failure notice]
  D --> F[Retry and dedupe state]
  E --> G[Channel delivery]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Focused mocked tests are useful, but the PR lacks after-fix production-boundary evidence showing a failed heartbeat retains work and a later successful heartbeat consumes it; redact private data in any trace. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve cancellation separately from failure (P2) - executeAgentTurn returns distinct aborted outcomes for restart and user cancellation, but this ternary records every non-settled outcome as failed. Heartbeat classification will therefore apply runner-failure finalization and telemetry to cancellations; carry an explicit cancelled state and add an abort regression instead.
  • Resolve merge risk (P1) - Cancelled heartbeat turns can be reported and finalized as agent-runner failures unless the new handoff retains cancellation separately.
  • Resolve merge risk (P1) - The PR has only mocked proof; retry retention and a later successful retry still need an after-fix production-boundary trace.
  • Resolve merge risk (P1) - Production code grows by net 32 lines for a private lifecycle-state bridge; the added boundary is plausible, but it should remain narrowly internal rather than becoming a parallel terminal-state model.
  • Resolve merge risk (P1) - The PR’s Codex-specific evidence claim requires direct contract recheck before any Codex compatibility conclusion.
  • Complete next step (P2) - The cancellation repair is concrete, but merge remains human-only until the contributor supplies real behavior proof and the Codex evidence claim is directly rechecked.

Findings

  • [P2] Preserve cancellation separately from failure — src/auto-reply/reply/agent-runner-execute.ts:393-396
Agent review details

Security

None.

PR surface

Source +32, Tests +189. Total +221 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 112 80 +32
Tests 4 253 64 +189
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 365 144 +221

Review metrics

Metric Value Why it matters
Production vs test LOC production +112/-80 (net +32); tests +253/-64 (net +189) The bug fix adds a lifecycle-status handoff and shared finalizer, so the production growth needs to remain justified by one canonical terminal-state boundary.

Merge-risk options

Maintainer options:

  1. Preserve cancellation semantics and prove recovery (recommended)
    Keep aborted turns distinct from failures, add an abort regression, and provide a production-boundary failure-to-successful-retry trace before merge.
  2. Accept failure labeling for cancellation
    Land with intentional cancellations recorded as runner failures, accepting misleading heartbeat failure telemetry and altered cancellation semantics.

Technical review

Best possible solution:

Preserve the canonical cancelled-versus-failed terminal category through heartbeat classification, retain unacknowledged work for both non-success outcomes, and attach a redacted injected-failure trace that shows a retained event followed by a successful retry.

Do we have a high-confidence way to reproduce the issue?

Yes for a source-level reproduction: an aborted reply-run outcome is explicitly possible and the new bridge converts it to failed; no live current-head run was performed.

Is this the best way to solve the issue?

No: the handoff is at the right owner boundary, but it must preserve cancellation separately from failure rather than collapsing every non-settled result into a runner failure.

Full review comments:

  • [P2] Preserve cancellation separately from failure — src/auto-reply/reply/agent-runner-execute.ts:393-396
    executeAgentTurn returns distinct aborted outcomes for restart and user cancellation, but this ternary records every non-settled outcome as failed. Heartbeat classification will therefore apply runner-failure finalization and telemetry to cancellations; carry an explicit cancelled state and add an abort regression instead.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 903af8bef557.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • remove mantis: telegram-visible-proof: Current Telegram visible-proof status is not_needed.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review merge-risk labels are merge-risk: 🚨 message-delivery, merge-risk: 🚨 session-state.

Label justifications:

  • P1: Incorrectly acknowledging a failed heartbeat can suppress due work and user-visible reminders until the next recovery path.
  • merge-risk: 🚨 message-delivery: The patch changes whether a failure notice is delivered and whether a later heartbeat retries the same work.
  • merge-risk: 🚨 session-state: The patch changes preservation of inspected events, pending-final recovery, and heartbeat dedupe state after non-successful turns.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Focused mocked tests are useful, but the PR lacks after-fix production-boundary evidence showing a failed heartbeat retains work and a later successful heartbeat consumes it; redact private data in any trace. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main failure inference: Current main infers runner failure only from a recognized rendered failure string, then can continue successful delivery bookkeeping; this is the source-level behavior the PR intends to replace. (src/infra/heartbeat-runner-delivery.ts:123, 903af8bef557)
  • Proposed owner-boundary handoff: The branch records the closed result from the reply runner before heartbeat code reads the shared reply-operation state, which is the appropriate producer-to-consumer direction for failure facts. (src/auto-reply/reply/agent-runner-execute.ts:393, d67c8e45b71b)
  • Cancellation is a distinct terminal category: The existing runner returns distinct aborted outcomes for restart and user cancellation, while the new bridge converts every non-settled result to failed; the canonical terminal-outcome owner separately classifies cancellation and failure. (src/auto-reply/reply/agent-runner-execution.ts:573, d67c8e45b71b)
  • Focused regression coverage: The branch tests a visible terminal failure and heartbeat retry/dedupe retention, but does not cover an aborted turn staying distinct from a runner failure. (src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts:1006, d67c8e45b71b)
  • Real behavior proof gap: The PR body explicitly reports mocked Telegram send-boundary tests and no live channel run; no production-boundary injected-failure trace with a later successful retry is provided. (d67c8e45b71b)
  • Codex contract review gap: The PR body relies on an OpenAI Codex terminal-status contract as evidence, but the required sibling source checkout was unavailable for direct verification; the changed implementation itself uses OpenClaw’s internal terminal result.

Likely related people:

  • steipete: Authored the current seven-commit heartbeat rewrite and requested the re-review. (role: recent area contributor; confidence: high; commits: d67c8e45b71b, e5b229f69229; files: src/infra/heartbeat-runner-delivery.ts, src/auto-reply/reply/agent-runner-execute.ts)
  • Ayaan Zaidi: Current-main history identifies a recent heartbeat delivery refactor on the same runtime surface. (role: recent adjacent contributor; confidence: medium; commits: 2c8ed54ddb60; files: src/infra/heartbeat-runner-delivery.ts, src/infra/heartbeat-runner-execution.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Represent aborted turns separately from failed turns and add the focused regression.
  • Add a redacted production-boundary injected-failure trace that shows retained work followed by a successful retry.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-08-03T05:09:52.134Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-05T04:07:00.897Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Classify silent runner failures before acknowledgement
  • reviewed 2026-08-06T03:36:29.966Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Preserve runner failure before quiet heartbeat acknowledgement
  • reviewed 2026-08-06T04:40:52.208Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Classify runner failures before quiet heartbeat acknowledgements
  • reviewed 2026-08-06T05:26:44.505Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Preserve silent runner failures before heartbeat acknowledgement | [P1] Retain the visible-partial failure contract when rebasing
  • reviewed 2026-08-06T06:39:00.628Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Classify marked failures before heartbeat acknowledgement | [P1] Rebase without dropping settled-final payload handling
  • reviewed 2026-08-07T02:43:44.326Z sha 6cd640d53f69f54209062ea755bb71b831a840fe :: needs real behavior proof before merge. :: [P1] Classify marked failures before acknowledgement | [P1] Preserve visible partial failures when rebasing

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Aug 6, 2026
@steipete steipete self-assigned this Aug 11, 2026
@steipete
steipete force-pushed the fix/heartbeat-failure-finalization-2026-08-03 branch from 6cd640d to 9f6fd24 Compare August 11, 2026 15:26
@steipete steipete changed the title fix(heartbeat): keep retryable work after runner failure alerts fix(heartbeat): keep failed work pending after alerts Aug 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Rank-up moves from the August 7 review:

  • Addressed “classify marked failures before acknowledgement”: terminal agent-turn state now comes from the reply-operation owner, and explicit failures route to the failure finalizer before quiet/empty acknowledgement branches. The silent failed-turn and message-tool privacy regressions are covered.
  • Addressed “preserve visible partial failures when rebasing”: the rewrite is based on current main, leaves the settled-visible-reply contract in agent-runner-failure-reply.ts intact, and the focused auto-reply E2E shard covers heartbeat failure after delivered partial output.
  • Addressed the dirty/stale-base risk: head 9f6fd2499cbd153d40e526c5774023cf8bc5fbc1 is mergeable after the maintainer rewrite.
  • Skipped live Telegram proof: this landing is intentionally using deterministic owner-boundary and mocked Telegram send-boundary proof only. The PR body states that gap explicitly and does not describe the evidence as live.

The refreshed PR body contains the exact upstream Codex terminal-turn contract, 211 focused tests, static checks, LOC split, and clean max-P2 autoreview.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete force-pushed the fix/heartbeat-failure-finalization-2026-08-03 branch from 9f6fd24 to 4899712 Compare August 11, 2026 15:38
@steipete
steipete force-pushed the fix/heartbeat-failure-finalization-2026-08-03 branch from d87a98f to d67c8e4 Compare August 11, 2026 16:01
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 11, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 11, 2026
@steipete
steipete merged commit b45ddf2 into openclaw:main Aug 11, 2026
135 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
* fix(heartbeat): keep failed work pending after alerts

Treat visible runner-failure notices as failed heartbeat turns, preserving queued cron and exec events plus prior heartbeat dedupe state for a later successful run.

Co-authored-by: Emma <[email protected]>

* fix(heartbeat): narrow failure reply payload

* fix(heartbeat): preserve failure reply privacy

* fix(heartbeat): isolate suppressed failure payloads

* refactor(heartbeat): keep terminal failure type private

* fix(heartbeat): consume terminal failure type

* refactor(heartbeat): keep terminal status internal

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Emma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants