1616 sys .path .insert (0 , str (ROOT ))
1717
1818from prompting import agenticcoding_prompt
19- from runtime import APIModel
19+ from runtime import APIModel , fallback_binary_label
2020
2121
2222def read_jsonl (path : str | Path ) -> list [dict [str , Any ]]:
@@ -111,12 +111,24 @@ def normalize_result(value: Any) -> str:
111111 raise ValueError (f"invalid result value: { value !r} " )
112112
113113
114- def failed_check (check_id : str , reason : str ) -> dict [str , str ]:
115- return {"check_id" : check_id , "result" : "fail" , "reasoning" : reason }
114+ def fallback_check (check_id : str , reason : str , key : str = "" ) -> dict [str , str ]:
115+ result = "success" if fallback_binary_label (key or check_id ) else "fail"
116+ return {
117+ "check_id" : check_id ,
118+ "result" : result ,
119+ "reasoning" : f"{ reason } ; assigned uniformly random { result } label" ,
120+ }
116121
117122
118- def parse_checks (raw : str | None , expected : list [dict [str , Any ]]) -> list [dict [str , str ]]:
123+ def parse_checks (
124+ raw : str | None ,
125+ expected : list [dict [str , Any ]],
126+ fallback_prefix : str = "" ,
127+ ) -> list [dict [str , str ]]:
119128 expected_ids = [str (item ["check_id" ]) for item in expected ]
129+ def fallback (check_id : str , reason : str ) -> dict [str , str ]:
130+ key = f"{ fallback_prefix } ::{ check_id } " if fallback_prefix else check_id
131+ return fallback_check (check_id , reason , key )
120132 try :
121133 parsed = extract_json (raw or "" )
122134 values = parsed if isinstance (parsed , list ) else [parsed ]
@@ -133,16 +145,16 @@ def parse_checks(raw: str | None, expected: list[dict[str, Any]]) -> list[dict[s
133145 output = []
134146 for check_id in expected_ids :
135147 if check_id in duplicate :
136- output .append (failed_check (check_id , "duplicate check_id in judge output" ))
148+ output .append (fallback (check_id , "duplicate check_id in judge output" ))
137149 continue
138150 value = by_id .get (check_id )
139151 if value is None :
140- output .append (failed_check (check_id , "judge output omitted this check_id" ))
152+ output .append (fallback (check_id , "judge output omitted this check_id" ))
141153 continue
142154 try :
143155 result = normalize_result (value .get ("result" ))
144156 except ValueError as exc :
145- output .append (failed_check (check_id , str (exc )))
157+ output .append (fallback (check_id , str (exc )))
146158 continue
147159 output .append ({
148160 "check_id" : check_id ,
@@ -151,7 +163,7 @@ def parse_checks(raw: str | None, expected: list[dict[str, Any]]) -> list[dict[s
151163 })
152164 return output
153165 except Exception as exc :
154- return [failed_check (check_id , f"judge output could not be parsed: { exc } " ) for check_id in expected_ids ]
166+ return [fallback (check_id , f"judge output could not be parsed: { exc } " ) for check_id in expected_ids ]
155167
156168
157169def evaluate_case (case : dict [str , Any ], trajectory : dict [str , Any ], api : APIModel , batch_size : int , style : str , max_chars : int ) -> dict [str , Any ]:
@@ -165,9 +177,16 @@ def evaluate_case(case: dict[str, Any], trajectory: dict[str, Any], api: APIMode
165177 raw = api .generate_chat ([{"role" : "user" , "content" : prompt }], max_tokens = 1024 , temperature = 0.0 )
166178 except Exception as exc :
167179 raw = None
168- parsed = [failed_check (str (item ["check_id" ]), f"judge request failed: { exc } " ) for item in batch ]
180+ parsed = [
181+ fallback_check (
182+ str (item ["check_id" ]),
183+ f"judge request failed: { exc } " ,
184+ f"{ case ['instance_id' ]} ::{ item ['check_id' ]} " ,
185+ )
186+ for item in batch
187+ ]
169188 else :
170- parsed = parse_checks (raw , batch )
189+ parsed = parse_checks (raw , batch , fallback_prefix = str ( case [ "instance_id" ]) )
171190 evaluated .extend (parsed )
172191
173192 by_category : dict [str , dict [str , Any ]] = {}
0 commit comments