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.

+5.5 pointslate orders caught when the model is retrained monthly instead of never (95% CI +3.8 to +7.1), flagging 10% of orders each week
2 of 4injected faults stopped by a data check before any training; the other two passed the champion/challenger gate
+0.19 APoffline gain shown by the model trained on a leaked feature: the gate's largest "improvement" of the whole replay. Under gate A, live outcomes rolled it back two months later
-0.9 pointsstrict gate against always shipping, with the faults present (CI -2.0 to +0.1): the safeguards did not pay for themselves in recall

What this shows

Late orders caught with 10% of orders flagged each week

Release policyClean datavs always ship, points (95% CI)With 4 faultsvs always ship, points (95% CI)Model versions in production (clean / faults)
Never retrain13.8%-5.5 (-7.1 to -3.8)13.8%-5.0 (-6.7 to -3.4)1 / 1
Retrain monthly, always ship19.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 worse17.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 that18.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 days18.3%-0.9 (-2.9 to +1.3)same–
Flag 10% at random9.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)

0.00.10.20.30.42017-07: 3.4% late of 3872 orders2017-08: 3.3% late of 4193 orders2017-09: 5.2% late of 4150 orders2017-10: 5.3% late of 4478 orders2017-11: 14.3% late of 7288 orders2017-12: 8.4% late of 5513 orders2018-01: 6.6% late of 7069 orders2018-02: 16.0% late of 6555 orders2018-03: 21.4% late of 7003 orders2018-04: 5.3% late of 6798 orders2018-05: 8.2% late of 6749 orders2018-06: 1.4% late of 6096 orders2018-07: 4.5% late of 6156 orders2018-08: 10.4% late of 6351 ordersNever retrain, 2017-07: AP 0.061, model v0-2017-07Never retrain, 2017-08: AP 0.046, model v0-2017-07Never retrain, 2017-09: AP 0.100, model v0-2017-07Never retrain, 2017-10: AP 0.075, model v0-2017-07Never retrain, 2017-11: AP 0.163, model v0-2017-07Never retrain, 2017-12: AP 0.091, model v0-2017-07Never retrain, 2018-01: AP 0.081, model v0-2017-07Never retrain, 2018-02: AP 0.171, model v0-2017-07Never retrain, 2018-03: AP 0.237, model v0-2017-07Never retrain, 2018-04: AP 0.086, model v0-2017-07Never retrain, 2018-05: AP 0.106, model v0-2017-07Never retrain, 2018-06: AP 0.025, model v0-2017-07Never retrain, 2018-07: AP 0.066, model v0-2017-07Never retrain, 2018-08: AP 0.173, model v0-2017-07Retrain monthly, always ship, 2017-07: AP 0.061, model v0-2017-07Retrain monthly, always ship, 2017-08: AP 0.052, model v1-2017-08-fullRetrain monthly, always ship, 2017-09: AP 0.120, model v2-2017-09-fullRetrain monthly, always ship, 2017-10: AP 0.084, model v3-2017-10-fullRetrain monthly, always ship, 2017-11: AP 0.180, model v4-2017-11-fullRetrain monthly, always ship, 2017-12: AP 0.118, model v5-2017-12-fullRetrain monthly, always ship, 2018-01: AP 0.144, model v6-2018-01-fullRetrain monthly, always ship, 2018-02: AP 0.332, model v7-2018-02-fullRetrain monthly, always ship, 2018-03: AP 0.365, model v8-2018-03-fullRetrain monthly, always ship, 2018-04: AP 0.108, model v9-2018-04-fullRetrain monthly, always ship, 2018-05: AP 0.142, model v10-2018-05-fullRetrain monthly, always ship, 2018-06: AP 0.043, model v11-2018-06-fullRetrain monthly, always ship, 2018-07: AP 0.094, model v12-2018-07-fullRetrain monthly, always ship, 2018-08: AP 0.105, model v13-2018-08-fullGate A: ship only if better (CI above 0), 2017-07: AP 0.061, model v0-2017-07Gate A: ship only if better (CI above 0), 2017-08: AP 0.050, model v1-2017-08Gate A: ship only if better (CI above 0), 2017-09: AP 0.094, model v1-2017-08Gate A: ship only if better (CI above 0), 2017-10: AP 0.077, model v3-2017-10Gate A: ship only if better (CI above 0), 2017-11: AP 0.162, model v4-2017-11Gate A: ship only if better (CI above 0), 2017-12: AP 0.100, model v4-2017-11Gate A: ship only if better (CI above 0), 2018-01: AP 0.097, model v4-2017-11Gate A: ship only if better (CI above 0), 2018-02: AP 0.306, model v7-2018-02Gate A: ship only if better (CI above 0), 2018-03: AP 0.357, model v7-2018-02Gate A: ship only if better (CI above 0), 2018-04: AP 0.108, model v7-2018-02Gate A: ship only if better (CI above 0), 2018-05: AP 0.128, model v10-2018-05Gate A: ship only if better (CI above 0), 2018-06: AP 0.033, model v7-2018-02Gate A: ship only if better (CI above 0), 2018-07: AP 0.088, model v7-2018-02Gate A: ship only if better (CI above 0), 2018-08: AP 0.139, model v7-2018-0217-0717-0817-0917-1017-1117-1218-0118-0218-0318-0418-0518-0618-0718-08

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

Policy1. Data check on the extract2. Champion/challenger gate (AP difference)3. Rollback watch on live outcomesLate 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 shipshipped; that month's average precision 0.077 against 0.084 with a clean extract17.7%
Gate Apassedshipped (+0.026)not rolled back; replaced by the next month's model12.7%
Gate Bpassedshipped (+0.012)rolled back after 1 month12.7%
Gate Cpassedshipped (+0.014)not rolled back; replaced by the next month's model17.7%
2018-01 · Price and freight arrive in cents instead of reais for the newest 45 days of the extract
Always shipshipped; that month's average precision 0.131 against 0.144 with a clean extract20.9%
Gate Ablocked––14.9%
Gate Bblocked––14.9%
Gate Cblocked––14.7%
2018-04 · A failed join leaves only orders from sellers in São Paulo state in the extract
Always shipshipped; that month's average precision 0.088 against 0.108 with a clean extract17.5%
Gate Ablocked––23.3%
Gate Bblocked––20.2%
Gate Cblocked––20.5%
2018-06 · The route late-rate feature is rebuilt with outcomes from 7 days after each order (target leakage)
Always shipshipped; that month's average precision 0.028 against 0.043 with a clean extract31.3%
Gate Apassedshipped (+0.189)rolled back after 2 months33.7%
Gate Bpassedshipped (+0.197)not rolled back; replaced by the next month's model33.7%
Gate Cpassedshipped (+0.163)not rolled back; replaced by the next month's model31.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

PolicyBlocked by data checkShippedChampion keptEscalated for approval (denied)Rollbacks
Gate A: ship only if better (CI above 0)05531
Gate B: ship if not worse09041
Gate C: as B, then refit on all data and ship that07420

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

CycleFaultRollback watch on the previous promotionDecisionEvidence
2017-08promotechallenger − champion AP +0.028 (CI +0.001 to +0.073) on 3030 orders, 112 late
2017-09keep (+0.002, CI -0.013 to +0.023, 1127 live orders)keep championchallenger − champion AP +0.013 (CI -0.005 to +0.032) on 3724 orders, 128 late
2017-10labelpromotechallenger − champion AP +0.026 (CI +0.009 to +0.058) on 4032 orders, 80 late
2017-11keep (-0.016, CI -0.036 to +0.005, 1101 live orders)promotechallenger − champion AP +0.025 (CI +0.005 to +0.048) on 3616 orders, 194 late
2017-12keep (+0.025, CI +0.008 to +0.044, 1142 live orders)keep championchallenger − champion AP +0.009 (CI -0.004 to +0.022) on 4263 orders, 251 late
2018-01unitsblocked by contractmedian 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-02promotechallenger − champion AP +0.130 (CI +0.078 to +0.173) on 4934 orders, 349 late
2018-03keep (-0.008, CI -0.139 to +0.070, 517 live orders)keep championchallenger − champion AP +0.016 (CI -0.004 to +0.039) on 6129 orders, 433 late
2018-04truncatedblocked by contractrow count fell from 50623 to 41811 (history should only grow)
2018-05promotechallenger − champion AP +0.034 (CI +0.006 to +0.061) on 6248 orders, 985 late
2018-06leakrollback (-0.016, CI -0.038 to -0.003, 2696 live orders)promotechallenger − champion AP +0.189 (CI +0.136 to +0.241) on 7306 orders, 365 late
2018-07wait (17 late outcomes so far)keep championchallenger − champion AP +0.023 (CI -0.002 to +0.049) on 4126 orders, 355 late
2018-08rollback (-0.018, CI -0.040 to -0.005, 7431 live orders)keep championchallenger − 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?

MonthLate rateAP, never retrainedAP, retrained monthlyPSI of the frozen model's scoresPSI promise daysPSI freight
2017-073.4%0.0610.0610.150.330.07
2017-083.3%0.0460.0520.080.220.10
2017-095.2%0.1000.1200.100.440.10
2017-105.3%0.0750.0840.220.310.12
2017-1114.3%0.1630.1800.340.430.11
2017-128.4%0.0910.1180.010.360.12
2018-016.6%0.0810.1440.010.170.12
2018-0216.0%0.1710.3320.060.200.10
2018-0321.4%0.2370.3650.020.450.37
2018-045.3%0.0860.1080.020.280.49
2018-058.2%0.1060.1420.030.390.53
2018-061.4%0.0250.0430.020.170.53
2018-074.5%0.0660.0940.070.850.57
2018-0810.4%0.1730.1050.331.900.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

Limits

Code: data preparation, pipeline (checks, gate, rollback, registry), replay and 8 tests; about 600 lines of Python. Ulf Fäldt Reifenberg · LinkedIn · GitHub