Versioning Models, Prompts, Data, and Tools › Canary, metrics, and the decision to promote or roll back

Michael BrenndoerferDecember 2, 20263 min read
Language AI HandbookAll chapters
Part 64 of 67Compound AI System Design
Chapter 489Versioning Models, Prompts, Data, and Tools › Canary, metrics, and the decision to promote or roll back
Reading section 7 of 14 · Canary, metrics, and the decision to promote or roll back · 3 minSection 7 of 14 · 3 min

Section 7 of 14 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Set a quality threshold, a minimum sample for each arm, and the decision time before examining results. For example, review one outcome per eligible unit and apply the same grader to both arms. Compare outcomes from contemporaneous, representative traffic and check that assignment is not confounded by traffic type or infrastructure. Canarying Releases

This notebook simulates independent, binary evaluator outcomes under two assumed pass probabilities. The 4,000 and 800 outcomes are a separate fixture for the decision rule. They are sampled directly per arm rather than drawn from the routing example. The observed rates are estimates of the assumed probabilities.

Let kak_a count passing outcomes in arm aa and nan_a count all judged outcomes in that arm. The measured canary loss dd subtracts the canary pass rate from the stable pass rate. Positive dd means a lower measured rate for the canary.

d=kstablenstable−kcanaryncanaryd = \frac{k_{\mathrm{stable}}}{n_{\mathrm{stable}}} - \frac{k_{\mathrm{canary}}}{n_{\mathrm{canary}}}

The fixture requires 500 outcomes in both arms and rolls back if the measured loss exceeds one percentage point. It compares the rates as exact fractions so a loss equal to the threshold stays on the review branch. This is a demonstration of a predeclared operational rule. It neither tests statistical significance nor establishes noninferiority. A real experiment should choose a sample plan and inference method for the design, expected variability, and cost of false decisions. Repeated monitoring needs a decision plan that accounts for repeated looks.

PythonIn [19]
CollapseExpand
def observe(
    rng: random.Random, pass_probability: float, n: int
) -> tuple[int, int]:
    return sum(rng.random() < pass_probability for _ in range(n)), n


def canary_decision(stable, trial, *, minimum=500, max_drop=0.01):
    stable_passes, stable_total = stable
    trial_passes, trial_total = trial
    if min(stable_total, trial_total) < minimum:
        return "COLLECT MORE"
    drop = Fraction(stable_passes, stable_total) - Fraction(
        trial_passes, trial_total
    )
    return "ROLL BACK" if drop > Fraction(str(max_drop)) else "READY FOR REVIEW"


rng = random.Random(1)
stable_observation = observe(rng, 0.92, 4_000)
canary_observation = observe(rng, 0.90, 800)
decision = canary_decision(stable_observation, canary_observation)
ConsoleOut [20]
CollapseExpand
stable: 3678/4000 = 91.950%
canary: 715/800 = 89.375%
Decision: ROLL BACK

The observed canary loss crosses the threshold in this run. The deployment can restore stable traffic while the candidate remains in the store for diagnosis. A result labeled READY FOR REVIEW would still require review of any guardrails outside this example. Canary traffic and shadow traffic also differ in whether the candidate's output is returned to the caller. Online Experiments and Production Evaluation

Check the branch that waits for evidence explicitly. Raising a fixed sample minimum protects the decision from being taken too early under this rule. It does not make the measurement represent the population or bound its error rate by itself.

PythonIn [21]
CollapseExpand
short_trial = (18, 20)
equal_rates = (470, 500)
print(canary_decision(stable_observation, short_trial))
print(canary_decision(equal_rates, equal_rates))
at_limit = canary_decision((460, 500), (455, 500))
assert at_limit == "READY FOR REVIEW"
print("At exactly one percentage point:", at_limit)
ConsoleOut [21]
CollapseExpand
COLLECT MORE
READY FOR REVIEW
At exactly one percentage point: READY FOR REVIEW

A useful rollout procedure specifies what each outcome triggers, including both paths that do not automatically change traffic. In this policy COLLECT MORE leaves the canary assignment in place, and READY FOR REVIEW permits the next check. ROLL BACK changes active assignment to stable after a loss beyond tolerance. Apply traffic guardrails for latency, resource cost, and critical failures separately. Their measurement units can be different from a pass rate. Latency may be summarized over a comparable time window, while a missing required permission check may merit an immediate stop regardless of the average.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy