Arrange Act Assert

Jag Reehal's thoughts on things, mostly product development

Same Commit. Different Behaviour.

25 Nov 2026

One commit, 16a65f7, and one basket branch into two pricing-engine variants. Control returns a total of 5850. Variant v2 fails with a total of 4680 instead of 5850. Caption: Same commit. Different behaviour.

A basket costs one customer €58.50. Another customer sends the same basket to the same commit and gets a 502, because a feature flag put them on different code.

Record the flag decisions on the trace and you can replay the pricing for that failed request under the variant the customer got, then turn it into a deterministic regression test that fails until you fix the bug.

One commit, two answers

With trunk-based development and continuous delivery, you can deploy code weeks before you release it. Feature flags keep the two apart. They also break an old habit: reading the Git SHA off the deploy log and checking out that commit to see what the customer saw.

A Git SHA identifies the code you deployed. To know which path through that code a request took, you need the rest of its execution context: the flag decisions, the request’s inputs, and the external state it read.

---
alt: "Four parts of the execution context lead to the observed behaviour: the code version, the feature flag decisions, the request inputs and the external state."
---
flowchart LR
  C["Code version"] --> B["Observed behaviour"]
  F["Flag decisions"] --> B
  R["Request inputs"] --> B
  E["External state"] --> B
Figure 1: The execution context. The demo records the first three. Its pricing reads no external state.

I built a small demo to work through what you need instead. A checkout service calls a pricing service, and a flag called pricing-engine picks between two implementations. Both live on main:

"pricing-engine": {
  "variants": { "control": "control", "v2": "v2" },
  "default": "control",
  "rules": [
    { "group": "internal", "variant": "v2" },
    { "group": "beta", "rollout": { "v2": 25 } }
  ]
}

I planted a bug in v2 that needs three conditions at once: the v2 variant, a basket in euros and a discount code. Of the 200 simulated users, 23 get v2, and about one checkout in 75 fails.

You could stare at those failures for a while. The same commit serves the users who fail and the users who don’t, and most checkouts on v2 succeed.

Record the decision with the request

The checkout service reads its flags through OpenFeature, a vendor-neutral API for flags. Autotel finds OpenFeature and adds a hook that records each evaluation, so the code that reads a flag stays ordinary:

const who = { targetingKey: user.id, group: user.group };
const engine = await flags.getStringDetails('pricing-engine', 'control', who);
const express = await flags.getBooleanDetails('express-shipping', false, who);

I add one attribute by hand, the basket, because a replay needs the input:

ctx.setAttributes({ 'checkout.request': JSON.stringify(request) });

The demo’s baskets are synthetic and hold no personal information. In production a basket, a discount code or an ID beside them can identify someone, so capture the fields a replay reads, redact the rest, and set a retention period.

Open a failed checkout in Autotel’s devtools and you can read the decision next to the error:

Devtools card for a failed POST /checkout by user-165 in the beta group. It shows the euro basket with discount code SAVE10, the pricing-engine flag at variant v2 with reason split and version 1 from flags.json, and the error: total 4680 != subtotal 7020 - discount 1170.

The attribute names come from OpenTelemetry’s feature flag conventions, so you can group by them in another backend. Look for three of them when you debug: the variant, the reason the user got it, and the version of the flag definition.

Answer once, at the edge

Pricing needs the flag too. If it asked the provider itself, someone could change the rollout between the two calls and one request would run control in one service and v2 in the next.

The checkout service evaluates the flag once and sends the answer along in W3C baggage, a request header that tracing libraries pass between services:

await context.with(featureFlagBaggage([engine]), () =>
  fetch(PRICING_URL, { method: 'POST', headers, body }),
);

Pricing sets featureFlagBaggageProvider() as its OpenFeature provider and reads the flag as it would anywhere else. It has no connection to the flag vendor, and its trace shows the same variant.

---
alt: "The checkout service asks the flag provider for pricing-engine once, gets v2, and sends the answer to pricing in baggage. Pricing reads v2 from the baggage. Both services record the answer on the same trace."
---
flowchart LR
  F["Flag provider"] -->|"v2, split, version 1"| A["checkout-api"]
  A -->|"POST /quote + baggage"| P["pricing"]
  A -.-> T["One trace"]
  P -.-> T
Figure 2: The checkout service evaluates the flag, and pricing reads the answer from baggage.

Baggage travels in a header, so a client can forge it. Follow four rules:

Find what the failures share

I left traffic running for three minutes, then asked devtools to compare the failed checkouts with checkouts as a whole:

Devtools Compare view. Of 24 failing checkout spans against 1657, variant v2 appears in 100 percent against 10 percent, discount code SAVE10 in 100 percent against 31 percent, and currency EUR in 100 percent against 40 percent. A line above the table reads: A hypothesis to check against individual traces, not a conclusion.

The variant, the discount code and the currency each sit at 100% in the failures. You pick no attribute to filter on, because the tool ranks them for you. I argued in Instrument Before You Know the Question that you can’t guess which field will matter, and here three of them mattered together.

Read the grey line above it too: “A hypothesis to check against individual traces, not a conclusion.” You have a correlation. Pick the flag in the same view and you can see why that caution belongs there:

Devtools comparing pricing-engine control with v2. Errors appear in 0 percent of control spans and 13 percent of v2 spans. The groups differ as well: 23 percent of v2 spans carry the internal group and no control spans do.

Spans on v2 fail 13% of the time and spans on control don’t fail. It looks like an A/B test. The users differ, though. Internal staff appear on the v2 side and not on the control side, because I targeted their group. To learn whether the variant causes the failure, you have to hold the basket still and change the variant.

Replay one request

Copy the trace ID and run:

pnpm repro 851b87e9a0c3071b5ff1acf4833c1af8
What was running at 2026-11-24T21:48:04.310Z
  code       16a65f7 (demo)
  user       user-165 (group beta)
  flag       express-shipping = on  (split, flags.json v1)
  flag       pricing-engine = v2  (split, flags.json v1)
  request    {"currency":"EUR","items":[...],"discountCode":"SAVE10"}

Replaying locally (▶ = what the user got)
  ▶ v2       FAILS   QuoteError: total 4680 != subtotal 7020 - discount 1170
    control  ok      total 5850

Reproduced. Only the v2 branch fails for this request.

The script reads the trace back and takes the basket and the variant from it. It runs the pricing code with that variant, then with the others. By the time you hear about a bug someone has often moved the rollout, so the script ignores today’s flags.

My first version jumped to a conclusion

The first version ran both variants and kept the result of one. Give it a basket in dollars, a currency the demo does not support, and both variants fail. The old script printed “Only the v2 branch fails for this request” whenever the recorded variant failed, whatever the others did.

A person might spot the second failure in the terminal. An agent reading the last line could go and rewrite the wrong function. The script now keeps the result for each variant and chooses between four verdicts:

Verdict Exit code You can say
variant-specific 1 The recorded error happens again, on the recorded variant alone
shared 1 It happens again, and another variant fails too
not-reproduced 0 The failure does not occur in this replay
insufficient-evidence 2 The trace or the code here can’t answer the question

The last row covers a replay that fails with a different error from the one in the trace, a checkout that succeeded, and a variant this checkout of the code does not have. It also covers a replay that can’t reach devtools. The old script crashed there with exit code 1, the code I had defined as “the bug reproduces”.

Turn the failure into a test

pnpm repro 851b87e9a0c3071b5ff1acf4833c1af8 --generate-test

The script writes this test (formatted here, imports trimmed), with the product names replaced:

const flags = { 'pricing-engine': 'v2' } as const;

const request: QuoteRequest = {
  currency: 'EUR',
  items: [
    { sku: 'item-1', qty: 2, unitPrice: 1800 },
    { sku: 'item-2', qty: 2, unitPrice: 1200 },
  ],
  discountCode: 'SAVE10',
};

it('charges the subtotal less the discount', () => {
  const result = quote(request, flags['pricing-engine']);

  expect(result.total).toBe(result.subtotal - result.discount);
});

The assertion states the business rule. A test that copied production’s 4680 would lock the bug in. The script refuses to write a test for a failure it could not reproduce, because you would have no evidence the test can fail.

It fails on the first run:

 FAIL  charges the subtotal less the discount
QuoteError: total 4680 != subtotal 7020 - discount 1170

The bug sits in v2. Euro promotions take the discount off, then a shared step takes it off again. Let each market take its own discount, once:

 const MARKETS = {
-  GBP: (subtotal) => subtotal,
+  GBP: (subtotal, discount) => subtotal - discount,
   EUR: (subtotal, discount) => subtotal - discount,
 };

-  return { subtotal, discount, total: afterMarket - discount };
+  return { subtotal, discount, total: afterMarket };

Run the replay again and both variants return 5850. The generated test passes, and you keep it. A green test covers this basket on this variant. You still decide which other cases deserve one.

The replay and the test run one function, pricing, on recorded inputs, and that is why they give the same answer each time. Neither replays the distributed checkout: the network, the timing and the other services stay outside.

Treat a flag change like a deploy

I made the fix above in a working copy. The running services kept serving 16a65f7, bug included, and I took these readings from them. With traffic flowing, I put the whole beta group on v2:

pnpm rollout pricing-engine 100

I deployed nothing. Then I asked Autotel’s MCP server what_changed across the minute before and the minute after. Trimmed to the checkout service, it answered:

{
  "changes": [],
  "flagChanges": [
    {
      "service": "checkout-api",
      "flag": "pricing-engine",
      "from": "1",
      "to": "2",
      "before": { "count": 600, "errorCount": 10, "errorRate": 0.017 },
      "after": { "count": 584, "errorCount": 33, "errorRate": 0.057 }
    }
  ],
  "unchanged": [{ "service": "checkout-api", "version": "16a65f7" }]
}

changes lists deploys, and it is empty. The commit is 16a65f7 on both sides. The error rate went from 1.7% to 5.7%, and the flag version going from 1 to 2 is the one change in the answer.

The timestamp Autotel gives you (cut from the output above) is the first request seen under the new version. With a cached provider or a quiet service, that can land well after someone pressed save.

Then I pulled the kill switch with pnpm rollout pricing-engine off. The failure count stood at 96. After another 198 checkouts it still stood at 96.

Hand the evidence to an agent

Claude can search the traces through the MCP server and run the replay itself. --json gives it a result it does not have to interpret (trimmed here):

{
  "verdict": "variant-specific",
  "reproduced": true,
  "codeVersionMatches": true,
  "recordedVariant": "v2",
  "results": {
    "v2": {
      "ok": false,
      "error": "QuoteError: total 4680 != subtotal 7020 - discount 1170"
    },
    "control": { "ok": true, "total": 5850 }
  }
}

With too little evidence, the script sets reproduced to null, so the agent can stop and say so.

This is the split from Let AI judge. Let code decide. The agent forms a theory and proposes a change, and the replay and the test give it the same verdict on each run. For keeping the fix itself readable, see Deterministic Complexity Gates for Humans and AI Agents.

Know where the guarantee stops

Run it

git clone https://github.com/jagreehal/autotel-feature-flags-demo
cd autotel-feature-flags-demo
pnpm install
pnpm devtools   # terminal 1, then open http://127.0.0.1:4318
pnpm start      # terminal 2
pnpm traffic    # terminal 3

You need Node 24 and no accounts: the flags come from a JSON file. Give it a minute to collect failures, copy a trace ID from devtools, and run pnpm repro.

Open a trace from your last production incident. You know which commit was running. Check whether the trace also tells you which path through that commit your customer’s request took, and if it doesn’t, record the flag decisions before the next one.

opentelemetryobservabilityautoteltestingai-agents