← Back to Pull requests

feat(rules): a scenario adds nodes to the shared network #104

Closed
unknown closed this pull request without merging on Nov 06, 2026 16:15 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 15:55 UTC
Author

Closes #103 (part of #35). This lands before #92's downstream migration.

Problem

A scenario's own Bayesian-network nodes, such as the gap a cut-in is staged at, belong in a rule file that lives with the scenario. Rule files could only be merged over one another (Rules.merged, Backend.use_rules), and a merge replaces silently. A scenario that reused a shared name would change the network every other scenario follows.

Changes

  • Rules.extended(added) adds added's nodes to these rules and replaces nothing. It refuses:

  • - a quantity both define;
    - an input both describe otherwise (default, or concept/unit);
    - taxonomies of different content.

    An added node may read the shared quantities and inputs.

  • Backend.add_rules(rules | path | None) holds a scenario's nodes and checks them when they are added.

  • - active_rules is the shared rules (a run's use_rules over them) extended by those nodes, joined once and cached.
    - use_rules checks that the scenario's nodes still add to the new shared rules.
  • docs/rules.md: new section "A scenario's nodes".
  • Tests

  • test_a_scenario_adds_nodes_to_the_shared_network covers:

  • - a node reading the shared grip, and a root;
    - the joined order and upstream;
    - sampling at quantiles;
    - refusing a redefined quantity and an input described otherwise.
  • test_a_backend_holds_a_scenarios_nodes covers:

  • - adding from a file;
    - the cache;
    - a run's rules over the shared ones keeping the scenario's nodes;
    - refusing a scenario that redefines a shared node (the earlier nodes are kept);
    - None dropping the nodes.
  • pytest passes locally (260 passed). The one mypy error in backend.py was there before this change.
  • ---
    _Generated by Claude Code_

    Diff: 227 lines (+170 / -57) across 2 files Reviewer: hakuturu583 Review duration: 19m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 227 lines diff across 2 files
    0.37
    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%
    60%
    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.325
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #104"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 36.9% (MEDIUM) · Higher = larger blast radius
    36.9%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 14.6% · Safe to merge
    14.6%