Compare old and new cost per successful speech turn. Return the top
drivers that need investigation.
Hidden answer: Python solution
import math
def cost_regression(old, new, tolerance=0.10):
if not math.isfinite(tolerance):
raise ValueError("tolerance must be finite")
if tolerance < 0:
raise ValueError("tolerance must be non-negative")
required = (
"successful_turns",
"gpu_dollars",
"avg_context_tokens",
"retry_rate",
"shadow_traffic_fraction",
)
for label, window in (("old", old), ("new", new)):
missing = [key for key in required if key not in window]
if missing:
raise ValueError(f"{label} missing metrics: {missing}")
for label, window in (("old", old), ("new", new)):
for key in required:
if not math.isfinite(window[key]):
raise ValueError(f"{label}.{key} must be finite")
if window[key] < 0:
raise ValueError(f"{label}.{key} must be non-negative")
if old["successful_turns"] <= 0 or new["successful_turns"] <= 0:
raise ValueError("successful_turns must be positive")
old_unit = old["gpu_dollars"] / old["successful_turns"]
new_unit = new["gpu_dollars"] / new["successful_turns"]
if old_unit <= 0:
raise ValueError("old unit cost must be positive")
relative = (new_unit - old_unit) / old_unit
drivers = []
for key in ("avg_context_tokens", "retry_rate", "shadow_traffic_fraction"):
if new[key] > old[key]:
drivers.append(key)
return {
"old_unit_cost": old_unit,
"new_unit_cost": new_unit,
"relative_delta": relative,
"regressed": relative > tolerance,
"drivers": drivers,
}
The useful metric is cost per successful user outcome, not total
spend alone. Rising traffic may be acceptable; rising unit cost
requires a capacity or product explanation. Do not hide zero-turn
windows with a fallback denominator; mark them as invalid telemetry
and investigate the pipeline before making a rollout decision.
Non-finite spend, traffic, retry, or context counters should also
block the decision rather than silently producing a false
non-regression.