Decision science, ML operations, production systems
A revenue system that runs itself, and knows when not to act.
A closed decision loop for a simulated API and cloud-compute business. It forecasts demand, measures price elasticity from randomised tests, proposes prices inside hard guardrails, plans payment retries by expected value, and retrains its own models. It can stage a new model in shadow, but only a named person can promote it.
01Events in
validated, archived
02Exactly-once state
Postgres + warehouse
03Models learn
forecast, elasticity, churn
04Optimiser decides
change, hold or freeze
05Decision recorded
before anything executes
06Back onto the bus
as a new event
↺ and back to 01. Promotion waits for a named person.
0.1288
Forecast vWAPE, held-out world
vs 0.1661 seasonal naive, 8,064 forecasts
0.15%
Error recovering hidden elasticity
−1.3335 estimated vs −1.3315 true, pooled
61.1%
Failed payments recovered
vs 54.6% fixed schedule, 445 episodes
48.7M
Events replayed at 500K customers
exact oracle state, 0 OOM kills, emulated 8 GB
Most pricing and MLOps demos stop at a model with a good offline metric. A system that actually sets prices and retries payments has to do four harder things.
Regressing demand on historical prices cannot say what a price change will do, because those prices were set for reasons. Praxis needed randomised price tests and an estimator that could be checked against the true answer.
A point-estimate optimiser exploits noise. The naive unconstrained optimum measured in this project would have lost about 1.95M a day in truth. The system had to know when not to move a price.
Pub/Sub delivers at least once, in no guaranteed order. Money and subscription state cannot tolerate a double charge, or a payment applied before its invoice exists.
Models drift. A system that retrains itself needs a gate between "retrained" and "serving", and has to survive its own failed runs.
And under all four: how do you stop yourself tuning a result into a pass?
praxis.simulator
The world, and its secrets
forecasting · elasticity · pricing · recovery
Models see only what a business would
praxis.science
The one package allowed on both sides. It scores model output against hidden truth with criteria pinned by hash before the run, on held-out worlds that are built and judged once.
Events come in, models learn from them, and decisions go back onto the bus as new events, recorded before anything can execute. Trace a path, or select any component.
Three models feed one objective. The optimiser writes a checksummed record before anything can execute, and the decision goes back onto the bus as a new event: the loop closes.
| Plane | Technology | Holds |
|---|---|---|
| Control | Postgres | projections, ledger, decisions, registry, incidents, audit |
| Analytical | DuckDB / BigQuery | event history, marts, features |
| Archive | Files / Cloud Storage | immutable raw data and events, replayable |
| Events | Pub/Sub | transport only; every consumer idempotent |
| Scheduled | Cloud Tasks | future payment retries |
Money is integer minor units and time is timezone-aware UTC throughout. Every artifact and decision carries content-derived ids, so the same inputs give the same ids on any machine, and a tampered artifact is refused on load.
One import is allow-listed, and it is worth stating: the forecasting evaluation CLI reads the simulator’s scenario config, never its truth, to label spike days.
Three models feed one objective, and each answers a different question: how much demand there is, how it responds to price, and what a lost customer costs. The optimiser combines them and decides on a deliberately pessimistic quantity.
Hierarchical elasticity model / praxis.elasticity
Each tier’s elasticity comes from five concurrent 50/50 price tests, pooled across 18 tier × industry cells by a PyMC model (NUTS, 4 chains × 2,000 draws, fixed seed). Customers are assigned to arms by hashing salt:customer_id, and every unit’s arm is recomputed and checked against the logged exposure.
Five steps, each able to end the cycle. A price change has to survive all of them, so most cycles end in hold or frozen, which is the point.
Validate inputs
Anything impossible ends the cycle as unavailable.
Evidence gates
Freeze before optimising if there is no randomised evidence, it is older than 365 days, a material tier has a non-negative elasticity or posterior SD above 0.25, or the forecast’s 80% band is wider than the forecast itself.
Candidate grid
A symmetric log grid over the max-step range on the price tick, plus the current price. The winner is refined over every tick between its grid neighbours.
Hard constraints
Floor and ceiling, 5% max step, 14-day cooldown, no extrapolation past the tested range (|log p/p₀| ≤ 0.1823), net margin ≥ 0.20 in every region, utilisation ≤ 0.85, extra 28-day churn ≤ 0.5 pp at the one-sided 95% bound, no segment above 10% churn, at most three price-change dates per customer in 90 days.
Confidence rule
A change also needs P(improvement) ≥ 0.90 under the least favourable posterior. Otherwise it freezes; if the current price is best, it holds.
The forecast is used at the current price. Elasticity comes only from randomised tests, never from the forecaster’s price features.
Hypothesis property tests compare the optimiser with a separate scalar implementation, and every constraint is checked on the exact integer price.
The system should not explore on live prices without a recorded, approved decision. The obvious baseline, an unconstrained point-estimate optimum, roughly tripled prices and lost 287K to 1.06M per day in truth.
49 candidates scored, 48 rejected with named reasons.
rule: 0.90
Predicted at decision time vs hidden truth
Contribution
Objective (after churn)
The contribution model was close. The churn slope was not: it had been measured in February at low utilisation, and by July the true slope was 20 to 30 times larger. That finding is why the churn model now scales its evidence by the current churn rate, and why the long-horizon guardrails exist.
Customers are assigned to arms by hashing a salt with their id. The evaluation world runs five concurrent 50/50 price tests on 8,000 customers after a four-week pre-period. Every unit’s arm is recomputed from the salt and checked against the logged exposure, so each is classed ok, missing, arm mismatch, contaminated, price error or conflicting.
When 20% of the control group was charged the treatment price, the gate detected it (0.200 measured as 0.189), IV landed within 0.5% of truth, and the artifact was still correctly refused. The truth is computed with the same unit weights as the OLS estimand, which is what makes “recovered the true elasticity” a meaningful statement.
Estimated elasticity against the hidden truth
seed 42 · 5 concurrent price tests · 8,000 customers
| Segment | Estimate | Truth | Relative error % |
|---|---|---|---|
| Pooled | -1.3335 | -1.3315 | 0.146 |
| Starter | -1.8753 | -1.8619 | 0.72 |
| Growth | -1.2099 | -1.2009 | 0.75 |
| Enterprise | -0.674 | -0.7104 | 5.13 |
8 of 8 pre-registered criteria pass and all 14 identifiable segment orderings are correct. Enterprise is the weakest at 5.1%. On a fresh replication world (seed 43) the tier and pooled estimates held but two cell-level checks failed, and that is reported, not re-rolled.
When a payment fails, a mixture-cure Weibull model estimates the probability it becomes collectible by each day. Retries only bracket that moment, so the model is fitted by interval-censored maximum likelihood. Try the planner below: it is the project’s formula, run on parameters you control.
share of failures that ever become collectible
typical days until the card works again
below 1: early or never; above 1: needs time
value = Σj [G(tj) − G(tj−1)] · A · (1 − δ tj) − cretry Σj (1 − G(tj−1)) − cfail Σj (1 − G(tj))
Only the first retry is acted on; after a failure the service re-plans from the conditional curve. Exhaustive search is affordable because the space is tiny, and it needs no defence of a heuristic. Here A = 100, δ = 0.01, cretry = 1, cfail = 6. Hard rules sit outside the model: no retry after day 20, and Praxis is the only retrier.
Only the demand forecaster is in the model registry, and it moves through a pinned state machine. Automation can carry a candidate as far as shadow; a named person decides the rest.
development time
production time
Scored on exactly the observations the champion sees. Automation can bring a model this far and no further.
The pre-registered candidate was LightGBM. On the development world ridge beat it (vWAPE 0.1349 vs 0.1404), and ten LightGBM variants did not close the gap. The simulated demand is close to linear in the scaled seasonal lags, so tree corrections fit noise, and searching further would have been tuning by forking paths.
The champion became a hybrid: ridge for the mean, calibrated LightGBM for the quantiles, where it had measured best. The decision was made before the held-out world was run.
Demand forecast error, lower is better
vWAPE · held-out seed 42 · 8,064 forecasts · 72 series
Ratio to seasonal naive 0.776 against a pre-registered limit of 0.90; 95% bootstrap CI of the difference [−0.0455, −0.0292]; 11 of 11 checks pass. The hybrid does no better than naive on unannounced spike days.
A tick rebuilds the synthetic world through yesterday, publishes the warehouse, runs the lifecycle for each unprocessed day and, if a shadow version has passed, files a pending promotion. It stops at the first failure without advancing, so the next tick retries the same days.
Cloud Scheduler fires
Starts the live Cloud Run job: up to 4 h, 4 vCPU / 8 GiB.
state.json
last_as_of: D − 1
status: running
illustrative; D is the day being operated
A replay of the documented workflow (ADR 0027), not a connection to the deployed system. Each step is a subprocess of an existing, tested CLI.
Wall time of the cloud catch-up ticks
seconds per tick · each tick operates up to 7 days · 2026-08-31 to 11-04
Retrain days cost far more than ordinary days, and grew with history because the required backtest scales with it. Tick 7 timed out at the 1,500 s step limit; state was not advanced and tick 8 retried. That led to a 4 vCPU / 4 h job and a sliding 364-day training window (ADR 0030), whose benefit is still an extrapolation.
2026-11-04Cloud bootstrap
1,001 s; first champion promoted by a named approver; catch-up ticks operate 2026-08-31 to 11-04.
2026-11-05Scheduled tick
Succeeded.
2026-11-06Scheduled tick
Succeeded.
2026-11-07Scheduled tick
Succeeded. Challenger in shadow with a ready flag.
2026-11-08Promotion
Scheduled tick succeeded; the owner promoted the shadow-passed version from the console.
2026-11-09Scheduled tick
Promoted version serving as champion; a new shadow started.
2026-11-10Drift → retrain
Residual and segment drift alarm, retraining requested on six triggers, candidate passed validation and registered as challenger (1,187 s lifecycle step).
Automatic rollback was not exercised in the cloud: it only applies to a champion on probation, so it is proven by the lifecycle drill, not by the deployment. Drift alarms on most days are consistent with a documented limit: on a growing world, a frozen champion drifts in a way retraining cannot fully fix.
Everything is Terraform-managed on Google Cloud: 14 modules and 110 managed resources in the live state. Idle cost is close to nothing; the only always-on piece is a Free Tier database VM.
Cloud Run job · live
Rebuilds the world, publishes the warehouse and runs the model lifecycle. Up to 4 h. Since the 2026-11-04 catch-up the scheduled tick succeeded on six consecutive days to 11-10; its whole history has exactly one failed execution, the tick-7 timeout.
Services run at min 0 with small caps; jobs run only when scheduled. The only always-on piece is the Free Tier database VM.
No external IP, NAT or load balancer. Anonymous requests get 403. The one exception is the read-only console, which holds no approver secret.
One service account per process with resource-level grants, no service-account keys, and secrets in Secret Manager with their own reader lists, never in Terraform state.
A GBP 10 budget notifies a spend-guard service that unlinks billing at GBP 8. The only measured cost: GBP 0.65 month to date on 2026-11-05.
2,205 tests at 98.79% line coverage, but the count is not the point. Each group of tests exists to establish one claim, and every pre-registered check has a test proving it is able to fail.
Not re-run: the emulator and slow suites, the Playwright journey, the scale ladder and the resilience suite. Coverage is from the committed 2026-11-09 report. Infrastructure destroy and recreate is proven only against mocked providers.
Resilience campaign: correctness and throughput, held together
12 injected failures per fault seed · criteria pinned by hash before each run
Failures handled, per fresh fault seed
Isolated 1% crashes dead-lettered 1,305 healthy messages; the stale-forecast alert never fired.
Flow control v1, forecast-freshness SLO tightened from 48 h to 24 h.
Redesigned on development data after the nightly performance gate caught 433 events/s.
Warehouse write path optimised after a second gate failure at 954 events/s.
Chaos throughput, events/s, against the nightly floor
│ floor 1,218 = 0.5 × local baseline
The v2 to v4 criteria files are identical except version, supersession and seed, and a test enforces it. The code changed three times; the criteria did not. One disclosure: the v1 criterion for consumer crashes had encoded the collateral dead-lettering as expected, and was rewritten once. Crashes are in-process exceptions, not OS kills.
A deliberately bad candidate must be rejected, a steady one must reach ready and be promoted by an approver, drift must be detected by a deadline, and a forced bad champion must be rolled back. Seed 601 failed one check: its steady world raised 30 alarm days against a limit of 0. Seed 621 passed 12 of 12. The criteria were not loosened; this is a pass on attempt two, and it is labelled as one.
With an adversarial provider obeying the injection, the harness refused all 28 prohibited actions. Attempt 5 shows a model following a stated procedure on unseen faults, not open-ended diagnosis. The deployed loop uses deterministic triage and makes no LLM call.
Every figure is from a pinned experiment or a held-out world scored once against hidden truth. All business data is synthetic; GBP means simulated units.
After earlier rounds failed or passed only on worlds where nothing moved, ADR 0031 re-ran the question on five fresh seeds with the method unchanged and three hypotheses written down first.
every world passes its unchanged per-world acceptance
seeds 901 and 905
mean true delta > 0 with CI lower bound > 0
+34.3/day, 95% CI [−113.9, +203.9]
at least 3 of 5 worlds change a price
3 of 5
True effect of the optimiser’s decisions, per held-out world
ADR 0031 · seeds 901–905 · method unchanged · simulated units per day
Mean +34.3 per day, 95% CI [−113.9, +203.9]. Pooled, the optimiser captured +171 of a 2,099 per day oracle. It never broke a constraint; the naive unconstrained optimum would have lost about 1.95M per day in the same worlds.
What the optimiser chose
40 decisions per world · change / hold / frozen
| Planner | Fixed | |
|---|---|---|
| Recovered | 61.1% | 54.6% |
| Failed retries per episode | 0.84 | 1.22 |
| Days restricted per episode | 2.1 | 5.3 |
| Mean days to recover | 9.8 | 6.9 |
| Value per episode | +47.72 | baseline |
paired 95% CI [+21.98, +75.99] · 98.5% vs 93.6% of oracle value
The planner recovers more and retries less, at a real cost: recovery takes about three days longer on average. Brier 0.1648 against 0.1659 for the rate table, PR-AUC 0.651 against 0.626.
The gate passed after an owner-approved amendment. The original ECE ≤ 0.03 limit was unattainable at about 500 rows: a perfectly calibrated model fails it 87% of the time. The raw ECE was 0.034 and would have failed the original. The amendment was written after the failure mode was understood, and it is disclosed here.
Scale ladder: replayed through the production consumers
M1 budget · 6 shards · 4 GiB harness cgroup · Postgres 1 GiB · one Linux host, in-memory broker
Events replayed (millions)
Throughput (events/s)
Each step: 10% duplicates, reordering and injected crashes, final state compared with an exact oracle (12 of 12 checks). Throughput fell 15% from 250K to 500K as the 2.5 GB database outgrew its 1 GB container (cache hit 98.5% → 94.6%). The 8 GB budget is emulated with cgroups. 1M was not run.
At 500K, after a host reboot, Postgres swapped up to 14.5 MB against a registered budget of zero, because docker restored the memory cap but not the swap cap. The gated harness check passed; the 3.3-hour step was not re-run. A separate Phase 14 run (8 shards, unconstrained host) reached 4,494.6 events/s and a 21.27 ms apply p99 at 100K; it is a different experiment and is not compared with the ladder.
Most are recorded as numbered ADRs, written before the code they govern.
PX-01 · ADR 0007, 0012
A simulator with hidden latent parameters, an import contract that stops model packages touching it, and one package, praxis.science, allowed to join the two. "Recovered the true elasticity" becomes a checkable sentence instead of a boast.
What it cost
Every result is about whether the methods recover a known answer in a simulated world, not about real customers.
From git history, ADRs and kept evidence files. Each failed run’s evidence stays in the repo next to the run that passed.
The forecaster I pre-registered lost to ridge on the mean
On the development world ridge beat LightGBM (vWAPE 0.1349 vs 0.1404), and ten LightGBM variants did not close the gap. Searching further would have been tuning by forking paths.
A hybrid champion, ridge mean plus calibrated LightGBM quantiles, chosen before the held-out world was run. LightGBM stays in every backtest as a reported challenger.
A serving defect that training could not see
Loading a forecast artifact rebuilt the ridge’s one-hot blocks in sorted order, not fit order, so every loaded model applied categorical coefficients to the wrong columns. Training and backtests never reloaded, so they were fine.
Fixed with a regression test that compares predictions, and serving parity became a validation check every candidate must pass.
Crash collateral in the warehouse consumer
Pub/Sub charged a delivery attempt to every message in a lease that ended without an ack, so a 1% crash rate dead-lettered 1,305 healthy messages.
Slow start after a restart, first deliveries and redeliveries processed separately, and a message redelivered twice processed alone. The first version of the fix ran at 433 events/s and the nightly gate caught it.
Tick 7 timed out in the cloud
A retrain hit the 1,500 s step limit. Retrain wall time grew from about 1,600 s to 2,000+ s as history grew, because the required backtest scales with history.
State was not advanced, so tick 8 retried the same days and found the completed retrain. Then a 4 vCPU / 4 h job and a sliding 364-day training window (ADR 0030), whose benefit is an extrapolation until about 2027-04.
The first deployments failed their own checks
Cloud smoke kept two failed runs before passing 46/46 and 50/50. Live smoke needed three runs (48/49, 47/49, 49/49): a missing warehouse catalog and a status-report selection bug.
Each failure kept as evidence, the checks unchanged between runs. The local trial had already caught three defects before any cloud tick, including the non-atomic directory publish.
A pre-registration error in the recovery gate
ECE ≤ 0.03 was unattainable at about 500 rows: a perfectly calibrated model fails it 87% of the time. The raw ECE was 0.034.
Amended with the owner’s approval after the failure mode was understood, disclosed, with the raw 0.034 shown beside the pass.
Every pre-registered check has a test proving it can fail. When a gate failed, the useful move was to keep the evidence beside the fix.
Guardrails made the optimiser harmless; they did not make it right. The remaining error is in price-driven churn, which a 28-day test barely identifies. The next step is an experiment design, not a better optimiser.
The nightly throughput floor caught two correct-looking fixes that were slow. A fix that passes the resilience suite and halves throughput is not a fix.
The first local trial of the live loop found three real defects before any cloud tick; the first cloud ticks found a retrain cost that grows with history.
The console is public and read-only: it shows the decisions the daily loop records, and its approve buttons return 503.