← Back to Pull requests

chore(policy-engine): add crate scaffold, policy model, and RE2/glob helpers #4928

Open
unknown opened this pull request with 353 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 25, 2026 16:05 UTC
Author

Change summary

Adds the otel-arrow-dfe-policy-engine crate scaffold, opentelemetry.proto.policies.v1development Rust data model (aligned with OTEP 4738 and open-telemetry/opentelemetry-proto#865), and core RE2/glob/numeric helper functions.

This is PR 1 of the 6-PR incremental split from closed reference PR #4795:

1. This PR: Crate scaffold, policy model (model.rs), RE2 AST validation/compilation, glob matching, and i64/f64 comparison helpers.
2. Dense bitset pool and required n-gram string index (bitset.rs, string_index.rs).
3. OTAP Arrow accessors, SIMD predicate kernels, and RFC 8949 CBOR reader (otap_ops.rs, columnar.rs).
4. Filter engine (compile.rs, field_eval.rs, engine.rs).
5. 4-stage log transforms (transform.rs).
6. Criterion benchmarks (benches/engine.rs).

Key design choices in PR 1:

  • Zero new third-party crates: Relies on the workspace unsafe_code = "deny" lint and depends only on four crates already present in rust/otap-dataflow/Cargo.lock (memchr, regex-automata, regex-syntax, thiserror).

  • Strict RE2 compatibility: Validates patterns at the regex_syntax::ast::Ast level before translating directly to HIR (multi_line(false)), rejecting non-RE2 syntax (lookarounds, backreferences, (?x)/(?u)/(?R) flags, set operators, nested classes, \u/\U, non-RE2 Unicode binary properties or long names), rewriting \d/\w/\s/\b/\B to RE2 ASCII semantics and \p{^Name}/\P{^Name} to negated classes, and enforcing source length (4 KiB), nesting depth (64), Thompson NFA (256 KiB), and hybrid DFA cache (64 KiB) bounds.

  • Exact cross-type numeric comparisons & non-exponential globs: Compares i64 against f64 without losing precision above 2^53 and matches /? globs without exponential backtracking.

  • Temporary #![allow(dead_code)] in model.rs: Kept strictly to src/model.rs for crate-internal engine helpers (parse_re2_hir, compile_, matches_glob, cmp_, apply_regex_redaction) until downstream modules wire them up in PRs 2-5.
  • Related issue

  • Relates to #4726, #4718, #4738, and #4795
  • Validation

    Unit tests in crates/policy-engine/src/tests/model.rs cover i64/f64 precision boundaries, predicate ordering, capture-template redaction (including reusable Captures buffers), glob matching, constructors, RE2 syntax rejections, \p{^Name}/\P{^Name} negation, (?i)\w case-folding parity, NFA/length/depth bounds, and HIR translation across all 206 entries in RE2_UNICODE_GROUPS.

    User-facing changes

    None (internal library crate not yet wired into a dataflow processor node; chore PR title).

    Diff: 353 lines (+264 / -89) across 4 files Reviewer: dashpole Review duration: 7345m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 353 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.351
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4928"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.7% · Safe to merge
    22.7%