← Back to PRs

#23588: fix(auto-reply): suppress repetitive HEARTBEAT_OK loops

by mohandshamada open 2026-02-22 13:25 View on GitHub →
size: XS
## 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 (`&nbsp;`) 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