Skip to content

Commit 468bfc2

Browse files
committed
fix(heartbeat): recognize HEARTBEAT_OK through reasoning blocks (fixes #95796)
1 parent ceb6922 commit 468bfc2

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

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

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

127+
it("recognizes heartbeat OK acknowledgements paired with reasoning blocks", () => {
128+
expect(
129+
isHeartbeatOkResponse({
130+
role: "assistant",
131+
content: [
132+
{ type: "reasoning", reasoning: "Checking system 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", thinking: "Let me verify." },
143+
{ type: "text", text: "HEARTBEAT_OK" },
144+
],
145+
}),
146+
).toBe(true);
147+
});
148+
127149
it("respects ackMaxChars overrides", () => {
128150
expect(
129151
isHeartbeatOkResponse(

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ function matchesHeartbeatPromptText(text: string, prompt: string | undefined): b
254254
return Boolean(normalized) && (text === normalized || text.startsWith(`${normalized}\n`));
255255
}
256256

257-
function resolveMessageText(content: unknown): { text: string; hasNonTextContent: boolean } {
257+
const REASONING_BLOCK_TYPES = new Set(["reasoning", "thinking"]);
258+
259+
function resolveMessageText(
260+
content: unknown,
261+
options?: { allowReasoningBlocks?: boolean },
262+
): { text: string; hasNonTextContent: boolean } {
258263
if (typeof content === "string") {
259264
return { text: content, hasNonTextContent: false };
260265
}
@@ -269,6 +274,9 @@ function resolveMessageText(content: unknown): { text: string; hasNonTextContent
269274
continue;
270275
}
271276
if (block.type !== "text" && block.type !== "input_text" && block.type !== "output_text") {
277+
if (options?.allowReasoningBlocks && REASONING_BLOCK_TYPES.has(block.type as string)) {
278+
continue;
279+
}
272280
hasNonTextContent = true;
273281
continue;
274282
}
@@ -336,7 +344,9 @@ export function isHeartbeatOkResponse(
336344
if (hasAssistantToolCall(message)) {
337345
return false;
338346
}
339-
const { text, hasNonTextContent } = resolveMessageText(message.content);
347+
const { text, hasNonTextContent } = resolveMessageText(message.content, {
348+
allowReasoningBlocks: true,
349+
});
340350
if (hasNonTextContent) {
341351
return false;
342352
}

0 commit comments

Comments
 (0)