@@ -680,8 +680,15 @@ def _metrics_payload(
680680) -> dict [str , Any ]:
681681 recorder_metrics = trace_recorder .metrics () if trace_recorder is not None else {}
682682 payload = {
683- "time_taken_seconds" : float (diagnosis_payload .get ("time_taken_seconds" ) or max (0.0 , (ended_at - started_at ).total_seconds ())),
684- "tool_calls_count" : len ((trace_recorder .tool_calls () if trace_recorder is not None else []) or diagnosis_payload .get ("tool_calls" ) or metadata .get ("tool_calls" ) or []),
683+ "time_taken_seconds" : float (
684+ diagnosis_payload .get ("time_taken_seconds" ) or max (0.0 , (ended_at - started_at ).total_seconds ())
685+ ),
686+ "tool_calls_count" : len (
687+ (trace_recorder .tool_calls () if trace_recorder is not None else [])
688+ or diagnosis_payload .get ("tool_calls" )
689+ or metadata .get ("tool_calls" )
690+ or []
691+ ),
685692 }
686693 for key in ("input_tokens" , "output_tokens" , "total_tokens" , "llm_call_count" ):
687694 if recorder_metrics .get (key ):
@@ -745,7 +752,9 @@ def _steps_from_tool_calls(tool_calls: Any) -> list[dict[str, Any]]:
745752 "name" : (item if isinstance (item , dict ) else {"tool" : str (item )}).get ("tool" )
746753 or (item if isinstance (item , dict ) else {}).get ("name" )
747754 or "tool" ,
748- "args" : (item if isinstance (item , dict ) else {}).get ("args" ) or (item if isinstance (item , dict ) else {}).get ("input" ) or {},
755+ "args" : (item if isinstance (item , dict ) else {}).get ("args" )
756+ or (item if isinstance (item , dict ) else {}).get ("input" )
757+ or {},
749758 }
750759 for index , item in enumerate (tool_calls , 1 )
751760 ]
@@ -756,9 +765,7 @@ def _final_diagnosis_step(diagnosis_payload: dict[str, Any], *, ended_at: dateti
756765 verdict = final .get ("verdict" ) or ("error" if final .get ("error" ) else "unknown" )
757766 fault_type = final .get ("fault_type" )
758767 location = final .get ("location" ) if isinstance (final .get ("location" ), dict ) else {}
759- location_text = ", " .join (
760- str (value ) for value in (location or {}).values () if value not in (None , "" )
761- )
768+ location_text = ", " .join (str (value ) for value in (location or {}).values () if value not in (None , "" ))
762769 parts = [f"Final diagnosis: { verdict } " ]
763770 if fault_type :
764771 parts .append (f"fault_type={ fault_type } " )
@@ -810,7 +817,9 @@ def _matching_result_row(result_rows: list[dict[str, Any]], index_row: dict[str,
810817 if row .get ("trace_id" ) == trace_id :
811818 return row
812819 for row in result_rows :
813- if row .get ("scenario_id" ) == index_row .get ("scenario_id" ) and row .get ("episode_id" ) == index_row .get ("episode_id" ):
820+ if row .get ("scenario_id" ) == index_row .get ("scenario_id" ) and row .get ("episode_id" ) == index_row .get (
821+ "episode_id"
822+ ):
814823 return row
815824 return None
816825
@@ -863,16 +872,16 @@ def _run_times(run_path: Path, index_rows: list[dict[str, Any]]) -> dict[str, st
863872 report_path = run_path / "report.json"
864873 if report_path .exists ():
865874 try :
866- summary = ( json .loads (report_path .read_text (encoding = "utf-8" )).get ("summary" ) or {})
875+ summary = json .loads (report_path .read_text (encoding = "utf-8" )).get ("summary" ) or {}
867876 if summary .get ("started_at" ) and summary .get ("completed_at" ):
868877 return {
869878 "started_at" : _normalise_iso_z (summary ["started_at" ]),
870879 "finished_at" : _normalise_iso_z (summary ["completed_at" ]),
871880 }
872881 except Exception :
873882 pass
874- starts = [row . get ( "started_at" ) for row in index_rows if row .get ("started_at" )]
875- ends = [row . get ( "ended_at" ) for row in index_rows if row .get ("ended_at" )]
883+ starts = [str ( value ) for row in index_rows if ( value := row .get ("started_at" ) )]
884+ ends = [str ( value ) for row in index_rows if ( value := row .get ("ended_at" ) )]
876885 now = _isoformat (datetime .now (UTC ))
877886 return {
878887 "started_at" : _normalise_iso_z (min (starts ) if starts else now ),
0 commit comments