โ€บNavigation
Dashboard โ€บ Crypto candidates โ€บ Cost-Realism Labels โ€บ iter 03

iteration 03 ยท S2โ€“S3 kernel ยท crypto cost-realism labels ยท 2026-07-14

The fast engine agrees with the referee โ€” bit for bit S2โ€“S3 DONE ยท 15/15 GREEN

← campaign board ยท ← iter 02 ยท issue #614

In plain language โ€” what happened this iteration

Yesterday's referee, today's player. Iteration 02 froze the correct answers into two golden answer sheets. Today we wrote the production version of the same math in Rust โ€” the fast, compiled language our real pipeline runs on โ€” and made it face the referee. The verdict: on the five "pick a price" labels (worst buy, worst sell, arrival, and both exit fills), the Rust engine matches the Python referee bit for bit โ€” not "very close", but literally the same number down to the last binary digit, on every one of the 1,310 bars across Bitcoin and Ethereum. On the three "average" labels (TWAP, VWAP, round-trip cost), the two agree to within about a ten-trillionth โ€” ten thousand times stricter than our one-in-a-billion requirement.

Why three separate checks? A single test can share a blind spot with the code it tests. So the kernel had to survive three independent challenges: (1) the Python referee's answer sheets, (2) a second, deliberately naive Rust implementation written a different way ("brute force") that must agree bit-for-bit, and (3) a battery of sanity laws โ€” the worst buying price can never sit below the average, an empty window must produce an honest "no data" (NULL), never a fake zero, and boundary microseconds must land on the correct side of every window edge. One interesting catch along the way: an average can mathematically land a hair (one part in 10ยนโถ) outside its price envelope purely from computer rounding โ€” our sanity check now tolerates exactly that hair, and nothing more.

What's next: the operator controls โ€” the /labels:* command set that reruns all of these proofs with one keystroke, plus the first three "guard" tests that make it structurally impossible for these forward-looking labels to ever sneak into the machine-learning feature set (which would be catastrophic cheating โ€” the model would see the future).

Grounded this iteration

crates/opendeviationbar-core/src/cost_realism_labels.rs: single-pass, horizon-parameterized kernel (compute_cost_realism_labels(ticks, last_agg_trade_id, close_time_us, horizon_us)) with Option<f64> NULL semantics; declared in lib.rs + re-exported; load_real_ethusdt_10k() added to the test-utils loader. tests/cost_realism_labels_test.rs: Leg 1 parity โ€” GATE 0 sha pins on BOTH input fixtures and oracle CSVs, TOL=0 via to_bits() on the 5 selection labels, โ‰ค1e-9 on twap/vwap/roundtrip (compile-asserted const), non-vacuous count equality both directions; Leg 2 brute-force filter+fold re-scan, bit-identical on all 1,310 mature anchors; Leg 3 property battery (entry envelope with documented 1e-12 relative slack for 1-ulp weighted-mean rounding โ€” observed 1.5e-11 at price ~1e5; exit ordering; arrival containment; roundtrip formula pin). 12 in-module unit tests pin empty-windowโ†’NULL (never 0), breach-TID exclusion, half-open ยตs boundaries, TWAP single-print/same-ยตs fallback, hand-pinned TWAP/VWAP/roundtrip values, H=1s parameterization, never-inf degeneracy.

tests green15 / 15
bit-exact labels5 of 8
bars compared1,310
continuous residual~1e-13
gateโ‰ค1e-9 (locked)
tripwires touched0

Artifacts + integrity pins

ArtifactPinNote
src/cost_realism_labels.rskernel + 12 unit testsNEVER wired into bar serialization โ€” guard-F surfaces untouched
tests/cost_realism_labels_test.rsBTC oracle b1f08e0bโ€ฆ / ETH c8c1b0e0โ€ฆ locked constsGATE 0 hard-halt on sha mismatch; input pins b2f7399eโ€ฆ/b105e51fโ€ฆ too
Tolerance consts1e-9 + const _: () = assert!(โ€ฆ)bit-exact legs use to_bits() equality โ€” no epsilon at all

Decisions made (for operator review at PR time)

#DecisionWhy
1Kernel is a standalone top-level core module, NOT wired into the processorADR D2 locked: no forward window at bar close; sidecar path intentionally uninvolved; tripwires (126/93/93/68) must stay unchanged
2Property-battery envelope assertions carry 1e-12 relative slackWeighted means can land 1 ulp outside [min,max] in float64 (observed 1.5e-11 @ ~1e5); a real crossed fill is orders of magnitude larger. Oracle-parity + brute legs remain slack-free.
3ETH aggTrades loader added to test_data_loader (test-utils only)โ‰ฅ2-symbol gate needs it; mirrors the BTC loader; no production surface touched

Next fire picks up here

S4 โ€” wiring + guards. .mise/tasks/labels.toml (oracle / oracle-fresh cmp -s drift guard / test / test-full / check-full / doctor โ€” explicit nextest filtersets, --no-tests=fail) + /labels:* slash wrappers (descriptions mirrored verbatim) + python/opendeviationbar/cost_realism_labels.py spec module (single column list + full COMMENT grammar strings, R5 SSoT) + guards A (naming law ^label_fwd_), E (COMMENT taxonomy + LOOKAHEAD_US โˆˆ {3000000,6000000} + NOT A FEATURE + #614 link), G (no bar_* names) in tests/test_cost_realism_labels.py. Branch feat/labels/pr-a-oracle.