The evaluation pipeline and the quality gate in CI

Study time
≈ 2.5 h (estimate)
Needs
L2-M07-L03
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M07 · Duration: ~135 min (estimate, including the independent exercise) · Previous: L03 · Next: L05

1. Introduction

Knowing how to compare two systems once is not enough: every time the prompt or model changes, the comparison must be rerun correctly, and the result must decide what happens next. This lesson teaches how to build a small evaluation pipeline: a checked config, a versioned dataset with a fingerprint, a cache keyed on every input, a fixed seed, a run record (manifest), and a regression gate that returns an exit code that CI understands. The key point is fail closed: missing data, a mismatched dataset or an unexpected error must all block, and never let a change through.

"Pipeline" here means the sequence of steps that run an evaluation, not the pipeline of a RAG application (L2-M06-L01). The lesson only describes a manual-trigger GitHub Actions workflow as sample text in the lab; it does not create or edit any workflow in the repository. Every system is simulated; the numbers do not describe a real model. The earlier policy still stands: the gate only decides whether the pipeline stops or continues; for every result, a person reads the report and decides on release (L2-M02-L05, L2-M04). The product of the lesson: a gate that can block a regression, with evidence from a run on your machine.

2. Learning objectives

  1. Check a config and find a misspelled key or a model alias. Practice: §8.3 (line 1).
  2. Explain the cache key and the number of cache hits. Practice: §8.2 part B, §8.3 (lines 2 and 3), §9 (TODO 3).
  3. Build a manifest and detect a manifest that was edited. Practice: §8.2 part B, §8.3 (line 4).
  4. Run the gate and read the four decisions with exit codes 0, 1, 2, 3. Practice: §8.2 part C, §8.3 (lines 5 to 9), §9 (TODO 1).
  5. Explain the ERROR cases and why fail closed. Practice: §8.2 parts D and E, §8.3 (lines 8 and 9).
  6. Check a sample manual-trigger workflow and state what the lint does not check. Practice: §8.2 part F, §8.3 (line 10), §9 (TODO 2).

3. Prerequisites and tools

  • L02 and L03 of this module; L1-M07-L04 (workflows, exit codes, the fail-closed report); L2-M02-L05 (manifest, fingerprint, release gate); L2-M03-L05 (per-slice regression). Code lab code-labs/l2-m07.
  • Disambiguation. Regression is quality getting worse between two versions, not statistical regression. A gate has two ways of being wrong: a false accept (Vietnamese "lọt": a real regression that the gate lets through) and a false reject (Vietnamese "oan": the gate blocks although there is no real regression). Baseline is the result of the version currently in use.

4. Concept explanation

4.1 The evaluation pipeline and the config

Evaluation pipeline: configuration → validate_config. If it finds problems, ERROR and stop; if clean, load the released dataset with its fingerprint → run the systems with a cache → manifest and results_digest → a gate against the baseline. Exit code 0 (PASS) lets a person review the report; codes 1, 2 or 3 block the pipeline.
Diagram: The evaluation pipeline and the config

The config is a dict: a name, the dataset version, the baseline, the candidate, the number of runs, the seed, alpha, the margin, the minimum number of items, and a few slice fields. validate_config returns error codes and reports unknown keys: aplha instead of alpha is not silently ignored and then replaced by a default. The model must be a dated id and exist in the lab's system table (L01 §4.2).

4.2 A versioned dataset with a fingerprint

A dataset version is a name plus a content fingerprint (the SHA-256 of canonical JSON, with items sorted by id, so row order does not change the result). registry.load_dataset fails closed: an unknown version, or a file that changed after release (the fingerprint does not match the pin in data/datasets.json), raises an error instead of returning mismatched data. Two results can be compared only when their fingerprints are equal (and non-empty). The lab's dataset v2 is v1 plus 20 pii items: the fingerprint differs, so baseline results on v1 cannot be compared with candidate results on v2; the baseline must be rerun on v2.

4.3 Cache and seed

The cache stores the result of each run, keyed by the SHA-256 of everything that changes the result: the model, the prompt, the shift, the content of the item (not just the item id), the run index, the seed and the simulator version. A key that forgets an input (for example drops the prompt) returns a stale result without an error; the lab's tests change each input in turn and check that the key changes with it. The cache does not know which model is behind an alias that has been repointed: the reason the lab rejects aliases. The cache saves time and money; it adds no statistical evidence. All randomness in the lab is generated from seed strings via SHA-256, so rerunning gives exactly the old result. With a real model, a repeated run is not guaranteed to give the same result (L1-M06); the lab does not simulate that.

4.4 The manifest

The manifest records the full config, the config hash, the dataset (version, fingerprint, number of items), the two systems, the seed, the number of runs, the simulator version, the results_digest (a hash of every pass flag), the Python version (for reference only, not part of the manifest_id) and the manifest_id. check_manifest recomputes the manifest_id and the config hash from the manifest's own parts. It detects an edit to results_digest, the dataset fingerprint, the simulator version or config, but it does not see an edit to seed, the number of runs, dataset.n_items, the top-level systems or the Python version (only compare_manifests and reproduce can compare those fields), and it does not detect a manifest forged with the correct hash (anyone can recompute a hash): keep the manifest somewhere nobody can overwrite it. reproduce reruns from the config and compares the results hash.

5. Technical deep dive

5.1 The gate: four decisions and exit codes

The lab's policy is non-inferiority: the candidate must not be worse than the baseline by more than margin. The paired bootstrap interval of (candidate minus baseline) gives: PASS (0) if the lower bound ≥ −margin; FAIL (1) if the upper bound < −margin; otherwise INCONCLUSIVE (2); any problem with the inputs or the policy is ERROR (3). Every code other than 0 blocks the pipeline. The gate runs for the whole set and for each slice, each slice with its own margin (the pii slice in the sample config is 0.01) and its own minimum number of items; the overall decision is the worst in the order ERROR > FAIL > INCONCLUSIVE > PASS (in line with L2-M03-L05's "one bad slice is enough to block" rule). A slice with fewer items than the minimum is INCONCLUSIVE. If no item differs, the interval is the ±(1 − 0.05^(1/n)) limit of L02, so identical results still only PASS when there are enough items (§8.3).

On the simulated run in §8.2: B against A, margin 0.02: overall there is no regression, the check and concept slices PASS, while hint, offtopic and pii are INCONCLUSIVE because there are too few items (20 to 40) to prove "not worse"; the gate gives INCONCLUSIVE (code 2), not PASS. S against A gives FAIL (code 1) (§8.2 part C). INCONCLUSIVE is not a fault of the gate; it is information: the current dataset is not enough to let an important slice through.

5.2 Fail closed: the gate must not guess

check_inputs turns each of the following into ERROR: a missing field; dataset fingerprints that differ or are empty; two results with the same manifest_id (SAME_RUN: comparing a run with itself always "passes"); duplicate item ids; mismatched lengths; a score that is not a fraction in [0, 1] (nan, 3/2, None); different lists of item ids (IDS_DIFFER: a candidate scored on fewer or easier items cannot be compared); the slice label of the same item differing between the two sides (SLICES_DIFFER); no items; a slice declared critical but absent. main (the core of the python -m lab.gate_cli command) catches every exception while reading files or deciding and returns 3; an unknown decision passed to exit_code is also 3. This is in the same spirit as L1-M07-L04: a missing or empty report is an error, not "green". This "ERROR" level has a price: one corrupt piece of data blocks the whole pipeline, and that is what is wanted.

5.3 A manual-trigger GitHub Actions workflow (sample text)

The lab has data/gate_workflow_sample.yml: a sample for reading only, in the lab folder, not in .github/, so it never runs. The only trigger is workflow_dispatch: GitHub's documentation says this event runs the workflow manually, and the "Run workflow" button only appears if the workflow file exists on the default branch [R1]. The gate step runs python -m lab.gate_cli ... and receives the runner's inputs through an intermediate environment variable (env) instead of inserting a ${{ ... }} expression directly into run:, which GitHub's security documentation names as the preferred approach for inline scripts to avoid script injection [R5]; because the runner's default shell runs with a stop-on-error flag (bash -e) and the step status comes from the exit code [R2], a code other than 0 makes the job fail. The step that keeps the decision has if: ${{ !cancelled() }}. The actions use the major version v7 (checked through the GitHub release API on 2026-11-04: actions/checkout v7.0.1, actions/setup-python v7.1.0, actions/upload-artifact v7.0.2) [R3].

continue-on-error: true lets the job pass when that step fails [R2], that is, it breaks the gate; || true after the command does the same. lint_workflow_text checks exactly three things, line by line in the text: the on: block has only workflow_dispatch (no push, pull_request, schedule...), no continue-on-error with a value other than false (including True or an expression), and no || true, || :, || echo ..., || exit 0 or ; exit 0. It does not check that the YAML is valid, expressions, action versions, secrets, an if: always() that changes the meaning, or other ways of swallowing the exit code such as || (exit 0); the last two examples pass the lint (the lab's tests pin this). Running automatically on every pull request is a team decision (cost, time, secrets), as L1-M07-L04 stated; OpenAI's documentation recommends setting up continuous evaluation to run evals on every change, and says quantitative evals that give a usable score can serve as the benchmark for automated regression checks [R4]. This lesson does not do that step.

6. The QA perspective

6.1 What the gate does not check

The gate does not know: whether the dataset is representative; whether the baseline is the right version; whether the margin is reasonable; whether the scores in the file were really produced by the system (someone could hand-write a valid result file; only reproduce from the manifest, in a trusted place, checks that); whether the policy file itself was edited (put it through review like code). The gate can falsely accept (a small regression below the margin, a regression in a subgroup that is not labelled as a slice, a slice with too few items, a mismatched dataset) and falsely reject (an INCONCLUSIVE due to too few items blocking a harmless change; a margin of 0 for a small slice almost always blocks). Both need a person to look. The gate only returns an exit code; it does not approve a release.

6.2 When the gate blocks

Read the reasons (which slice, why). FAIL: a person looks at the slice and at real error samples (L2-M05-L04). INCONCLUSIVE: add items for that slice, or the signer accepts the risk in writing. ERROR: fix the inputs, not the gate. Do not rerun with another seed until it passes: that is selecting on the result (L01, L2-M01-L04).

7. Real-world scenarios

Scenario 1 (fictional): "Green because the total is good". A candidate beats the baseline overall and on the concept slice, but the pii slice (20 items) has the interval [−0.183; 0.050]. A one-line report says "no regression". The gate gives INCONCLUSIVE because pii cannot prove "not worse" beyond 0.01. The team adds pii items (v2) and reruns the baseline on v2.

Scenario 2 (fictional): "The dataset changed silently". Someone added 20 items to a released dataset without changing the version. load_dataset reports that the fingerprint does not match; if that is bypassed, comparing the old baseline with the new candidate gives DATASET_DIFFERENT. The rule: every change is a new version.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m07
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 79 passed

8.2 Run the demo

python -m lab.demo l04

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). Every system is a simulation:

A. config problems: []  with a typo: ['UNKNOWN_KEY:aplha', 'MISSING:alpha']
B. run 1: cache hits/misses 0 1200  manifest 2bd728efc749 digest 45019287c26b dataset v1 51be75ec232c
   run 2: cache hits/misses 1200 1200  reproduce: (True, [])
C. gate B vs A (margin 0.02): INCONCLUSIVE exit 2 ['hint:INCONCLUSIVE', 'offtopic:INCONCLUSIVE', 'pii:INCONCLUSIVE']
   check: n=50 PASS interval [0.020, 0.193] margin 0.020
   concept: n=70 PASS interval [-0.010, 0.133] margin 0.020
   hint: n=40 INCONCLUSIVE interval [-0.108, 0.092] margin 0.020
   offtopic: n=20 INCONCLUSIVE interval [-0.150, 0.050] margin 0.020
   pii: n=20 INCONCLUSIVE interval [-0.183, 0.050] margin 0.010
   gate S vs A: FAIL exit 1 ['overall:FAIL', 'check:FAIL', 'concept:FAIL', 'hint:FAIL', 'offtopic:FAIL', 'pii:INCONCLUSIVE']
D. candidate with one item missing: ['IDS_DIFFER', 'SLICES_DIFFER']
   dataset v2 against v1 results: ['DATASET_DIFFERENT']
E. CLI core on files (baseline A, candidate S, policy): FAIL overall:FAIL check:FAIL concept:FAIL hint:FAIL offtopic:FAIL pii:INCONCLUSIVE -> exit 1
   missing file -> 3 ERROR FileNotFoundError
F. workflow sample triggers: ['workflow_dispatch']  lint: []  with a push trigger: ['TRIGGER_NOT_ONLY_WORKFLOW_DISPATCH:push']

Reading the output: A checks the config (clean, and a mistyped key). B runs the pipeline twice: the second time hits the cache 1200 times and reproduce returns (True, []). C is the gate for B against A (overall and per slice) and then S against A. D is two ERROR cases. E is the command-line core on three temporary files (S against A gives code 1) and with a missing file (code 3). F is the lint of the sample workflow.

8.3 Try it yourself

Save it as try_l04.py in the lab's root folder (next to lab/, not inside lab/), run python try_l04.py, then delete the file:

from fractions import Fraction as F
from lab import data, gate as G, pipeline as P, workflow as W

cfg = data.load_json("config_example.json")
bad = {k: v for k, v in cfg.items() if k != "margin"}
bad["marign"] = "1/50"
print(P.validate_config(bad))

item = {"id": "CO001", "slice": "concept", "hard": 5}
system = {"model": "tutor-a-2026-03-01", "prompt": "p00", "shift": 0}
print(P.Cache.key(system, item, 0, "x") == P.Cache.key({**system, "prompt": "p01"}, item, 0, "x"))
cache = P.Cache()
first = P.run_pipeline(cfg, cache)
print(cache.hits, cache.misses, first["manifest"]["python"])

m = first["manifest"]
print(P.check_manifest(m), P.check_manifest({**m, "results_digest": "0" * 64}))


def synth(scores, run, n_slices=2):
    n = len(scores)
    return {"manifest_id": run, "dataset_fingerprint": "fp", "ids": [f"I{i:03d}" for i in range(n)],
            "slices": ["concept"] * (n // 2) + ["check"] * (n - n // 2), "scores": [str(s) for s in scores]}


policy = {"margin": "1/50", "min_n": 100, "min_slice_n": 20, "critical_slices": ["check"], "slice_margins": {}}
base = [F(i % 2) for i in range(200)]
better = [F(1) if i % 5 == 0 else x for i, x in enumerate(base)]
worse = [F(0) if i % 3 == 1 else x for i, x in enumerate(base)]
for name, cand in (("better", better), ("worse", worse), ("same", base), ("short", base[:-1])):
    r = G.gate(synth(base, "b"), synth(cand, "c"), policy)
    print(name, r["decision"], r["exit_code"], r["reasons"][:2])
print(G.exit_code("pass"), G.exit_code("PASS"), G.worst([]))

text = (data.DATA / "gate_workflow_sample.yml").read_text(encoding="utf-8")
print(W.lint_workflow_text(text.replace("workflow_dispatch:", "pull_request:")), W.lint_workflow_text(text.replace("policy.json", "policy.json || (exit 0)")))

Output (Python 3.14.6; on Python 3.12.14 only line 3 differs, printing 3.12 instead of 3.14 because that is the Python version recorded in the manifest):

['UNKNOWN_KEY:marign', 'MISSING:margin']
False
0 1200 3.14
[] ['MANIFEST_ID_MISMATCH']
better PASS 0 []
worse FAIL 1 ['overall:FAIL', 'check:FAIL']
same INCONCLUSIVE 2 ['check:INCONCLUSIVE', 'concept:INCONCLUSIVE']
short ERROR 3 ['IDS_DIFFER', 'SLICES_DIFFER']
3 0 ERROR
['TRIGGER_NOT_ONLY_WORKFLOW_DISPATCH:pull_request'] []

Reading it: line 1: the unknown key marign and the missing margin. Line 2: changing the prompt changes the cache key (False). Line 3: the first run has no cache hits and 1200 misses, then the manifest's Python version. Line 4: an intact manifest ([]) and an edited manifest. Lines 5 to 8: four synthetic results: PASS code 0; FAIL code 1; two identical results are INCONCLUSIVE code 2 because each slice has only 100 items (the ±0.03 limit is larger than the 0.02 margin); the version missing one item is ERROR code 3. Line 9: exit_code("pass") is 3 (lowercase is not a valid decision), PASS is 0, an empty list is ERROR. Line 10: changing the trigger to pull_request is caught by the lint; || (exit 0) slips through.

8.4 Run the lesson's tests

python -m pytest tests/test_l04_pipeline_gate.py -v

Result: 23 passed. Read test_unusable_inputs_are_errors, test_a_dataset_that_changed_after_release_fails_closed and test_the_workflow_sample_is_manual_only_and_the_lint_names_what_it_checks. The cache and command-line tests only write to pytest's temporary folder; the tests run on in-memory values and the lab's data files.

8.5 Troubleshooting

Symptom Cause Fix
ConfigError: UNKNOWN_KEY:... A key name was mistyped Fix the key; do not add the key to the allow list just to make the error go away
ValueError: ... changed after release The dataset file was edited Release a new version with a new fingerprint and rerun the baseline
The gate gives IDS_DIFFER The two results were scored on different items Rerun both on the same dataset version

9. Independent exercise

Problem: Write a tiered gate rule, fix a sample workflow so it no longer has an automatic trigger, and fix a cache-key function.

Requirements: complete exercises/test_l04_gate.py:

  1. TODO 1: tiered_exit(slice_decisions, critical) following the rule in the file (ERROR, then FAIL in the overall set or a critical slice, then INCONCLUSIVE, then PASS); return the exit code.
  2. TODO 2: fix the WORKFLOW string so lint_workflow_text reports no errors, while keeping the gate command and the workflow_dispatch trigger.
  3. TODO 3: rewrite my_key so that two runs share a key only when everything that changes the result is equal.

Test data: the cases in the file (11 cases for TODO 1), the sample workflow and the key function are right inside exercises/test_l04_gate.py; nothing is placed under .github/.

Deliverable: the function and the two values above, in the file exercises/test_l04_gate.py itself.

Acceptance criteria: python -m pytest exercises/test_l04_gate.py passes (13 tests). The tests do not check whether your tiered rule is the right policy for the product, and the lint knows only the three things in §5.3.

Hints: TODO 1: write the "empty list" and "unknown string" cases first. TODO 2: run the lint and fix each error code. TODO 3: list every input of Cache.key in lab/pipeline.py, then check each one yourself by changing it.

10. Knowledge check

0/18 done · Results are kept in this browser only.

P02 · True or false

Reordering the lines of dataset_v1.jsonl (without changing the content of any item) changes the fingerprint, and load_dataset("v1") raises an error.

P04 · Select all that apply

Select every change that alters the cache key of a run (Cache.key).

P05 · Put in order

Put the steps of the lab's evaluation pipeline in order.

  1. Run the baseline and the candidate, each run going through a cache keyed by every input
  2. Compute results_digest and build the manifest
  3. load_dataset loads the released version and checks the fingerprint
  4. The gate compares the candidate with the baseline and returns exit code 0, 1, 2 or 3
  5. validate_config checks the configuration and also reports unknown keys
  6. A person reads the report and decides

P06 · Match

Match each gate error code with what it reports.

P07 · Spot the bug

The function below turns the gate's decision into an exit code but makes the gate "guess" on an unknown decision. Find the bug.

EXIT = {"PASS": 0, "FAIL": 1, "INCONCLUSIVE": 2, "ERROR": 3}

def exit_code(decision):
    return EXIT.get(decision, 0)

P08 · Short answer

Aggregate results (simulated): 240 items, two slices concept and check, 120 items each. The candidate differs from the baseline only on 12 items of the check slice (all 12 go from pass to fail). Policy: margin 1/25, min_n 100, min_slice_n 20, check is a critical slice. Which decision does the gate return, which exit code, what are the reasons, and why is one slice enough to block?

P09 · Essay

Write 5-8 sentences: on the same 240-item aggregate data set as P08, the candidate loses 6 passing items, all in the concept slice (−0.025 overall), and the gate gives INCONCLUSIVE (code 2) with reasons of ['overall:INCONCLUSIVE', 'concept:INCONCLUSIVE']. Someone proposes re-running with another seed "until it passes". State what the gate is saying, what to do, and why the proposal is wrong.

P11 · Recall

Lesson: L2-M07-L02

Two results (simulated) are identical on 200 items, two slices concept and check of 100 items each, different run ids, margin 1/25, min_n 100, min_slice_n 20. According to the "no item differs" reading of L2-M07-L02, what does the gate give?

P12 · Recall

Lesson: L2-M03-L05

A candidate beats the baseline on the whole dataset and on most slices, but on the critical slice pii the gate gives FAIL. Since the total is better, the gate should let it through.

P13 · Multiple choice

Take the manifest m of a valid run. Which of the following edits still leaves check_manifest returning an empty list?

P14 · Select all that apply

Select everything the gate does not check.

P15 · True or false

In the gate step of the sample workflow, replacing "$CANDIDATE" with ${{ inputs.candidate_result }} directly in run: still passes lint_workflow_text, so this way of writing it is safe.

P16 · Multiple choice

Which edit to the sample workflow makes lint_workflow_text return [] while the gate step can still have its exit code swallowed?

P17 · Short answer

The gate gives FAIL on the check slice in a simulated run. State the reviewer's first three actions and one thing that must not be done.

P18 · True or false

The pipeline's second run hits the cache on every run, so its result is stronger evidence than the first.

11. Summary

  • Concepts: the evaluation pipeline; a config that checks for unknown keys; a versioned dataset with a fingerprint; a cache keyed on every input; the manifest and manifest_id; the non-inferiority gate with four decisions and exit codes; fail closed; a manual-trigger workflow that is only sample text.
  • Skills: checking a config, running the gate, reading the blocking reasons, checking a manifest and a sample workflow.
  • Traps: a cache that forgets an input; a dataset that changes without a version change; comparing a result with itself; || true or continue-on-error; treating INCONCLUSIVE as green; rerunning until it passes.
  • You can now: look at a "green" CI job and ask: did it really run the gate, with which exit code, on which dataset, and who read the reasons.

12. References

ID Title Publisher URL Accessed Relevance
R1 Events that trigger workflows GitHub Docs https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows 2026-11-04 Read the page text: workflow_dispatch, only runs when the file is on the default branch
R2 Workflow syntax for GitHub Actions GitHub Docs https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions 2026-11-04 Read the page text: the default shell stops on error, step status comes from the exit code, continue-on-error
R3 Latest releases of actions/checkout, actions/setup-python, actions/upload-artifact GitHub API https://api.github.com/repos/actions/checkout/releases/latest (and the other two repositories) 2026-11-04 Read the JSON response: the latest version numbers
R4 Evaluation best practices OpenAI API docs https://platform.openai.com/docs/guides/evaluation-best-practices 2026-11-04 Read the page text: continuous evaluation, quantitative evals for automated regression checks
R5 Security hardening for GitHub Actions GitHub Docs https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions 2026-11-04 Read the page text: code injection through expressions in run:, the intermediate environment variable

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Evaluation pipeline Pipeline đánh giá: chuỗi bước chạy đánh giá (khác pipeline RAG)
Quality gate Cổng chất lượng: trả mã thoát cho CI
Non-inferiority Không kém hơn: không tệ hơn baseline quá margin
Fail closed Fail closed: thiếu hay lỗi thì chặn, không cho qua
Exit code Mã thoát: 0 PASS, 1 FAIL, 2 INCONCLUSIVE, 3 ERROR
Dataset fingerprint / version Dấu vân tay / phiên bản dataset
Cache key Khóa cache: gồm mọi đầu vào làm đổi kết quả
Run manifest Manifest lần chạy: cấu hình, dataset, seed, mã băm kết quả
Manual-trigger workflow Workflow chạy tay (workflow_dispatch)