Skip to content

fix(heartbeat): prevent replies disappearing during active heartbeats - #123458

Merged
obviyus merged 6 commits into
mainfrom
t3code/replicate-telegram-poteto-mode-issue
Aug 14, 2026
Merged

obviyus merged 6 commits into
mainfrom
t3code/replicate-telegram-poteto-mode-issue

Conversation

@obviyus

@obviyus obviyus commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #40611.

Problem

A Telegram DM arriving during an active default heartbeat could reach the model but never receive a visible reply. The default heartbeat and DM share one session, transcript, and delivery route.

Root cause

Reply admission lacked an explicit ownership handoff from background heartbeat work to a visible turn. The visible prompt could be steered into the heartbeat while that heartbeat still owned terminal delivery. A finalizing heartbeat was also treated as non-abortable, allowing its send to escape the handoff.

Fix

  • Visible same-session turns supersede and drain the exact heartbeat operation/embedded handle, including finalizing owners and session-slot replacement.
  • Supersession is a distinct terminal result. Final heartbeat projection suppresses delivery, scratch writes, and event consumption.
  • Scheduled work remains queued and retries after a 60-second idle grace. Fresh manual/immediate wakes bypass deferred background work; direct cron retry remains within its 120-second budget.
  • Opt-in isolated heartbeat sessions remain concurrent. No Telegram, provider, config, or compatibility special case.

Proof

Before editing, the original owner regressions failed in three places: heartbeat finalized instead of reporting preemption, scheduled busy work retried after 1 second, and preempted work was lost (3 failed, 79 passed).

ClawSweeper later found the terminal-boundary variant. The added owner regression failed on old behavior with status: ran and a sendable result; fixed behavior returns { status: "skipped", reason: "preempted" } and performs no Telegram send.

Exact local head 034bfb7462c3dea1e9b97f52f83b1e4618e086d7:

  • Focused heartbeat, cron, admission, embedded-run, and reply-run suites: 59 files, 1,567 tests, 7 Vitest shards passed.
  • Production build: 11 tsdown invocations, 36 plugin control-plane modules, runtime postbuild passed.
  • pnpm lint: passed.
  • pnpm tsgo: passed.
  • pnpm check:test-types: passed.
  • pnpm deadcode:dependencies: passed.
  • git diff --check: passed.
  • Distill + Greybeard exact-head audits: zero actionable structural, lifecycle, allocation, timer, or rebase-integration findings.
  • Open-PR overlap search: no overlapping implementation found.

Covered boundaries: no partial send, no scratch write, retained event work, exact-handle replacement/drain, finalization-safe suppression, isolated-session non-preemption, fresh manual/immediate wake bypass, cadence/cooldown preservation, and direct-cron 120-second cap.

Before-fix live Telegram reproduction, redacted:

heartbeat -> provider: OPENCLAW_E2E_DRAFTPROOF HEARTBEAT_40611_HOLD
user -> bot: Please answer with OPENCLAW_E2E_OK only.
heartbeat trace -> provider: user prompt accepted
bot -> user: heartbeat draft only
bot -> user: [no OPENCLAW_E2E_OK reply]

Exact-head CI run 31798091029: passed, 104 jobs, zero failures.

Exact-head ClawSweeper final local review: PASS; patch correct, 0 findings, security cleared, no maintainer decision, 0 Rank-up moves.

Final Telegram changed-path proof (real QA user, fresh gateway, exact checkout; redacted):

setup: DM /status establishes delivery route
heartbeat -> provider: OPENCLAW_E2E_DRAFTPROOF HEARTBEAT_40611_HOLD
+6s user -> bot: Please answer with OPENCLAW_E2E_OK only.
heartbeat provider call -> AbortError: superseded by a newer session writer
bot -> user: OPENCLAW_E2E_OK
25s timeline: 1 typing event, 1 bot message; no heartbeat draft, edit, deletion, or extra message

Provider log: 5 requests, including the held heartbeat path and the visible follow-up. Gateway and mock teardown were clean; no pending webhook updates.

Base-drift rebuttal: rebased onto 508b35d9278c2d95638d69ea59a4d712f5bcfb3d immediately before this proof; head remains mergeable and exact-head CI is green. Main advanced during proof. Fast-lane drift policy says BEHIND merges and only CONFLICTING rebases; no rebase churn.

Production delta: +288/-76 (net +212). Tests/support: +725/-129 (net +596). Growth owns typed supersession, exact-handle lifecycle handoff, and retained retry policy; Distill found no smaller coherent owner-boundary expression.

Maintainer decision

Accepted by Ayaan in the authoring thread: scheduled busy/preempted heartbeat work uses the 60-second idle grace instead of the former 1-second retry. This intentionally prioritizes visible conversation continuity while retaining background work. Fresh manual/immediate wakes bypass deferred scheduled work.

Ready for maintainer review; no merge will be performed by this agent.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 8:16 AM ET / 12:16 UTC.

ClawSweeper review

What this changes

The PR makes visible turns preempt same-session heartbeats, suppresses preempted heartbeat output, and defers retained heartbeat work before retrying it.

Regression provenance

Possible regression — suspected (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review. The branch addresses a current shared-session reply-loss path and has credible changed-path Telegram proof, but it intentionally changes scheduled heartbeat retry behavior from the existing one-second retry to a 60-second idle grace.

Priority: P1
Reviewed head: 034bfb7462c3dea1e9b97f52f83b1e4618e086d7
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong changed-path proof and focused ownership repair support mergeability once the default retry-policy decision is recorded.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides a redacted exact-head real Telegram changed-path trace showing the heartbeat abort and one visible reply with no stray heartbeat delivery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides a redacted exact-head real Telegram changed-path trace showing the heartbeat abort and one visible reply with no stray heartbeat delivery.
Evidence reviewed 6 items Current-main behavior: Current main sees an occupied reply operation and waits for it; it has no heartbeat-specific visible-turn handoff at this decision point.
Branch owner-boundary repair: The PR adds a heartbeat-specific preempt-and-drain path before queue-policy steering, then disables steer/followup for that preempted visible turn.
Finalization fence: The branch records supersession even for an abort-frozen finalizing reply operation, which is necessary to stop a terminal heartbeat delivery from escaping the handoff.
Findings None None.
Security None None.

How this fits together

Heartbeat work and channel replies enter the same reply-operation and embedded-run lifecycle. This change gives a user-visible turn ownership of that lifecycle, then prevents the preempted background run from delivering stale output or consuming retained work.

flowchart LR
  A[Scheduled heartbeat] --> C[Shared reply operation]
  B[Visible channel turn] --> C
  C --> D{Heartbeat owns session?}
  D -->|yes| E[Preempt and drain heartbeat]
  E --> F[Deliver visible reply]
  E --> G[Retain heartbeat work]
  G --> H[Retry after idle grace]
Loading

Decision needed

Question Recommendation
Should scheduled heartbeats that are busy or preempted use the proposed 60-second idle grace instead of current one-second retry behavior? Accept the 60-second idle grace: Prioritize visible conversation continuity and retain deferred heartbeat work for a later retry.

Why: This is an intentional default scheduling-policy change with user-visible latency consequences; source inspection can establish the mechanics but cannot choose the desired product tradeoff.

Before merge

  • Resolve merge risk (P1) - Scheduled heartbeats that hit requests-in-flight or preemption now wait 60 seconds rather than the current one-second retry, so existing background work can be delayed.
  • Resolve merge risk (P1) - Production code grows by a reported net 212 lines across lifecycle ownership and retry policy; the added exact-handle lifetime is not represented by a smaller existing owner abstraction.
Agent review details

Security

None.

PR surface

Source +278, Tests +530. Total +808 across 37 files.

View PR surface stats
Area Files Added Removed Net
Source 24 354 76 +278
Tests 13 659 129 +530
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 37 1013 205 +808

Review metrics

Metric Value Why it matters
Production versus test delta production +288/-76 (net +212); tests/support +725/-129 (net +596) The reported expansion adds explicit terminal ownership and retained-work policy, so maintainers should assess the lifecycle surface alongside the behavior fix.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #40611
Summary: This PR explicitly targets the canonical open report's shared-session heartbeat contention and reply-loss behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the scheduled idle grace (recommended)
    Record maintainer acceptance that retained scheduled heartbeat work may wait up to 60 seconds after busy or preempted skips.
  2. Narrow the retry-policy change
    Retain the current fast retry for non-preempted scheduled busy skips if maintainers want the reply-loss repair without changing that existing cadence.
  3. Pause pending scheduling direction
    Do not merge until the intended default balance between visible replies and background-work freshness is settled.

Technical review

Best possible solution:

Land one shared-session supersession path only after a maintainer records acceptance of the 60-second scheduled idle grace and its delayed-background-work tradeoff.

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

No independent current-main run was executed in this read-only review; source shows visible turns only waiting on the shared owner, and the PR supplies a redacted before/after Telegram trace for that path.

Is this the best way to solve the issue?

Yes, with the retry-policy decision resolved: the branch repairs ownership at reply admission and embedded-run lifetime rather than adding a Telegram-specific workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a redacted exact-head real Telegram changed-path trace showing the heartbeat abort and one visible reply with no stray heartbeat delivery.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦞 diamond lobster.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: Current main can leave a visible channel turn without a reply while a same-session heartbeat owns the active run.
  • merge-risk: 🚨 compatibility: The PR changes the default retry cadence for scheduled busy or preempted heartbeat work from one second to 60 seconds.
  • merge-risk: 🚨 message-delivery: The patch deliberately suppresses terminal heartbeat delivery after visible-turn supersession, so an ownership mistake could affect message delivery.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides a redacted exact-head real Telegram changed-path trace showing the heartbeat abort and one visible reply with no stray heartbeat delivery.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a redacted exact-head real Telegram changed-path trace showing the heartbeat abort and one visible reply with no stray heartbeat delivery.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The change alters visible Telegram reply delivery and is directly demonstrable in a short Telegram Desktop flow.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Available blame for the active heartbeat retry and reply-admission lines resolves to the shallow-history boundary commit; deeper history is unavailable locally. (role: current-main source-boundary author; confidence: medium; commits: 73e2489a5ecb; files: src/infra/heartbeat-wake.ts, src/auto-reply/reply/reply-turn-admission.ts)

Rank-up moves

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

  • Record maintainer acceptance of the 60-second scheduled idle grace before merge.

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 (8 earlier review cycles)
  • reviewed 2026-08-14T04:33:40.684Z sha 9684e79 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T05:13:53.846Z sha c5ba413 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T06:07:29.558Z sha 329d4a7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T06:43:45.036Z sha 329d4a7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T07:44:10.833Z sha 62e80fe4b57d876f2b1cf362d88d8f4a0712a6fe :: found issues before merge. :: [P2] Assert the supersession cancel reason
  • reviewed 2026-08-14T08:17:47.519Z sha 34523170f3027ff39e5aab2e6c0721fee7fd7171 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T08:34:29.298Z sha 1caacff :: found issues before merge. :: [P1] Preserve visible-turn precedence after heartbeat finalization
  • reviewed 2026-08-14T12:03:03.189Z sha 034bfb7 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels Aug 14, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 14, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@obviyus
obviyus force-pushed the t3code/replicate-telegram-poteto-mode-issue branch from 62e80fe to 97b4107 Compare August 14, 2026 07:48
@obviyus
obviyus force-pushed the t3code/replicate-telegram-poteto-mode-issue branch 2 times, most recently from 6583254 to 3452317 Compare August 14, 2026 08:11
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@obviyus
obviyus force-pushed the t3code/replicate-telegram-poteto-mode-issue branch from 3452317 to 1caacff Compare August 14, 2026 08:28
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@obviyus
obviyus force-pushed the t3code/replicate-telegram-poteto-mode-issue branch from 1caacff to 034bfb7 Compare August 14, 2026 11:54
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@obviyus

obviyus commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer decision confirmed: accept the 60-second idle grace for scheduled busy/preempted heartbeat work. This prioritizes visible conversation continuity while retaining background work; fresh manual/immediate wakes continue to bypass the defer.

@obviyus obviyus self-assigned this Aug 14, 2026
@obviyus
obviyus merged commit 7fcdded into main Aug 14, 2026
199 checks passed
@obviyus

obviyus commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

@obviyus
obviyus deleted the t3code/replicate-telegram-poteto-mode-issue branch August 14, 2026 12:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…openclaw#123458)

* fix(heartbeat): prioritize visible turns over active runs

* fix(heartbeat): preserve embedded run ownership

* fix(heartbeat): drain preempted run ownership

* test(heartbeat): cover retained preemption work

* fix(heartbeat): retain work across visible preemption

* fix(heartbeat): fence finalizing supersession
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 mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL 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.

Heartbeat drift fix (PR #39182) causes aggressive retry that blocks Telegram during active conversations

1 participant