← Back to Pull requests

fix(rules): bugs fuzzing found in fits and distributions; property tests and a weekly fuzz #33

Closed
unknown closed this pull request without merging on Nov 03, 2026 06:07 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 04:29 UTC
Author

🔍 What

Property-based fuzzing of the rule fitting from #32 and of the distributions it fits. The fuzzing used Hypothesis in Python, plus randomized Rust tests through the editor's document. It found 11 bugs; this PR fixes them all. Each is kept as a unit test, and the properties now run in CI.

🐛 Bugs found and fixed

Distributions (src/rules.rs)

| Input | Symptom | Fix |
|---|---|---|
| Normal, mean 38 sd from its range (a fit can leave it so) | NaN quantile, cdf, pdf and mean: the mass underflowed | Truncated normal worked in logarithms (Truncated): an asymptotic tail series beyond z = 35, differences from their own series or Taylor's, a Newton inverse, and a value placed by its offset from the range's near end |
| Normal, a range 1e-6 wide, 153 sd away | cdf(quantile(p)) off by 1e-6 (mean + sd*z and the log differences cancelled) | Same |
| Normal, range starting 4 sd into the tail | quantile not monotone near the end | Taylor step for small offsets |
| Normal, a = -38 in the central case | quantile(0) NaN: inverse_phi's Halley step overflowed | Skip the step when it isn't finite |
| Triangular, low/mode tiny next to high | quantile below low, or falling as p rose (high - sqrt(...) cancelled) | Right branch computed from the mode up |
| Triangular, subnormal side | cdf 0/0 | Ratios rather than a product's quotient |

Fit (src/rules_fit.rs)

| Input | Symptom | Fix |
|---|---|---|
| One row on a triangular's end | The fit ended below the rules as written | End at the best of the fit, its start, and the rules as written |
| One row on a normal's end | The mean ran off the range, squeezing the distribution into a spike min_spread didn't stop | A normal's spread is its truncated one (interquartile range / 1.349) |
| Two max-joined parts tied at the row | The report wasn't the written file's log-likelihood: rounding flipped which part decides | The report describes the values as written |

Editor (crates/openodd-editor/src/rules_doc.rs)

| Input | Symptom | Fix |
|---|---|---|
| Small values | tidy kept digits after the point capped at 15, so 1e-14 kept one significant digit | 11 significant digits at any size |
| Values ≥ 1e15 | Written as huge integers the reader rejects | Written with an exponent |
| A distribution whose points an extended file gives | Written flat; a fit overwrote the base's points at 11 digits | DistDoc.shape keeps the nesting, and the base's points stay as written |

✅ Tests in CI

  • tests/test_rules_fit_properties.py (Hypothesis, derandomized in CI, about 2 s).

  • - What a fit promises: it never ends below the rules as written; held values don't move; the fitted file reads back alone and extending; the report matches the written file; everything stays finite.
    - Any rows, holds and JSON either work or fail with RulesError, never a panic.
    - Distributions: the quantile is monotone and inside the range, cdf undoes quantile, and summaries are finite.
    - Every case fuzzing found is kept as an @example.
    - Against the unfixed code, 5 of its 8 tests fail.
  • Rust unit tests for each bug.

  • Randomized Rust tests:

  • - random_distributions_read_everywhere (2000 seeds)
    - random_fits_round_trip_through_the_document: random fits written into the editor's document and read back (120 seeds)
  • .github/workflows/fuzz.yml: weekly and on demand, the same tests with random cases at length (OPENODD_FUZZ_EXAMPLES, default 3000; OPENODD_FUZZ_SEEDS, default 20000).
  • Locally:

  • cargo fmt --check, clippy (native and wasm32), and cargo test --workspace pass.

  • wasm builds pass, and pytest gives 210 passed, 4 skipped.

  • At fuzz scale:

  • - Python properties: 3 random rounds of 5000 examples.
    - Distributions: 200,000 Rust seeds.
    - Editor round trip: 20,000 seeds.

    ⚠️ Note

    min_spread for a normal now bounds its spread as truncated rather than its sd parameter. The two are the same unless the mean sits near or outside the range. The docs are updated.

    ---
    _Generated by Claude Code_

    Diff: 515 lines (+386 / -129) across 6 files Reviewer: hakuturu583 Review duration: 98m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 515 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.374
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #33"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.7% (MEDIUM) · Higher = larger blast radius
    47.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.6% · Safe to merge
    20.6%