@@ -226,9 +226,11 @@ impl EvaluationRunHistoryItem {
226226 }
227227
228228 fn pass_rate_basis ( & self ) -> usize {
229- ( self . passed_count * 10_000 )
230- . checked_div ( self . total_count )
231- . unwrap_or ( 0 )
229+ if self . total_count == 0 {
230+ return 0 ;
231+ }
232+ let basis = ( self . passed_count as u128 * 10_000 ) / self . total_count as u128 ;
233+ basis. min ( usize:: MAX as u128 ) as usize
232234 }
233235
234236 pub fn matches_filter ( & self , filter : EvaluationRunHistoryFilter ) -> bool {
@@ -1071,11 +1073,19 @@ fn evaluation_case_statuses(
10711073) -> Result < Vec < EvaluationCaseStatus > , String > {
10721074 cases
10731075 . iter ( )
1074- . map ( |case| match EvaluationCaseStatus :: from_wire ( & case. status ) {
1075- EvaluationCaseStatus :: Unknown ( status) => Err ( format ! (
1076- "invalid fidelity suite: unknown case status {status:?}"
1077- ) ) ,
1078- status => Ok ( status) ,
1076+ . map ( |case| {
1077+ if case. index . checked_add ( 1 ) . is_none ( ) {
1078+ return Err ( format ! (
1079+ "invalid fidelity suite: case index {} cannot be displayed one-based" ,
1080+ case. index
1081+ ) ) ;
1082+ }
1083+ match EvaluationCaseStatus :: from_wire ( & case. status ) {
1084+ EvaluationCaseStatus :: Unknown ( status) => Err ( format ! (
1085+ "invalid fidelity suite: unknown case status {status:?}"
1086+ ) ) ,
1087+ status => Ok ( status) ,
1088+ }
10791089 } )
10801090 . collect ( )
10811091}
@@ -1272,6 +1282,14 @@ fn compare_evaluation_runs(
12721282 }
12731283}
12741284
1285+ fn signed_usize_delta ( current : usize , previous : usize ) -> isize {
1286+ if current >= previous {
1287+ current. saturating_sub ( previous) . min ( isize:: MAX as usize ) as isize
1288+ } else {
1289+ -( previous. saturating_sub ( current) . min ( isize:: MAX as usize ) as isize )
1290+ }
1291+ }
1292+
12751293#[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
12761294pub struct TraceSummary {
12771295 pub total : usize ,
@@ -2153,10 +2171,10 @@ impl TraceStore {
21532171 previous_trace_id : previous. trace_id ,
21542172 current_failed_count,
21552173 previous_failed_count,
2156- failed_delta : current_failed_count as isize - previous_failed_count as isize ,
2174+ failed_delta : signed_usize_delta ( current_failed_count, previous_failed_count) ,
21572175 current_pass_rate,
21582176 previous_pass_rate,
2159- pass_rate_delta_points : current_pass_rate as isize - previous_pass_rate as isize ,
2177+ pass_rate_delta_points : signed_usize_delta ( current_pass_rate, previous_pass_rate) ,
21602178 action : current. action . clone ( ) ,
21612179 } ) ;
21622180 }
@@ -3209,6 +3227,47 @@ mod tests {
32093227 assert ! ( errors[ 0 ] . message. contains( "SKIPPED" ) ) ;
32103228 }
32113229
3230+ #[ test]
3231+ fn rejects_case_index_that_cannot_be_displayed_one_based ( ) {
3232+ let mut store = TraceStore :: new ( 10 ) ;
3233+ let run = store. begin_with_action (
3234+ "Running master-huineng fidelity" ,
3235+ TraceAction :: FidelityDryRunSkill {
3236+ slug : "huineng" . to_string ( ) ,
3237+ } ,
3238+ Some ( "python3 scripts/test-fidelity.py --master master-huineng --json" ) ,
3239+ "Queued." ,
3240+ ) ;
3241+ store. finish_success_with_detail (
3242+ run,
3243+ "master-huineng fidelity finished" ,
3244+ format ! (
3245+ r#"[{{
3246+ "schema_version": 1,
3247+ "master": "master-huineng",
3248+ "mode": "graded",
3249+ "outcome": "completed",
3250+ "total": 1,
3251+ "passed": 1,
3252+ "failed": 0,
3253+ "results": [
3254+ {{"index": {}, "question": "overflow", "status": "PASS"}}
3255+ ]
3256+ }}]"# ,
3257+ usize :: MAX
3258+ ) ,
3259+ Duration :: from_millis ( 50 ) ,
3260+ ) ;
3261+
3262+ let errors = store. records . back ( ) . unwrap ( ) . evaluation_errors ( ) ;
3263+ assert_eq ! ( errors. len( ) , 1 ) ;
3264+ assert_eq ! (
3265+ errors[ 0 ] . kind,
3266+ EvaluationEvidenceErrorKind :: MalformedPayload
3267+ ) ;
3268+ assert ! ( errors[ 0 ] . message. contains( "index" ) ) ;
3269+ }
3270+
32123271 #[ test]
32133272 fn rejects_evaluation_payload_for_wrong_skill_scope ( ) {
32143273 let mut store = TraceStore :: new ( 10 ) ;
@@ -4139,6 +4198,24 @@ mod tests {
41394198 ) ;
41404199 }
41414200
4201+ #[ test]
4202+ fn pass_rate_calculation_handles_large_legacy_counts ( ) {
4203+ let item = EvaluationRunHistoryItem {
4204+ trace_id : 1 ,
4205+ scope : "master-huineng" . to_string ( ) ,
4206+ status : TraceStatus :: Succeeded ,
4207+ passed_count : usize:: MAX ,
4208+ total_count : usize:: MAX ,
4209+ failed_count : 0 ,
4210+ mode : EvaluationMode :: Graded ,
4211+ duration_ms : None ,
4212+ action : None ,
4213+ trend : EvaluationRunTrend :: New ,
4214+ } ;
4215+
4216+ assert_eq ! ( item. pass_rate_percent( ) , 100 ) ;
4217+ }
4218+
41424219 #[ test]
41434220 fn annotates_evaluation_run_history_with_scope_trends ( ) {
41444221 let mut store = TraceStore :: new ( 10 ) ;
@@ -4808,6 +4885,47 @@ mod tests {
48084885 ) ;
48094886 }
48104887
4888+ #[ test]
4889+ fn saturates_large_legacy_regression_deltas ( ) {
4890+ let mut store = TraceStore :: new ( 10 ) ;
4891+ let old_run = store. begin_with_action (
4892+ "Running master-huineng fidelity" ,
4893+ TraceAction :: FidelityDryRunSkill {
4894+ slug : "huineng" . to_string ( ) ,
4895+ } ,
4896+ Some ( "legacy fidelity" ) ,
4897+ "Queued." ,
4898+ ) ;
4899+ store. finish_success_with_detail (
4900+ old_run,
4901+ "legacy fidelity finished" ,
4902+ "Testing: master-huineng\n Result: 0/1 passed (0%)" ,
4903+ Duration :: from_millis ( 50 ) ,
4904+ ) ;
4905+ let new_run = store. begin_with_action (
4906+ "Running master-huineng fidelity" ,
4907+ TraceAction :: FidelityDryRunSkill {
4908+ slug : "huineng" . to_string ( ) ,
4909+ } ,
4910+ Some ( "legacy fidelity" ) ,
4911+ "Queued." ,
4912+ ) ;
4913+ store. finish_success_with_detail (
4914+ new_run,
4915+ "legacy fidelity finished" ,
4916+ format ! (
4917+ "Testing: master-huineng\n Result: 0/{} passed (0%)" ,
4918+ usize :: MAX
4919+ ) ,
4920+ Duration :: from_millis ( 50 ) ,
4921+ ) ;
4922+
4923+ let regressions = store. evaluation_regressions ( 8 ) ;
4924+
4925+ assert_eq ! ( regressions. len( ) , 1 ) ;
4926+ assert_eq ! ( regressions[ 0 ] . failed_delta, isize :: MAX ) ;
4927+ }
4928+
48114929 #[ test]
48124930 fn persists_trace_history_and_next_record_id ( ) {
48134931 let path = temp_path ( "trace-history" ) ;
0 commit comments