Versioning Models, Prompts, Data, and Tools › Canary, metrics, and the decision to promote or roll back
Language AI HandbookAll chapters 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 count passing outcomes in arm and count all judged outcomes in that arm. The measured canary loss subtracts the canary pass rate from the stable pass rate. Positive means a lower measured rate for the 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]Expand
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]Expand
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]Expand
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]Expand
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!