← Back to Pull requests

feat(Control/Monad): Weakest preconditions and mcvgen for free monads #604

Open
unknown opened this pull request with 186 lines diff across 2 files
View on GitHub
unknown unknown commented on May 28, 2026 05:31 UTC
Author

This PR adds Cslib/Foundations/Control/Monad/Free/WP.lean, which gives FreeM programs a Std.Do.WP interpretation by lifting logical handlers into the predicate-transformer monad PredTrans.

A logical handler {ι : Type u} → F ι → PredTrans ps ι assigns each operation of the effect signature F a PredTrans ps specification. Since PredTrans ps is a monad and FreeM is free, FreeM.liftM extends such a handler to a monad morphism FreeM F → PredTrans ps; this is the weakest precondition and is compositional wrt the monadic structure.

A FreeM.WP F ps typeclass selects a default handler for F and induces WP (FreeM F) ps and WPMonad (FreeM F) ps instances, so that Std.Do.Triple and mvcgen apply to FreeM F programs. The main coherence lemma is FreeM.liftM_wp_eq_wp_liftM, and FreeM.wp_lift exposes the one-operation case.

Handlers are provided for cslib's existing FreeState and FreeReader, along with @[spec] lemmas Spec.get_FreeState, Spec.set_FreeState, and Spec.read_FreeReader that let mvcgen step through state and reader programs.

CslibTests/FreeMonadWP.lean contains example Triples discharged by mvcgen, covering the supplied state and reader handlers, custom effects, combined effects, and demonic choice.

The design follows Vistrup, Sammler, Jung, Program Logics à la Carte (POPL 2025), which uses coinductive free monads (ITrees) and Iris separation logic. Here we use inductive free monads and Std.Do program logic.

Diff: 186 lines (+139 / -47) across 2 files Reviewer: tannerduve Review duration: 268541m
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.43) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 186 lines diff across 2 files
0.43
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%
40%
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
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.313
Real PR Conversation Timeline
1 comments
"Review active on #604"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 40.9% 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.8% (MEDIUM) · Higher = larger blast radius
42.8%
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: 40.9% · Lower = rushed or shallow review
40.9%
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: 25.2% · Safe to merge
25.2%