Skip to content

Commit e4eafaf

Browse files
committed
fix: heartbeat filter ignores reasoning/thinking blocks in HEARTBEAT_OK detection
Fixes #95796
1 parent 0fed640 commit e4eafaf

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ describe("isHeartbeatOkResponse", () => {
124124
expect(isHeartbeatOkResponse(toolCallOnlyMessage)).toBe(false);
125125
});
126126

127+
it("matches HEARTBEAT_OK when message contains reasoning/thinking blocks", () => {
128+
expect(
129+
isHeartbeatOkResponse({
130+
role: "assistant",
131+
content: [
132+
{ type: "reasoning", text: "Checking heartbeat status..." },
133+
{ type: "text", text: "HEARTBEAT_OK" },
134+
],
135+
}),
136+
).toBe(true);
137+
138+
expect(
139+
isHeartbeatOkResponse({
140+
role: "assistant",
141+
content: [
142+
{ type: "thinking", text: "No tasks to report." },
143+
{ type: "text", text: "HEARTBEAT_OK" },
144+
],
145+
}),
146+
).toBe(true);
147+
});
148+
149+
it("rejects long responses with reasoning blocks that exceed ackMaxChars", () => {
150+
expect(
151+
isHeartbeatOkResponse(
152+
{
153+
role: "assistant",
154+
content: [
155+
{ type: "reasoning", text: "Checking tasks..." },
156+
{ type: "text", text: "You have 200 unread emails. HEARTBEAT_OK. Additionally there are calendar alerts pending." },
157+
],
158+
},
159+
300,
160+
),
161+
).toBe(false);
162+
});
163+
127164
it("respects ackMaxChars overrides", () => {
128165
expect(
129166
isHeartbeatOkResponse(

‎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)