Protocols · the seams
The golden corpus
ThreatProtocol.kt and threat_protocol.py are two hand-written
implementations of the same grammar, and neither is authoritative. The shared truth is a
measured corpus at protocol/threat-protocol-golden.json, read by both
test suites.
What it contains
known_precision_limits sectionjetson/tests/test_threat_protocol_golden.pyapp/src/test/java/…/core/vision/ThreatProtocolGoldenTest.ktBoth suites fail loudly if the corpus is missing or truncated, rather than skipping — a corpus that failed to load would make every assertion vacuously true, which is a failure mode this project has been bitten by before. Both suites also assert a minimum vector count. Verified by hiding the file and watching both go red.
Both CI workflows are triggered by changes under protocol/**. That
filter is deliberate: jetson-ci.yml was previously path-filtered to
jetson/** alone, so a corpus-only change would have skipped the Python
half entirely — the shared artifact would have been enforced on one side.
Why it exists
Before the corpus, the two implementations had silently drifted in ten measured ways out of 90 differentially-fuzzed frames. None was visible by reading either file; both were correct on their own terms. The cause in every case was the same: a wire format had inherited its host language's numeric parser. Three of the ten:
- Kotlin's float parser accepts Java source syntax, including hex floats — so
0x1p3in an azimuth field became a live contact bearing 8° on the driver's HUD, while the Python side rejected the same frame. That is the one that mattered. - Python's
int()accepts underscores, surrounding whitespace and unbounded magnitudes — a 4000-digit track id parsed fine there and was dropped on the tablet. - A
sizeof3.5e38is finite in 64-bit and infinite in 32-bit, so one side kept the contact and the other discarded it.
Both sides now check explicit numeric grammars, and the Python side rounds parsed values through 32-bit float so both agree on the range and clamp boundaries. Result: 0 divergences over 111 cases, compared at exact equality.
known_precision_limits is not a to-do list
The producer holds 64-bit floats and the tablet 32-bit, so a handful of values whose two
roundings straddle a decimal boundary are spelled differently by each side
(1.45 → 1.4 vs 1.5). Both parsers accept either
spelling, and the difference is far below one wire digit — far below anything the HUD can
draw.
They are recorded so nobody “fixes” them, are kept out of
format_vectors, are not asserted as agreement, and are covered by a
test proving both spellings still parse to the same contact. This is inherent to a 64-bit producer
and a 32-bit consumer, not a defect.
Regenerating
Identical inputs were run through both implementations and only agreed-upon results were
written. The differential harness that did this is not checked in; unlike
ZCOVER and $ZVER, the ZTHREAT corpus has no generator in the
tree. If you change the format, re-run
that differential comparison rather than hand-editing the JSON. Hand-editing lets you
write down what you believe instead of what the code does, which is the exact failure this file
exists to prevent.
Changing the format means changing three things: the Python side, the Kotlin side, and the corpus.
Converted fromprotocol/README.md · docs/PROTOCOLS.md §3.5