advanced27 min studyLesson 417 in Engineering

A replay tests a counterfactual only within its captured world

Design paired failure replays with controlled inputs, initial state, dependencies, and oracles while limiting claims to the conditions actually reproduced.

On this page

What you’ll understand

  • Define the intervention and measured outcome of a replay comparison.
  • Control workload and state rather than only matching request text.
  • Separate a reproduced mechanism from a universal production causal claim.

A counterfactual asks how an outcome would differ if one aspect of a system had changed while the relevant context stayed appropriately comparable. A replay approximates that question by running captured or constructed work under different conditions. Its strength depends on what the environment preserves: versions, initial state, concurrency, timing, dependencies, and the measurement oracle. A patched build succeeding once is useful evidence, but it does not recreate every hidden condition of the original incident or guarantee that every future workload is protected.

Name the intervention before constructing the replay

Specify the mechanism being changed, such as a cache-capacity rule, retry budget, or allocation lifetime, and define the outcome that would demonstrate the failure. Keep that outcome distinct from incidental logs. If the suspected problem is duplicate commitment, an HTTP success response is not a sufficient oracle; inspect the committed effects. If it is GPU memory retention, latency alone can miss a leak that has not yet exhausted the device. The replay must expose the claimed mechanism rather than simply produce a familiar error string.

Capture artifact identities, configuration, request ordering, relevant data snapshots, and initial resource state. A cold cache and a warm cache are different conditions even when requests are identical. Seeds can help make some random choices reproducible, but do not control thread scheduling, asynchronous dependencies, or hardware nondeterminism by themselves. Explicitly stub or record external services when appropriate and state what realism that removes. A simulator that assumes the desired behavior cannot independently verify that behavior in the real dependency.

Δi=Yi(1)−Yi(0)\Delta_i=Y_i(1)-Y_i(0)
Y_i(1) and Y_i(0) denote outcomes under the defined changed and baseline conditions for replay case i. For latency, Δ_i is in milliseconds and negative values indicate a faster changed run. Their comparability depends on the controlled context; both potential outcomes cannot simply be read from one production event.↔ Scroll wide equations horizontally.

Pair cases and challenge equivalence

Run baseline and changed configurations against the same declared case set, controlling reset and warm-up rules. Record repeated runs when nondeterminism matters and avoid treating many requests within one shared run as independent replicas. If the baseline no longer reproduces the failure, investigate whether the captured context is missing the triggering condition before claiming the patch fixed it. A positive control helps show that the oracle detects the old failure, while negative controls test that the harness does not label unrelated behavior as the mechanism.

A successful replay supports a bounded claim: under these inputs, state, and modeled dependencies, the change altered the specified outcome. Generalization to production needs evidence that the omitted conditions are not essential or tests that exercise them. Shared-resource interference, long-duration accumulation, different prompt shapes, and real cancellation timing can all lie outside a short deterministic fixture. Preserve those limits in the incident report so later readers do not turn a narrow reproduction into a universal causal proof.

Δ‾=1n∑i=1nΔi\overline\Delta=\frac1n\sum_{i=1}^{n}\Delta_i
This is the arithmetic mean paired difference over n>0 declared replay cases, using the same outcome unit as Δ_i. It is a descriptive case-set summary; uncertainty and production generalization require a sampling and dependence model not supplied by this average.↔ Scroll wide equations horizontally.

A toy replay can expose one mechanism exactly

The cache lab provides a small fully specified replay world. Its request sequence is address (i·s) mod 16, initial cache empty, and replacement rule LRU. That makes a capacity intervention inspectable without guessing hidden server state. It does not represent a model-serving cache's concurrency, serialization, entry sizes, or admission policy. A correct conclusion about this world can motivate a real fixture, while a mismatch in the real fixture can reveal which assumption was missing.

Reset, set both C=3 and s=4, predict zero initial hits over the sixteen requests already evaluated, then inspect and Play or Step. Reset again and set both C=4,s=4 to compare twelve initial hits with the same trace and initial-state rule. Playback extends the deterministic trace up to 4,096 requests; edits retain time, so Reset is required for equal-length comparisons. The capacity change causes the hit-count difference in this explicit model, but does not by itself establish what caused a production incident.

Summarize four paired replay cases

Four fictional paired cases have baseline latencies [120,100,110,90] ms and changed latencies [100,90,95,85] ms. Assume the stated pairing and controlled context are valid; no population-sampling claim is made.

  1. Subtract baseline from changed for each pair: the differences are [−20,−10,−15,−5] ms. Every observed case is faster under the changed condition.

  2. The sum of differences is −50 ms, giving mean −50/4 = −12.5 ms. Baseline mean is 105 ms and changed mean is 92.5 ms, agreeing with that difference.

  3. Report a twelve-and-a-half-millisecond descriptive improvement on these four cases. Do not infer a production-wide effect size, confidence interval, or absence of long-run regressions without additional design and evidence.

The result

The paired case set improves by 12.5 ms on average. The result supports only the controlled replay conditions and the declared latency oracle.

Explore the model

Interactive lab

Interactive lab · cache

Replay one changed condition in a fully specified model

Compare fresh Reset → set both C=3,s=4 and Reset → set both C=4,s=4 cases at the initial sixteen requests. Predict hits, then Play or Step. The deterministic trace caps at 4,096 requests and contains no real service concurrency or external dependencies.

Replay one changed condition in a fully specified modelA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAn exact model intervention supports an exact model claim; production counterfactuals need evidence about omitted conditions.

Check your understanding

A patched replay succeeds, but the baseline replay no longer reproduces the original failure. What should the investigator do?

Try it yourself

A memory-leak replay lasts one minute and the changed build does not exhaust memory. The original incident accumulated over six hours. What is missing, and how should the oracle and claim be adjusted?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

A short run can miss a slow accumulation mechanism even when final allocation succeeds. Measure the retained state or a justified long-duration surrogate.

Compare with the solution

The replay has not exercised the original duration or necessarily measured the retention mechanism. Inspect allocation lifetimes and retained-memory growth under controlled work, extend the run or use a justified accelerated fixture, and verify the baseline exposes the same mechanism. State the conditions actually tested rather than claiming universal leak removal from one minute without exhaustion. Acceleration must preserve the relevant lifecycle instead of merely assuming it.

Take it with you

  • Counterfactual replay needs a defined intervention, controlled state, and a mechanism-specific oracle.
  • A baseline reproduction and negative controls strengthen interpretation of a changed run.
  • Descriptive replay improvements do not automatically generalize to the production population.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.