← Back to Pull requests

experiments/filterlang: enforce Request immutability via inferred const types #1702

Closed
unknown closed this pull request without merging on Nov 29, 2026 20:54 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 16:59 UTC
Author

Enforces immutability of Request (and other read-only host objects and nested collections) through experiments/filterlang's type system using purely inferred const qualifiers, without adding a surface-syntax const keyword or complicating the common case.

Summary of Changes


  • Inferred const type qualifier (types.go, unify.go): Added Const and internal inferred qualifier variables with canonical flattening (idempotent const, Nullable outermost, scalar value types bool/int/str/None collapsing automatically), transitive MakeConst, covariant T -> const T assignability without stripping const, and const-preserving Join/JoinConst.

  • Host-object & method capabilities (builtins.go, eval_builtins.go, value.go, eval.go): Added BuiltinMethod.Mutates (default false = read-only), HostField (Writable default false) with defensive nil-type guards, Builtins.RegisterField/Fields and RegisterType/Type, and an opt-in MutableHostObject runtime interface alongside read-only HostObject.

  • Parser & AST (ast.go, parser.go, scc.go, program.go): Added AttributeAssignStatement and IndexAssignStatement nodes so mutation attempts parse cleanly and reach the type checker, without adding any surface-syntax const keyword.

  • Type-checker enforcement (checker.go, narrowing.go, host.go): Both def handle(request): and def handle(request: Request) -> Action: (as well as annotated and unannotated helpers) infer mutability from usage across calls, return types, control flow, and nested loops. Mutating a value implies it must be mutable; passing read-only Request (or nested fields/collections) to mutating operations is rejected at compile time with plain-English caret-formatted diagnostics and hints.

  • Tests (const_test.go, updated test suites): Added unit tests covering Const unification/subtyping, parser support, inferred mutability across annotated and unannotated handle/helpers, nested host fields/collections, nested-loop widening, defensive nil-field guards, plain-English diagnostics, and runtime defense in depth.
  • Fixes #1693

    Diff: 269 lines (+201 / -68) across 3 files Reviewer: justinsb Review duration: 235m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 269 lines diff across 3 files
    0.39
    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.335
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1702"
    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: 39.4% (MEDIUM) · Higher = larger blast radius
    39.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: 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: 15.6% · Safe to merge
    15.6%