Skip to content

fix(heartbeat): keep private final reply off-channel in message_tool mode - #94088

Closed
Bartok9 wants to merge 3 commits into
openclaw:mainfrom
Bartok9:fix/94053-heartbeat-private-final
Closed

Bartok9 wants to merge 3 commits into
openclaw:mainfrom
Bartok9:fix/94053-heartbeat-private-final

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • When messages.visibleReplies: "message_tool" is configured, a heartbeat that returns plain final text without calling heartbeat_respond no longer leaks that text to the channel.
  • The no-tool-call fallback is now treated as a silent heartbeat ack, honoring the message_tool_only privacy contract.

Motivation

Closes #94053.

With visibleReplies: "message_tool", the heartbeat runner forces the heartbeat response tool and passes sourceReplyDeliveryMode: "message_tool_only" to the agent. The privacy contract is that nothing user-facing reaches the channel unless the model surfaces it via heartbeat_respond.

But if the model returned plain final text and did not call the tool, heartbeatToolResponse was undefined and the runner fell through to normalizeHeartbeatReply() → durable channel delivery. Any final text whose HEARTBEAT_OK token wasn't at an edge (so it survived stripping) was delivered to the Telegram DM/channel — exactly the leak in the issue's log:

[source-reply/private-final] agent produced a long private final reply without calling the configured delivery tool (message_tool_only); response kept private and not delivered to the source channel
[telegram] outbound send ok ... operation=sendMessage deliveryKind=text chunkCount=1

The first line says it was kept private; the second line shows it was sent anyway.

Fix

After resolving the reply payload, if the run forces the response tool and the operator explicitly opted into visibleReplies: "message_tool", and the model returned outbound text without a tool response, treat it as a silent heartbeat ack (restore updatedAt, optionally emit the OK token, mark commitments, return ran) instead of delivering the raw text.

Two payloads are still delivered to preserve existing behavior:

  • notices explicitly marked deliverDespiteSourceReplySuppression (e.g. Codex runtime usage-limit / failure notices), and
  • relayable exec-completion events.

Scope is intentionally limited to the explicit message_tool opt-in. The Codex-harness default also forces the response tool but expects plain-text fallback delivery, so its behavior is unchanged (verified by the existing tool-response and default-unset suites).

Real behavior proof

  • Behavior addressed: with visibleReplies: "message_tool", a heartbeat whose final reply is plain text (no heartbeat_respond call) containing HEARTBEAT_OK mid-string was delivered to the Telegram channel. After the fix that private text is suppressed and the run still completes as a silent ack.

  • Real environment tested: node v25.5.0 on macOS (Darwin arm64), this branch rebased on openclaw/main. The shipped runHeartbeatOnce from src/infra/heartbeat-runner.ts was driven directly via a standalone tsx script (no test framework / no mocking library) against a real on-disk session store under a temp dir; only the leaf Telegram send was a plain recorder so channel delivery could be observed.

  • Exact steps or command run after this patch:

    1. Seed a real sessions.json with lastChannel/lastProvider/lastTo pointing at a Telegram group.
    2. Build a real config with messages.visibleReplies: "message_tool".
    3. Provide a getReplyFromConfig that returns plain final text (no heartbeat_respond call) with HEARTBEAT_OK mid-string.
    4. node_modules/.bin/tsx .tmp-heartbeat-proof.mts → call runHeartbeatOnce({ cfg, deps }) and record every Telegram send.
    5. Repeat with the source file reverted to openclaw/main to capture the pre-fix behavior.
  • Evidence after fix: live captured stdout from the shipped runner (private text NOT delivered):

    === running SHIPPED runHeartbeatOnce with visibleReplies=message_tool ===
    [reply] sourceReplyDeliveryMode=message_tool_only forceHeartbeatTool=true
    [result] status=ran
    [observed] telegram sends recorded = 0
    PROOF: private final text was NOT delivered to the channel (leak suppressed).
    
  • Observed result after fix: runHeartbeatOnce returned status=ran and the recorder captured 0 Telegram sends — the private text never reached the channel. Re-running the same script with src/infra/heartbeat-runner.ts reverted to openclaw/main reproduced the original leak live:

    === running SHIPPED runHeartbeatOnce with visibleReplies=message_tool ===
    [reply] sourceReplyDeliveryMode=message_tool_only forceHeartbeatTool=true
    [telegram] outbound send -> -1001234567890 :: "Reviewed the overnight logs and the deployment is HEARTBEAT_OK, but I noticed three private follow-ups I am tracking internally."
    [result] status=ran
    [observed] telegram sends recorded = 1
    LEAK: private text reached channel: [{"to":"-1001234567890","text":"..."}]
    

    So the same shipped code path leaks before the patch and is silent after it.

  • What was not tested: delivery through a live Telegram API endpoint (the runner's channel-plugin send seam was exercised with a recorder rather than real credentials); the Codex-harness plain-text fallback path is intentionally unchanged and is covered by the existing default-unset and tool-response suites.

Supplemental automated checks

  • npx vitest run src/infra/heartbeat-runner.tool-response.test.ts — 16 passed (15 existing + 1 new regression asserting sendTelegram is not called in message_tool_only mode).
  • npx vitest run src/infra/heartbeat-runner.returns-default-unset.test.ts src/infra/heartbeat-runner.ghost-reminder.test.ts src/infra/heartbeat-runner.skips-busy-session-lane.test.ts src/infra/heartbeat-runner.commitments.test.ts src/infra/heartbeat-runner.respects-ackmaxchars-heartbeat-acks.test.ts src/infra/heartbeat-runner.scheduler.test.ts — all pass (no regression in default / Codex-harness / commitment paths).
  • npx oxlint + npx oxfmt on both changed files — clean.

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
…mode

When messages.visibleReplies is set to "message_tool", the heartbeat run
forces the heartbeat response tool and sourceReplyDeliveryMode=
message_tool_only. If the model returns plain final text without calling
heartbeat_respond, that private text leaked to the channel, bypassing the
configured privacy mode. Treat the no-tool-call fallback as a silent
heartbeat ack instead of delivering the raw text.

Scope is limited to the explicit visibleReplies="message_tool" opt-in so
the Codex-harness default (which also forces the tool but expects plain-text
fallback delivery) is unchanged. Notices marked
deliverDespiteSourceReplySuppression and relayable exec-completion events
are still delivered.

Closes openclaw#94053
@Bartok9
Bartok9 force-pushed the fix/94053-heartbeat-private-final branch from 5bfeb52 to 1a5fb44 Compare June 17, 2026 11:43
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 1:26 AM ET / 05:26 UTC.

Summary
The PR suppresses plain no-tool heartbeat final text under explicitly configured message_tool visibility, preserves marked notices and relayable exec completions, redacts the heartbeat event preview, and adds regression coverage.

PR surface: Source +82, Tests +44. Total +126 across 2 files.

Reproducibility: yes. at high confidence. The linked issue supplies deterministic steps and logs, while the contributor's standalone production-runner script records one outbound send before the patch and zero after it; current-main drift should still be checked after rebase.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #94053
Summary: The open issue is the canonical bug report and this PR is its strongest remaining implementation candidate; the other same-root PRs are closed unmerged.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rebase onto current main and rerun the focused heartbeat delivery suites before landing.

Mantis proof suggestion
A native Telegram before/after recording would close the remaining gap between the recorder-based proof and actual channel delivery without requiring code changes. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: reproduce a heartbeat with messages.visibleReplies="message_tool" that returns plain final text without heartbeat_respond, and capture that no private text appears in Telegram while an explicitly notified heartbeat still delivers.

Risk before merge

  • [P2] The patch intentionally turns a model's plain-text heartbeat fallback into silence for explicit message_tool users, so an incomplete exception check could suppress a legitimate system notice or completion event.
  • [P1] The branch is behind current main; heartbeat delivery, recovery, and event bookkeeping have active adjacent development, so the final merge result should be refreshed and reviewed rather than assuming the older base still composes unchanged.
  • [P1] The supplied real-run proof observes the Telegram send seam through a recorder rather than a live Telegram API round trip, leaving a small channel-integration proof gap.

Maintainer options:

  1. Refresh and verify the delivery matrix (recommended)
    Rebase onto current main and rerun coverage for suppressed private finals, notified tool responses, marked notices, exec completions, and default-unset behavior before merge.
  2. Accept the bounded proof gap
    Land after source review while accepting that the contributor's real-run proof recorded the Telegram seam rather than exercising a live Telegram endpoint.
  3. Pause if fallback semantics changed
    Pause or close this branch if current maintainers intend plain-text heartbeat fallback to remain visible despite explicit message-tool configuration.

Next step before merge

  • No automated repair is identified: the prior defect is fixed, and the remaining work is a current-main refresh plus ordinary owner review of the intentional delivery-policy change.

Maintainer decision needed

  • Question: After refreshing this branch onto current main, does the explicit message_tool contract intentionally require silent handling of every unmarked no-tool heartbeat final while preserving only marked notices and relayable exec completions?
  • Rationale: The implementation is technically sound, but the final authority for intentionally suppressing fallback heartbeat output across channel targets belongs to the current heartbeat delivery-policy owners.
  • Likely owner: joshavant — He merged and reviewed the foundational scheduled-heartbeat message-tool policy and is the strongest available owner for its intended delivery semantics.
  • Options:
    • Refresh and land (recommended): Rebase onto current main, rerun the focused heartbeat suites, confirm the two exception classes, and merge the privacy fix.
    • Require live Telegram proof: Pause landing until a native Telegram run demonstrates that private fallback text stays absent while an explicitly notified heartbeat still delivers.
    • Preserve fallback delivery: Close or redesign the PR only if maintainers decide explicit message_tool visibility should still permit plain-text heartbeat fallback delivery.

Security
Cleared: The diff narrows a private-output exposure, redacts the remaining status-preview path, and introduces no dependency, credential, permission, package-resolution, or new code-execution surface.

Review details

Best possible solution:

Rebase onto current main, retain the explicit message-tool-only suppression with the notice and exec-relay exceptions plus metadata-only preview, rerun focused heartbeat coverage, and land this as the canonical fix for the linked issue.

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

Yes at high confidence. The linked issue supplies deterministic steps and logs, while the contributor's standalone production-runner script records one outbound send before the patch and zero after it; current-main drift should still be checked after rebase.

Is this the best way to solve the issue?

Yes. Handling the exception in the heartbeat runner is the narrowest maintainable fix because that path resolves and durably delivers its own payloads rather than relying entirely on the normal reply dispatcher; the patch also preserves the existing notice and exec-relay escape hatches.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • remove merge-risk: 🚨 security-boundary: Current PR review merge-risk labels are merge-risk: 🚨 message-delivery.

Label justifications:

  • P2: The PR fixes a reproducible privacy and unwanted-delivery bug limited to explicitly configured heartbeat message-tool mode.
  • merge-risk: 🚨 message-delivery: Merging changes whether no-tool heartbeat finals are delivered or suppressed, and an incorrect exception boundary could hide legitimate notices or relay output.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR includes pre/post live output from the production heartbeat runner using a real on-disk session store, showing one recorded Telegram send before the fix and zero after; the latest preview redaction is additionally covered by focused regression testing.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes pre/post live output from the production heartbeat runner using a real on-disk session store, showing one recorded Telegram send before the fix and zero after; the latest preview redaction is additionally covered by focused regression testing.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The user-visible result is the absence of a leaked heartbeat message in Telegram, which is straightforward to demonstrate in a short native Telegram Desktop recording.
Evidence reviewed

PR surface:

Source +82, Tests +44. Total +126 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 82 0 +82
Tests 1 44 0 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 126 0 +126

What I checked:

  • Established privacy contract: Current user documentation says explicit messages.visibleReplies: "message_tool" keeps a no-tool final reply private rather than automatically delivering it, matching the behavior this heartbeat-specific patch enforces. (docs.openclaw.ai) (docs/gateway/config-channels.md, 9f5609382b54)
  • Concrete linked reproduction: The canonical issue provides deterministic configuration, model-output, and Telegram log evidence showing the runner claims the final is private and then sends it to Telegram anyway. (github.com) (src/infra/heartbeat-runner.ts:1863, 9f5609382b54)
  • Focused suppression boundary: The branch limits suppression to explicit message-tool visibility with no heartbeat tool response, while allowing payloads marked deliverDespiteSourceReplySuppression and relayable exec-completion events through. (src/infra/heartbeat-runner.ts:1863, 0ec420a9c76a)
  • Prior finding resolved: The latest commit replaces the private reply text in emitHeartbeatEvent.preview with a metadata-only suppression marker, closing the previously reported gateway/debug-preview exposure. (src/infra/heartbeat-runner.ts:1900, 0ec420a9c76a)
  • Regression coverage: The added test verifies message_tool_only is forced, Telegram delivery is not invoked, the run completes, and the stored heartbeat preview does not contain the private final text. (src/infra/heartbeat-runner.tool-response.test.ts:416, 0ec420a9c76a)
  • Real behavior proof: The PR body reports a standalone run of the production heartbeat runner with an on-disk session store: the same scenario recorded one outbound Telegram send before the patch and zero after it. (src/infra/heartbeat-runner.ts:1863, 0ec420a9c76a)

Likely related people:

  • steipete: Prior heartbeat-policy review identified current-line ownership and the largest recent contribution count across the heartbeat runner and reply-delivery path. (github.com) (role: recent area contributor; confidence: high; commits: 0241a6e7aecc, e510042870cf; files: src/infra/heartbeat-runner.ts, src/auto-reply/reply/dispatch-from-config.ts)
  • joshavant: Merged the foundational scheduled-heartbeat message-tool policy and contributed its delivery chat-type regression work and live proof. (github.com) (role: reviewer and merger; confidence: high; commits: ad2f5cda1c2d, bd9c78f957b8; files: src/infra/heartbeat-runner.returns-default-unset.test.ts, src/infra/heartbeat-runner.ts)
  • neeravmakwana: Authored the merged change that made scheduled heartbeats honor message-tool visibility and established the policy seam extended by this PR. (github.com) (role: introduced related behavior; confidence: high; commits: 0078b90, bd9c78f957b8; files: src/infra/heartbeat-runner.ts, src/infra/heartbeat-runner.tool-response.test.ts)
  • vincentkoc: Recent merged work refactored reply payload and source-delivery contracts used by message_tool_only suppression. (role: adjacent delivery-policy contributor; confidence: medium; commits: 7c91d0dbc985, a88fbf0f6476, 74e7b8d47b18; files: src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/source-reply-delivery-mode.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (2 earlier review cycles)
  • reviewed 2026-06-24T10:16:30.066Z sha 799a52e :: needs changes before merge. :: [P1] Do not publish suppressed private text in heartbeat previews
  • reviewed 2026-07-16T04:46:29.418Z sha 0ec420a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed 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 Jun 21, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 21, 2026
@xuwei-xy

Copy link
Copy Markdown

Nice implementation! I appreciate the clear commit messages and focused changes.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 16, 2026
@Bartok9

Bartok9 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant and ready for review. This keeps a non-empty no-tool heartbeat final reply off the source channel in message_tool visible-reply mode, while preserving marked notices and relayable exec-completion delivery (regression test included; CI green, MERGEABLE). Noted the review point about not exposing the suppressed text via the heartbeat event preview — happy to redact/omit preview on the silent path and add coverage that Telegram isn't called and getLastHeartbeatEvent() doesn't carry the private final text. @clawsweeper re-review

…preview

Addresses ClawSweeper P1: the message_tool_only no-tool suppression path
copied the private reply text into emitHeartbeatEvent.preview, which is
stored as lastHeartbeat, broadcast to gateway subscribers, returned by
last-heartbeat, and rendered in the Debug view. Replace with a metadata-only
marker so the off-channel reply is not exposed via operator status surfaces.
Regression test asserts Telegram is not called and getLastHeartbeatEvent()
does not carry the private final text.
@Bartok9

Bartok9 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review point: pushed a commit that redacts the suppressed private final text from the heartbeat event preview on the message_tool_only silent-ack path. emitHeartbeatEvent.preview is now a metadata-only marker ([private heartbeat reply suppressed]) instead of replyPayload.text.slice(0, 200), so the off-channel reply is no longer exposed via lastHeartbeat / gateway subscribers / last-heartbeat / Debug view.

Added regression coverage in heartbeat-runner.tool-response.test.ts asserting that on this path Telegram is not called and getLastHeartbeatEvent().preview does not contain the private final text. Full suite green (16 passed); oxlint + oxfmt clean. @clawsweeper re-review

@clawsweeper clawsweeper Bot added 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. 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 16, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 17, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thank you, @Bartok9, for the detailed privacy analysis and Telegram regression coverage. Closing as already fixed on current main: #115629 merged 32e522e and closed #94053. The canonical implementation suppresses private heartbeat finals under both direct and group message_tool_only policies while preserving explicit heartbeat notifications, marked operator notices, relayable execution completions, and due commitments. I independently reran the current-main production-path regression: node scripts/run-vitest.mjs src/infra/heartbeat-runner.tool-response.test.ts — 35/35 tests passed, including both real heartbeat-to-Telegram delivery fixtures. This PR is therefore superseded; no further privacy or delivery change is needed.

@steipete steipete closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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 runner leaks private final replies to Telegram in message_tool_only mode

3 participants