Skip to content

RFC-0028: The host kind contract, everything the runner asks of a simulator

Status: Accepted (the operator, 2026-12-02): steps 1 to 6 are to be built on branch seams, to merge when baseline-a ends; open questions 1, 2 and 4 as recommended, and question 3 answered by a trace (section 6). Built: steps 1 to 6 (2026-12-02), merged into main, with the amendments marked in sections 3, 4 and 6. It designs gap 1 of RFC-0033. The number was reserved by NXT-D0 §1. Date: 2026-12-02 Builds on: ADR-0027 decision 1 (a simulator is a host kind; nothing outside it names Pollen, MuJoCo, Gazebo or ROS), ADR-0029 (contact and proximity), RFC-0025 §3.4 (a reset returns when settled), NXT-D0 §1 (the minimal dispatch), RFC-0033 (register row 5). Evidence: the code read at 4f68ae8, and the contact block of baseline-a's first 131 result.json files. Nothing was run for this RFC. What is not verified is in section 8.

1. Motivation

ADR-0027 decision 1 says the runner names no simulator. Today it does, in five places:

What Where What it knows of the duck's simulator
The world file labrunner/scene.py:115 mjcf, called at challenge.py:65 MuJoCo XML from Pollen's scene_backlash.xml, through host.scenarios and host.scene_dir
Contact labrunner/contact.py the body server's touches op (a Pollen patch); MuJoCo's check of recorded poses, run with host.microduck_rl's python; circle_host decides a host has no physics because it has no Pollen checkout
Truth 22 reads of host.truth_port in the runner, Mission Control and the duck one field used both as "this host has a truth" and as a TCP port
The camera labrunner/camera.py:24-81 opens the duck's body server (simhost.truth.Body) on that port
The payload's independence challenge.py:98, remote.truth_connections counts TCP connections to the truth port, to show the navigator reads no truth

Gazebo, the simulator of MVP 2 (RFC-0025), would need an edit in each. That is gap 1.

2. What exists

simhost.kinds.Kind is five fields: parse, reset, down, truth, simulates. Two kinds use it: pollen-duck-sim and nxt-kinematic-sim. NXT-D0 §1 refused a base class until a third kind shows what the kinds share. Gazebo is that third kind and is not built. So this RFC writes the contract from what the runner asks, not from a third implementation.

3. Proposal: the kind answers everything the runner asks of a simulator

The Kind entry grows to the functions below. The runner calls them only through simhost functions that take the host.

Function Returns Duck (pollen-duck-sim) NXT (nxt-kinematic-sim)
parse(raw, source) the kind's host as now as now
world(host, scene, out) the kind's world file for a lab scene, read by shape (section 6, question 1) mjcf, moved to simhost.duckworld; reads the scene's boxes and floors the scene's own scene.json (scene.path); nothing written
reset(host, world) nothing, once a truth sample stamped after the reset is read as now as now
down(host) nothing as now as now
has_truth(host) true when the kind reads a truth truth_port set true
truth(host) a reader: read() gives (pose, z, quat, sim_time), close() Body on the port nxt.Truth
truth_address(host) the truth's (host, port), or none 127.0.0.1, truth_port nxt-web's
contacts(host, sampler, obstacles, floors, checker) a contact source, or none the touches op, else MuJoCo's check the footprint circle
checkout(host) the simulator's source checkout, whose commit a run's build records, or none microduck_rl none
socket(host, name) the Unix socket of the robot's robot, depth, map, gate or camera, or none (added by the review of the merge) the host file's sockets none: the robot is reached over TCP
simulates the sensor kinds it makes readings for as now as now

socket has a sibling, require_socket(host, name), for a caller that cannot do without the socket: it raises a HostError naming the file, the kind and the socket. A caller that can do without asks socket and handles none: no camera, no zero move.

connections() is not in the table: it is a method of NxtHost (nxt-web and nxt-gate, its page and its gate's address), read by the NXT's own code, not a function of the kind. The duck's sockets are the socket row.

A contact source has by (its name: simulator, mujoco, circle), step_s (its time resolution: 0.005 for the touches op, the sample period for a check of recorded poses), poll (per truth sample) and finish (per run, with the run's folder). Amended when built (step 3, 2026-12-02): there is no finish. Its only work would be running MuJoCo's checker and reading its answer, which is evaluating, so the runner does it (labrunner.contact.by_source) with the command the source carries. The source is simhost.contactsource.Source; step_s 0.005 is the body server's TIMESTEP (body_server.py:66 in Pollen's checkout).

Rules:

  1. Nothing outside simhost reads a kind's fields: truth_port, microduck_rl, scene_dir, scenarios, pollen. scripts/check_boundaries.py already reads every file with ast. It grows one rule for these attribute names outside simhost. Amended after the merge: sockets joined the list (the review found host.sockets["camera"] in the runner, and the NXT's host has none), and so did a call of .as_json() on a host. The navigator's own sockets dictionary (duck_lab.nav) and the duck's probes (rule 5) are not flagged for sockets. The check is a lint for honest code, not a wall: it does not catch getattr with a variable name, vars(host), attrgetter, asdict, an as_json kept as a bound method, or reading the host file's JSON directly, and it does not scan scripts/.
  2. A contact source says what it is. result.json's contact records by (it does today) and adds step_s. A run evaluated by a coarser source says so (ADR-0029). A kind with no source gives no verdict, as a duck host with neither source does today.
  3. The camera reads the pose from truth(host), not from the duck's body server.
  4. A test-only third kind exercises the contract in the runner's tests. It is neither the duck nor the NXT, so a duck assumption left in the runner fails there first.
  5. The duck's probes stay the duck's. The 83 scripts in robots/duck/sim/probes may use the duck's kind directly; they are not the runner.

4. Order of building

Each step comes with its tests first, on branch seams.

  1. has_truth and truth_address replace the 22 reads of truth_port. This is mechanical, and it is the most callers.
  2. world: mjcf moves into the duck's kind. labrunner.scene keeps miniview_scene.
  3. contacts: contact.py's three sources become two kinds' sources, and circle_host goes.
  4. The camera through truth(host).
  5. The boundary rule (rule 1) and the test-only kind (rule 4).
  6. Then RFC-0033 question 4: one RPC client in runfile, used by the kinds' readers and the runner's clients. Amended when built: the kinds' readers speak no JSON-RPC (Pollen's body server over TCP, the NXT's HTTP), so runfile.jsonrpc.Client and Stream serve the three JSON-RPC clients (labrunner.rpc, duck_lab.nav.client, straight.py); the gate's lease refusal moves to robotgate.lease_lost.

5. Alternatives considered

  • A base class or a typing.Protocol for Kind. A table of functions already names the contract, and a class adds nothing two kinds need. Revisit with Gazebo.
  • Kinds as entry-point plugins. Rejected in NXT-D0 §1: every kind lives in this repository.
  • Gazebo made to look like Pollen's body server, behind a bridge that speaks its ops. The runner would not change, but every kind would pretend to be MuJoCo: geom names, a touches op, an MJCF world. Rejected.
  • Keep contact in the runner, with a branch per kind. This is what exists. A third kind adds a third branch.
  1. Does world take the Scene or the scene.json path? Recommended: the Scene, validated and versioned (scene_version, RFC-0033 gap 3), and an output folder. Amended when built (step 2, 2026-12-02): the recommendation could not hold. The runfile Scene has rooms, bounds and drops but no floors or boxes, and the duck's MuJoCo world is made of them; they exist only in the challenge scene the runner draws per seed (labrunner.scene.Scene). simhost imports no other package, so world reads the scene by shape: the duck's needs id, boxes and floors; the NXT's needs path, its stored scene.json. Adding floors to scene.json would change the Observatory's scene format; it waits until a kind must build a world from a stored scene (Gazebo on the apartment).
  2. Must a kind give a physics-step contact source before its runs count toward a milestone? Recommended: yes. Runs evaluated by a coarser source are recorded and reported apart.
  3. Who places the robot at the scene's start: the world file or a call after the reset? Traced 2026-12-02: the duck's body server always starts the duck at the origin facing +x and takes no position (simulator.py:4), so the lab moves the world instead: every challenge is drawn in the start's frame, and a probe's start re-frames it (challenges.py:1, :665-678). The NXT takes its host file's start (nxt.py:82-85). The answer, for step 2: the start is a pose in the scene's frame. A kind that cannot place the robot (Pollen's body server) is given a scene re-framed so the start is its origin, as the challenges are; a kind that can (nxt-web's --start) takes the start. Corrected 2026-12-02: this answer first said the NXT's start leaves its host file. Step 2 showed it cannot: the apartment is one frame shared by its evaluator, Mission Control and the Observatory, so re-drawing it around the NXT's start moves every room and hazard, and a start in scene.json is a format change. The NXT's start stays in its host file until a scene carries one.
  4. Gazebo's reset and clock. Its reset all sets simulation time to zero, and the sampler's clock epoch per reset is ADR-0027's unbuilt "clock epoch". Recommended: settle these in the Gazebo kind's own step, with this contract unchanged.

7. Consequences

  • The runner, the camera and the evaluator stop naming MuJoCo; a third kind adds a KINDS entry and no runner edit.
  • result.json's contact gains step_s; the run format stays 2 (an added field).
  • 22 call sites change in step 1, across three projects. The baseline's code does not change under it: the work is on branch seams, merged when baseline-a ends.

8. Not verified

  • Nothing was run. Gazebo is not installed here, and nothing in this RFC was checked against it.
  • The 22 reads of truth_port are counted, not classified one by one into predicate and port.
  • Whether the NXT kind's runs skip the real-time factor check, given that it has no simulation time (simhost/nxt.py:39), was not read.
  • Whether any probe imports runner code that step 2 or 3 moves was not checked.
  • Whether the boundary check's blind spots (rule 1) hide a read today: the check passes, and nothing else was searched for what it cannot see.
  • Rule 1's other fields after step 2: six probes read scenarios to re-reset to a world an earlier run wrote, and runfile/build.py:97 reads microduck_rl; steps 3 and 5 take them.