Quest 01 / 02 · Capstone
Build a two-model patch review workbench with Semgrep, Pydantic AI and MLflow
- static analysis
- structured LLM outputs
- LLM-as-a-judge evaluation
- experiment tracking
- reactive Python apps
- diff parsing
- CI regression testing
Why now Factory reported different Terminal-Bench 4 completion rates across coding agent setups running the same model. A separate 33-pairing study found a two-model judge panel matched human votes on seven of eight clear calls and left 21 for people. This build applies that abstention design to Python patches with Semgrep and logs open traces in MLflow to follow Hugging Face's guide on inspectable evaluation.
Build it You will build a local Python review service that scans candidate patches with Semgrep Community Edition before requesting typed Pydantic AI verdicts from two distinct Ollama models. Matching verdicts resolve automatically while judge disagreements enter a reactive marimo triage queue. A local MLflow server stores every review prompt alongside its execution trace and accuracy score.
From the news
- Coding agents are growing up at the review desk 2026-11-24 · source
- A second model improved a small LLM judging panel 2026-11-26 · source
- Factory reports different completion rates across coding harnesses 2026-11-23 · source
- Hugging Face publishes a guide to agent evaluation 2026-11-23 · source
- Semgrep makes the engine and service distinction matter 2026-11-25 · source
- MLflow keeps experiment records beside application traces 2026-11-25 · source
Tools
- Semgrep
The Community Edition engine uses LGPL-2.1. The AppSec Platform combines commercial analysis and proprietary rules with free and paid hosted plans; AI credits and contributor limits depend on the plan.
- Ollama
Ollama's runtime uses the MIT license, while model weights have their own licenses. Local execution has no Ollama usage charge; optional cloud inference uses metered credits, subscriptions and enterprise terms.
- Pydantic AI
Pydantic AI uses the MIT license and is free to use. Model providers, deployment infrastructure and optional Pydantic commercial services have separate terms and costs.
- MLflow
The MLflow project is free Apache 2.0 software and can run on a local server. Managed hosting, storage and external model calls have separate charges.
- marimo
The local marimo notebook is free Apache 2.0 software. Hosted products, optional assistants and remote data services have separate terms; their paid entitlements are not established here.
Data
- CTSSB-1M Dataset Kaggle
Supplies single-statement Python bug fixes so the workbench can test whether Semgrep and both judges distinguish broken lines from clean repairs.
- 136K Python Problems: Pass/Fail Code Benchmark Kaggle
Provides pass-and-fail Python coding problems across difficulty tiers for measuring workflow completion rates and two-model judge agreement.
- Who Writes AI Code? 1.3M Open-Source AI Commits Kaggle
Supplies open-source commit histories with AI coding-agent labels to calibrate metadata risk signals and stratify review load by authorship cohort.
Milestones
Reproducible patch and commit benchmark splits
- Download all three Kaggle datasets, inspect their folder layouts and column headers with pandas, and document the schema before writing loader code.
- Sample 2,000 paired buggy and fixed Python snippets from CTSSB-1M and construct unified diffs so each row carries a ground-truth verdict.
- Draw a stratified sample of 1,000 items across difficulty tiers from the 136K Python Problems set and write seeded training, validation and test splits.
- Aggregate commit metadata from the AI-commits dataset by repository and authorship label, then run a verification script confirming zero identifier overlap across splits.
Local Semgrep rules and typed dual-judge core
- Install Semgrep Community Edition locally and run its open Python ruleset on a CTSSB-1M sample to capture baseline static findings as JSON.
- Start Ollama locally and pull two distinct open-weight coding models from separate families so the panel avoids identical single-model failure modes.
- Define a Pydantic AI response schema requiring an approve or reject or abstain verdict alongside cited line numbers and a plain-text defect note.
- Connect the orchestration loop so each patch runs Semgrep first, queries both Ollama judges independently, and emits an abstain status whenever they disagree.
Workflow comparisons and trace logging in MLflow
- Launch a local MLflow tracking server and log dataset split hashes alongside the Semgrep rule version and exact Ollama model tags.
- Build two distinct review workflows that keep both Ollama models fixed while varying diff context width and whether Semgrep findings appear in the prompt.
- Execute both workflows across the validation split and log per-patch traces, judge latency, schema retry counts and unanimous-call accuracy to MLflow.
- Compare single-judge baselines against the two-model abstention panel in MLflow to measure how precision rises when uncertain patches route to people.
Reactive human triage app in marimo
- Persist every review outcome alongside Semgrep findings and both judge rationales in a local SQLite ledger indexed by patch identifier and run.
- Build a reactive marimo notebook that queries SQLite for abstained patches and renders each unified diff beside both model explanations.
- Add form controls in marimo so a reviewer records an authoritative verdict and error tag, writing corrections straight back into the ledger.
- Display an authorship panel in marimo that compares AI-authored commit shares from the open-source commits dataset against your abstention rate by patch size.
Held-out test audit and CI guardrails
- Freeze the winning review workflow from validation and run one clean evaluation pass over the untouched held-out test splits.
- Write pytest unit tests covering diff normalization, Pydantic AI schema retries, abstention routing and SQLite ledger updates.
- Configure a CI job that runs unit tests plus a 50-patch deterministic fixture check on every push, failing if schema validity drops below 98 percent.
- Publish a technical README comparing single-judge and dual-judge precision alongside abstention rates by tier and five concrete defect classes both models still miss.
Architecture
A Python ingestion pipeline normalizes sampled patches and benchmark tasks into Parquet splits keyed by task identifier and authorship cohort. Each candidate patch runs through local Semgrep Community Edition rules before two distinct Ollama models return typed Pydantic AI verdicts with a decision and cited line range. Unanimous verdicts write directly to a SQLite review ledger, while disagreements enter a marimo triage app for human resolution. A local MLflow server records every prompt template alongside judge traces and evaluation counts.
Deliverables
- A Git repository containing the dataset sampling scripts, Semgrep wrapper, dual-judge Pydantic AI runner and SQLite ledger.
- A reactive marimo triage notebook stored as a versioned Python file that reads and updates the SQLite review queue.
- Exported MLflow comparison tables and open trace samples for two review workflows evaluated on identical local models.
- A technical README covering setup steps, dataset attributions, tier-by-tier test scores and five analyzed failure cases.
How to measure it
Report precision and recall on the held-out CTSSB-1M and Python problem test splits for each individual model and for the unanimous two-model panel. Record unanimous-call precision beside the abstention rate, aiming for an 8-point precision gain where single-model accuracy leaves headroom while keeping abstention between 15 and 45 percent. Compare both review workflows in MLflow by pass accuracy alongside median latency in milliseconds and schema retry counts.
Done when
- The split script prints row counts by source and split and exits with status zero when no patch identifier appears in multiple splits.
- Local Semgrep Community Edition scans the CTSSB-1M sample offline and writes structured JSON findings without calling any hosted service.
- Both Ollama judges return valid Pydantic AI verdict objects on at least 98 percent of test patches after bounded retries.
- On the held-out test split, the summary table compares single-judge and unanimous two-model precision alongside abstention share and records either a precision gain or a high-baseline ceiling.
- Every judge disagreement enters the SQLite abstention queue, and resolving an item in marimo updates the persisted ledger immediately.
- The local MLflow UI displays side-by-side runs for at least two review workflows using identical Ollama models with full traces and latency percentiles.
- Unit tests and the 50-patch CI fixture pass cleanly, and the README reports held-out confusion tables plus five documented false negatives.
Stretch goals
- Add a third local Ollama judge as a tie-breaker mode in MLflow and measure whether majority voting beats abstention on precision.
- Connect Open Code Review or Arm Metis to the same local Ollama endpoint and compare its line-level defect recall with your custom runner.
- Estimate a tiered routing bill from recorded token counts by pricing unanimous versus abstained cohorts against published provider rates.
- Train a small classifier on authorship records from the open-source commits corpus to prioritize high-risk diffs before judge inference.
