# Regression testing shouldn't be scheduled weekly; it should be scheduled by change source

Date: 2025-03-08
Category: Technology
Tags: Regression Testing, Evaluation Sets, Prompt
Summary: Changing one line, a model alias being quietly swapped behind the scenes, and an index rebuild all have different blast radii. I've split regression tests into four tiers by change source and spelled out each tier's trigger conditions, cost, and boundaries.

I deleted the line in the system prompt that said "restate the user's question before giving a conclusion." The reasoning was solid: the model is strong enough, the line is verbose, and it wastes tokens. CI was all green, unit tests all passed, and that batch of smoke cases passed too.

Three days later, support forwarded a ticket: a user asked about refund timelines, and the reply answered with the invoice title. The question was "followed" in the response—it just answered the wrong subject.

After that, I rescheduled the entire regression testing cadence. The conclusion is one sentence: the frequency of regression tests should not be decided by the calendar, but by the change source.

## Watching only the code diff is not enough

The behavior of an LLM application is roughly determined by four things together: code, prompt, model, and retrieval index. I count tool schemas on the prompt side, because they go in together with the context.

Traditional CI only sees the first. We spend a lot of effort strictly controlling code changes, while changes to the other three often don't even have a commit record.

The model part is the most hidden. Some vendors' version numbers carry dates, like `xxx-2024-08-06`, so you know exactly what you're using; other aliases point to floating implementations that get silently swapped behind the scenes one day. My approach is to log a column in the call logs with the real model field from the response body—not the alias I passed in, but the value the server returned. Once I pulled the July logs and August logs and did a `distinct`, and found the value under the same alias had changed, with not a single line of code touched. For those few days the output format pass rate dropped a bit, and nobody could say why, until I dug out that column.

The index has a bigger blast radius. Re-chunking, changing chunk size, switching embedding models—after any rebuild, the top-k retrieval distribution changes. If you only test end-to-end answers, what you see is "less accurate than before," but you can't tell whether retrieval fetched the wrong material or the model failed to use the material well.

Prompt is even more direct: the impact of one line is often bigger than a refactor. A code refactor at most breaks one branch; a prompt change drifts the whole system's tone, boundaries, and refusal policy together.

## I split it into four tiers by change source

| Tier | Trigger | Case count | Cost per run (rough) | Frequency |
| --- | --- | --- | --- | --- |
| smoke | Any PR | 20 | A few dimes, two or three minutes | Several times a day |
| core | Prompt directory hash changes, tool schema changes, before release | Around 100 | A dozen or so yuan | A few times a week |
| full | Model version string changes, index manifest changes, quarterly | 400+ | One or two hundred yuan | Once or twice a month |
| manual | Monthly spot check | Sample 30 | Half a person-day | Monthly |

Deciding which tier to run doesn't rely on people remembering—it's handled by a script of a few dozen lines. After each run, three kinds of fingerprints are written into `.eval/last_run.json`, and the next time work starts, they're compared first:

```python
import hashlib, json, os, pathlib

def fp(paths):
    h = hashlib.sha256()
    for p in sorted(map(str, paths)):
        h.update(pathlib.Path(p).read_bytes())
    return h.hexdigest()[:12]

current = {
    "prompt": fp(pathlib.Path("prompts").rglob("*.md")),   # 含工具描述
    "model":  os.environ["MODEL_VERSION"],                # 服务端返回的真实版本
    "index":  pathlib.Path("index/manifest.sha").read_text().strip(),
}

last_path = pathlib.Path(".eval/last_run.json")
last = json.loads(last_path.read_text()) if last_path.exists() else {}

if not last or current["model"] != last.get("model") or current["index"] != last.get("index"):
    print("full")
elif current["prompt"] != last.get("prompt"):
    print("core")
else:
    print("smoke")
```

There's a tradeoff worth mentioning here: I deliberately keep the full set within a few hundred cases. Once it takes half an hour and costs a few hundred yuan, people start finding reasons to skip it—"it should be fine this time." A test that gets skipped is equivalent to no test. Better to cover a narrower scope, but make it cheap enough that no one can bear to skip it.

As for "how often to run the full set," my answer is: no fixed period, only triggers. Model version changed, run it; index rebuilt, run it; if nothing has changed for a quarter, run it once anyway to confirm it hasn't been affected by environment drift.

## Fingerprints themselves can lie

The script above looks simple, but the hard part is making the fingerprints trustworthy. Three common problems.

If the prompt directory contains templates with timestamps, environment names, or experiment splits mixed in, the hash differs every time, and the result is running the core set every day. After a week of that, people start suspecting the script is broken and then bypass it manually. The fix is to extract the dynamic parts into placeholders and hash only the template itself.

The model fingerprint must really come from the server response body. If that column is a manually filled environment variable that nobody updates, it quickly degenerates into a hardcoded constant that can never trigger the full set.

The index manifest must be written by the indexing script after success. It must not be written when the rebuild starts, and certainly not edited by hand. A manifest left behind by a mid-way failure is worse than none: it tells you "the index changed, already tested," when what was actually tested was the old index.

There's also an easily overlooked branch: when `last_run.json` doesn't exist (new machine, CI cache cleared), the default should be to fall back to running the full set, not to default to smoke. Running it for the first time in a new environment, spending a bit more is better than missing tests.

## Verdicts can't be pass/fail

This is the hardest part of LLM regression. Traditional assertions are only right or wrong; LLM outputs have no single correct answer.

My cases now have two kinds of assertions. The first is hard assertions: whether the JSON parses, whether required fields are present, whether things that should be refused are refused, whether sensitive words leak. These must pass 100%; one failure blocks the merge, no negotiation. The second is soft assertions: keyword inclusion, regex, or another model scoring against a rubric. Soft assertions have tolerance—for example, dropping at most one level on a five-level score counts as a pass.

Where to set the tolerance line is debatable, and I know some people object to it being this loose. But my experience is that setting it too tight buys you a pile of false positives, and after two weeks the team starts ignoring red. Once the red line is treated as noise, the four tiers above are wasted too.

Then there's flakiness. Running the same case three times can give different results, especially when temperature isn't set to zero. My approach is to run three times and take the majority, while recording consistency across the three runs; cases with high variance are pulled out into a separate column, not counted against the red line, only observed. This "flakiness leaderboard" is actually what I should look at most—it tells me more about where the system is unstable than the pass rate does.

## Index rebuilds are the big change most easily missed

I missed one once. After changing the chunking rules and rebuilding the index, the core set ran, and the end-to-end pass rate dropped from just over ninety percent to just over eighty. I thought the new chunking was bad and spent half a day tuning parameters, only to find that two old document ids in the retrieval results no longer existed—the rebuild script had deleted them, but the mapping table wasn't updated.

Since then I've split out the retrieval layer to test separately. A set of about sixty cases, each "query → expected hit document id," no model involved, pure retrieval, runs in tens of seconds. It only enters the main flow when the index changes, but an incremental version also runs daily—new documents pushing things out of top-k is something I've hit more than once.

In the manifest I always store four things: embedding model name, chunk parameters, total document count, content hash. Miss any one, and it won't reconcile after some rebuild.

The smallest action I take now is: scan the model field that appears in the call logs every day, and email myself when an unseen new value shows up. The regression testing schedule ultimately comes down to this string comparison.

## The premise of this tiering is that changes can be captured

For a team of two or three people, with prompts changed ten times a day and a hundred-case core set costing a dozen or so yuan per run, there's really no need to be this granular: smoke on PRs, core on merge to main, full only when the model version changes—that's enough.

Conversely, if the cost of a product error is high—involving money or compliance responses—the little bit saved by tiering doesn't matter; you'd rather run the full suite plus manual spot checks on every release. Tiering exists so that things can run when they need to, not so you can run less.

The real precondition is that the change itself can be captured by a fingerprint. If prompts are edited in some config platform and never enter the repo, if nobody maintains the model version, and if the index manifest is handwritten, this whole setup degrades into "relying on people remembering"—in which case you're better off honestly falling back on a calendar, which at least won't miss things so completely.

In your CI, when was the last time a real model version was recorded?
