← Back to PRs

#19339: fix(heartbeat): skip isError payloads when resolving heartbeat reply

by aldoeliacim open 2026-02-17 18:02 View on GitHub →
size: S trusted-contributor
## Summary Fixes #19302. `resolveHeartbeatReplyPayload` iterates the reply payload array backwards and picks the last non-empty payload. When `buildFinalReplyPayloads` appends a tool error summary (`isError: true`) after the agent's `HEARTBEAT_OK` text, the error payload wins and gets delivered to the channel — causing spurious error alerts during heartbeats. ## Fix Two-pass strategy in `resolveHeartbeatReplyPayload`: 1. **First pass** (backwards): skip `isError: true` payloads, prefer the agent's actual reply 2. **Fallback pass** (backwards): if no non-error payload exists, return the last error payload This preserves existing behavior when there are no error payloads, and correctly suppresses tool error leaks when the agent has already responded with `HEARTBEAT_OK`. ## Tests Added `heartbeat-reply-payload.test.ts` with 8 test cases covering: - Single/array payloads - Error-after-agent-text (the bug scenario) - Error-only arrays (fallback behavior) - Empty payloads - Mixed ordering <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes spurious error alerts during heartbeats by implementing a two-pass payload selection strategy in `resolveHeartbeatReplyPayload`. When tool errors are appended after an agent's `HEARTBEAT_OK` response, the first pass now skips `isError: true` payloads to prefer the agent's actual reply. The fallback pass ensures error payloads are still returned when no non-error content exists. - Refactored payload content detection into a reusable `hasContent` helper - Added comprehensive test coverage with 8 test cases covering single/array payloads, error-after-text scenarios, error-only fallback, empty payloads, and mixed ordering - Preserves backward compatibility for all existing scenarios while fixing the bug where tool error summaries leaked to channels <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is well-designed with a clear two-pass strategy that preserves all existing behavior while fixing the specific bug. Comprehensive test coverage validates all edge cases including the bug scenario, fallback behavior, and mixed ordering. The implementation is clean, follows the codebase patterns, and doesn't introduce any breaking changes or side effects. - No files require special attention <sub>Last reviewed commit: 9308590</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs