88
99from . import agents , localio
1010from .run_transport import Assignment , WorkerAttempt , WorkerResult
11+ from .worker_failure import normalized_failure
1112
1213
1314def assignment_payload (assignments : list [Assignment ]) -> list [dict [str , object ]]:
@@ -38,6 +39,16 @@ def worker_payload(results: list[WorkerResult]) -> list[dict[str, object]]:
3839 entry ["failure_phase" ] = result .failure_phase
3940 if result .failure_kind is not None :
4041 entry ["failure_kind" ] = result .failure_kind
42+ if not result .ok :
43+ failure = normalized_failure (
44+ failure_phase = result .failure_phase ,
45+ failure_kind = result .failure_kind ,
46+ detail = result .detail ,
47+ timed_out = result .timed_out ,
48+ status = result .status ,
49+ )
50+ if failure is not None :
51+ entry ["failure" ] = failure .payload ()
4152 if result .transport_warning is not None :
4253 entry ["transport_warning" ] = dict (result .transport_warning )
4354 if result .thread_id is not None :
@@ -73,12 +84,15 @@ def worker_payload(results: list[WorkerResult]) -> list[dict[str, object]]:
7384 if result .endpoint_host is not None :
7485 entry ["endpoint_host" ] = result .endpoint_host
7586 if result .attempts :
76- entry ["attempts" ] = [_attempt_payload (attempt ) for attempt in result .attempts ]
87+ entry ["attempts" ] = [
88+ _attempt_payload (attempt , attempt_number = index )
89+ for index , attempt in enumerate (result .attempts , start = 1 )
90+ ]
7791 payload .append (entry )
7892 return payload
7993
8094
81- def _attempt_payload (attempt : WorkerAttempt ) -> dict [str , object ]:
95+ def _attempt_payload (attempt : WorkerAttempt , * , attempt_number : int ) -> dict [str , object ]:
8296 payload : dict [str , object ] = {
8397 "kind" : attempt .kind ,
8498 "worker" : attempt .worker ,
@@ -99,6 +113,17 @@ def _attempt_payload(attempt: WorkerAttempt) -> dict[str, object]:
99113 payload ["stdout_log" ] = attempt .stdout_log
100114 if attempt .stderr_log is not None :
101115 payload ["stderr_log" ] = attempt .stderr_log
116+ if not attempt .ok or attempt .failure_phase is not None or attempt .failure_kind is not None :
117+ failure = normalized_failure (
118+ failure_phase = attempt .failure_phase ,
119+ failure_kind = attempt .failure_kind ,
120+ detail = attempt .detail ,
121+ timed_out = attempt .timed_out ,
122+ status = "" ,
123+ attempt = attempt_number ,
124+ )
125+ if failure is not None :
126+ payload ["failure" ] = failure .payload ()
102127 return payload
103128
104129
0 commit comments