Skip to content

fix: preserve heartbeat outcomes across retries and cancellation - #144377

Merged
obviyus merged 5 commits into
mainfrom
codex/issue-144148-heartbeat-retry
Sep 10, 2026
Merged

obviyus merged 5 commits into
mainfrom
codex/issue-144148-heartbeat-retry

Conversation

@obviyus

@obviyus obviyus commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #144148.

Thanks @JLahullier for the correlated retry trace.

Related: #143278.

What Problem This Solves

Fixes an issue where a heartbeat lost an accepted alert and scratch update after overload retry completed without another tool call. Compaction and cancellation could also lose or misreport the outcome.

Why This Change Was Made

Keep the latest complete accepted response in run carryover and compaction. Preserve direct-abort reasons and record held reply operations before aborted dispatch returns.

User Impact

Retries retain alerts and scratch proposals; quiet heartbeats stay quiet. Stop and preemption suppress delivery and report their actual result. Existing revision and uncertain-delivery safeguards remain.

Evidence

The compiled Gateway reproduced lost output, then stored the proposal and delivered one alert after the fix. Twelve public scenarios passed, including retry, quiet output, cancellation, concurrent writes and lost acknowledgement. Restart recovery refused blind replay. The integration passed 151 focused checks; live Telegram delivery was not tested.

@obviyus obviyus self-assigned this Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 10, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 10, 2026, 5:06 PM ET / 21:06 UTC (Revision 3).

ClawSweeper review

What this changes

Preserves accepted heartbeat alerts and private monitor notes across retries and compaction, and records cancellation outcomes before deferred cleanup finishes.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still contains the response-loss and cancellation-classification gaps. The focused patch addresses them through existing owners, with supporting Gateway observations and no actionable introduced defect found.

Priority: P1
Reviewed head: 7b4304321c320f62b404def0f440f90b5ec85200

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant regression coverage and concrete after-fix Gateway observations.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured compiled-Gateway observations exercise response acceptance, overload, and a no-tool retry through the production path, showing one intended alert and scratch revision 0→1 after the fix; cancellation, stale writes, privacy, and uncertain delivery are also covered.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured compiled-Gateway observations exercise response acceptance, overload, and a no-tool retry through the production path, showing one intended alert and scratch revision 0→1 after the fix; cancellation, stale writes, privacy, and uncertain delivery are also covered.
Evidence reviewed 9 items Current main still needs the repair: At fetched main, attempt carryover retains MCP presentation state but not heartbeatToolResponse; compaction still clears the response. The deferred owner still uses an unclassified default abort reason, and aborted dispatch does not record its held operation.
Carryover is bounded to the existing run: The run loop creates carryover before its retry loop and applies it before attempt normalization. The patch retains the newest complete response; a new run receives fresh carryover.
Failure suppression and privacy remain owned downstream: Heartbeat dispatch exits before scratch writes for cancellation and supersession, suppresses scratch on failed outcomes, and retains expectedRevision checks. The payload owner separates scratch from public channel data. These changes carry response data without granting new execution authority or changing the stored format.
Findings None None.
Security None None.

How this fits together

Heartbeats run background agent checks and turn accepted responses into alerts or silent outcomes. The agent runtime carries those responses to dispatch, which controls delivery and revision-checked updates to private monitor notes.

flowchart TD
  A[Heartbeat check] --> B[Agent accepts response]
  B --> C[Retry and compaction carryover]
  C --> D[Final run outcome]
  E[Stop or preemption] --> D
  D --> F[Heartbeat dispatch]
  F --> G[Revision-checked private notes]
  F --> H[Alert or intentional silence]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +226. Total +234 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 11 3 +8
Tests 5 275 49 +226
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 286 52 +234

Review metrics

None.

Technical review

Best possible solution:

Keep accepted responses within the existing run lifecycle while leaving privacy, revision checks, cancellation suppression, and delivery reconciliation with their established owners.

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

Yes: accept a heartbeat response, trigger a provider overload, and complete the retry without another tool call. Current-main source and the reporter’s correlated trace establish the loss mechanism; this review did not execute it.

Is this the best way to solve the issue?

Yes: the patch repairs the existing carryover and cancellation owners without adding another persistence path, configuration option, or plugin API.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 83129f42703f.

Labels

Label justifications:

  • P1: A reported production heartbeat retry silently loses accepted monitor updates and replaces the intended alert with fallback text.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured compiled-Gateway observations exercise response acceptance, overload, and a no-tool retry through the production path, showing one intended alert and scratch revision 0→1 after the fix; cancellation, stale writes, privacy, and uncertain delivery are also covered.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured compiled-Gateway observations exercise response acceptance, overload, and a no-tool retry through the production path, showing one intended alert and scratch revision 0→1 after the fix; cancellation, stale writes, privacy, and uncertain delivery are also covered.

Evidence

What I checked:

  • Current main still needs the repair: At fetched main, attempt carryover retains MCP presentation state but not heartbeatToolResponse; compaction still clears the response. The deferred owner still uses an unclassified default abort reason, and aborted dispatch does not record its held operation. (src/agents/embedded-agent-runner/run/attempt-result.ts:39, 83129f42703f)
  • Carryover is bounded to the existing run: The run loop creates carryover before its retry loop and applies it before attempt normalization. The patch retains the newest complete response; a new run receives fresh carryover. (src/agents/embedded-agent-runner/run-loop.ts:318, 7b4304321c32)
  • Failure suppression and privacy remain owned downstream: Heartbeat dispatch exits before scratch writes for cancellation and supersession, suppresses scratch on failed outcomes, and retains expectedRevision checks. The payload owner separates scratch from public channel data. These changes carry response data without granting new execution authority or changing the stored format. (src/infra/heartbeat-dispatch.ts:181, 7b4304321c32)
  • Reporter corrected the mechanism with correlated evidence: In [Bug]: heartbeat_respond scratch is not persisted when the heartbeat notifies (notify=true / needs_attention) on 2026.9.3 #144148, JLahullier withdrew the notification-rebuild hypothesis and supplied a trace showing acceptance, two overload retries, successful completion with fallback text, and an unchanged scratch revision. This supports repairing retry carryover rather than rewriting persistence.
  • Captured after-fix Gateway observations: The supplied PR body reports a compiled Gateway and actual QA recipient: baseline lost the intended alert and retained scratch revision 0; the candidate delivered the alert once and stored the exact proposal at revision 1 without another tool call. It also records quiet, failure, cancellation, preemption, stale-write, privacy, and uncertain-acknowledgment results on integration build 67e2f8c1744c2a5c2c1978699eadc6444ce4b0c9. These are supplied observations, not reviewer-executed tests. The captured context identity is sourceRevision 1eaae50152df37238b7f64eb003588a0e33f59eddaeb134ba6553093fdb57de9. (67e2f8c1744c)
  • Release behavior checked: The v2026.9.3 source explicitly clears heartbeatToolResponse during compaction retry. A local release-blob read failed; the GitHub contents API supplied the release source successfully. (src/agents/embedded-agent-subscribe.ts:321, 1391f7cd2d40)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • anandnsharma: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-10T20:24:59.005Z sha 92323ea :: blocked before merge. :: none
  • reviewed 2026-09-10T20:41:59.183Z sha 7b43043 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 10, 2026
@obviyus

obviyus commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-unrelated-red
pr: 144377
head: 7b43043
run: 34527083283 attempt: 1
failed: checks-node-compact-small-23 job=103038859583 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit 490ca57 into main Sep 10, 2026
189 of 192 checks passed
@obviyus
obviyus deleted the codex/issue-144148-heartbeat-retry branch September 10, 2026 21:14
@obviyus

obviyus commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 490ca57. Thanks @JLahullier for the correlated retry trace.

  • Bug: a successful retry lost an accepted heartbeat alert and private scratch proposal. Cancellation and preemption also lost their intended outcome classification.
  • Fix: preserve the accepted response within its existing run and record cancellation through the existing lifecycle owners.
  • Proof: the compiled Gateway, public system-event command, real HTTP provider retry, and QA recipient passed all twelve scenarios on integration snapshot 67e2f8c1744c, containing reviewed PR head 7b4304321c32. Baseline scratch stayed at revision 0 with no intended alert; the candidate stored revision 1 and delivered the alert once. Independent acceptance and exact-head review passed. No live Telegram or Control UI claim is made.

CI remains red for three unrelated 30-second child-process timeouts in src/cli/one-shot-exit.test.ts:542: proxy validate --proxy-url --help --json, proxy validate --proxy-url -h --json, and proxy validate --proxy-url invalid --json. The genuine help control passed. All jobs in candidate run 34527083283, attempt 1 finished; checks-node-compact-small-23, job 103038859583 is the sole failed child, reflected by the aggregate gate.

The tested main parent c1bb68a8305a has identical CLI, proxy, child-runner, dependency, and cache inputs. These fresh invalid-URL children invoke none of the changed heartbeat/agent/dispatch operations; the diff adds no top-level work or process handle, and its tests are absent from that isolated shard. The timeout mechanism remains unknown. Main-parent run 34527038233 was cancelled and is not a matching reproduction. Existing transform-cache setup came from #143527, commit e570417ec3f5; that provenance does not establish the timeout's cause.

The normal guarded merger accepted the standing unrelated-CI approval. No assertion, timeout, or proof requirement was weakened. The isolated runtime is terminated and its access key is removed; full private evidence and failure history are retained.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 11, 2026
…nclaw#144377)

## What Problem This Solves

Fixes an issue where a heartbeat loses its accepted alert and private scratch update when the provider overloads after `heartbeat_respond` and the normal retry completes without another tool call. Compaction could also clear that response. Cancellation checks exposed related gaps: user Stop could emit a failure notice, and foreground preemption could be reported as busy before cleanup finished.

Closes openclaw#144148. Thanks @JLahullier for the correlated retry trace. Related: openclaw#143278; this proof does not establish that report's Telegram delivery path.

## Why This Change Was Made

Retain the latest complete accepted response in the existing run carryover and during compaction. Preserve the established direct-abort reason at the deferred owner, and record the exact held reply operation before an aborted dispatch returns.

## User Impact

Successful heartbeat retries retain their alert and scratch proposal. Quiet heartbeats remain quiet. Cancellation and preemption suppress delivery and report their actual outcome. Scratch revision checks and uncertain-delivery handling remain with their existing owners.

## Evidence

- Compiled Gateway and actual QA recipient: baseline accepted a response, overloaded, then completed its retry with scratch revision 0 and no intended alert. The candidate stores the exact proposal at revision 1 and delivers the intended alert once, without another tool call or outward fallback.
- All twelve public scenarios passed on the canonical CI integration build `67e2f8c1744c`, whose PR parent is `7b4304321c32`: notifying/quiet responses, no-tool retries, failure, cancellation, preemption, concurrent/stale writes, protected monitor removal, byte limits, uncertain acknowledgment recovery, and privacy with a real finished run-history row.
- Lost-acknowledgment proof records real upstream acceptance, a failed/unconfirmed terminal, restart recovery refusing blind replay, and later reads showing the same one message and scratch revision. Historical fixture failures and their independent method corrections remain preserved.
- Hidden missing-monitor and tool-size guards have separate source-boundary proof. All 11,426 deployed compiled files match the hosted artifact; plugin/runtime selection was independently verified. No live Telegram or Control UI validation is claimed.
- Owner regression tests failed before correction. The resolved merge passes 151 focused checks and formatting; the final test-type correction also passed its focused checks. Hosted lint and type checks pass.
- CI run [34527083283](https://github.com/openclaw/openclaw/actions/runs/34527083283) completed with three proxy CLI subprocess timeouts in `checks-node-compact-small-23`; the aggregate gate reflects that job. Source and child-command analysis found them unrelated to the heartbeat paths. The exact timeout cause remains unknown; no timeout or assertion was weakened.

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

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: heartbeat_respond scratch is not persisted when the heartbeat notifies (notify=true / needs_attention) on 2026.9.3

1 participant