---
title: "The bug will not reproduce in staging. Which condition is missing? | Proofline"
description: "A failure that staging will not reproduce depends on a condition production had at that moment and staging lacks."
url: https://proofline.sh/learn/bug-will-not-reproduce-in-staging/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# The bug will not reproduce in staging. Which condition is missing?

A failure that staging will not reproduce depends on a condition production had at that moment and staging lacks. It may be the size or shape of the data, concurrency, a configuration value or flag, a version, or the time. List those conditions from the failing request's own logs, diff each one against staging, and test them. Start from the full production set and remove one condition at a time, because adding conditions to staging one at a time misses a failure that needs two of them together.

Deployment failures The Proofline team November 24, 2026 7 min read

## The symptom and the explanations

The example is illustrative. A fictional `profile-export` service writes customer profiles to a shared object store and reads them back. On Monday between 13:00 and 13:40 UTC, a few exports in production came back with the wrong size and failed their checksum. Staging ran the same build, and every export there passed, including exports of the affected customers' profiles copied from production.

Four differences between the two environments were on the table, and each had an advocate:

-   Production profiles run up to 200 KB, and the staging fixtures stop at 30 KB.
-   Production runs four export workers, and staging runs one.
-   The `async_export` flag is on in production and off in staging.
-   Production writes to the store in `eu-west-1`, and staging in `us-east-1`.

Any one of them could be the cause, and so could any pair. [Choose the observation where explanations disagree](/learn/which-observation-separates-two-explanations/)

## What each explanation predicts

The observations are experiments: each one sets the four conditions and runs the export. The columns are three of the possible explanations.

| Experiment | Large profiles alone | The flag alone | Large profiles and concurrency together |
| --- | --- | --- | --- |
| Staging as it is | passes | passes | passes |
| Staging plus large profiles | fails | passes | passes |
| Staging plus four workers | passes | passes | passes |
| Staging plus the flag | passes | fails | passes |
| Production minus large profiles | passes | fails | passes |
| Production minus four workers | fails | fails | passes |
| Production minus the flag | fails | passes | fails |

The middle rows are what most people try: add one production condition to staging and see whether it breaks. Under the third explanation every one of them passes, which reads as "cannot reproduce" when the cause is sitting in the table. The bottom rows start from a configuration known to fail and take one condition away at a time. A row that passes names a condition the failure needs. Under the third explanation, two rows pass, and they name both conditions.

This is the reasoning of cutting a reproduction down, applied to environment conditions instead of code.

## The lab: a failure that needs two conditions

The script models the export's write path. A profile larger than 64 KiB is written in two parts, and the store attaches each tail part to the most recent head part it received, whoever sent it. With one worker the parts arrive in order. With several workers taking turns, a tail can arrive after another worker's head and join the wrong profile. The flag and the region are real settings in the model and do not reach this code. It needs Python 3.8 or later.

```
import itertools

CHUNK = 64 * 1024     # the store takes at most 64 KiB per write

def save(profiles, workers):
    """Send each profile in parts of at most CHUNK bytes; return the ones stored wrong."""
    streams = [[] for _ in range(workers)]
    for i, (name, size) in enumerate(profiles):
        streams[i % workers].append((name, "head", min(size, CHUNK)))
        if size > CHUNK:
            streams[i % workers].append((name, "tail", size - CHUNK))
    arrived = [p for turn in itertools.zip_longest(*streams) for p in turn if p]
    stored, last = {}, None
    for name, kind, n in arrived:          # the bug: a tail joins the latest head, whoever sent it
        if kind == "head":
            stored[name], last = n, name
        else:
            stored[last] += n
    return [name for name, size in profiles if stored[name] != size]

def run(env):
    # flag and region change other code paths in the service; they do not reach save()
    sizes = [10_000, 200_000, 12_000, 90_000, 30_000, 150_000] if env["large"] else [10_000, 12_000, 30_000, 8_000]
    bad = save([(f"p{i}", s) for i, s in enumerate(sizes)], env["workers"])
    return "FAIL" if bad else "ok"

PROD    = {"workers": 4, "large": True,  "flag": "on",  "region": "eu-west-1"}
STAGING = {"workers": 1, "large": False, "flag": "off", "region": "us-east-1"}

print(f"production {run(PROD)}, staging {run(STAGING)}")
print("staging plus one production condition:")
for k in PROD:
    print(f"  + {k:8s} {run({**STAGING, k: PROD[k]})}")
print("production minus one condition:")
for k in PROD:
    print(f"  - {k:8s} {run({**PROD, k: STAGING[k]})}")
```

Save it as `staging.py`. Before running it, write down which of the eight experiments fail. The prediction, if the failure needs both large profiles and more than one worker, is that all four "plus one" rows pass, and that exactly two "minus one" rows pass: the ones that remove `workers` and `large`.

```
python3 staging.py
```

Python 3.11 printed:

```
production FAIL, staging ok
staging plus one production condition:
  + workers  ok
  + large    ok
  + flag     ok
  + region   ok
production minus one condition:
  - workers  ok
  - large    ok
  - flag     FAIL
  - region   FAIL
```

Adding any single production condition to staging reproduced nothing. Four experiments, four passes, and a reasonable team would have concluded that the bug was not in the code. Removing one condition at a time from production found both: the export passed without concurrency and passed without large profiles, and failed with either of the others removed. The flag and the region were cleared in two runs.

The prediction would have failed if any "plus one" row had failed, which would mean a single condition is enough, or if a third "minus one" row had passed. To vary it, set `"workers": 2` in `PROD`: the failure still needs both conditions. Change every size in the large list to 65,536 bytes or less and the production row passes, because no profile is written in two parts.

## Read it on a real system

Collect the conditions from the failing request itself, not from what production usually looks like. Its request ID leads to the log lines that record the input's size, the instance or worker that handled it, the build, and the flags it evaluated. Then read the same items in staging and compare.

For configuration, diff what each environment runs. `describe-task-definition` returns an ECS task definition's container definitions, including environment and secrets references, and a Cloud Run revision describes the same for a revision. [describe-task-definition](https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html) · [gcloud run revisions describe](https://cloud.google.com/sdk/gcloud/reference/run/revisions/describe) · [Diff two task definitions or revisions](/learn/diff-ecs-task-definitions-and-cloud-run-revisions/)

```
aws ecs describe-task-definition --profile PROFILE --region REGION \
  --task-definition profile-export:88 --output json --no-cli-pager > prod-td.json
gcloud run revisions describe profile-export-00088-abc --region REGION --format=json > prod-rev.json
```

For the database, compare the server version and every setting, then the shape of the row the failing request touched. `version()` returns the server's version string, `pg_settings` holds every parameter with the source of its current value, `pg_column_size` returns the bytes one stored value uses, and `pg_stat_activity` has a row per server process, which shows how many sessions were active from each application. [version()](https://www.postgresql.org/docs/current/functions-info.html) · [pg\_settings](https://www.postgresql.org/docs/current/view-pg-settings.html) · [pg\_column\_size](https://www.postgresql.org/docs/current/functions-admin.html) · [pg\_stat\_activity](https://www.postgresql.org/docs/current/monitoring-stats.html)

```
SELECT version();
SELECT name, setting, source FROM pg_settings ORDER BY name;
SELECT id, pg_column_size(body) AS stored_bytes FROM profiles WHERE id = 'p-1842';
SELECT application_name, state, count(*) FROM pg_stat_activity GROUP BY 1, 2 ORDER BY 3 DESC;
```

Run each read-only query in both environments and diff the output. `pg_stat_activity` shows the present, not 13:00; for concurrency at the time of the failure, use the service's own metrics or the overlap of request spans on the instance that failed.

Then run the subtraction in staging: raise staging to the production value of every condition you found, confirm it fails, and set each condition back one at a time.

## Where the method misleads

The subtraction tests only the conditions you listed. If staging still passes with every listed condition raised to production's value, a condition is missing from the list, and the next places to look are the ones that never appear in configuration: the data's history, such as a row written by an old release, the time of day, and the load from other tenants. [Bugs that pass CI and fail in production](/learn/ci-passes-production-fails/)

Concurrency failures depend on timing, and the lab's deterministic turn-taking hides that. A real race may fail once in fifty runs with four workers. Run each experiment enough times that a pass means something; the arithmetic is the same as watching for a rare failure after a fix. [How long to watch after a fix](/learn/how-long-to-watch-after-a-fix/)

Some conditions cannot be copied. Production data may hold personal information, and production scale may not fit in staging. Reproduce the property instead of the data: profiles of the same size and encoding, or the same number of concurrent writers on one instance.

## Questions

### Why does a bug happen in production but not in staging?

Because production had a condition at the time of the failure that staging lacks, often a combination: larger or older data, more concurrent work, a different setting or flag, a newer dependency, or a particular time. The failing request's logs name the conditions it ran under, and a diff against staging turns them into a short list to test.

### Why not add production conditions to staging one at a time?

Because a failure that needs two conditions together passes every one-at-a-time test. Start from a configuration that fails, with every production condition present, and remove one at a time; each removal that makes the failure disappear names a condition it needs.

### What if staging fails with all production conditions and passes when any one is removed?

Then every listed condition is needed, which is rare and worth checking with a second run of each experiment. More often, one of the removals changed two things at once, such as a config file that sets several values, and needs splitting.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [How can we catch bugs that pass CI but break in production?](/learn/ci-passes-production-fails/)
    
    Deployment failures The Proofline team November 19, 2026 1 min read
    
-   ### [Did the fix work, or did the trigger stop?](/learn/verify-fix-by-reintroducing-trigger/)
    
    Deployment failures The Proofline team November 24, 2026 8 min read
