@@ -523,6 +523,15 @@ def display(
523523 fn ("\n " )
524524
525525
526+ def _output_sequence_to_str (output_sequence : str | list [str ]) -> str | None :
527+ if isinstance (output_sequence , list ):
528+ return "" .join (output_sequence )
529+ elif isinstance (output_sequence , str ):
530+ return output_sequence
531+ else :
532+ return None
533+
534+
526535def output_sequence_from_data (
527536 data_bytes : bytes ,
528537 join_chunks : bool = True ,
@@ -553,51 +562,37 @@ def output_sequence_from_data(
553562 logging .warning ("Failed to decode data bytes" )
554563 return None , None
555564
556- output_sequence = None
557- reasoning_sequence = None
558-
565+ output , reasoning = None , None
559566 if isinstance (decoded_data , str ):
560567 # If decoded value is a string, it's the output sequence
561- output_sequence = decoded_data
568+ output = decoded_data
562569 elif isinstance (decoded_data , dict ):
563570 # If decoded value is a dict, extract 'output' and optionally 'reasoning'
564571 if "output" not in decoded_data :
565572 logging .warning ("Dictionary data missing required 'output' key" )
566573 return None , None
567574
568575 # Extract output - can be string or list of strings
569- output = decoded_data ["output" ]
570- if isinstance (output , list ):
571- if join_chunks :
572- output_sequence = "" .join (output )
573- else :
574- output_sequence = output
575- elif isinstance (output , str ):
576- output_sequence = output
577- else :
576+ output = (
577+ _output_sequence_to_str (decoded_data ["output" ])
578+ if join_chunks
579+ else decoded_data ["output" ]
580+ )
581+ if output is None :
578582 logging .warning (f"Output field has unexpected type: { type (output )} " )
579583 return None , None
580584
581585 # Extract reasoning if present - can be string or list of strings
582586 if "reasoning" in decoded_data :
583- reasoning = decoded_data ["reasoning" ]
584- if isinstance (reasoning , list ):
585- if join_chunks :
586- reasoning_sequence = "" .join (reasoning )
587- else :
588- reasoning_sequence = reasoning
589- elif isinstance (reasoning , str ):
590- reasoning_sequence = reasoning
591- else :
592- logging .warning (
593- f"Reasoning field has unexpected type: { type (reasoning )} "
594- )
595- # Continue with output_sequence, reasoning is optional
587+ reasoning = (
588+ _output_sequence_to_str (decoded_data ["reasoning" ])
589+ if join_chunks
590+ else decoded_data ["reasoning" ]
591+ )
596592 else :
597593 logging .warning (f"Decoded data has unexpected type: { type (decoded_data )} " )
598594 return None , None
599-
600- return output_sequence , reasoning_sequence
595+ return output , reasoning
601596
602597
603598class MetricsReporter :
@@ -664,7 +659,8 @@ def stop_performance_tracking_timestamp_ns(self) -> float:
664659 """Returns the timestamp_ns of the STOP_PERFORMANCE_TRACKING event.
665660
666661 This method is cached to prevent re-derivation. If the event is not found,
667- returns positive infinity.
662+ returns positive infinity, since this indicates that the performance run is probably still
663+ running, or the test was killed before it could complete.
668664
669665 Returns:
670666 float: The timestamp_ns of STOP_PERFORMANCE_TRACKING event, or float('inf') if not found.
@@ -677,6 +673,9 @@ def stop_performance_tracking_timestamp_ns(self) -> float:
677673 """ ).fetchone ()
678674
679675 if result is None :
676+ logging .warning (
677+ "No STOP_PERFORMANCE_TRACKING event found, performance run not yet complete"
678+ )
680679 return float ("inf" )
681680 return float (result [0 ])
682681
0 commit comments