By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Part 1 produced a service that works. Part 2 makes it operable: every request leaves a trace and a cost record, latency percentiles are computed from those records, the eval report is attached to the exact change, and a release gate decides promote or roll back from evidence rather than opinion.
from math import ceil
def percentile(values: list[int], pct: float) -> int:
"""Nearest-rank percentile; no interpolation, no external dependency."""
if not values:
raise ValueError("no latency samples")
ordered = sorted(values)
rank = ceil(pct / 100 * len(ordered)) - 1
return ordered[max(0, rank)]
latencies_ms = [180, 240, 300, 420, 610, 900, 1400, 2600, 3800, 9200]
p50 = percentile(latencies_ms, 50)
p95 = percentile(latencies_ms, 95)
EVIDENCE = {
"eval_score": 0.96,
"error_rate": 0.004,
"p95_ms": p95,
"approval_bypasses": 0,
}
GATES = {
"eval_score": lambda value: value >= 0.92,
"error_rate": lambda value: value <= 0.01,
"p95_ms": lambda value: value <= 4000,
"approval_bypasses": lambda value: value == 0,
}
failed = [
name for name, passed in GATES.items() if not passed(EVIDENCE[name])
]
print(f"p50={p50}ms p95={p95}ms")
print("gate:", "promote" if not failed else f"rollback {failed}")decide_gate(evidence) returns promote or rollback with the failing signal names.blocked.Key takeaways
Part 2 adds traces, cost records, percentile reporting and a promote/rollback gate.
The eval report must be tied to a change fingerprint so the evidence matches the shipped version.
The gate is a pure function over recorded evidence; it never mutates production.
Same evidence must produce the same decision, and a blocked decision names the failing signals.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.