LexQLexQ
Back to patterns
GeneralApprovalOperationsIntermediate

Counting Changed Decisions Before Deploy with Decision Replay

Replay a day of stored decisions on the candidate version to count how many real decisions a rule change would move.

Sanghyun Park·October 11, 2026Updated November 22, 202615 min read15 min

The problem

A marketplace auto-approves refunds up to $50 from established accounts, and the team wants to raise the limit to $75. Replaying one day of stored refund decisions on the $75 version shows that 407 of that day's 2,000 refunds would have moved from review to automatic approval.

Refunds that are not auto-approved go to a support agent, and the review queue held 1,176 that day. At $75 it would have held 769, and automatic approvals would have risen from 824 to 1,231. Support asked for the change to shorten that queue, but finance reads the same 407 as refunds that would go out with no one looking at them.

A control run, which replays the same day on the live $50 version, changes none of the 2,000 decisions, so all 407 changes come from the new limit. A control run would report changes if another version had decided part of the day, as happens around a deploy, or if the day included failed or batch calls (see Edge cases).

The refund router makes three checks. The amount must be within the limit, the account at least 30 days old, and its refunds in the last 90 days fewer than three. Unit tests with hand-picked refunds can verify each check. The number support needs comes from a day's real refunds instead: how many pass all three at $75 but not at $50.

Counting the day's refunds by amount alone gives 473. Why should support plan around 407?

The naive approach

Suppose the router still lived in code: one Java method with the three checks. Sizing a new limit would then mean writing a second method beside it.

public class RefundRouter {

    static final BigDecimal LIMIT_USD = new BigDecimal("50.00");
    static final int MIN_ACCOUNT_AGE_DAYS = 30;
    static final int MAX_RECENT_REFUNDS = 3;

    private final AccountRepository accounts;
    private final RefundRepository refunds;

    public Route route(RefundRequest req, Instant now) {
        Account account = accounts.find(req.accountId());
        long ageDays = Duration.between(account.createdAt(), now).toDays();
        if (ageDays < MIN_ACCOUNT_AGE_DAYS) {
            return Route.MANUAL_REVIEW;
        }
        Instant since = now.minus(Duration.ofDays(90));
        if (refunds.countSince(req.accountId(), since) >= MAX_RECENT_REFUNDS) {
            return Route.MANUAL_REVIEW;
        }
        if (req.amountUsd().compareTo(LIMIT_USD) <= 0) {
            return Route.AUTO_APPROVE;
        }
        return Route.MANUAL_REVIEW;
    }

    // Sizing the $75 proposal: one day's refunds between the two limits.
    public long estimateMoved(LocalDate day, BigDecimal newLimitUsd) {
        return refunds.findCreatedOn(day).stream()
                .filter(r -> r.amountUsd().compareTo(LIMIT_USD) > 0)
                .filter(r -> r.amountUsd().compareTo(newLimitUsd) <= 0)
                .count();
    }
}

For the 2,000 refunds of 2026-10-07, estimateMoved would return 473, the count of refunds above $50 and up to $75.

The estimate copies one of the router's three checks. The real router runs in LexQ, covered in the next section, and LexQ stored each refund's inputs. Those inputs show that 66 of the 473 still go to review at $75. Fifty-three come from accounts younger than 30 days, and 13 from older accounts with three or more refunds in 90 days. The estimate overstates the change by 16%.

Adding the other two checks means rebuilding each refund's inputs as they were when it arrived. In code, route computes the account's age and its 90-day refund count at that moment and stores neither. The estimate can rebuild both from timestamps, but only with a second copy of route's logic that runs over past data. That copy has to match route on details such as whether the 90-day count includes the refund being routed.

Nothing in code records the routes route returns. The estimate assumes the current code decided every refund that day. If a hotfix changed route at noon, the morning's refunds went through code that no longer exists, and the estimate cannot tell. Each later change to route also needs a matching edit to estimateMoved, which no test enforces.

Logging each request's inputs and route would solve both problems, and one query would then count the same 407. But a person writes that query's conditions from the plan, "raise the limit to $75," so a mistake made while editing the rules never reaches it. Suppose the edit that raised the limit also changed the age check from 30 days to 3 by mistake. The query still returns 407, while rerunning the day's refunds through the mistaken rules with the method in the next section changes 535 decisions, including refunds from accounts as young as 3 days.

Defining the pattern

Decision Replay runs stored production calls through a candidate version and compares each result with the decision stored when the call ran. LexQ is the hosted service that runs the router's rules. The refunds service calls it once per refund and sends facts, named values such as refundAmountUsd. The rules answer with actions, such as setting the fact refundRoute to AUTO_APPROVE. LexQ stores the facts and actions of every call that reaches the rules; a call rejected before they run, such as one over the TPS limit, is not stored.

The stored decision is the baseline, and it is never recomputed. A window replay reads the stored calls of one policy group, the unit that holds one decision's rules and their versions, over whole days set with --from and --to.

Replay fits a policy group that already serves production calls, like the refund router, when the change is a new version of that group. A router that has not gone live has no stored calls to replay, so Impact Simulation gives the estimate instead. It runs both versions over the same requests, taken from an uploaded file while the router has no traffic. With traffic, they can come from execution logs, as in Testing a Rule Change Before Deploy with Impact Simulation. Replay also does not fit a candidate that reads a new fact, because no stored call sent that fact.

In LexQ the router is one policy group with two rules. The auto-approve rule holds the three checks and sets refundRoute to AUTO_APPROVE. A catch-all, whose empty condition matches every refund, sets it to MANUAL_REVIEW. Both rules carry the mutex group key refund-route in Single mode (mutexMode: EXCLUSIVE), so when both match a refund only the higher-priority rule, the one listed first, is selected. The live version, v1, has the $50 limit. The candidate, v2, is a draft cloned from v1, with the limit raised to 75 and the rule renamed to match.

{
  "name": "Auto-approve: up to $75, established account",
  "condition": {
    "type": "GROUP",
    "operator": "AND",
    "children": [
      {
        "type": "SINGLE",
        "field": "refundAmountUsd",
        "operator": "LESS_THAN_OR_EQUAL",
        "value": 75,
        "valueType": "NUMBER"
      },
      {
        "type": "SINGLE",
        "field": "accountAgeDays",
        "operator": "GREATER_THAN_OR_EQUAL",
        "value": 30,
        "valueType": "NUMBER"
      },
      {
        "type": "SINGLE",
        "field": "refundsLast90Days",
        "operator": "LESS_THAN",
        "value": 3,
        "valueType": "NUMBER"
      }
    ]
  },
  "actions": [
    {
      "type": "SET_FACT",
      "parameters": { "targetVar": "refundRoute", "value": "AUTO_APPROVE" }
    }
  ],
  "mutexGroup": "refund-route",
  "mutexMode": "EXCLUSIVE",
  "mutexStrategy": "HIGHEST_PRIORITY",
  "mutexLimit": 1,
  "isEnabled": true
}

The refunds service now computes accountAgeDays and refundsLast90Days when the refund arrives and sends them with refundAmountUsd, so the values the rules saw are stored with the call, next to the route they produced.

Two rules in the refund-route mutex group: the $75 auto-approve rule first, then the catch-all that sends everything else to review

Decision Replay strategy

The check is two replays of the same day. The first, the control run, uses the live v1 as its candidate. For 2026-10-07 it changes 0 of 2,000 decisions, because v1 decided every stored call that day and its rules reproduce the same actions. The second run uses v2.

# Control: v1 against the decisions it made
lexq replay start --version-id <v1-version-id> \
  --from 2026-10-07 --to 2026-10-07 --max-records 5000

# Candidate: v2 against the same decisions
lexq replay start --version-id <v2-version-id> \
  --from 2026-10-07 --to 2026-10-07 --max-records 5000

--max-records is set above the day's 2,000 calls, because the default cap would replay only part of the day (see Edge cases).

v2 passes when all four of these hold:

  • The control run changes 0 decisions.
  • Neither run reports an error or capped, the flag for a window that held more calls than --max-records.
  • The blast radius lists each action the candidate added or removed, with its call count; the LexQ console calls each one an effect. It must hold exactly one pair: MANUAL_REVIEW removed and AUTO_APPROVE added, on the same number of calls. A higher limit can only move refunds from review to approval, so an AUTO_APPROVE removed, or any third action, cannot come from the $75 limit.
  • The job keeps a sample of the changed calls. Each sample, when opened, must be a refund above $50 and up to $75 from an account that passes the other two checks. Of the four conditions, only this one can catch a slip like the one in the naive approach, where the age check dropped from 30 days to 3. That slip only adds approvals, so the blast radius stays one pair, but some changed calls come from accounts under 30 days old.
Three replay jobs on Refund Auto-Approval for 2026-10-07: v2 with 407 of 2,000 changed, v1 with 0 of 2,000 changed, and an earlier v2 run that replayed 1,000 records and changed 184

A window replay is billed per record, one for each stored call it replays. This check was billed for 4,000 records, half of them for the control run. Replayed decisions stay in the job's result: replaying the day pays out no refund and adds nothing to the review queue. They are not added to the execution history either, which is the list of production calls that later replays read. Replaying 2026-10-07 again the next day still finds 2,000 calls.

Decision Trace output

Each stored call keeps its decision trace, the record of each rule's outcome on that call, and the replay reads its baseline from there. lexq replay get --id <job-id> returns the v2 job's result. The job's result shows its counts and blast radius (other fields omitted):

{
  "totalCount": 2000,
  "processedCount": 2000,
  "errorCount": 0,
  "changedCount": 407,
  "capped": false,
  "summary": {
    "recordsReplayed": 2000,
    "recordsChanged": 407,
    "determinism": "DETERMINISTIC",
    "effectBlastRadius": [
      {
        "action": {
          "type": "SET_FACT",
          "parameters": { "targetVar": "refundRoute", "value": "MANUAL_REVIEW" }
        },
        "direction": "REMOVED",
        "recordCount": 407
      },
      {
        "action": {
          "type": "SET_FACT",
          "parameters": { "targetVar": "refundRoute", "value": "AUTO_APPROVE" }
        },
        "direction": "ADDED",
        "recordCount": 407
      }
    ]
  },
  "changedSamples": [ ... ]
}
  • totalCount: calls the job set out to replay, which is the window up to the cap. processedCount: calls replayed so far.
  • changedCount: calls whose actions differ between the stored decision and v2.
  • capped: false here; true would mean some calls in the window were not replayed.
  • determinism: whether v2 can answer the same input differently on another run. Its rules read nothing but the request's facts.
  • effectBlastRadius: the blast radius described above, shown in the console as Effect Blast Radius.
  • changedSamples: one entry per sampled call, a traceId with its effect changes.
Replay Result for the v2 job: 2,000 replayed, 0 errors, 407 changed, with MANUAL_REVIEW removed and AUTO_APPROVE added on 407 records each

A single replay reruns one stored call on the candidate. Running it on one changed sample, a $64.99 refund from an 84-day-old account with no recent refunds, shows why the decision moved.

lexq replay decision --trace-id 6bd369f9-dd46-410c-b5fa-b338b09c8a52 \
  --version-id <v2-version-id>
{
  "traceId": "6bd369f9-dd46-410c-b5fa-b338b09c8a52",
  "decisionChanged": true,
  "determinism": "DETERMINISTIC",
  "effectChanges": [
    {
      "action": {
        "type": "SET_FACT",
        "parameters": { "targetVar": "refundRoute", "value": "MANUAL_REVIEW" }
      },
      "direction": "REMOVED"
    },
    {
      "action": {
        "type": "SET_FACT",
        "parameters": { "targetVar": "refundRoute", "value": "AUTO_APPROVE" }
      },
      "direction": "ADDED"
    }
  ],
  "baselineFired": [
    { "ruleName": "Manual review: everything else", ... }
  ],
  "candidateFired": [
    { "ruleName": "Auto-approve: up to $75, established account", ... }
  ]
}

baselineFired is read from the stored call's decision trace and lists only the rule that was selected there, the catch-all. The full trace, in the figure below, records the $50 rule as NO_MATCH, because (refundAmountUsd <= 50) was false for 64.99. candidateFired comes from running v2 now. The comparison looks at actions only. A refund of $50 or less that v1's rule approved gets the same AUTO_APPROVE from v2's renamed clone, so it does not count as a change.

Execution Detail of one changed refund. The stored trace shows the $50 rule as No Match and the catch-all as Selected. Single Decision Replay on v2 reports Decision changed: Baseline (stored) fired the catch-all, Candidate fired the $75 rule, and Effect Changes lists MANUAL_REVIEW removed and AUTO_APPROVE added

Edge cases

The default cap is 1,000 calls, and it keeps the newest. Without --max-records, a replay of the same day covers only the later 1,000 refunds and reports 184 changed, with capped set. That 184 is less than half of the day's 407 changes. The cap goes up to 50,000 calls; a window holding more calls than that has to be split into shorter ones.

The window 2026-10-07 to 2026-10-08 spans v2's deploy, so it holds decisions from both versions. A replay of that window on v2 after 2026-10-08 ends reports 407 of 4,000 changed, though v2 is live. All 407 are day-1 decisions that v1 made. With v2 live, that replay is itself the control run, and over a window that spans a deploy it is not 0. A v3 that keeps the $75 limit and changes something else would report those 407 on top of its own change. Windows are whole days in the organization's time zone, so a deploy day with traffic before and after the deploy holds both versions. For the next change after v2, start the window on 2026-10-08, v2's first full day.

Each refund is one plain call, but replay treats three other kinds of stored calls differently. Composite calls, which evaluate several policy groups in one request, are left out of the window. A batch call, which sends many requests at once, is not replayed request by request, so its result can differ from the routes in the batch. A failed call has its facts stored but no actions, so any action the candidate takes counts as added. When a control run reports changed decisions and no deploy falls in the window, check the window's execution history for failed and batch calls first.

v2 reads only the three facts the refunds service already sends. A candidate that also read a chargeback count would still run in a window replay, though no stored call carries one. The replay treats a condition on the missing fact as not met. The rule does not fire, and the call can count as a change. A single replay of one such call stops with an error instead, which makes it a quick check before the window runs.

The job gives finance no dollar total for the 407 refunds. A changed sample's amount shows only when its trace is opened.

A dispute over one refund is a question about one call, so it takes a single replay like the one in Decision Trace output. Deciding Subscription Proration with a Time-Travel Audit replays a disputed May charge on September's version to ask whether the September policy would decide it differently.

Production rollout

Every one of the 2,000 refunds of 2026-10-07 has already been replayed on v2, so v2 is deployed to all refunds without an A/B test. During a ramp, support agents would still review some $60 refunds from established accounts while v2 would auto-approve others just like them. The deploy's memo cites both replay jobs, v1 with 0 changed and v2 with 407, so the deployment record keeps the reason $75 shipped.

Deployment Detail for v2 of Refund Auto-Approval, with v1 as the previous version. The memo cites the replay of 2026-10-07: v1 changed 0 decisions and v2 changed 407
Day 1  v1 live, 2,000 refunds stored
       control run on v1: 0 of 2,000 changed
       candidate run on v2: 407 of 2,000 changed
       deploy v2; the memo cites both replay jobs
Day 2  v2 live all day, 2,000 refunds stored
Day 3  replay day 2 on v1: 429 of 2,000 changed

Once v2 has served a full day, that day is replayed on v1. No deploy falls inside the window, so every decision compared is one v2 made. For 2026-10-08, v1 would have decided 429 of v2's 2,000 refunds differently, with AUTO_APPROVE removed and MANUAL_REVIEW added on 429 calls each. That is 21% against a predicted 20%. The same replay decides whether v2 stays, and either result listed below calls for a rollback:

  • The blast radius shows any effect other than AUTO_APPROVE removed and MANUAL_REVIEW added. The deployed rules then differ from the replayed ones. v2 was replayed as a draft. Publishing, a separate step before any deploy, locks a version's rules, and until then the draft stays editable.
  • The changed share climbs past the predicted 20% plus the margin support and finance agreed on. More refunds are then arriving just under the new limit than on 2026-10-07.

Neither shows on 2026-10-08, so v2 stays. A rollback to v1 is a deployment too, so a later replay window that includes the rollback day can hold decisions from both versions, as the window spanning v2's deploy does. A replay does not time the rules, so it cannot say whether the deploy made routing slower. The auto-approve rule and the catch-all are timed separately on live calls, by the per-rule profile in Sizing a Hot-Path Rule Rewrite with Per-Rule Profiling.


See how LexQ works for yourself in the playground.

Move one rule out of your code.

Try LexQ free, no credit card required.

Start Free