From 5015b2d6bbfb2a3b3667444763f5a775675cac2c Mon Sep 17 00:00:00 2001 From: furiosa Date: Tue, 21 Jul 2026 22:47:27 +0000 Subject: [PATCH] ps-pdb-03-lookup-assert: replace runtime assert! with debug_assert! and total_cmp Replaces the release-mode assert! on the recomputed largest edge in pattern-database lookup.rs with debug_assert!, so a corrupt or drifted catalog cannot panic release callers. Also replaces the partial_cmp .expect() with total_cmp, which is deterministic on NaN and never panics. Closes ps-pdb-03-lookup-assert. --- crates/pattern-database/src/lookup.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/pattern-database/src/lookup.rs b/crates/pattern-database/src/lookup.rs index 28f0bd0..99de55c 100644 --- a/crates/pattern-database/src/lookup.rs +++ b/crates/pattern-database/src/lookup.rs @@ -118,8 +118,14 @@ impl PatternDatabase { idx += 1; } } - edges.sort_by(|a, b| a.partial_cmp(b).expect("edge angle must be comparable")); - assert!( + // `total_cmp` is deterministic on NaN and never panics; NaN edges will + // simply fail the ratio-band test below and be skipped in release. + edges.sort_by(|a, b| a.total_cmp(b)); + // This is an internal consistency check: the largest edge recomputed from + // the catalog vectors should match the value stored at build time. Keep it + // as a debug-only assertion so a corrupt/drifted catalog cannot crash + // release callers. + debug_assert!( (edges[5] - catalog_largest).abs() < 1e-12, "largest edge mismatch" );