Add bin/eval to score a classifier on saved merge requests
What does this MR do and why?
Part of #40: the read-only evaluation (B3) its upstream review needs before it goes live, including the replay of the upstream stage (B3a, merged in from !98 (merged)). #42 also lists landing a harness as make eval, but nothing here depends on #42.
Related to gitlab-org/gitlab#637889, which it does not close. bin/eval records a tier and its reasons without changing any approval, label or merge, but only for saved merge requests in the flow's categories. That work item still needs its sample, runs on new merge requests, and output in Snowflake.
It adds bin/eval and make eval, which run a classifier on saved merge requests and score its answers against labels. Nothing is written to any merge request, but every run is a model call and a Duo session in the project origin points at. It combines the read-only harnesses that exist today:
| From | What it brings |
|---|---|
| The docs suite in the closed !26 (closed) | The classifier and its prompt come out of the compiled flow, so nothing is copied. The diff is handed over in the tool's own bytes. The 31 documentation cases, including the adversarial ones with a floor. |
| The read-only evaluation snippet ($6071062) | The 37 pilot cases and the 30 gitlab-org/gitlab cases. Refusing a flow that keeps a write tool. |
| The harness behind #42's research | Pinning the model and checking modelMetadataName for every session. Concurrent runs that resume. Running the steps after the model. |
How it works
- Each run's flow is cut from
flows/<flow>.yml. The two merge request reads are replaced by saved responses, and the flow stops beforeapply_labels, and beforeclear_labelson the refusal and failure routes.EvalFlow.check!refuses a flow with any tool beyondcreate_file_with_contents,read_fileandrun_command, andspec/eval/eval_flow_spec.rbasserts that against both flows. - By default a run goes through the gate, the model,
approval_rules,raise_below_oneanddecide_labels, so it records what the flow would decide.--classifier-onlyscores the model alone. A saved merge request is replayed as open and ready, because the gate refuses any other. --variant main=git:origin/main --variant branch=flows/deps.ymlcompares two flows. The report lists the cases the second one rateslow, or approves, more often, and in the flow mode the cases it labels less cautiously.- With no
--variant, a run sends the suite'svariants, or the working tree's flow where it names none.deps-pilotsnamesproduction: git:0.26.0, the deps flow the three pilots pin in the AI catalog (version 1.3.0, whosedefinition_hashmatches that tag'sflows/deps.yml), so a default run scores what they run, withoutapproval_rules. The monolith'sflows/flow.ymlis the same at0.26.0and on this branch, so its suites keep the working tree's flow. bin/eval snapshot <suite>saves a case by running only the flow's own two reads. Saved merge requests keep no one's email address, and snapshot refuses a case whose project's merge requests are not public, since they are committed to this public repository.--outresumes a stopped run. A resume keeps every variant, model and case the directory has, and refuses a label that names a different flow than before, or a different suite or mode. Options refuse a value that is itself a flag, so--out --show-flowcan't start a real run.
What production does that it copies or works around
glab duo cli runreads and writes files in the root of the git checkout around its working directory. Each run gets a temporary directory outside every checkout, andbin/evalrefuses to run otherwise.- The CLI's
read_filemasks strings it takes for secrets and appends a note, and ago.sumhash can look like one. Saved responses are therefore passed to the steps that read them as literal inputs, never read back from a file. - Duo filters every tool response before a step reads it: it strips HTML comments and other hidden content, and encodes the tags its prompts use as delimiters. A saved response has been through those filters. A response built from a
.diff, and the fetch's replayed output, go through a port of them,evals/lib/tool_filter.rb, which refuses what it can't mirror.
The upstream stage (from !98 (merged))
The deps flow gains an upstream stage in #40: a fetch of the Go module's two zips, a judge with no tools, and keep_higher_tier, which keeps the higher tier at the start of the decide_labels step. It is built in a separate MR to a shared contract, so either can land first. This MR replays it:
- One answer file per agent. The suite's classifier saves its answer to
answer.txt, and every other agent toanswer.<agent>.txt, because the file tool won't overwrite. Result rows record the judge's answer asjudge.- On
deps-gitlab, whoseflows/flow.ymlhas three classifiers, a case the gate sends toclassify_impactorclassify_spec_riskcounts as "No answer", rather than having that classifier's tier scored as a deps tier.
- On
- Replaying the fetch. The sandbox can't reach upstream, but
run_commandsteps passEvalFlow.local?.bin/eval snapshottakesfetch_upstream's compiled command fromflows/deps.ymland runs it with Ruby, outside the sandbox. It runs in a scratch directory holding the case's savedmr.json,mr_diff.jsonand atier.txtoflow. It saves<case>.upstream.out,.upstream.jsonand.upstream_route.txtbeside the case. The runner isUpstream.fetchinevals/lib/upstream.rb, so specs can reach it.- It never overwrites a saved file, and it skips a case with only some of the three saved.
- It saves nothing from a fetch that timed out, wrote no JSON or route, or failed for a reason of the machine or the moment (
fetch failed, a 429 or 5xx from a host, nogit), so the next snapshot tries again. The fetch runs in a process group of its own, so a timeout or an interrupt stops everythingshstarted. - In a run,
EvalFlowswapsfetch_upstreamfor a stand-in that starts as the fetch does, withrm -f upstream.json upstream_route.txt judge.txt && mv tier.txt tier_model.txt. It then copies the savedupstream.jsonand route when the tier that reaches it, afterapproval_rulesandraise_below_one, islow, or writes routeskipwhen it isn't. review_upstream'supstreaminput becomesExit code: 0and the saved stdout, through Duo's tool filters, as a literal, because that is what the CLI passes on from arun_command. Reads are given the same way.- The snapshot's fetch runs with no git config, attributes or checkout of the developer's around it, so the diff it saves is the one the stage ships.
- A flow without
fetch_upstreamis unchanged. A flow that keeps it but has no saved output raisesEvalFlow::Unsaved, andbin/evalaborts withrun bin/eval snapshot.--show-flowuses a placeholder instead, so it needs no fetch.
- Report.
- A new Upstream stage section has per-group totals: judged, check, incomplete, skipped, judge unreadable, as expected, and lowered by the stage.
- Its per-case table shows what the stage did, the judge's tiers, the tiers labelled, and whether those are more or less cautious than the first variant's. The judge's answer is read as
keep_higher_tierreads it: one JSON object whose tier islow,mediumorhigh. Less cautious is in bold.xmarks a run itsupstreamdoesn't expect, and lowered by the stage marks a run labelled below the tier that reached the stage. A skipped run shows that tier. - Right after the summary, a new Less cautious than
mainsection lists every case a later variant labels less cautiously, so none can be missed.
- Suites.
deps-pilots.ymldocuments an optionalupstream:key:keep,raise,checkorincomplete. Every case has one. 28 are set from their saved output, where it decides the outcome without the judge. The nine the fetch routes to the judge were set by a person reading the judge's saved input against its rubric:keepfor seven, andraisefor gitlab-org/gitlab-elasticsearch-indexer!860 (merged) (a new exported function that opens a file) and !865 (an unescaping fix the release notes don't mention). With the stage, 4 of the 14 low-labelled cases are left for the flow to approve; the other 10 should go to a person.upstream:holds only a variant whose flow has the stage, whichmeta.jsonrecords per variant. There, approving a case whoseupstreamisraise,checkorincompletecounts as a wrong approval, and "Approvable cases approved" leaves the case out. A flow without the stage is held to the labels alone, and "lowcases ratedlow" counts every case the labels accept as low either way.deps-upstream.ymlscaffolds the six planted cases from #40's evaluation plan. Each is one of the eight low Go module bumps indeps-pilots, with its merge request files copied unchanged; es-indexer-859 and -865, two gitaly bumps the fetch routes to the judge, are not used.planted:says what to edit in the saved upstream output. The cases the judge must read sit on the three zoekt bumps the fetch routes to the judge. The three es-indexer bumps are over the fetch's 48 KB cap, soover-the-capneeds no edit. All six are planted.
Checked against the stage as built
The stage is !99 (closed), at 8973f78f, where keep_higher_tier runs at the start of the decide_labels step rather than as a step of its own, and the fetch also clears judge.txt, since the file tool won't overwrite one left in place. spec/eval passes on this branch with its flows/deps.yml laid over, with no example skipped, and so does its spec/deps. A replay of the stand-in, then that flow's own classify_change and decide_labels commands, across sixteen upstream results, ends on the tier the report expects in every one, including one with a stale judge.txt. It also provides what the contract left open:
fetch_upstreamreads onlymr.json,mr_diff.jsonandtier_model.txt.- It needs only Ruby,
gitand the two hosts, with timeouts of 10 and 30 seconds per request. - It prints only the judge's input, on the judge route, and discards
git's stderr. - It reads the tier as
decide_labelsdoes. keep_higher_tierraises any checksum butok,uncheckedincluded.- Its red-flag rules are
os/exec,net/http,unsafe,plugin,cgo,go:linkname,func init,encoded stringandbinary file. - An unexpected error is reported as
fetch failed: <class>.
Once the stage lands, bin/eval run on a deps suite aborts until bin/eval snapshot has saved each case's upstream output. spec/eval passes saved output to every eval_flow call on the real flows that reaches the fetch, and the deps chain spec pins only the classifier, its answer and write_tier_file, so the stage landing won't break spec/eval. Specs that hold the stage's fetch to the stand-in are skipped until then, and pass with !99 (closed)'s flow laid over.
Validation
One pass on claude_sonnet_5_5_vertex, with every session confirmed through modelMetadataName:
| Suite | Mode | Accepted | Wrong low |
Wrong approval |
|---|---|---|---|---|
deps-pilots |
classifier only | 29/32 | 2 (1 provisional) | n/a |
deps-pilots |
flow | 28/32 | 2 (1 provisional) | 0 |
deps-gitlab, runtime below 1.0 |
flow | 5/6 | 1 | 1: gitlab-org/gitlab!260517 (merged) (httparty) |
docs, 3 cases |
classifier only | 1/3 | 1 | n/a |
The deps-pilots flow run sent the working tree's flows/deps.yml, with approval_rules; a default run now sends the pilots' 0.26.0. These runs predate the upstream replay, the tool filters for .diff cases and the relabelled docs adversarial cases, which are now labelled on their content. The replay changes no flow deps-pilots or docs sends. On deps-gitlab, a case the gate sends to another classifier now counts as "No answer".
deps-upstream against !99 (closed)'s flow at 46ff512d, on the same model, gave each planted case its expected outcome. checksum-mismatch and red-flag went to a person without the judge. undocumented-change was judged medium, and text-for-the-judge high, the judge naming the comment aimed at it. over-the-cap was incomplete. tests-only was judged low and approved. Its first planting kept release notes about code its diff no longer showed, which the judge rated medium, so it was rebuilt and run again. Every judge answer was valid JSON. Since then, 8973f78f has rewrapped the judge's prompt with the same words and changed no fetch output, so the saved upstream files still hold.
On 36 of the 37 pilot cases, the model's tier is within #42's per-case range on Sonnet 5.5. The other one, gitlab-org/gitlab-zoekt-indexer!1039 (merged), came back low in classifier-only mode, which is within #42's raw-model rate for that case.
Labels to confirm
- gitlab-org/lab-bench/bench!153 (closed) (
cargo-zigbuild, a build tool below 1.0): #42's case list says≥ medium, and the snippet's list sayslowunder the rule for development tools. It is marked provisional. Every pilot wronglowon Sonnet 5.5 in #42 is this case. - gitlab-org/lab-bench/bench!110 (merged), !98 (merged) and !112: the three tiers #42 already asks the rubric's owner to confirm. They are marked provisional.
Not in this MR
- A harness that is only in a local clone, which pins more models.
--modeltakes any model identifier. - Labelled cases for
classify_spec_risk. - Runs of the deps suites on this branch's own
flows/deps.yml, which has nofetch_upstreamuntil !99 (closed) lands.--variant stage=git:origin/jecsanders-40-upstream-reviewruns the stage before then.
How to set up and validate locally
make checkruby bin/eval run deps-pilots --show-flowprints the flow a run would send, with no model call.make eval SUITE=deps-pilots ARGS="--repeat 1 --only zoekt-1073"makes one model call.