Skip to content

Commit 42e22d4

Browse files
committed
fix(heartbeat-filter): preserve HEARTBEAT_OK detection with reasoning/thinking blocks
The `isHeartbeatOkResponse` function was incorrectly rejecting assistant messages that contained non-text content blocks like "reasoning" or "thinking", even when the text content was a valid HEARTBEAT_OK acknowledgement. This caused heartbeat transcript filtering to fail, leaving stale heartbeat prompts and acknowledgements in the model context, leading to: - Major context size inflation - Model confusion from tool call artifacts that should have been filtered - 100% reproduction rate when heartbeat ACK contains reasoning blocks The fix removes the overly broad `hasNonTextContent` check, allowing messages with reasoning/thinking blocks to be properly evaluated for HEARTBEAT_OK content. Fixes issue #95796 ## Evidence ### Before Fix ```ts const message = { role: "assistant", content: [ { type: "reasoning", text: "Let me check..." }, { type: "text", text: "HEARTBEAT_OK" }, ], }; isHeartbeatOkResponse(message); // → false ❌ (should be true) ``` ### After Fix ```ts isHeartbeatOkResponse(message); // → true ✅ ``` ## Test Coverage Added test case verifying HEARTBEAT_OK detection works correctly with: - reasoning blocks - thinking blocks - output_text blocks (existing behavior preserved)
1 parent ea56b13 commit 42e22d4

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎src/auto-reply/heartbeat-filter.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,36 @@ describe("isHeartbeatOkResponse", () => {
135135
),
136136
).toBe(false);
137137
});
138+
139+
it("matches HEARTBEAT_OK even when the message contains reasoning/thinking blocks", () => {
140+
// This tests the fix for issue #95796 where messages with reasoning blocks
141+
// were incorrectly rejected by isHeartbeatOkResponse due to hasNonTextContent check.
142+
const messageWithReasoning = {
143+
role: "assistant",
144+
content: [
145+
{ type: "reasoning", text: "Let me check the heartbeat status..." },
146+
{ type: "text", text: "HEARTBEAT_OK" },
147+
],
148+
};
149+
expect(isHeartbeatOkResponse(messageWithReasoning)).toBe(true);
150+
151+
// Also test with thinking block (another common non-text block type)
152+
const messageWithThinking = {
153+
role: "assistant",
154+
content: [
155+
{ type: "thinking", text: "Processing heartbeat request" },
156+
{ type: "text", text: "**HEARTBEAT_OK**" },
157+
],
158+
};
159+
expect(isHeartbeatOkResponse(messageWithThinking)).toBe(true);
160+
161+
// Test with output_text (should still work as before)
162+
const messageWithOutputText = {
163+
role: "assistant",
164+
content: [{ type: "output_text", text: "HEARTBEAT_OK" }],
165+
};
166+
expect(isHeartbeatOkResponse(messageWithOutputText)).toBe(true);
167+
});
138168
});
139169

140170
describe("filterHeartbeatTranscriptArtifacts", () => {

‎src/auto-reply/heartbeat-filter.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,7 @@ export function isHeartbeatOkResponse(
336336
if (hasAssistantToolCall(message)) {
337337
return false;
338338
}
339-
const { text, hasNonTextContent } = resolveMessageText(message.content);
340-
if (hasNonTextContent) {
341-
return false;
342-
}
339+
const { text } = resolveMessageText(message.content);
343340
return stripHeartbeatToken(text, { mode: "heartbeat", maxAckChars: ackMaxChars }).shouldSkip;
344341
}
345342

0 commit comments

Comments
 (0)