#23588: fix(auto-reply): suppress repetitive HEARTBEAT_OK loops
size: XS
Cluster:
HEARTBEAT_OK Suppression Fixes
## Summary
- Adds detection for repetitive HEARTBEAT_OK patterns in model responses
- Suppresses responses that consist entirely of repeated HEARTBEAT_OK tokens
- Handles plain text, whitespace variations, and HTML-wrapped tokens
## Problem
Some models (e.g., Codex 5.3) may produce repetitive HEARTBEAT_OK responses like:
- `HEARTBEAT_OK HEARTBEAT_OK HEARTBEAT_OK...`
- `HEARTBEAT_OK\nHEARTBEAT_OK\nHEARTBEAT_OK...`
These repetitive responses get sent to messaging channels (Telegram, etc.), causing spam and wasting API quota.
## Solution
Added an `isRepetitiveHeartbeatOk` function that detects when a response consists entirely of repeated HEARTBEAT_OK tokens (with optional whitespace and HTML tags). When detected in `stripHeartbeatToken`, the response is treated as a heartbeat ack and marked with `shouldSkip: true`.
The pattern handles:
- Plain text: `HEARTBEAT_OK HEARTBEAT_OK HEARTBEAT_OK`
- With whitespace: `HEARTBEAT_OK\nHEARTBEAT_OK\n`
- With HTML: `<b>HEARTBEAT_OK</b> HEARTBEAT_OK`
Fixes #23560
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds detection and suppression for repetitive `HEARTBEAT_OK` responses that some models produce. The implementation correctly handles plain text, whitespace variations, and HTML-wrapped tokens through normalization and regex matching. The fix prevents spam to messaging channels and unnecessary API quota consumption.
**Key changes:**
- Introduced `isRepetitiveHeartbeatOk` helper that normalizes text by stripping HTML tags and collapsing whitespace before pattern matching
- Added early-return check in `stripHeartbeatToken` to catch repetitive patterns before further processing
- Pattern correctly handles case-insensitive matching and various formatting styles
**Notes:**
- No test coverage added for the new repetitive detection logic - existing tests only cover single token stripping
- HTML entity handling (` `) is not implemented in the normalization, though unlikely to be an issue in practice
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minimal risk
- The change is well-scoped and addresses a specific issue. The logic is straightforward and defensive (early return on fast path). However, the lack of test coverage for the new functionality prevents a score of 5.
- No files require special attention
<sub>Last reviewed commit: 1d0db13</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#15575: fix(heartbeat): suppress prefixed HEARTBEAT_OK ack replies (#15505)
by TsekaLuk · 2026-02-13
83.3%
#17371: fix(heartbeat): always strip HEARTBEAT_OK token from reply text
by BinHPdev · 2026-02-15
80.0%
#16321: Fix #12767: suppress HEARTBEAT_OK leakage in Telegram DM replies
by tdjackey · 2026-02-14
79.4%
#6094: auto-reply: ignore HTML comments in heartbeat check
by rudrapanchal81 · 2026-02-01
79.1%
#11859: fix: filter HEARTBEAT_OK messages from chat.history when showOk is ...
by Zjianru · 2026-02-08
77.6%
#11647: fix(webchat): filter HEARTBEAT_OK messages from chat.history response
by liuxiaopai-ai · 2026-02-08
76.1%
#19916: fix: strict silent-reply detection to prevent false positives with ...
by hayoial · 2026-02-18
75.3%
#12774: fix: webchat heartbeat should respect showAlerts config
by a2093930 · 2026-02-09
75.1%
#22277: fix: prevent heartbeat model override from bleeding into main session
by zhangjunmengyang · 2026-02-21
75.0%
#17006: fix(heartbeat): skip delivery when showOk is false
by Limitless2023 · 2026-02-15
74.6%