Skip to content

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.replay lists them in the evaluated event'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.check keeps the run's first (self.broken) and returns nothing for the rest; its rules are one if/elif chain, so a sample that breaks two reports the first in the chain. watch() stops the navigator (break_goal) only on what check returns, so a fall or bounds after another rule's breach does not stop it today.
  • The drop margin and the lowest trunk. min_drop_m and lowest_trunk_m are in the verdict's stats (result.json), with no time and no place. The evaluated event (challenge.evaluated) carries none of the stats.
  • The truth copy's integrity. unpaired and max_gap_ms (runfile.truthcopy.stats) go to result.json only, 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

  1. A contact is its own event, in two phases, as an alert is. One contact event marks the onset of each touching episode of a (part, obstacle) pair, and one marks its end.
  2. The episode is as contact.replay groups them: a pair's touch more than contact.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, as Evaluator._track_ring ends an alert, and a run's open episodes end after the sampler stops, before the evaluated event.
  3. Only obstacles count. Touches are filtered as contact.from_touches filters them (the scene's obstacle names); Source.poll keeps everything that is not a floor.
  4. Enter carries {phase: "enter", t, truth_t, part, obstacle, depth_m, by, truth, pos}. truth is 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}.
  5. 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 t is its time; the file's time only orders it.
  6. The cap. A run keeps at most 200 episodes as events. The rest are counted in the evaluated event's raw (contact_events_omitted).
  7. A reading, not a verdict. contact.from_touches still decides the verdict, at the end, from the whole run's touches. A run can have contact events and no verdict (the real-time factor too low, or no floor touch reported), and the page does not read a FAIL from a contact event; only evaluated is a verdict.
  8. The lists. contact joins wire.RAW_KINDS, store.EVALUATOR_FIELDS and runstore.js's EVALUATOR_FIELDS, with the fields above.
  9. 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 the evaluated event'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).
  10. 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).
  11. A body server with the older patch gives no point. The event then has no pos or deep_pos, and the page draws the marker at the event's truth position (the roadmap's standing choice), labelled as such.
  12. Changing the patch changes the simulator in the operator's Pollen checkout. scripts/host-setup applies it with the operator's go: it reverts body_server.py to the pinned checkout's file, then applies the new patch, and its marker (and scripts/host-check's) names the patch's version, so an old patch reads as not applied.
  13. Every broken invariant is recorded, and a stop rule stops whenever it breaks. Evaluator.check evaluates each rule on its own (fall, drop_margin, contact by the circle, bounds) and tracks an episode per rule that ends after 0.5 s clear. Each onset writes an invariant event {rule, why, first}. first is true on the run's first; when two rules break on the same sample, the first in today's chain order is.
  14. 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.
  15. A run keeps at most 50 such events; the rest are counted in the evaluated event's raw (invariant_events_omitted).
  16. 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_goal is called at most once a run.
  17. The verdict does not change. The run's first broken rule alone is in failed (self.broken stays the first; explore.verdict reads it), so a run that broke two rules still fails on the first.
  18. The lists. first joins store.EVALUATOR_FIELDS["invariant"] and runstore.js's.
  19. 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} and lowest_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, through challenge.evaluated, in the evaluated event's raw, where each adds t, the run time. (Corrected while building stage 6: the accepted text named t in the stats, which the evaluator cannot know.) Both join the evaluated entry of store.EVALUATOR_FIELDS and of runstore.js's, with contact_events_omitted and invariant_events_omitted. min_drop_m and lowest_trunk_m stay, so readers of result.json do not change.
  20. The run file carries its truth copy's integrity. TruthCopy.finish writes truth_copy (ticks, paired, unpaired, max_gap_ms, max_gap_t) into the end record. The validator already accepts the extra field. store.apply's end branch and runstore.js's keep it on the run, and result.json keeps 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 counted unpaired in every run; unpaired is again the ticks the truth missed while it ran.)
  21. 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 invariant events, not contact events.
  • Tests, each with a case that must fail:
  • A recorded run with touches gives one contact enter per episode as contact.replay counts 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 fall after a drop_margin breach calls break_goal once, and the verdict's failed is the breach only.
  • The drop margin's time and place match the sample that set it, in result.json and in the evaluated event.
  • end carries truth_copy, and the store and the live page keep it.
  • The live page receives the contact and invariant fields (runstore.eventOf parity with store.apply).
  • The patch: robots/duck/sim/test_touches.py on 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.replay already uses.
  • Two kinds, contact and contact_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, phase enter or exit). Finding the onsets alone becomes a check of phase.
  • 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.poll subtracts 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.