Personal project by Ulf Fäldt Reifenberg, built for a job application with coding agents. Unofficial, not affiliated with any company. Public data only (Olist, Brazilian e-commerce orders 2016–2018, CC BY-NC-SA 4.0).
Do release gates pay for themselves when an order-risk model is retrained every month?
A model that flags, at the moment of purchase, the orders most likely to arrive late. 82,271 real orders are replayed over 14 months with 13 retraining cycles, once on the data as it is and once with four pipeline faults injected, under five release policies.
What this shows
- Retraining matters more than anything else here. The late rate swings from 1.4% to 21.4% between months. A model frozen in July 2017 catches 13.8% of late orders at a 10% flag budget; monthly retraining catches 19.3%.
- The model barely beats a one-line rule. Flagging by the route's late rate over the last 30 days catches 18.3%; the difference to the retrained model is +0.9 points (CI -1.3 to +2.9). With purchase-time features only, most of the signal is "this route is in trouble right now".
- Gates cost recall when nothing is wrong. Holding out the newest 28 days, refusing promotions that are not proven, and denying every escalation by default cost 1 to 2 points on the clean data. Refitting on all data after the gate (C) recovers most of gate B's loss, but then the model that ships is not the model that was tested, and right after a promotion the gate compares near-twins: in March 2018 challenger and champion were the same model (difference +0.000).
- Each safeguard caught what it was built for and nothing else. The data check stopped the unit change and the truncated extract. The gate could not see a label definition that changed upstream (its holdout had the same wrong labels) and it rewarded the leaked feature, because the holdout was built by the same faulty code. Only live outcomes exposed the leak.
- Always shipping heals itself. A bad monthly model is replaced a month later, and the faults cost the always-ship policy 0.4 points overall. On this data the case for the gates is knowing what went into production and why, not a better average.
Late orders caught with 10% of orders flagged each week
| Release policy | Clean data | vs always ship, points (95% CI) | With 4 faults | vs always ship, points (95% CI) | Model versions in production (clean / faults) |
|---|---|---|---|---|---|
| Never retrain | 13.8% | -5.5 (-7.1 to -3.8) | 13.8% | -5.0 (-6.7 to -3.4) | 1 / 1 |
| Retrain monthly, always ship | 19.3% | – | 18.9% | – | 14 / 14 |
| Gate A: ship only if better (CI above 0) | 18.1% | -1.1 (-2.2 to +0.0) | 17.9% | -0.9 (-2.0 to +0.1) | 6 / 7 |
| Gate B: ship if not worse | 17.4% | -1.9 (-2.8 to -1.0) | 17.4% | -1.5 (-2.4 to -0.6) | 10 / 11 |
| Gate C: as B, then refit on all data and ship that | 18.6% | -0.7 (-1.3 to -0.1) | 18.4% | -0.4 (-1.0 to +0.1) | 8 / 9 |
| One-line rule: flag by the route's late rate, last 30 days | 18.3% | -0.9 (-2.9 to +1.3) | same | – | |
| Flag 10% at random | 9.9% | same | – |
7,174 late orders among 82,271 bought July 2017 to August 2018. Each order is scored by whichever model was in production when it was bought. Intervals: bootstrap over purchase days, paired between policies.
Month by month (clean data)
Bars: share of orders delivered late. Lines: average precision of the model in productionnever retrainedretrained monthly, always shippedgate A
Four injected faults, three layers of defence
| Policy | 1. Data check on the extract | 2. Champion/challenger gate (AP difference) | 3. Rollback watch on live outcomes | Late orders caught that month |
|---|---|---|---|---|
| 2017-10 · Label definition changed upstream for the newest 90 days: late only if more than 5 days after the estimate | ||||
| Always ship | shipped; that month's average precision 0.077 against 0.084 with a clean extract | 17.7% | ||
| Gate A | passed | shipped (+0.026) | not rolled back; replaced by the next month's model | 12.7% |
| Gate B | passed | shipped (+0.012) | rolled back after 1 month | 12.7% |
| Gate C | passed | shipped (+0.014) | not rolled back; replaced by the next month's model | 17.7% |
| 2018-01 · Price and freight arrive in cents instead of reais for the newest 45 days of the extract | ||||
| Always ship | shipped; that month's average precision 0.131 against 0.144 with a clean extract | 20.9% | ||
| Gate A | blocked | – | – | 14.9% |
| Gate B | blocked | – | – | 14.9% |
| Gate C | blocked | – | – | 14.7% |
| 2018-04 · A failed join leaves only orders from sellers in São Paulo state in the extract | ||||
| Always ship | shipped; that month's average precision 0.088 against 0.108 with a clean extract | 17.5% | ||
| Gate A | blocked | – | – | 23.3% |
| Gate B | blocked | – | – | 20.2% |
| Gate C | blocked | – | – | 20.5% |
| 2018-06 · The route late-rate feature is rebuilt with outcomes from 7 days after each order (target leakage) | ||||
| Always ship | shipped; that month's average precision 0.028 against 0.043 with a clean extract | 31.3% | ||
| Gate A | passed | shipped (+0.189) | rolled back after 2 months | 33.7% |
| Gate B | passed | shipped (+0.197) | not rolled back; replaced by the next month's model | 33.7% |
| Gate C | passed | shipped (+0.163) | not rolled back; replaced by the next month's model | 31.3% |
Each fault hits the training extract of one cycle; the next month's extract is clean again. I chose the faults and wrote the checks, so "the unit change is caught by a median check" is by construction. The rows I did not design are the label change and the leak.
False alarms: the same safeguards on 13 clean cycles
| Policy | Blocked by data check | Shipped | Champion kept | Escalated for approval (denied) | Rollbacks |
|---|---|---|---|---|---|
| Gate A: ship only if better (CI above 0) | 0 | 5 | 5 | 3 | 1 |
| Gate B: ship if not worse | 0 | 9 | 0 | 4 | 1 |
| Gate C: as B, then refit on all data and ship that | 0 | 7 | 4 | 2 | 0 |
Escalations came from the calibration check (predicted against observed late rate more than 2x apart). With a base rate that moves fifteen-fold between months that check fires on real change, not on faults; a default of "deny" then keeps a stale model in place. One clean-data rollback: the May 2018 model was worse than its predecessor on the May orders whose outcome was known by 1 June.
Decision trail for gate A with the faults present
| Cycle | Fault | Rollback watch on the previous promotion | Decision | Evidence |
|---|---|---|---|---|
| 2017-08 | promote | challenger − champion AP +0.028 (CI +0.001 to +0.073) on 3030 orders, 112 late | ||
| 2017-09 | keep (+0.002, CI -0.013 to +0.023, 1127 live orders) | keep champion | challenger − champion AP +0.013 (CI -0.005 to +0.032) on 3724 orders, 128 late | |
| 2017-10 | label | promote | challenger − champion AP +0.026 (CI +0.009 to +0.058) on 4032 orders, 80 late | |
| 2017-11 | keep (-0.016, CI -0.036 to +0.005, 1101 live orders) | promote | challenger − champion AP +0.025 (CI +0.005 to +0.048) on 3616 orders, 194 late | |
| 2017-12 | keep (+0.025, CI +0.008 to +0.044, 1142 live orders) | keep champion | challenger − champion AP +0.009 (CI -0.004 to +0.022) on 4263 orders, 251 late | |
| 2018-01 | units | blocked by contract | median price_sum in the newest 60 days is 5990.0, reference 85.9 (outside 3x); median freight_sum in the newest 60 days is 1510.0, reference 16.8 (outside 3x) | |
| 2018-02 | promote | challenger − champion AP +0.130 (CI +0.078 to +0.173) on 4934 orders, 349 late | ||
| 2018-03 | keep (-0.008, CI -0.139 to +0.070, 517 live orders) | keep champion | challenger − champion AP +0.016 (CI -0.004 to +0.039) on 6129 orders, 433 late | |
| 2018-04 | truncated | blocked by contract | row count fell from 50623 to 41811 (history should only grow) | |
| 2018-05 | promote | challenger − champion AP +0.034 (CI +0.006 to +0.061) on 6248 orders, 985 late | ||
| 2018-06 | leak | rollback (-0.016, CI -0.038 to -0.003, 2696 live orders) | promote | challenger − champion AP +0.189 (CI +0.136 to +0.241) on 7306 orders, 365 late |
| 2018-07 | wait (17 late outcomes so far) | keep champion | challenger − champion AP +0.023 (CI -0.002 to +0.049) on 4126 orders, 355 late | |
| 2018-08 | rollback (-0.018, CI -0.040 to -0.005, 7431 live orders) | keep champion | challenger − champion AP -0.002 (CI -0.024 to +0.009) on 6804 orders, 121 late |
Every row is an entry in an append-only SQLite registry with the hash of the training extract.
Would a drift alarm have asked for retraining?
| Month | Late rate | AP, never retrained | AP, retrained monthly | PSI of the frozen model's scores | PSI promise days | PSI freight |
|---|---|---|---|---|---|---|
| 2017-07 | 3.4% | 0.061 | 0.061 | 0.15 | 0.33 | 0.07 |
| 2017-08 | 3.3% | 0.046 | 0.052 | 0.08 | 0.22 | 0.10 |
| 2017-09 | 5.2% | 0.100 | 0.120 | 0.10 | 0.44 | 0.10 |
| 2017-10 | 5.3% | 0.075 | 0.084 | 0.22 | 0.31 | 0.12 |
| 2017-11 | 14.3% | 0.163 | 0.180 | 0.34 | 0.43 | 0.11 |
| 2017-12 | 8.4% | 0.091 | 0.118 | 0.01 | 0.36 | 0.12 |
| 2018-01 | 6.6% | 0.081 | 0.144 | 0.01 | 0.17 | 0.12 |
| 2018-02 | 16.0% | 0.171 | 0.332 | 0.06 | 0.20 | 0.10 |
| 2018-03 | 21.4% | 0.237 | 0.365 | 0.02 | 0.45 | 0.37 |
| 2018-04 | 5.3% | 0.086 | 0.108 | 0.02 | 0.28 | 0.49 |
| 2018-05 | 8.2% | 0.106 | 0.142 | 0.03 | 0.39 | 0.53 |
| 2018-06 | 1.4% | 0.025 | 0.043 | 0.02 | 0.17 | 0.53 |
| 2018-07 | 4.5% | 0.066 | 0.094 | 0.07 | 0.85 | 0.57 |
| 2018-08 | 10.4% | 0.173 | 0.105 | 0.33 | 1.90 | 0.53 |
PSI against the frozen model's training data; above 0.2 marked. It fired in 2017-10, 2017-11, 2018-08. The largest gaps between the frozen and the retrained model (February and March 2018) came with a score PSI of 0.06 and 0.02: the scores looked the same while the relation between inputs and lateness had changed. A score-drift alarm would not have triggered the retraining that mattered most, and the promise-days PSI sat above 0.2 in most months, so it could not single those months out either.
How it works
- Label and maturity. Late means delivered after the estimated date. An order's outcome counts as known on its estimated date, not on delivery; otherwise the newest training data would hold only fast, on-time orders. Training data therefore lags about three to four weeks.
- Features, purchase time only. 22 features: promised days, basket, weight, category, states, payment, and as-of history (the seller's past late rate, the route's and the customer state's late rate over the last 30 days, the overall rate over 14), each computed only from orders that had matured before the purchase. Model: gradient-boosted trees (scikit-learn), CPU.
- Layer 1, data check. Row count may not fall, state coverage may not shrink, recent medians of price, freight, weight and promise stay within 3x of the last accepted extract, recent outcomes may not be missing.
- Layer 2, gate. The challenger is trained without the newest 28 matured days and compared with the champion on them: paired bootstrap interval of the difference in average precision. Promotions with a calibration gap or a region that loses recall go to a person; in the replay nobody answers, so they are denied.
- Layer 3, rollback. After a promotion the previous model keeps scoring in shadow. When enough live orders have matured (300 orders, 20 late), the two are compared; if the new one is worse with the interval below zero, the registry restores the previous version.
Limits
- One public dataset, one model family, one seed, untuned. Average precision is low (0.14 on average): lateness is mostly decided after purchase.
- Faults are injected by me, one cycle each, and the data checks were written knowing them.
- Monthly cycles on a laptop with SQLite; no orchestrator, no cloud ML platform, no process-mining platform such as Celonis, no real approver. Flagging is evaluated as recall at a fixed budget; whether an intervention would have prevented the delay is not measured.
- The rollback watch sees short-promise orders first, so its early sample is not representative; both models are compared on the same orders.
Code: data preparation, pipeline (checks, gate, rollback, registry), replay and 8 tests; about 600 lines of Python. Ulf Fäldt Reifenberg · LinkedIn · GitHub