Skip to content

perturbation-sim: NaN/panic hardening sweep (total_cmp + cascade NaN-abort + stats guard) before the kanban/jitson wiring#554

Merged
AdaWorldAPI merged 2 commits into
mainfrom
claude/perturbation-sim-nan-hardening
Jun 19, 2026
Merged

perturbation-sim: NaN/panic hardening sweep (total_cmp + cascade NaN-abort + stats guard) before the kanban/jitson wiring#554
AdaWorldAPI merged 2 commits into
mainfrom
claude/perturbation-sim-nan-hardening

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Foundation-hardening on perturbation-sim before the kanban ↔ Lance-subscription ↔ jitson loop rides on it. Disk-light — no cranelift/ndarray build touched (default build only).

What it fixes

  • NaN-panic ("speaking errors"): 20 partial_cmp(...).unwrap() sites across 14 example filesf64::total_cmp (never panics, deterministic NaN order). The lib src/ had none in non-test code — the foundation wasn't panicking; this hardens the example/probe surface.
  • Cascade NaN-abort (the "timeout for NaN"): simulate_outage now breaks if any theta/flow value is non-finite (same style as the islanding break) — a NaN can neither propagate into the perturbation shape nor spin to max_rounds.
  • stats.rs empty-slice guard: mean/pop_var returned 0/0 = NaN on an empty slice. Currently unreachable (all callers validate len ≥ 2) but wired at the source so a future caller can't leak it.
  • NaN-source audit (src/): eigen, flow, perturbation, resilience, rolling_floor float producers were checked — all already guarded (SPECTRAL_GAP_FLOOR / rel_tol / .max(eps) / filter). Verified, no change needed.

Gates

  • clippy --all-targets: zero warnings (default build, cranelift-free).
  • cargo-machete: not installed in env; manual audit — the only declared dep is the optional, feature-gated ndarray (not removed; it's behind ndarray-simd).
  • 95 lib tests pass.

Branched off main pre-#553; the 18 files are pre-existing examples + cascade.rs + stats.rs that #553 never touched, so it merges cleanly onto the post-#553 main.

🤖 Generated with Claude Code


Generated by Claude Code

…e NaN-abort, stats empty-guard

Foundation-hardening before the kanban↔Lance↔jitson wiring rides on it.

- NaN-panic fix: 20 `partial_cmp(...).unwrap()` sites across 14 example files
  replaced with `f64::total_cmp` (never panics; deterministic NaN order). The
  lib `src/` had none in non-test code — the foundation was not panicking; this
  hardens the example/probe surface (the "speaking errors").
- Cascade NaN-abort: `simulate_outage` now breaks if any `theta`/`flow` value is
  non-finite (matching the islanding-break style) — a NaN can neither propagate
  into the perturbation shape nor loop to max_rounds. The "timeout for NaN".
- stats.rs: empty-slice guard on `mean`/`pop_var` (0/0 = NaN). Currently
  unreachable (all callers validate len ≥ 2) but wired at the source so a future
  caller can't leak it.
- NaN-source audit (src/): eigen, flow, perturbation, resilience, rolling_floor
  float producers all already guarded (SPECTRAL_GAP_FLOOR / rel_tol / .max(eps)
  / filter) — verified, no change needed.
- clippy --all-targets: zero warnings (default build, no ndarray-simd/cranelift).
  cargo-machete: not installed; only dep is the optional feature-gated ndarray.
- 95 lib tests pass.

Disk-light: no cranelift/ndarray build touched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CcpLeEC3XK8Eye53GKBVvi
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AdaWorldAPI, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca2b5c3e-de62-43e1-ba6e-72e923c39b63

📥 Commits

Reviewing files that changed from the base of the PR and between 2e84972 and ebd2468.

📒 Files selected for processing (18)
  • crates/perturbation-sim/examples/buffer.rs
  • crates/perturbation-sim/examples/calibrate.rs
  • crates/perturbation-sim/examples/explore.rs
  • crates/perturbation-sim/examples/hhtl_levels.rs
  • crates/perturbation-sim/examples/hhtl_resident.rs
  • crates/perturbation-sim/examples/iberian.rs
  • crates/perturbation-sim/examples/meta_hops.rs
  • crates/perturbation-sim/examples/modifier_validity.rs
  • crates/perturbation-sim/examples/reinforce.rs
  • crates/perturbation-sim/examples/resilience.rs
  • crates/perturbation-sim/examples/rolling_floor.rs
  • crates/perturbation-sim/examples/scorecard.rs
  • crates/perturbation-sim/examples/simulate.rs
  • crates/perturbation-sim/examples/validate.rs
  • crates/perturbation-sim/examples/validate_mediators.rs
  • crates/perturbation-sim/examples/weakest_links.rs
  • crates/perturbation-sim/src/cascade.rs
  • crates/perturbation-sim/src/stats.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 657f0fb3bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/perturbation-sim/src/cascade.rs Outdated
// NaN guard: a non-finite angle/flow signals numerical failure; treat
// as terminal (matching the islanding-break style) so NaN cannot
// propagate into the output shape or keep the loop alive.
if theta.iter().any(|x| !x.is_finite()) || flow.iter().any(|x| !x.is_finite()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid returning the non-finite state after aborting

When this new guard fires (for example after a solver failure or large finite inputs that overflow dc_flows), theta and/or flow are already the non-finite vectors assigned above. The break then falls through to build node_field and edge_field from those same values at lines 168–172, so the advertised NaN-abort still returns NaN/Inf in the perturbation shape and downstream rankings/statistics can be corrupted. Preserve the last finite state or sanitize/return an error before constructing the shape.

Useful? React with 👍 / 👎.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

…pe (codex #554 P2)

The previous guard broke the loop on a non-finite theta/flow, but the shape was
then built from those SAME non-finite values (node_field/edge_field at the
build step) — so the "abort" still leaked NaN/Inf into the perturbation shape
and downstream rankings/stats.

Fix: seed theta/flow with the finite base state and overwrite them each round
ONLY after the new values are confirmed finite (theta_next/flow_next). A
non-finite round now breaks WITHOUT adopting it, so theta/flow/components_final
retain the last finite state and the shape is built from that — never from
NaN/Inf. Matches the islanding-break semantics (which already left a finite
proxy).

New test perturbation_shape_is_always_finite locks the invariant across all
terminal paths (converge / cascade / island); islanding_is_flagged also now
asserts finite shape. clippy --all-targets clean; cascade suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CcpLeEC3XK8Eye53GKBVvi
@AdaWorldAPI AdaWorldAPI merged commit 5d1c6b9 into main Jun 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants