← Back to PRs

#15575: fix(heartbeat): suppress prefixed HEARTBEAT_OK ack replies (#15505)

by TsekaLuk open 2026-02-13 16:37 View on GitHub →
gateway stale size: S
## Summary Prevents heartbeat ack leakage when the model returns `responsePrefix + HEARTBEAT_OK` (for example, `[helper] HEARTBEAT_OK`). Closes #15505. ## Problem Heartbeat token filtering only stripped edge-positioned `HEARTBEAT_OK`. If a reply already contained a configured `responsePrefix`, token stripping could miss it and send a visible ack message. ## Root Cause `normalizeHeartbeatReply()` ran `stripHeartbeatToken()` directly on raw payload text, without accounting for a leading configured response prefix. ## Changes - `src/infra/heartbeat-runner.ts` - In `normalizeHeartbeatReply()`, strip a leading configured `responsePrefix` before heartbeat token detection. - Preserve existing behavior for non-token replies (prefix is still reapplied for actual alert text). - `src/infra/heartbeat-runner.respects-ackmaxchars-heartbeat-acks.test.ts` - Added regression test: `[helper] HEARTBEAT_OK` is treated as ack noise and not delivered. ## Tests - `pnpm vitest run src/infra/heartbeat-runner.respects-ackmaxchars-heartbeat-acks.test.ts src/infra/heartbeat-runner.returns-default-unset.test.ts` - Passed (43/43). ## Sign-Off lobster-biscuit <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates heartbeat reply normalization to treat `responsePrefix + HEARTBEAT_OK` (e.g. `[helper] HEARTBEAT_OK`) as heartbeat ack noise by stripping a leading configured `responsePrefix` before running `stripHeartbeatToken()`. It also adds a regression test ensuring prefixed heartbeat acks are not delivered. The change fits into the existing heartbeat flow by adjusting `normalizeHeartbeatReply()` (used by `runHeartbeatOnce`) so token detection works even when the model prepends the configured response prefix, preventing visible ack leakage to outbound channels. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge after addressing a small prefix normalization inconsistency. - Core logic change is localized and covered by a regression test; the main remaining concern is inconsistent handling of whitespace in `responsePrefix` between detection and reapplication which can lead to duplicated/odd prefixes in delivered messages for configs with stray whitespace. - src/infra/heartbeat-runner.ts <sub>Last reviewed commit: f9e9150</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs