@@ -135,6 +135,51 @@ describe("isHeartbeatOkResponse", () => {
135135 ) ,
136136 ) . toBe ( false ) ;
137137 } ) ;
138+
139+ it ( "matches heartbeat acks that include reasoning blocks" , ( ) => {
140+ // Model-internal reasoning blocks should not prevent heartbeat filtering.
141+ expect (
142+ isHeartbeatOkResponse ( {
143+ role : "assistant" ,
144+ content : [
145+ { type : "thinking" , thinking : "Checking for new tasks..." } ,
146+ { type : "text" , text : "HEARTBEAT_OK" } ,
147+ ] ,
148+ } ) ,
149+ ) . toBe ( true ) ;
150+
151+ expect (
152+ isHeartbeatOkResponse ( {
153+ role : "assistant" ,
154+ content : [
155+ { type : "reasoning" , reasoning : "Nothing to do" } ,
156+ { type : "text" , text : "HEARTBEAT_OK" } ,
157+ ] ,
158+ } ) ,
159+ ) . toBe ( true ) ;
160+
161+ expect (
162+ isHeartbeatOkResponse ( {
163+ role : "assistant" ,
164+ content : [
165+ { type : "redacted_thinking" , data : "redacted..." } ,
166+ { type : "text" , text : "HEARTBEAT_OK" } ,
167+ ] ,
168+ } ) ,
169+ ) . toBe ( true ) ;
170+ } ) ;
171+
172+ it ( "does not match heartbeat when reasoning is mixed with non-text content" , ( ) => {
173+ expect (
174+ isHeartbeatOkResponse ( {
175+ role : "assistant" ,
176+ content : [
177+ { type : "thinking" , thinking : "Checking..." } ,
178+ { type : "tool_use" , id : "tool-1" , name : "search" , input : { } } ,
179+ ] ,
180+ } ) ,
181+ ) . toBe ( false ) ;
182+ } ) ;
138183} ) ;
139184
140185describe ( "filterHeartbeatTranscriptArtifacts" , ( ) => {
@@ -189,6 +234,30 @@ describe("filterHeartbeatTranscriptArtifacts", () => {
189234 }
190235 } ) ;
191236
237+ it ( "removes heartbeat pairs where the assistant response includes reasoning blocks" , ( ) => {
238+ const messages = [
239+ { role : "user" , content : "Hello" } ,
240+ { role : "assistant" , content : "Hi there!" } ,
241+ { role : "user" , content : HEARTBEAT_PROMPT } ,
242+ {
243+ role : "assistant" ,
244+ content : [
245+ { type : "thinking" , thinking : "Checking for due tasks..." } ,
246+ { type : "text" , text : "HEARTBEAT_OK" } ,
247+ ] ,
248+ } ,
249+ { role : "user" , content : "What time is it?" } ,
250+ { role : "assistant" , content : "It is 3pm." } ,
251+ ] ;
252+
253+ expect ( filterHeartbeatTranscriptArtifacts ( messages , undefined , HEARTBEAT_PROMPT ) ) . toEqual ( [
254+ { role : "user" , content : "Hello" } ,
255+ { role : "assistant" , content : "Hi there!" } ,
256+ { role : "user" , content : "What time is it?" } ,
257+ { role : "assistant" , content : "It is 3pm." } ,
258+ ] ) ;
259+ } ) ;
260+
192261 it ( "removes prompt-only interrupted heartbeat spans" , ( ) => {
193262 const messages = [
194263 { role : "user" , content : HEARTBEAT_TRANSCRIPT_PROMPT } ,
0 commit comments