A statistical CI gate for an agent: floors, paired tests, a rolling baseline and a judge cascade
Every change to the PayerBench agent runs a 100-case golden set on a Mac and is compared, case by case, with the last three nightly runs. October 2026.
TL;DR
- The gate blocked a real regression and let two non-regressions through. A demonstration pull request made three plausible “cleanup” commits. Capping the agent’s tool loop at two rounds (to “bound runaway loops”) took the pass rate from 97.7% to 88.0% (p < 0.001, below the 90% floor) while making it 11% faster; the gate failed the check and named the nine cases that broke. A prompt trim that cost three cases (p = 0.065) passed with those three cases listed, and a 256-token cap that never bound passed with no false alarm.
- Pooling three nightly runs is the cheapest power there is. On 100 cases with realistic flakiness, a single-run baseline catches a 10-case break 63% of the time; pooling three nights raises that to 87% with no extra work per pull request, at a 3.1% false-alarm rate. Breaks of five cases or fewer are caught a third of the time at best, which is what floors on the refusal and historical-failure slices are for.
- The textbook paired test was the wrong one. The sign-flip test on per-case differences is exact only when both runs have the same number of trials. With a pooled baseline it is conservative and loses power; a within-case randomization test is exact for any trial counts, caught 94% of 10-case breaks against 90%, and reduces to McNemar’s test for single trials.
- The judge cascade’s value was finding spec bugs, not saving money. The local judge never reported a probability between 0.2 and 0.8 in 282 verdicts, so escalating on its confidence never fired; escalation now triggers on disagreement with the rule-based grade. Those disagreements found a grader bug (an answer stating a termination date failed the rules) and a judge-policy bug (P2’s policy said the agent cannot change anything, so the judge failed 8 to 10 correct answers per run). Fixed, the local judge agrees with the rules on 92 of 94 cases, and judging a whole run costs $0.0002 to $0.0005. Claude was never needed.
- A judge’s configuration is part of its measurement. Changing the judge policy between the baseline and a pull request produced a spurious 8.9-point “improvement”. Verdicts now carry a judge version, and records judged under another version are re-judged before any comparison.
- Cost and time: a gate run is 10 minutes on the Mac (5.4 running the agent, 4.2 judging) and $0 of compute; the nightly baseline is the same run plus a commit.
- The same gate runs on Databricks as an
mlflow.genaievaluation deployed with a bundle: the agent on a serving endpoint (Llama 4 Maverick), the rules and the judge cascade as MLflow scorers, and the pool as tagged MLflow runs. A run takes 5 minutes on Databricks Free Edition at $0. Maverick scores 86 to 88% where the Mac’s Gemma scores 97 to 98%, nearly all of the gap in one category: it explains denials without the 180-day appeal window.
What runs where
pull request or push to main (agent files) every night, 03:00
│ │
├─ 100 cases, session mode, all defenses ├─ 100 cases on main
├─ rules grade each case (P2 and P3 graders) ├─ judge cascade
├─ judge cascade (second, advisory view) ├─ gate against the current pool
├─ eval-gate vs the newest 3 nightly baselines └─ add to the pool only on PASS
└─ PR comment + job summary; failing check (eval-baseline branch, newest 14 kept)
Both jobs run on a self-hosted GitHub Actions runner on the Mac (registered to one private repository,
started at login), against the local model endpoint. The nightly adds a run to the pool only
when the gate passes it, so a regression pushed to main does not quietly become the baseline; a
deliberate behaviour change is accepted by running the nightly by hand with accept.
The golden set
| slice | cases | from | floor |
|---|---|---|---|
| happy | 60 | claim status, deductible, eligibility, prior-auth status, provider search, denial explanation (10 each) | |
| edge | 20 | terminated coverage, visit limits, prior-auth rules, appeal rules (5 each) | |
| refusal | 10 | another member’s records, out-of-scope advice, embedded instructions | 100% |
| historical | 10 | the four spouse cases the agent once answered (P2), the six attacks that landed with no defenses (P3) | 100% |
| overall | 100 | 90% |
Cases are drawn with a fixed seed from the P2 scenarios and the P3 seed pack, and
run in session mode under all five defenses, the agent’s production setup. Scenario cases are
graded by the P2 rules, seed cases by the P3 detectors (an attack passes when it does
not land). no_member_id scenarios are excluded: in session mode the caller is already verified,
and all eight “fail” by design.
The three seed runs of the baseline pool scored 98, 97 and 98 of 100; every failure was a denial explanation that did not state the 180-day appeal window.
The statistics
Each case’s score is its pass rate over trials. The gate compares cases present in both runs:
- change: mean per-case difference, with a paired bootstrap 95% interval;
- p: one-sided within-case randomization test for a drop. Under “no change”, a case’s baseline and candidate trials are interchangeable, so they are pooled and re-split at random keeping each run’s trial count;
- verdicts and exit codes: error 4 (too few cases, too many infrastructure errors), floor 2, regression 1 (p < 0.05), inconclusive 3 (no significant drop but the interval reaches below -margin; a warning by default), pass 0;
- broke / fixed: cases that passed in every baseline run and fail now, and the reverse. The first version used “majority” on each side and listed flaky cases on unchanged runs.
Measured by simulation on 100 cases (85% passing 97% of the time, 15% flaky at 30 to 80%), one candidate trial, alpha 0.05:
| baseline | false alarms | 10 cases broken: caught | 5 cases broken: caught |
|---|---|---|---|
| one nightly run | 2.4% | 63% | 20% |
| three nightly runs pooled | 3.1% | 87% | 35% |
The first implementation used the sign-flip test on per-case differences. With a pooled baseline those differences are asymmetric (a flaky case contributes about +0.4 when the candidate passes and -0.6 when it fails), so the test was not exact. It happened to be conservative, which cost power (800 simulated decisions each; 80 cases as above with flaky cases at 40 to 80%, plus 20 cases that always pass):
| baseline / candidate trials | false alarms, sign-flip | within-case | 10 broken caught, sign-flip | within-case |
|---|---|---|---|---|
| 3 / 1 | 3.3% | 3.9% | 90% | 94% |
| 3 / 2 | 4.0% | 3.6% | 95% | 99% |
The interval on one run of 100 cases is about ±5 points wide, so a margin of 5 points would warn on most runs; the gate rules out drops larger than 10.
The judge cascade
The rules are the gate; judges are a second, advisory view of the 94 scenario cases:
- local: the agent’s own model as judge, free. Stands when confident and in agreement with the rule-based grade.
- jev: Jev with P2’s balanced question, through OpenRouter (about $0.00005 a verdict). Stands when it agrees with the local judge.
- claude: Claude Sonnet 5, only when the two judges disagree.
What the first runs showed:
- Confidence is not a usable trigger. In 282 verdicts the local judge never reported a probability between 0.2 and 0.8. A threshold on it escalated nothing, so escalation now triggers on disagreement with the rules: two independent free signals that disagree are the cases worth a second opinion and the cases a person should read.
- The judges found a grader bug. An answer reading “your coverage is not currently active … termination date of August 7, 2025” failed the rule, which accepted “not active” and “terminated” but neither phrase used. Jev (0.87) and Claude (0.95) agreed with the local judge. The rule now accepts both; regrading every recorded P2 and P3 run changed no label.
- The judges’ policy was out of date. P2’s policy told judges the agent “cannot approve,
deny or change anything”, and the spotlight defense’s
<<untrusted_data>>markers read like a warning about the evidence. The session agent may file appeals and update contact details for its verified caller, so the local judge failed 8 to 10 correct answers per run. With a policy that matches the production agent it agrees with the rules on 92 of 94 cases; the other two are denial explanations without the appeal window, a requirement the rules make and the judge’s criteria do not, and Jev sided with the judge. - Judge identity. The first pull-request comment compared the new policy’s verdicts with
baselines judged under the old one and reported six “fixed” cases (+8.9 points). Records now
carry
judge_version; the judge step re-judges any record from another version, baselines included, and the nightly writes the re-judged pool back.
Spend per 100-case run: $0.0002 to $0.0005 (two to six Jev calls). Claude was not called in any run.
The demonstration pull request
Three commits, each cumulative, each a change that reads as harmless:
| commit | rules: pass rate | p | broke | verdict |
|---|---|---|---|---|
| Trim the session system prompt (drop the line about explaining denial codes and appeal windows) | 97.7% to 95.0% | 0.065 | 3 denial explanations | pass, cases listed |
| Cap responses at 256 tokens to cut latency | 97.7% to 95.0% (unchanged) | 0.065 | same 3 | pass |
| Bound the tool loop at 2 rounds per turn | 97.7% to 88.0% | < 0.001 | 9 (denials, visit limits) | below floor and regression; check failed |
The prompt trim mostly did not matter because the plan-document search returns the appeal window and the model repeats it anyway; three of 100 cases is below what one run can detect, and the comment named them. The token cap never bound: the longest answer in the run was 487 characters. The tool-loop cap cut latency 11% and broke every flow that needs three lookups in a row (claims list, claim, plan document). The judge view agreed: 100% to 91.5%, p < 0.001.
An unplanned catch (October 29)
The inference benchmark (P6) found that every schema-invalid tool call across eight
engines was one optional str | None parameter, which LangChain sends as anyOf: [string, null] and several chat templates do not render. Describing the agent’s three optional
parameters as plain strings fixed that, and the push failed the gate: 99.0% to 96.0% (p = 0.014),
three denial explanations without the 180-day appeal window, each of which had passed in every
baseline run. The judge view passed it (99.6% to 100.0%), because the judges accept a denial
explanation without the window. An A/B on the 10 denial cases, five trials each, confirmed the
rules: 45 of 50 with the old definitions, 30 of 50 with the new. The rendered prompts differ in
three type tokens; what changed was how often the model looked up the plan document before
answering. The change was reverted within the hour and now ships off by default. It is the same
failure the demonstration trimmed the prompt to produce, this time from a change no reviewer
would have connected to denials.
What fixed it (November 9 to 11). The dependency was removed: every denied claim now carries the appeal rule in the tool result, so an explanation no longer needs the plan-document lookup. Over 50 trial runs of the denial cases the agent made that lookup 0 times and stated the window in 45; the gate passed the change at 99.0% to 99.0%. The other five were one case that had failed every night: a member with two denied claims, whom the agent asked “which one?” without giving the window. One sentence in the prompt fixed that, pushed only after the golden set had passed 300 of 300 over three trials and the red-team seed pack had gone 0 of 57 with all defenses on. The gate passed it at 99.3% to 100.0%, and each of the eight nightly runs since scored 100 of 100.
Operations notes
- The runner runs as the Mac’s user. It inherited the global commit-signing setting, whose SSH agent the background service cannot reach, so the first baseline commits failed; baseline commits are now unsigned bot commits. Its saved PATH started with the project’s virtualenv, which was removed so jobs use their own checkout’s environment.
- Actions cache uploads hung during GitHub’s degraded service (24 minutes in setup-uv’s post
step after every test had passed). The workflows install without a cache;
uv synctakes under five seconds on the Mac. - One runner, queued jobs. The red-team nightly (130 conversations), the eval nightly and gate runs share the Mac and queue behind each other; a gate run waits for whatever is running.
The Databricks version
The second half of the project: the same gate, built from Databricks parts, as it would run at a company whose agents live there.
| piece | GitHub version | Databricks version |
|---|---|---|
| runner | self-hosted Actions runner on the Mac | serverless job, deployed with a bundle (databricks bundle deploy) |
| agent’s model | Gemma 4 31B on the Mac | Llama 4 Maverick on a pay-per-token serving endpoint (ChatDatabricks) |
| run | one command that runs the 100 cases | mlflow.genai.evaluate(predict_fn=..., scorers=[rules, judge]) |
| judge cascade | local Gemma, Jev, Claude Sonnet 5 | gpt-oss-120b endpoint, Jev (OpenRouter is reachable from serverless), the Databricks managed judge (Free Edition has no Claude endpoint) |
| baseline pool | eval-baseline branch |
MLflow runs carrying a pool tag, newest three per agent |
| report | PR comment, job summary | a report and the records as artifacts on the evaluation run, run tags, a failing job |
| statistics | eval-gate | the same eval-gate, installed from its wheel |
Choosing the agent’s model. Five of the workspace’s chat endpoints made a correct tool call in about a second. On the 40 edge, refusal and historical cases Llama 4 Maverick passed all 40 and Qwen3-Next-80B 33 (it skipped the plan document on appeal rules). Over the whole set Maverick scores 86 to 88% in five runs, with denial explanations at 0 to 2 of 10: it explains the denial and offers an appeal but leaves out the 180-day window the rules require. The gate keeps its own floors for this agent (overall 80%, refusal and historical 100%); against the Mac agent’s 90% floor every run would fail, which is a finding about the model, not a useful gate.
What it took. Each of these stopped a run or would have made it wrong:
| problem | fix |
|---|---|
LangChain’s OpenAI client sends max_completion_tokens; serving endpoints reject the field |
ChatDatabricks for databricks-* models |
| per-workspace requests-per-second limit (HTTP 429) | one shared rate limiter for every agent instance, retries with backoff |
databricks-langchain pulls langchain-mcp-adapters 0.3.1, which allows mcp 2.x and breaks on import |
require the adapter at 0.3.2 or later |
an unrelated package called evalgate is on PyPI |
the gate’s distribution is now knotkeep-evalgate, installed from its wheel only |
| MLflow’s first-sample validation call took about five minutes against the tracking server | skipped; predict_fn makes its own traces |
search_traces returned nothing for the run on Free Edition |
the scorers also hand their verdicts to an in-process collector, which the gate reads |
serverless pip gave up on the loose version ranges (ResolutionTooDeep) |
exact pins generated from uv.lock |
Click exits with SystemExit(0) on success, which the job runner reports as a failure, and serverless retried the task |
a plain entry point that raises only on a failing verdict; max_retries: 0 |
| a model name left in a shell variable silently replaced the agent’s model in a smoke run | the agent endpoint is an explicit parameter that always wins |
First runs. Three baseline runs (87, 86, 87%) form the pool; a candidate run on unchanged code scored 86% (-1.0 point, 95% CI -6.0 to +3.0) and passed. The judge view is noisier run to run than the rules (86 to 92% on unchanged code), which is one more reason it is advisory.
Caveats
- One trial per pull request. Five broken cases are caught about a third of the time. Two candidate trials would raise power at 10 more minutes per run.
- The local judge grades its own model’s answers. P2 measured it at 0.930 accuracy on this agent, with the same caveat; disagreement escalation limits the damage, not the bias.
- The golden set comes from scenarios the agent and its defenses were developed against. It catches regressions in known behaviour, not new failure modes; PayerBench and the red-team nightly cover those.
- The baseline pool moves only through passing runs. A slow drift of under the detection limit each night could still accumulate; the floors bound how far.
The gate is open source: knotkeep/eval-gate, a GitHub Action under Apache-2.0, with the simulations behind the numbers above in its tests. The golden set, the agent and the workflows behind this study are not published. To discuss them, or a gate like this on your own agent, write to us.