Assign prompt or model variants by a stable conversation hash, pin the variant at the first turn, and measure mid-thread switches under a ramp.
Why per-request canaries break conversations
A canary for a web service usually assigns each request independently: a load balancer sends five percent of requests to the new build, and because requests are independent, that is fine. A prompt change or a model change for an assistant is different. A conversation is a sequence of turns that depend on each other. If turn three is answered by the new prompt and turn four by the old one, the customer sees a change in tone, format or policy in the middle of a thread, and your metrics attribute the outcome of that conversation to neither variant cleanly.
The fix is an old experimentation idea applied at the right unit: assign the variant per conversation, deterministically, and keep that assignment for the life of the conversation. This guide builds that assignment for a synthetic help-desk assistant at Belgavi's Book Store, measures how three policies behave while a ramp moves from 5 to 20 to 50 percent, and covers the operational details that make the assignment trustworthy.
The three policies
The companion example simulates 400 conversations of six turns each while the treatment share steps from 500 to 2000 to 5000 basis points over those turns. Every number below is from that synthetic run and is pinned by its tests; none is a measurement of a real assistant.
Per-request random assignment draws a fresh random number on every turn. With this schedule, 338 of 400 conversations saw both variants and 198 switched from treatment back to control at least once. That second number is the damaging one: a customer who received the new behaviour loses it on the next turn.
Hash recomputed each turn computes a bucket from the conversation id and compares it with the current ramp. Because the bucket is stable and the ramp only rises, a conversation can move from control to treatment but never back. In the simulation 179 conversations still saw both variants, all of them in the forward direction, and zero switched backwards. That is better but not good enough: every conversation open during a ramp step changes behaviour mid-thread.
Hash pinned at the first turn computes the same bucket once, when the conversation starts, stores the variant with the conversation, and reuses it. In the simulation zero conversations saw both variants. The cost is that a ramp step only affects new conversations, so exposure follows the ramp with a lag equal to typical conversation length. In this synthetic run, 25 conversations were in treatment at the first turn and the same 25 at the last, even though the ramp had reached 50 percent, because none of them started after the ramp moved.
A monotone hash assignment
# Author: Sandeep Belgavi. Deterministic conversation bucket in 0..9999.
BUCKETS = 10_000
def fnv1a32(text):
h = 0x811C9DC5
for byte in text.encode("utf-8"):
h ^= byte
h = (h * 0x01000193) & 0xFFFFFFFF
return h
def assign(conversation_id, salt, ramp_bp):
if not 0 <= ramp_bp <= BUCKETS:
raise ValueError("ramp_bp must be within 0..10000")
bucket = fnv1a32(f"{salt}:{conversation_id}") % BUCKETS
return "treatment" if bucket < ramp_bp else "control"The comparison bucket < ramp_bp is what makes ramps monotone. Raising the ramp from 2000 to 5000 adds buckets 2000 to 4999 to treatment and removes none. Lowering it for a rollback removes buckets from the top and adds none. The test suite checks this property for 2000 identifiers across five ramp levels.
FNV-1a is used here because it is short, has published reference values in RFC 9923 and can be reproduced in the browser lab exactly. Any hash with good distribution works. What matters is that the hash input is stable, the salt is explicit, and the same function runs everywhere an assignment is made. If the chat service and the analytics pipeline compute buckets with different hashes, they will disagree about which conversations were in treatment.
Pin the assignment where the conversation lives
Recomputing is tempting because it needs no storage. Pinning needs one extra field on the conversation record, written on the first turn: the variant, the salt and the ramp that produced it. That record has three uses beyond stability.
It makes analysis honest. Metrics join on the stored variant rather than recomputing it, so a later salt or ramp change cannot silently rewrite history.
It makes rollback explicit. Lowering the ramp stops new conversations from entering treatment, but pinned conversations keep their variant. If the new prompt is actively harmful, a rollback must also overwrite the pinned variant for open conversations. That is a deliberate operation with a log entry, rather than an accidental side effect of a configuration change.
It survives replicas. Several service instances handling turns of the same conversation will agree, because they read the stored value rather than each computing one with whatever configuration they last loaded.
Salts, layers and what not to hash
Change the salt only when you intend to reshuffle everyone, for example when starting an unrelated experiment. The companion example shows why: with a constant 20 percent ramp, changing the salt halfway through recomputed assignments for open conversations and produced 66 treatment-to-control switches among 400 conversations. Pinning prevents that too, but only for conversations that already have a stored variant.
When two experiments run at once, give each its own salt so their buckets are independent. Using one salt for both means the same conversations land in treatment for both, and the effects cannot be separated.
Hash a stable conversation or case identifier, not a request id, a session cookie that rotates, or a user id when one user may hold several unrelated conversations. A user-level assignment is reasonable when the change alters something the user carries between conversations, such as memory behaviour. For a prompt that only shapes replies within a thread, the conversation is the natural unit.
Measuring a pinned canary
Because exposure lags the ramp, read results by the stored variant and by conversation start time, not by wall-clock window. A conversation that started before the ramp step belongs entirely to control even if it continued for hours afterwards.
Compare conversation-level outcomes: resolution without escalation, number of turns, customer follow-up within a day, refunds reversed later. Turn-level metrics such as average reply length are useful diagnostics but can mislead when the two variants produce conversations of different lengths.
Check the split itself. The fraction of new conversations in treatment should track the ramp. In the simulation, ten thousand fresh identifiers at 2000 basis points produced a treatment share of 0.1983. A persistent deviation larger than sampling noise usually means the identifiers are not as random as assumed, for example sequential ids hashed with a weak function, or a client that creates new conversations on retries.
Failure modes
Conversation forks. If an assistant can branch a conversation, decide whether the branch inherits the parent's variant. Inheriting is usually right; recomputing for the branch id puts one customer thread in two variants.
Retries that create new conversations. A client that opens a fresh conversation after an error gives that customer a second roll of the dice. Detect this by joining on customer and time window, not only on conversation id.
Long-lived conversations. Pinned assignments can keep an abandoned variant alive for weeks in threads that reopen occasionally. Give each experiment an end date after which open conversations are migrated deliberately to the winning variant.
Variant-dependent tools. If the new prompt relies on a tool the old one does not have, a conversation pinned to control must not see that tool even after the tool ships. Bind the tool list to the stored variant, not to deployment state.
When this is unnecessary
A change that does not affect what the user sees, such as a faster model producing the same structured output for a back-office classifier, can be canaried per request. Each call is independent, and mixing variants inside a conversation has no user-visible effect. The conversation-level design is for changes that a customer could notice between one turn and the next.
Interactive experiment
Conversation canaries: sticky hash assignment, ramps and mid-thread switches. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.