ADR-0033 — A run records each contact, every broken invariant, the drop margin and its truth copy's integrity, at their time¶
Status: Accepted by the operator on 2026-12-03 ("also accept adr"), before the advisor's review
was in. The review's fixes are folded in below; the one that changes a run's course (decision 4,
a stop on any fall or bounds) went back to the operator, who chose it ("Stop on it").
Date: 2026-12-03
Context documents: ADR-0029 (contact is MuJoCo's
collision; the simulator's touches first),
docs/wip/OBSERVATORY-ROADMAP.md (the replay's gaps; this is
stage 6), RFC-0019 (an event's raw is its record)
Context¶
The roadmap's inventory lists what a run evaluates but does not record with a time or a place, so a person replaying it cannot see where it went wrong (read on main, 2026-12-03):
- Contacts.
contact.replaylists them in theevaluatedevent's raw, written once the run is over: the first 40 touching episodes and the deepest, the rest counted, each with its time, part, obstacle and depth. None has a position. The simulator's touches op (robots/duck/sim/patches/body-server-touches.patch) reports{part, other, first_t, last_t, depth_m, steps}per pair; MuJoCo's contact has a point (mjContact.pos), which the patch does not pass on. The checker (robots/duck/sim/contacts.py) does not record it either. - Every broken invariant after the first.
Evaluator.checkkeeps the run's first (self.broken) and returns nothing for the rest; its rules are oneif/elifchain, so a sample that breaks two reports the first in the chain.watch()stops the navigator (break_goal) only on whatcheckreturns, so afallorboundsafter another rule's breach does not stop it today. - The drop margin and the lowest trunk.
min_drop_mandlowest_trunk_mare in the verdict's stats (result.json), with no time and no place. Theevaluatedevent (challenge.evaluated) carries none of the stats. - The truth copy's integrity.
unpairedandmax_gap_ms(runfile.truthcopy.stats) go toresult.jsononly, because the run record is written at the run's start. The run file and the page never have them, and the largest gap has no time.
What makes this an ADR is the run file. Its order is a rule: mcapio.Recorder refuses a record
whose time goes back, and the truth copy holds a runner's record for a later time until the copy
reaches it (TruthCopy.add_ahead). A record can be written at its own time only while the copy has
not passed it. The simulator's touches arrive with each truth sample (50 ms), so they can be written
that way, as the proximity alerts are. The checker's contacts exist only after the run ends, when
the copy has passed every one of them.
A record's fields reach the page only through three lists: wire.RAW_KINDS (the reader keeps the
event's raw), store.EVALUATOR_FIELDS (the store keeps the named fields) and runstore.js's
EVALUATOR_FIELDS (the live page does). Every new field below is named in all three.
Decision¶
- A contact is its own event, in two phases, as an alert is. One
contactevent marks the onset of each touching episode of a (part, obstacle) pair, and one marks its end. - The episode is as
contact.replaygroups them: a pair's touch more thancontact.ONSET_GAP_S(0.5 s) after its previous touch (by the touches' own times) starts a new one.watch()keeps the open episodes. On each truth sample it ends any whose last touch is 0.5 s old, asEvaluator._track_ringends an alert, and a run's open episodes end after the sampler stops, before theevaluatedevent. - Only obstacles count. Touches are filtered as
contact.from_touchesfilters them (the scene's obstacle names);Source.pollkeeps everything that is not a floor. - Enter carries
{phase: "enter", t, truth_t, part, obstacle, depth_m, by, truth, pos}.truthis the trunk's truth position[x, y]at the sample, as an alert's is. Exit carries{phase: "exit", t, truth_t, part, obstacle, deepest_m, deepest_t, deep_pos, steps, duration_s}. - Its time. The event is written at its run time when the copy has not passed it (the usual
case: the copy runs up to 0.2 s behind). Otherwise it is written at the copy's last time,
behind any record already held. The event's own
tis its time; the file's time only orders it. - The cap. A run keeps at most 200 episodes as events. The rest are counted in the
evaluatedevent's raw (contact_events_omitted). - A reading, not a verdict.
contact.from_touchesstill decides the verdict, at the end, from the whole run's touches. A run can havecontactevents and no verdict (the real-time factor too low, or no floor touch reported), and the page does not read a FAIL from acontactevent; onlyevaluatedis a verdict. - The lists.
contactjoinswire.RAW_KINDS,store.EVALUATOR_FIELDSandrunstore.js'sEVALUATOR_FIELDS, with the fields above. - The checker's contacts stay where they are. On a host whose source is the checker
(
mujoco), contacts are known only after the run. They stay in theevaluatedevent's list, which stage 1 shows, and are not written as events at a time the copy has passed. With the simulator's source, the checker's contacts stay beside the simulator's, deciding nothing (ADR-0029). - A contact has a position. The body-server patch passes MuJoCo's contact point (world frame,
metres; the midpoint between the two surfaces) for each pair's first step and for its deepest
step (
first_pos,deep_pos). Where a pair touches at several points in one step, the deepest point counts, for the first step as for the deepest. The checker adds the point of each contact it finds (contacts.py,c.pos). - A body server with the older patch gives no point. The event then has no
posordeep_pos, and the page draws the marker at the event'struthposition (the roadmap's standing choice), labelled as such. - Changing the patch changes the simulator in the operator's Pollen checkout.
scripts/host-setupapplies it with the operator's go: it revertsbody_server.pyto the pinned checkout's file, then applies the new patch, and its marker (andscripts/host-check's) names the patch's version, so an old patch reads as not applied. - Every broken invariant is recorded, and a stop rule stops whenever it breaks.
Evaluator.checkevaluates each rule on its own (fall,drop_margin,contactby the circle,bounds) and tracks an episode per rule that ends after 0.5 s clear. Each onset writes aninvariantevent{rule, why, first}.firstis true on the run's first; when two rules break on the same sample, the first in today's chain order is. - The episode's end is not written: it only keeps one onset from being written for every sample. An invariant is a point in time; a contact or an alert is a span.
- A run keeps at most 50 such events; the rest are counted in the
evaluatedevent's raw (invariant_events_omitted). - The run's course changes (the operator, 2026-12-03, "Stop on it"). A rule in
STOPS(fall,bounds) stops the navigator at its first onset even after another rule broke. Today only the run's first broken rule can.break_goalis called at most once a run. - The verdict does not change. The run's first broken rule alone is in
failed(self.brokenstays the first;explore.verdictreads it), so a run that broke two rules still fails on the first. - The lists.
firstjoinsstore.EVALUATOR_FIELDS["invariant"]andrunstore.js's. - The drop margin and the lowest trunk have a time and a place, in the run file. The evaluator
keeps
min_drop: {m, truth_t, x, y}andlowest_trunk: {m, truth_t, x, y}: the time (the sampler's clock; the evaluator has no run time) and truth position of the sample that set each. Both are in the verdict's stats (result.json, in every mode) and, throughchallenge.evaluated, in theevaluatedevent's raw, where each addst, the run time. (Corrected while building stage 6: the accepted text namedtin the stats, which the evaluator cannot know.) Both join theevaluatedentry ofstore.EVALUATOR_FIELDSand ofrunstore.js's, withcontact_events_omittedandinvariant_events_omitted.min_drop_mandlowest_trunk_mstay, so readers ofresult.jsondo not change. - The run file carries its truth copy's integrity.
TruthCopy.finishwritestruth_copy(ticks,paired,unpaired,max_gap_ms,max_gap_t) into theendrecord. The validator already accepts the extra field.store.apply'sendbranch andrunstore.js's keep it on the run, andresult.jsonkeeps its copy. A tick with no truth is already in the file as a tick without truth. (Added while running the baseline after stage 6:after_truth, the ticks past the truth's last sample once the runner says its sampler stopped. Since the sampler stops at the verdict, the navigator's last tick, written as it is closed, had no truth and was countedunpairedin every run;unpairedis again the ticks the truth missed while it ran.) - An older run is read as it is. No migration: a run recorded before this has none of the new events or fields, and the page shows what a run has, as stage 1 does for the verdict.
The roadmap calls stage 6 runner work; decisions 1, 4, 5 and 6 also change the store's and the live page's field lists. They are part of this stage, so a field is never recorded that the page cannot receive.
Consequences¶
- Positive:
- A replay places each contact at its point and time, and every broken rule at its time.
- The live page sees a contact as it happens, not after the verdict.
- The assessment (the roadmap's step 6) runs on files that hold what stages 2, 3 and 5 draw.
- A duck that falls or leaves the scene stops, whatever broke before.
- Negative:
- The patch change needs the operator's Pollen checkout patched again (
scripts/host-setup, with the simulator down, under the simulator lock). - A run that broke another rule before a fall or bounds now ends sooner than the same run did before this. Its verdict is the same, and it was already a FAIL.
- A file can hold up to 250 more events. A typical run's count is not known. Of the 2,346 truth
logs in
/work/microduck-nav-runs, 8 have the touches field; 4 have touching episodes, at most 3 a run. - A contact or invariant event's time in the file can be later than its own
t, by about a sample period, when the copy has already passed it. - Neutral:
- The verdict and
result.json's existing fields are unchanged; the tests that pin them stay as they are. - The NXT's contacts are the circle's, so they are
invariantevents, notcontactevents. - Tests, each with a case that must fail:
- A recorded run with touches gives one
contactenter per episode ascontact.replaycounts them, at its onset, with a point and the truth position. - Touches into a non-obstacle give none.
- An episode open at the end gets its exit before
evaluated. - The 201st episode is counted, not written.
- Two rules on one sample give two events, the chain's first with
first: true. - A
fallafter adrop_marginbreach callsbreak_goalonce, and the verdict'sfailedis the breach only. - The drop margin's time and place match the sample that set it, in
result.jsonand in theevaluatedevent. endcarriestruth_copy, and the store and the live page keep it.- The live page receives the
contactandinvariantfields (runstore.eventOfparity withstore.apply). - The patch:
robots/duck/sim/test_touches.pyon a world built there, where a box touched at a known point reports that point.
Alternatives considered¶
- The position from the checker only, with no patch change. It poses the body at the 20 Hz truth samples, so a touch between two samples has no point. That gap is why ADR-0029 put the simulator's touches first.
- The marker at the truth pose for good. That is the trunk's position, up to the reach (0.1175 m) from where the body touched; a contact at a door's jamb would be drawn in the doorway.
- Every 50 ms touch as an event. A pair touching for a second gives 20. Episodes are the unit
contact.replayalready uses. - Two kinds,
contactandcontact_end. Each new kind is an entry in every field list and in the page's kind maps; one kind with a phase is one, and mirrors the alert (anomaly,phaseenter or exit). Finding the onsets alone becomes a check ofphase. - The checker's contacts written into the file at their times. It runs after the copy has passed them, and the recorder refuses a time that goes back. Writing them at the end time would place them wrongly.
- Record every rule, but stop only on the run's first (today's course). The operator chose the stop: a run after a fall or out of the scene means nothing more, whatever broke first.
- Every broken rule in the verdict's
failed. That changes what a run is evaluated by, not what it records. It is out of scope; a change to evaluating gets its own decision.
Not covered¶
- The real duck has no touches op and no physics, so it gets no contact events; how a real robot's contact is sensed is open (ADR-0029).
- The cost of patching the Pollen checkout again was not measured, and neither was the body server's per-step cost of keeping two points per pair.
- How the page draws a contact's span or an invariant's point is stage 2's (the map) and stage 7's (the lanes). This ADR decides what is recorded, not how it is drawn.
- The clearance minimum's time and place are not added: stage 5 computes the tightest point on
request (
observatory clearance). - The episode gap and the caps (0.5 s, 200, 50) are choices. Eight runs are too few to set them from; the baseline (the roadmap's step 5) shows whether they hold.
Source.pollsubtracts a simulator-time interval from the sampler's clock, and the touches are read after the pose. A touch's time can be off by the two clocks' drift within one poll; this predates the ADR and is not measured.