← Back to Pull requests

feat(rules): rule files extend others by path, URL or git source; exact load-time checks #28

Closed
unknown closed this pull request without merging on Oct 31, 2026 00:56 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 00:22 UTC
Author

Summary

This is a follow-up to #27, which was merged before its review fixes were pushed. It does two things:

1. Fixes the two load-time check bugs that Codex found in #27. They are in v0.15.0.
2. Lets a rule file extends other files, so a per-vehicle file only has to write what differs from a shared weather model.

🐛 Fixes from the #27 review

  • A coverage gap between sample points was missed. The checks read each input on an even grid only. Terms [0, 0, 33.3] and [33.3, 100, 100] leave 33.3 uncovered, yet the file loaded and then failed at run time. Terms are piecewise linear between their corners, so a gap (in coverage or in firing) starts and ends at a corner. The checks now also read every term corner and the midpoint between neighbouring points, which finds every such gap.

  • The firing check ignored its budget. It grew as 2^n past 15 inputs (25 inputs meant about 33 million evaluations). A rule base needing more than CHECK_LIMIT (one million) points is now refused immediately, with a message to split it.
  • Both cases have regression tests.

    ✨ extends

    # vehicles/mini.yaml
    version: 1
    extends: https://example.com/rules/base_weather.yaml   # or a list, merged in order
    quantities:
      tire_friction:
        rule_bases:
          water:
            rules: [...]        # replaced; the inputs come from base_weather.yaml
    

    | Reference | How it is read |
    |---|---|
    | ../base.yaml | relative to the file naming it (a local file, a URL, or a file in a git checkout), or an absolute path |
    | https://... | fetched by the host: Python's openodd.rules.fetch_url (urllib, 30 s timeout, 4 MB max) or the browser's fetch. http:// is refused |
    | {url, sha256} | same, refused unless the content has that digest |
    | {git, rev, path} | the existing git sources (cached per commit, $OPENODD_CACHE) |

  • Merging. A quantity, rule base or input that a later file names replaces the earlier one of that name. Quantities and rule bases merge field by field; inputs and a rule base's rules are replaced whole. null removes an entry.

  • Merge keys. <<: *anchor is now expanded, for sharing part of a mapping within one file.

  • Cycles. A file that extends itself, through any chain, is refused.

  • Checking. The merged set is checked as a whole, so an extending file does not need to be complete on its own.

  • Record. Rules.files lists every file read with its SHA-256, so a run can record exactly which rules it used.
  • API

  • Core: RuleSet::load / parse_with / load_over / parse_over / references. Resolution goes through a Fetch trait. Files reads local files and git sources and calls a host closure for URLs; Given takes files fetched in advance. The core gains no HTTP dependency, so it still builds for wasm.

  • Python:

  • - Rules.read(path or URL, fetch=) and Rules.from_text(text, source, base=, fetch=)
    - Rules.read_over() / text_over(): read a file that names only its changes over rules already in hand
    - Rules.files
    - Rules.merged() now merges deeply and can raise RulesError
    - Backend.use_rules() accepts a URL and reads the file over the backend's rules, so a run's file can be partial
  • WebAssembly:

  • - new RulesView(text, source, files), RulesView.references(), files()
    - merge() reads a partial file
    - loadRules(RulesView, url, {text}) in viewer.js fetches the whole extends chain. The rules.html editor uses it. Git sources can't be read in the browser and give an explicit error.

    ⚠️ Behaviour change

    Rules.merged() used to replace whole quantities; it now merges down to the rule base. A file that restates a whole quantity gets the same result as before. The only visible difference is that a rule base present only in the earlier file is now kept, where before it was dropped. Callers that relied on that should set it to null.

    ✅ Tests

  • cargo fmt --check, cargo clippy --workspace --all-features --all-targets -D warnings

  • cargo test --workspace: 95 core tests pass, including 11 new rule tests (relative paths, chained files, lists, cycles, URLs through the host, sha256 pins, a git source at a tag in a local repository, deep merge with null, merge keys, partial files over rules in hand, plus the two check regressions)

  • pytest: 180 passed, 4 skipped (5 new extends tests)

  • The view tests pass as WebAssembly in Node (wasm-bindgen-test-runner); cargo build -p openodd --no-default-features --target wasm32-unknown-unknown succeeds

  • Chromium (Playwright): loadRules follows vehicles/mini.yaml → sample_rules.yaml, giving grip 0.30–0.50 and inheriting visibility, with both files recorded. A missing file reports its URL and the 404. No page errors.
  • 📝 Docs

    docs/rules.md has a new "Extending a rule file" section and an updated "Checks" section. docs/wasm.md covers loadRules, references, files and the new constructor argument.

    Release: minor (new API).

    ---
    _Generated by Claude Code_

    Diff: 636 lines (+477 / -159) across 7 files Reviewer: hakuturu583 Review duration: 34m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 636 lines diff across 7 files
    0.50
    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.386
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #28"
    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: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    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: 21.8% · Safe to merge
    21.8%