Your Agent Canary Ran for an Hour. It Needed Fifteen.

Catching a 2%→3% task-failure regression at 5% canary traffic takes about 15 hours. Peeking hourly raises false alarms from 5.8% to 25.9%.


Model upgrades, prompt edits, a new tool description, a rebuilt retrieval index: every one of these changes what an agent does, and most teams ship them the way they’d ship a config tweak. Flip it, watch the dashboard for a bit, move on.

The better teams canary them. Five percent of traffic goes to the new build, someone watches task success for an hour, and if nothing looks wrong it goes to everyone. That’s the right instinct with the wrong arithmetic. An hour at 5% is 100 tasks. At a 2% baseline failure rate, that’s two expected failures. You can’t tell 2% from 3% with two failures. You can’t tell 2% from 6%.

How many tasks a canary needs

The question a canary answers is a two-sample test: is the canary’s failure rate higher than the baseline’s? How many canary tasks you need depends on three things:

  • The baseline failure rate. Rare events need big samples.
  • The smallest regression you care about. Halving the regression roughly quadruples the sample.
  • The traffic split. The baseline arm is large, so most of the uncertainty is in the canary arm.

For an agent with a 2% task-failure rate handling 2,000 tasks an hour, at 80% power and a one-sided 5% significance level:

Regression to catchCanary shareCanary tasks neededTimeExtra failures if the regression is real
2.0% → 3.0%5%1,48514.8 h~15
2.0% → 3.0%20%1,8064.5 h~18
2.0% → 3.0%50%3,0133.0 h~30
2.0% → 2.5%5%5,53155.3 h~28
2.0% → 2.5%20%6,64916.6 h~33
2.0% → 2.2%5%32,982329.8 h~66

Two things stand out.

An hour is nowhere near enough. Even the coarse question (did failures go from 2% to 3%?) takes about 15 hours at 5% traffic. A 25% relative regression takes more than two days. Below that, a canary isn’t the right instrument at all; you need an offline paired eval on a fixed set, where the same tasks run on both builds.

A bigger canary is faster but costs more failures. Going from 5% to 20% traffic cuts the wait from 15 hours to under 5, for about three more failed tasks if the regression is real. Going to 50% saves another hour and a half and costs about two-thirds more failures. The middle of that curve is usually the sweet spot, and where it sits depends on what a failed task costs you.

Peeking

The other habit worth breaking is watching the canary and rolling back the moment it looks significantly worse. Each look is another chance for noise to cross the line.

I simulated 2,000 canaries at 5% traffic over a 24-hour window, with and without a real regression, using a one-sided z-test at the 5% level. The rates are illustrative and the numbers describe the test, not any real agent. The script is at the end.

ScenarioTest once at 24 hPeek every hour
No regression (false alarm rate)5.8%25.9%
Regression to 3.0% (detection rate)94.0%97.2%

Peeking hourly buys three points of detection and costs a fourfold increase in false alarms. One in four good builds gets rolled back for nothing. That sounds like a safe failure until you notice what it trains people to do: a team that sees canaries fail on healthy builds learns to override the canary.

The simplest fix is to split the significance level across the looks you plan to take. With 24 hourly looks at 0.05/24 each, false alarms fell to 1.8% and detection of the 2%→3% regression fell to 77.7%. That correction is conservative. A proper sequential test (an SPRT, or an alpha-spending boundary from the clinical-trials literature) keeps more of the power while still letting you stop early. Either is better than eyeballing.

What counts as a failure

All of this assumes you can count failed tasks, which for an agent is the hard part. Error codes catch the loud failures. The ones a model change tends to introduce are quieter: a task that completes with a worse answer, an extra tool call, a refusal where there used to be an action.

A useful canary metric for an agent is usually a composite:

  1. Hard failures. Errors, timeouts, tool calls rejected by policy.
  2. Validated failures. Outputs that fail a schema or a deterministic check.
  3. Escalations. Tasks the agent handed back to a human.
  4. Cost and steps per task. A model that needs three more tool calls per task is a regression even if it gets there.

Pick the metric and the minimum regression before the canary starts, then compute the duration. If the duration is unacceptable, that’s information: the metric is too noisy, or the change is too risky to verify in production and needs more offline evaluation first.

A canary policy for agent changes

  1. Treat behavior changes as deploys. Model version, prompt, tool descriptions, retrieval index, context assembly. If it can change what the agent does, it goes through the canary.
  2. Size the canary from the math. Baseline rate, minimum regression, traffic share in; canary duration out.
  3. Plan your looks. Decide how often you’ll check, and use a sequential test or a split significance level.
  4. Keep a hard stop. Separately from the statistics, roll back immediately on any high-severity incident attributed to the canary. One severe failure isn’t a statistical question.
  5. Pair it with offline evals. The canary catches what your eval set didn’t cover. It’s the last gate, not the only one.

The script

Standard library only. Seeded, so you get exactly the numbers above. Save as agent_canary.py and run it with python3.

"""How long must an agent canary run? Power, and the cost of peeking.
Synthetic, seeded, stdlib only. Rates are illustrative, not from any real agent.
"""
import math
import random
from statistics import NormalDist

Z = NormalDist()
BASE_FAIL = 0.02        # task failure rate of the current build
TASKS_PER_HOUR = 2000   # total agent tasks per hour across the fleet


def canary_tasks_needed(p1, p2, share, alpha=0.05, power=0.80):
    """Canary-arm sample size for a one-sided two-proportion z-test (is the canary worse?)
    with unequal arms: the baseline gets (1-share)/share tasks for every canary task."""
    k = (1 - share) / share
    za, zb = Z.inv_cdf(1 - alpha), Z.inv_cdf(power)
    pbar = (p2 + k * p1) / (1 + k)
    num = (za * math.sqrt(pbar * (1 - pbar) * (1 + 1 / k))
           + zb * math.sqrt(p2 * (1 - p2) + p1 * (1 - p1) / k)) ** 2
    return math.ceil(num / (p2 - p1) ** 2)


def z_worse(f_c, n_c, f_b, n_b):
    p_c, p_b = f_c / n_c, f_b / n_b
    p = (f_c + f_b) / (n_c + n_b)
    se = math.sqrt(p * (1 - p) * (1 / n_c + 1 / n_b)) or 1e-12
    return (p_c - p_b) / se


def binom(rng, n, p):
    # normal approximation is fine at these sizes; keeps stdlib-only and fast
    x = round(rng.gauss(n * p, math.sqrt(n * p * (1 - p))))
    return min(n, max(0, x))


def run_canary(canary_fail, share, hours, peek_hourly, rng, alpha=0.05):
    zcrit = Z.inv_cdf(1 - alpha)
    fc = nc = fb = nb = 0
    for _ in range(hours):
        c = int(TASKS_PER_HOUR * share)
        b = TASKS_PER_HOUR - c
        fc += binom(rng, c, canary_fail); nc += c
        fb += binom(rng, b, BASE_FAIL); nb += b
        if peek_hourly and z_worse(fc, nc, fb, nb) > zcrit:
            return True
    return z_worse(fc, nc, fb, nb) > zcrit


if __name__ == "__main__":
    print("canary tasks needed (80% power, one-sided alpha 0.05), baseline 2.0% failure")
    for p2 in (0.03, 0.025, 0.022):
        for share in (0.05, 0.20, 0.50):
            n = canary_tasks_needed(BASE_FAIL, p2, share)
            hrs = n / (TASKS_PER_HOUR * share)
            extra = n * (p2 - BASE_FAIL)
            print(f"  regress to {p2:.1%}: {n:6d} canary tasks; at {share:.0%} traffic = {hrs:6.1f} h,"
                  f" ~{extra:4.0f} extra failed tasks if the regression is real")
    rng = random.Random(3)
    TRIALS = 2000
    print("\nsimulated, 5% canary traffic, fixed 24 h horizon")
    for label, p2, peek in (("no regression, test once", BASE_FAIL, False),
                            ("no regression, peek hourly", BASE_FAIL, True),
                            ("regress to 3.0%, test once", 0.03, False),
                            ("regress to 3.0%, peek hourly", 0.03, True)):
        hits = sum(run_canary(p2, 0.05, 24, peek, rng) for _ in range(TRIALS))
        print(f"  {label:30s} flagged {hits / TRIALS:6.1%}")
    # Bonferroni-style fix for 24 looks: alpha/24 per look
    hits = sum(run_canary(BASE_FAIL, 0.05, 24, True, rng, alpha=0.05 / 24) for _ in range(TRIALS))
    print(f"  {'no regression, peek, alpha/24':30s} flagged {hits / TRIALS:6.1%}")
    hits = sum(run_canary(0.03, 0.05, 24, True, rng, alpha=0.05 / 24) for _ in range(TRIALS))
    print(f"  {'regress to 3.0%, peek, alpha/24':30s} flagged {hits / TRIALS:6.1%}")

Full output:

canary tasks needed (80% power, one-sided alpha 0.05), baseline 2.0% failure
  regress to 3.0%:   1485 canary tasks; at 5% traffic =   14.8 h, ~  15 extra failed tasks if the regression is real
  regress to 3.0%:   1806 canary tasks; at 20% traffic =    4.5 h, ~  18 extra failed tasks if the regression is real
  regress to 3.0%:   3013 canary tasks; at 50% traffic =    3.0 h, ~  30 extra failed tasks if the regression is real
  regress to 2.5%:   5531 canary tasks; at 5% traffic =   55.3 h, ~  28 extra failed tasks if the regression is real
  regress to 2.5%:   6649 canary tasks; at 20% traffic =   16.6 h, ~  33 extra failed tasks if the regression is real
  regress to 2.5%:  10878 canary tasks; at 50% traffic =   10.9 h, ~  54 extra failed tasks if the regression is real
  regress to 2.2%:  32982 canary tasks; at 5% traffic =  329.8 h, ~  66 extra failed tasks if the regression is real
  regress to 2.2%:  39355 canary tasks; at 20% traffic =   98.4 h, ~  79 extra failed tasks if the regression is real
  regress to 2.2%:  63553 canary tasks; at 50% traffic =   63.6 h, ~ 127 extra failed tasks if the regression is real

simulated, 5% canary traffic, fixed 24 h horizon
  no regression, test once       flagged   5.8%
  no regression, peek hourly     flagged  25.9%
  regress to 3.0%, test once     flagged  94.0%
  regress to 3.0%, peek hourly   flagged  97.2%
  no regression, peek, alpha/24  flagged   1.8%
  regress to 3.0%, peek, alpha/24 flagged  77.7%

Limits

  • Independent tasks assumed. Real agent traffic is bursty and correlated: a bad hour for one tenant shows up as a cluster of failures. Correlation makes the effective sample smaller and the canary longer.
  • Stationary baseline assumed. If the baseline failure rate drifts during the canary (time of day, a dependency having a bad afternoon), a concurrent baseline arm protects you; a comparison to last week’s numbers doesn’t.
  • Normal approximations. The power formula and the simulated counts both use normal approximations to the binomial. At these sample sizes they’re close; at very low failure rates use an exact test.
  • Failure has to be countable. The whole method rests on a task-failure metric you trust. For many agent changes, building that metric is most of the work.

A canary is a statistical test with a deploy attached. Run it long enough to mean something.

Frequently asked questions

How long should a canary run for an AI agent model or prompt change?

Long enough to collect the number of canary tasks a power calculation says you need, which depends on your baseline failure rate, the smallest regression you care about, and the canary's traffic share. With a 2% baseline task-failure rate and 2,000 tasks an hour, detecting a rise to 3% with 80% power takes about 1,500 canary tasks, which is roughly 15 hours at 5% traffic. Detecting a rise to 2.5% takes about 55 hours at the same share.

Is it OK to check an agent canary dashboard every hour and roll back if it looks worse?

Only if your test accounts for the repeated looks. In a simulation of a canary with no real regression, testing once after 24 hours raised a false alarm 5.8% of the time, while testing every hour and stopping at the first significant result raised one 25.9% of the time. Use a sequential test or split your significance level across the planned looks.

What should trigger a canary for an AI agent?

Any change that can alter the agent's behavior: a model version, a system prompt or tool description edit, a retrieval index rebuild, a new tool, or a context-assembly change. These are deploys of the agent's behavior even when no code changed, and they deserve the same progressive rollout as a code release.

Comments