Skip to main content

Gating pull requests on evals

A prompt edit, a new model snapshot or a routing change can quietly make answers worse. CI gating runs an eval on every pull request, compares it with the last trusted run of the same eval on your main branch, and fails the job when a threshold is crossed. Everything runs on your gateway: the CI job only starts the run, waits, and reports. This is an enterprise feature like the rest of evals.

The pieces are a ci key type that can do nothing but start eval runs and read their verdicts, the GET /eval/runs/{run_id}/verdict route, and the spanwayctl evals gate command. There is no published GitHub Action. The workflow below calls the CLI directly, so you can copy it into any repository.

A real-world scenario​

A support bot's prompts live in a repository. Last month a well meant prompt edit dropped the refund answer pass rate from 92% to 70% and nobody noticed for a week. The team adds a CI job that runs their golden dataset against the bot's models on every pull request and fails the check when the pass rate drops by more than three points from the last trusted run on main.

Steps​

  1. A proxy admin creates the pull request key. In the Admin UI open Virtual Keys, click + Create New Key, choose the key type CI (evals), pick the team, the models and the allowed datasets, set a budget and click Create Key. The API call is the same as the curl in CI keys.

  2. Create a second key the same way with Baseline writer ticked and refs/heads/main as its ref, and store it in a protected CI environment only main jobs can read.

  3. Commit a spec file such as the support-golden example in spanwayctl evals gate and call the CLI from the workflow, as in A GitHub Actions workflow.

  4. Open a pull request. The job starts the run, waits, and posts the report. To read the verdict yourself:

    curl "$SPANWAY_URL/eval/runs/$RUN_ID/verdict?report_detail=summary" -H "Authorization: Bearer $SPANWAY_CI_KEY"
  5. In the Admin UI open Evals, then the Runs tab, and click the run, which carries a CI badge. The CI gate box shows the same verdict the job got.

Expected result​

The job exits 0 and the check turns green when every threshold holds. When the pass rate falls past max_pass_rate_drop, the verdict's conclusion is failed, the job exits 1, and the pull request comment lists the failed check with its actual value, limit and baseline value.

CI keys​

A CI key is a virtual key with key_type set to ci. Only proxy admins can create, change or regenerate one, and the gateway refuses any CI key that does not have all of the following.

FieldWhy
team_idThe runs and their spend belong to that team. A CI key never has a user_id.
modelsThe models it may run, judge models included. Every model in a run is checked against the key's models and the team's models before the run starts.
max_budgetCaps what its runs spend.
metadata.eval_ci.datasetsThe dataset ids it may run. Ids, never names, so renaming a dataset or creating a new one under an allowed name grants nothing.

allowed_routes is set to eval_ci_routes for you and cannot be changed. A CI key can call POST /eval/runs, GET /eval/runs, GET /eval/runs/{run_id}, GET /eval/runs/{run_id}/results, GET /eval/runs/{run_id}/verdict, POST /eval/runs/{run_id}/cancel, and for a run with submitted outputs GET /eval/runs/{run_id}/items, POST /eval/runs/{run_id}/outputs and POST /eval/runs/{run_id}/finish, and nothing else, whatever role it carries. Every model call of its runs, judge calls included, stays within the key's budgets and rate limits and passes the key's and team's guardrails. Writes on those paths that a CI key is not given, such as deleting a run, are refused by the route itself. A CI key sees only the runs it started: listing returns only those, and any other run id answers 404.

curl -X POST "$SPANWAY_URL/key/generate" \
-H "Authorization: Bearer $SPANWAY_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"key_alias": "support-bot-pr-gate",
"key_type": "ci",
"team_id": "support",
"models": ["gpt-5.5", "claude-sonnet-5-5"],
"max_budget": 20,
"rpm_limit": 120,
"metadata": {"eval_ci": {"datasets": ["6c1f..."]}}
}'

In the Admin UI, a proxy admin picks the key type "CI (evals)" when creating a key, chooses the datasets and, for a baseline writer, the refs.

Budgets and rate limits​

A run's completions go through the gateway's router directly, not through the request path a normal API call takes, so the gateway applies the CI key's limits itself. Before a run starts it checks the key's budget and its team's budget and refuses the run with 429 when either is spent. Every completion of the run, judge calls included, checks both budgets again and passes the key's rpm, tpm and parallel request limits first. A completion refused by a rate limit is retried with backoff a few times and then recorded as an errored item, and a completion refused by a budget is recorded as an errored item without being sent. Spend is logged against the CI key and its team like any other request, and each spend row carries the run id.

A CI key can have at most 5 runs pending or running at once (EVAL_CI_MAX_ACTIVE_RUNS, an environment variable on the gateway, 5 by default). Runs older than two hours (EVAL_CI_STALE_RUN_SECONDS, 7200 by default) do not count, so a run orphaned by a gateway restart cannot block the key. Runs started at the same moment cannot get past the cap together. When several of them race for the last slot, more than one may be refused with 429, so retry a refused run once another finishes.

Baselines and trust​

A run is compared with a baseline. Runs that should be compared share a baseline_key, for example support-bot. A run only becomes a baseline when it is trusted, and the gateway decides that, never the request:

  • a run started by a proxy admin is trusted, unless its CI context names a pull request
  • a run started by a CI key is trusted only when the key has metadata.eval_ci.baseline_writer set, the run's reported git ref is one of the key's metadata.eval_ci.baseline_refs, and the run names no pull request

The CI context is reported by the job, so a baseline writer key must live where only jobs on protected branches can read it, for example a GitHub Actions environment with required reviewers or branch protection. Use two keys: a pull request key without baseline_writer, and a baseline writer key in that protected environment.

{"eval_ci": {"datasets": ["6c1f..."], "baseline_writer": true, "baseline_refs": ["refs/heads/main"]}}

The automatic baseline is the newest trusted completed run with the same baseline_key on the gate's baseline_ref (refs/heads/main when unset) that completed before the run being judged was created. For a run a CI key started, the baseline must also have been started by the same key or a key of the same team, so a rotated key still finds its baselines and another team's runs with the same baseline_key are never used. This depends only on the run, so an admin opening the run in the Admin UI sees the same verdict the CI job got. A run a proxy admin started is compared with any team's trusted run. A gate can name a specific baseline_run_id instead, and so can the verdict request. A named baseline must be completed and visible to the caller, so a CI key cannot compare against another team's run.

Runs are scoped to the key that started them. Regenerating a CI key changes its hash, so the new key no longer sees the runs the old one started, though its baselines are still found through the team.

The gate​

The gate is sent with the run and every threshold is optional. Each is checked per model, so one weak model fails the gate even when the average looks fine.

ThresholdFails when
min_pass_rateA model's pass rate is under the value, or it has no scored items.
min_mean_scoreA model's mean score is under the value, or it has no scored items.
max_error_rateMore than this share of a model's items errored.
max_pass_rate_dropA model's pass rate fell by more than this since the baseline.
max_mean_score_dropA model's mean score fell by more than this since the baseline.
max_cost_increaseA model's cost rose by more than this ratio over the baseline (0.2 is 20%). Skipped when the baseline cost nothing.
max_new_failuresMore items than this passed in the baseline and fail or error now. Skipped when the baseline ran another dataset.
require_baselineNo baseline was found.

Checks against the baseline are skipped when there is no baseline or the model is not in it. The verdict's conclusion is pending while the run is going, error when the run failed, was cancelled or produced no model results, failed when any check failed, passed when at least one check passed and none failed, and neutral when nothing could be checked.

curl "$SPANWAY_URL/eval/runs/$RUN_ID/verdict?report_detail=summary" \
-H "Authorization: Bearer $SPANWAY_CI_KEY"

The response lists every check with its actual value, limit and baseline value, per-model figures beside the baseline's, the first 50 regressed items with the total count, and markdown, a ready to post report with every value escaped. report_detail=summary leaves item ids and the run link out of the report and the response, which suits public repositories. The run link is only included when PROXY_BASE_URL is an https URL.

spanwayctl evals gate​

spanwayctl evals gate reads a spec file, starts the run with the CI context of the job, polls the verdict and exits with 0 for passed or neutral, 1 for failed, 2 for an error, a timeout or a gateway it cannot reach, and 3 for bad usage such as a missing key or an invalid spec. On timeout or when the job is cancelled (SIGTERM or SIGINT) it cancels the run right away, even in the middle of a wait between polls, so it stops spending. It reads SPANWAY_PROXY_URL and SPANWAY_PROXY_API_KEY.

dataset: support-golden
models: [gpt-5.5, claude-sonnet-5-5]
scorer: {type: exact_match, case_insensitive: true}
baseline_key: support-bot
gate:
min_pass_rate: 0.85
max_pass_rate_drop: 0.03
max_new_failures: 2
require_baseline: true

dataset is a dataset name (or use dataset_id). --dataset, --model (repeatable) and --baseline-key override the spec, --timeout (default 1800 seconds) and --poll (default 10) control the wait, --report-detail summary asks for the shorter report, and --github-comment posts the report on the pull request. In GitHub Actions the command writes conclusion, run_id, baseline_run_id and message to the step outputs and the report to the job summary. In GitLab CI it reads the merge request from the predefined variables, and projects in subgroups are supported. The job link is only kept when it is https. When a CI variable is invalid the command prints a warning and leaves just that field out, and only an invalid ref or commit sha drops the whole CI context, which also means the run can never become a baseline. spanwayctl evals verdict RUN_ID prints a run's verdict without starting anything and never cancels it.

The pull request comment is one comment per baseline key, updated in place by later runs. Only a comment written by the same token is updated, so a comment someone else wrote with the same marker is never touched. If the token cannot comment or the pull request API cannot be reached, the command prints a warning and the exit code is unchanged.

Systems that run outside the gateway​

An agent or pipeline that runs in the CI job itself, rather than as a gateway model, is gated with a logged run whose outputs are submitted. POST /eval/runs with mode: logged and outputs_source: submitted starts the run without running anything. GET /eval/runs/{run_id}/items returns the items at the dataset version the run pinned. POST /eval/runs/{run_id}/outputs takes up to 100 outputs at a time, each an item_id, a model label and either the final output text, which is appended to the item's turns as the reply, or the whole transcript. Every output is scored right away exactly as a logged run scores a stored conversation, so submitting a system's outputs gives the same scores and verdict as baking the same conversations into a dataset. An item id the dataset does not have, the same item twice in one batch, or an item already submitted for that model refuses the whole batch. Two batches sent at the same moment with the same item keep the result stored first, and the later response counts it in already_submitted. POST /eval/runs/{run_id}/finish records an error row for every item that got no output from a model that submitted anything, writes the summary and completes the run, so GET /eval/runs/{run_id}/verdict gates it like any other run. Storing a batch and finishing take the same lock on the run, so a batch still being scored when the run finishes gets a 409 and stores nothing, and the summary always covers every stored result. A submitted run nobody finishes stays running until it is finished or cancelled with POST /eval/runs/{run_id}/cancel. The same run starts from the Admin UI: on the Evals page, open the Runs tab, click New run, pick the dataset, set Run mode to Score logged conversation, set Outputs to Submitted by an outside system, pick a scorer and click Start run. The run detail then shows Outputs as submitted and the run stays running until your system posts its outputs and finishes it.

A CI key starts submitted runs and reads their items only when its metadata.eval_ci has "read_items": true, since reading items shows the key the inputs of every dataset it may run. It still never sees expected, expected_tool_calls or expected_outcome, which the gateway strips from the items it returns to a CI key. A CI key reads, submits to and finishes only the runs it started, and its judge calls count against its budgets. GET /eval/runs/{run_id}/items answers 400 for a run that scores its dataset itself.

{"eval_ci": {"datasets": ["6c1f..."], "read_items": true}}

spanwayctl evals experiment run does all of it around a local command:

spanwayctl evals experiment run --dataset support-golden --gate '{"min_pass_rate": 0.85}' --baseline-key support-agent \
-- python agent.py

The command reads one item per line as JSON on stdin, without expected or the other fields scorers compare against, and prints one JSON line per item with item_id and output or transcript, plus an optional model (--model, default local, labels lines without one). --scorer takes the scorer as JSON (exact match by default), and the exit codes are those of spanwayctl evals gate. A command that fails, prints a line that is not a valid output, or has a batch refused cancels the run. The TypeScript client's evals.runs.experiment(run, produce) does the same with an async function per item.

A GitHub Actions workflow​

Copy this into .github/workflows/evals.yml. The pull request job uses a key without baseline_writer. The push job on main runs in a protected environment and uses the baseline writer key, so each merge records the new baseline. Pull requests from forks are skipped because they cannot read your secrets.

name: evals
on:
pull_request:
push:
branches: [main]

concurrency:
group: evals-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
gate:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'push' && 'evals-baseline' || 'evals' }}
timeout-minutes: 40
container:
image: registry.spanway.ai/spanway/spanway-ai:<your gateway version>
options: --entrypoint ""
steps:
- uses: actions/checkout@v4
- name: Gate on evals
env:
SPANWAY_PROXY_URL: ${{ vars.SPANWAY_URL }}
SPANWAY_PROXY_API_KEY: ${{ secrets.SPANWAY_CI_KEY }}
GITHUB_TOKEN: ${{ github.token }}
run: spanwayctl evals gate --spec .spanway/evals.yaml --github-comment

The job runs inside the gateway image, which carries spanwayctl, so pin the image tag to the version your gateway runs and give the runner access to the registry your onboarding pack names. Store the pull request key as SPANWAY_CI_KEY in the evals environment and the baseline writer key under the same name in the evals-baseline environment, and restrict evals-baseline to the main branch. Do not switch the trigger to pull_request_target, which runs with your secrets on code from forks. Use --report-detail summary in public repositories so item ids from your dataset do not appear in comments.

Gateway gates and Lens​

The gateway gate judges eval runs: a dataset sent through the models your gateway serves, scored and compared with a baseline. Lens looks at traces of agents running in production. Use the gateway gate for changes you can test against a fixed dataset before merging.

Errors​

Status or exit codeMessageMeaning and fix
400 on /key/generatea ci key needs a team_id, its runs are billed to that teamGive the key a team.
400 on /key/generatea ci key needs an explicit list of models it may runList the models, judge models included.
400 on /key/generatea ci key needs a max_budget, which caps what its runs spendSet max_budget.
400 on /key/generatea ci key needs metadata.eval_ci with a non-empty list of dataset idsAllow at least one dataset id.
400 on /key/generatea baseline writer needs metadata.eval_ci.baseline_refs, the refs it may recordAdd the protected refs.
400 on /key/generatea ci key belongs to a team, not a user, so user_id must be emptyRemove user_id.
400 on the verdicta run cannot be its own baseline, baseline run <id> is <status>, not completedName a different, completed baseline run.
404run_id=<id> not foundA CI key only sees the runs it started. A regenerated key no longer sees the old key's runs.
429The run is refused before it starts, for example this ci key already has 5 runs in progress, wait for one to finishThe key or team budget is spent, or the key already has EVAL_CI_MAX_ACTIVE_RUNS runs active. Wait or raise the budget.
403this ci key cannot run dataset <id>, it is not allowlistedThe dataset is not in the key's metadata.eval_ci.datasets. Add it, or run an allowlisted dataset.
403ci key limits could not be checkedThe gateway could not read the key's budgets and limits, so it refused the run rather than run it unchecked. Check the database and Redis, then retry.
403key cannot call model <model>The run or its judge names a model the CI key's models list does not allow. Add the model to the key.
403this ci key cannot start submitted runs, its eval_ci has no read_itemsSubmitted runs need the dataset items, so the key needs metadata.eval_ci.read_items: true.
403this ci key cannot read dataset items, its eval_ci has no read_itemsReading the items of a submitted run needs read_items on the key.
409already submitted: <item>/<model>, ...Those items already have an answer for that model in this run. Send only new items.
409run <run_id> is <status>The run finished, failed or was cancelled before this batch or finish landed, so nothing was stored. Start a new run.
Exit code 2A timeout or an unreachable gatewayCheck SPANWAY_PROXY_URL and raise --timeout. The run is cancelled on timeout.
Exit code 3Bad usageA missing key or an invalid spec file. Fix the spec or set SPANWAY_PROXY_API_KEY.

Logs​

Gating writes no log lines of its own. A run a CI key starts logs like any other run, as the Evals logs list, and every change a CI key makes is written to the audit log with changed_by ci key <alias>.