Skip to content

Running the simulated duck from an agent

Pollen's scripts/duck-sim (in the host's Pollen checkout, named in its host file: /work/pollen/microduck on the operator's workstation; pinned at 094d4bb4, robots/duck/sim/pollen-pins.json) is written for a person at a terminal. Driven by an agent or a script, from a process with no terminal, two of its habits change meaning. This page is how robotics-lab runs it unattended: the challenge runner (lab-challenge), the evaluation, the explorers and the probes all go through the host's reset, simhost.reset (libs/simhost, RFC-0021).

Why: the sudo lockout (2026-11-16)

Every duck-sim down, the plain one included, first runs down_containers. That asks sudo systemctl is-active about sixteen container units (duck-a … duck-p). For a person, that is at most one password prompt. From a process with no terminal, sudo has nowhere to ask: each of the sixteen asks is a failed password conversation (pam_unix(sudo:auth): conversation failed in the journal). The machine's PAM counts failures with pam_faillock (deny=10 unlock_time=120 in /etc/pam.d/system-auth), so ten failures lock the user's sudo for two minutes.

The challenge runs stop the simulator every ~70 s, so the operator's sudo stayed locked for as long as they ran. A correct password typed at the time was refused ("Sorry, try again"), which looked like a forgotten password. su marko -c true accepted the same password, because su fell between the lockouts.

The duck-ether stop in plain down uses sudo -n, which fails without asking and is not counted. Only down_containers locks.

The rule

An agent never runs a command that can make sudo ask with no terminal. In duck-sim that means:

  • Use only up, down, drive, status, ctl and stand, with the patch below applied.
  • Never boot, rootfs or shell. These need sudo by design (systemd-nspawn, mounts) and are a person's commands.

The patch (a local change, not sent upstream)

robots/duck/sim/patches/duck-sim-sudo-free-down.patch drops sudo from the is-active check. Asking whether a unit runs needs no root. The stop and umount that follow are reached only when a container really runs, and still prompt a person as before. On this machine no duck-* unit exists, so they are never reached.

cd /path/to/pollen/microduck     # the host file's `pollen.microduck` (`simhost show`); scripts/host-setup applies the patch itself
git apply /path/to/robotics-lab/robots/duck/sim/patches/duck-sim-sudo-free-down.patch          # apply
git apply --reverse --check /path/to/robotics-lab/robots/duck/sim/patches/duck-sim-sudo-free-down.patch && echo applied

Re-apply it after any update or reset of the Pollen checkout. The operator decided on 2026-11-16 to keep it local: for a person, upstream's line is right.

The guards

  • simhost.duck_sim() refuses to run a duck-sim that still has the sudo check, and names the patch. Every runner fails at its first reset instead of locking the user out. robots/duck/tests/test_simhost.py checks it both ways.
  • robots/duck/sim/probes/sudo_free_down.py runs one real down through simhost.down and fails if the user's faillock tally was written during it. It also prints the tally's records (time, service or terminal), which is how a lockout is read without root. Run it with no simulator in use: it stops the simulator.

One simulator job at a time: scripts/sim-lock

The simulator is one process set on fixed ports, reset by every run; two jobs at once corrupt each other. Every simulator target (make sim-duck, sim-nxt, sim-gate-scenarios, sim-deployed) runs under scripts/sim-lock, an exclusive fcntl.flock on one file, so a person and every agent take the same lock without being told to.

  • The file is ${XDG_RUNTIME_DIR:-/tmp}/robotics-lab-sim.lock, or the one ROBOTICS_LAB_SIM_LOCK names. Every job on a machine must resolve to the same file: set the variable in the shell profile or the session's environment if the default differs.
  • A job that finds the lock held says who holds it (the holder's pid and command) and waits up to 7200 s (--timeout, or ROBOTICS_LAB_SIM_LOCK_TIMEOUT); then it exits 75 without running. With nobody holding the lock it runs at once, and the command's exit status, output and signals are its own.
  • Any other command: scripts/sim-lock -- <command>. scripts/sim-lock --path prints the file.
  • Nested use is safe: a recipe under sim-lock that starts sim-lock again does not wait for itself (ROBOTICS_LAB_SIM_LOCK_HELD).
  • The same lock is what flock -w 7200 <file> <command> takes, so an old-style job and a new one exclude each other. But do not wrap a make sim-* target in flock(1) on the same file: the target's own sim-lock cannot see that holder and waits for it. Run the target directly (it takes the lock itself), or with ROBOTICS_LAB_SIM_LOCK_HELD=<the file> set under an outer flock.
  • Not covered: a job that runs the simulator by other means (uv run lab-challenge, a probe script, simhost reset) is under the lock only if it is started as scripts/sim-lock -- ....

When sudo says "Sorry, try again"

  1. Read the tally: uv run python sim/probes/sudo_free_down.py (in robots/duck/, nothing running), or the record file /run/faillock/<user> directly. Many entries seconds apart, whose source is the service sudo rather than a terminal, mean a script is failing sudo. The operator's own attempts carry a terminal (/dev/pts/N).
  2. Find the caller: list running sudo processes with their parents (ps -o pid,ppid,args) while the failures arrive.
  3. Stop it, wait two minutes (unlock_time=120), then try once.