← Back to Pull requests

[STF] exception_policy: an lvalue erased sink is viewed, not cloned, and an unhooked success passes unboxed #12000

Closed
unknown closed this pull request without merging on Oct 29, 2026 19:21 UTC
View on GitHub
unknown unknown commented on Oct 14, 2026 08:22 UTC
Author

Description

Stacked on #11967 (itself on #11889 and #11888; only the last commit here is new).

Behind exception_sink (type_erase), every guard cost about 18 ns per call on the success path, ten times the typed sink, and none of it was the virtual dispatch that erasure asks for. Two causes in the shell, both invisible to users of the API:

1. The sink was cloned on every call. __normalize returned every sink-tagged policy by value, so the erased sink handed to on_throw was copied, and exception_sink's copy constructor clones the boxed policy: one heap allocation and one deallocation per guarded call, however the sink was passed. An lvalue exception_sink now normalizes to a by-reference view (__erased_ref_t) that forwards the hook, the success channel and the entry gate. An rvalue is still moved in, so a sink built on every call keeps its one allocation, which is what building it costs.
2. The result was boxed for a hook that did not exist. The callable's result was put into std::any, passed through the virtual on_success(std::any) and unboxed with a type check, although the wrapped policy had no success hook. sink_base now records at erasure time whether the policy has one (has_success_hook, conservatively true for hand-written models), and the shell returns the value unboxed when it does not.

Behaviour is unchanged on every path. The remaining 2 to 3 ns over hand-written code is the virtual entry gate and the view.

Checklist


  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • 🤖 Generated with Claude Code

    Diff: 210 lines (+157 / -53) across 2 files Reviewer: caugonnet Review duration: 22259m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 210 lines diff across 2 files
    0.36
    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.320
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #12000"
    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.5% (MEDIUM) · Higher = larger blast radius
    36.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: 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.4% · Safe to merge
    14.4%
    Repository