Skip to content

Cut-over to the X3's staging engine: the operator's runbook

For the operator, on the X3, after the homelab's staging engine is installed (the recipe, ADR-0013) and after the X3's maintenance window: the first up builds both images on an empty image store, and image builds wait for that window. The plan behind it is PROD-ON-X3.md; the deploy script is described in DEPLOY.md. Nothing here has been run: each command has the check that tells you it worked, and each step says what to do if the check fails.

What moves: the Observatory and Mission Control (project robotics-lab) from the shared engine (default context) to the staging engine (staging, socket /run/docker-staging.sock). The host's robot processes (gate, navigator, simulator) stay where they are.

The mapping

deploy.py takes four folders; the old ones are the Makefile's defaults:

  • --data is the lab's runs and scenes, mounted read only in the Observatory: /work/robotics-lab/data becomes /srv/robotics-lab/data.
  • --viewer-state is the Observatory's state folder (index.sqlite, its backups): /work/robotics-lab/state/miniview becomes /srv/robotics-lab/state/observatory.
  • --control-state is Mission Control's state folder (mission-control.sqlite, the gate's log): /work/robotics-lab/state/control becomes /srv/robotics-lab/state/mission-control.
  • --deploy-state is the record of what is deployed and the exported trees: /work/robotics-lab/state/deploy becomes /srv/robotics-lab/state/deploy.

The old copies stay where they are until you remove them yourself.

Precondition: the deployed commit contains 9ef2d59 or later. Before it, an open drawer in Mission Control covers STOP and STOP ALL (on a phone and on a desktop). No real robot goes on a stack older than that. The fix is CSS in the image, so it needs the X3's maintenance window (the build hold) first.

0. Before anything: read what is there

ls /work/robotics-lab/state
du -sh /work/robotics-lab/data /work/robotics-lab/state/*
sudo -n /usr/local/libexec/robotics-staging-deploy status
docker --context default ps --filter label=com.docker.compose.project=robotics-lab \
  --format '{{.Names}}  {{.Image}}  {{.Status}}'
python3 -c "import json; d = json.load(open( \
  '/work/robotics-lab/state/deploy/robotics-lab.json')); print(d['current'])"

Check: the state folder holds control, deploy and miniview (2026-11-24: 107 MB in all, the data 1.9 GB); status answers without an error (the engine and the script are installed); both containers of robotics-lab are Up ... (healthy); the record names the commit that runs (2026-11-24: 4e13c2e1f1bd). Write that sha down: it is the rollback's.

If status fails, stop: the engine is not ready and nothing below applies.

1. The robots folder, with the duck's meshes

robots/duck/meshes is generated by make robots and ignored by git, so the root-owned checkout at /srv/robotics-lab/checkout (a clone of GitHub's main) has none. The Observatory mounts a robots folder (--robots-dir) and Mission Control mounts the folder of each registration, so staging gets a folder of its own, /srv/robotics-lab/robots, which the homelab's setup has made (owned by robotics): fill it with a copy of robots/ of ~/deploy/robotics-lab (which holds the generated meshes).

cd ~/deploy/robotics-lab && git status --short && git log --oneline -1
ls robots/duck/meshes | wc -l
sudo cp -a --reflink=auto ~/deploy/robotics-lab/robots/. /srv/robotics-lab/robots/
sudo chown -R robotics:robotics /srv/robotics-lab/robots
diff -r ~/deploy/robotics-lab/robots /srv/robotics-lab/robots 2>&1 | head
sudo ls /srv/robotics-lab/robots/duck/meshes | wc -l
sudo -u robotics test -r /srv/robotics-lab/robots/duck/registration.json && echo robotics-reads-it

Check: the first two lines show a clean ~/deploy checkout; the meshes count is the same on both sides (38 on 2026-11-24); diff prints nothing (the copy keeps the modes, so you can read it); the last line prints robotics-reads-it.

The folder is a copy, so it drifts. Whenever robots/ changes in git, or make robots makes new meshes, empty the folder and copy again before the next deploy (the folder itself stays):

sudo find /srv/robotics-lab/robots -mindepth 1 -delete
sudo cp -a --reflink=auto ~/deploy/robotics-lab/robots/. /srv/robotics-lab/robots/
sudo chown -R robotics:robotics /srv/robotics-lab/robots

The homelab's wrapper passes --robots-dir /srv/robotics-lab/robots to up and rollback (its recipe lists it). Without that argument deploy.py would mount robots/ of the checkout, which has no meshes; check it before step 4: grep robots-dir /usr/local/libexec/robotics-staging-deploy.

2. The staging installation file

/etc/robotics-staging/installation.json, root:robotics 0640. It is derived from ~/.config/robotics-lab/installation.json (which stays as it is: the dev stack and the host's processes keep reading it). Paths now under /srv; the container runs as robotics, so every path it names must be readable by uid robotics. No secrets: the telemetry endpoints are tailnet URLs and need no token.

Write the template to your home first, read it, then install it:

{
  "installation": 1,
  "data": "/srv/robotics-lab/data",
  "index": "/srv/robotics-lab/state/observatory/index.sqlite",
  "observatory": "http://127.0.0.1:8070",
  "state": "/srv/robotics-lab/state/mission-control",
  "robots": {
    "duck": {
      "navigator": "127.0.0.1:8061",
      "gate": "/srv/robotics-lab/gate/duck-a-gate.sock",
      "registration": "/srv/robotics-lab/robots/duck/registration.json"
    }
  },
  "telemetry": {
    "environment": "staging",
    "traces": "https://vtraces.tail6d0ed4.ts.net/insert/opentelemetry/v1/traces",
    "metrics": "https://vm.tail6d0ed4.ts.net/opentelemetry/v1/metrics",
    "logs": "https://vlogs.tail6d0ed4.ts.net/insert/opentelemetry/v1/logs",
    "metrics_interval_s": 15
  },
  "runs": { "archive_after_days": 30 }
}

What differs from today's file, key by key:

  • data, index: the staging copies of step 3. data is robotics:robotics-data; the index's folder is robotics's.
  • state was ~/.local/state/robotics-lab, a path under your home that robotics cannot enter (/home/marko is drwx------). Mission Control's profile store is <state>/profiles, mounted read-write; here it lives inside Mission Control's state folder. The old store is empty (checked 2026-11-24), so nothing is copied. deploy.py makes the folder as robotics.
  • robots.duck.registration was /work/robotics-lab/main/robots/duck/registration.json, a folder owned by marko: now the copy of step 1, owned by robotics. Mission Control mounts its folder read only and reads the description and meshes there.
  • robots.duck.gate was ~/.cache/duck-sim/duck-a-gate.sock: see the gate below.
  • robots.duck.navigator stays 127.0.0.1:8061: both containers use the host's network.
  • telemetry is new in this file, with environment: "staging"; the URLs are the ones of TELEMETRY.md. runs.archive_after_days is 30 (the default, written out).
  • The file has no profile key for the duck, as today.

The gate socket must change, and the gate is yours to restart. Today the gate's socket is /home/marko/.cache/duck-sim/duck-a-gate.sock, and the same folder holds the robot's own sockets (duck-a.sock and others, srw-rw---- marko:marko). Two things stop robotics there:

  1. The deploy mounts a gate's folder only when no other socket lives in it; with other sockets it mounts the gate's socket alone, and the container must then be restarted after every gate restart (it says so in the deploy output). A folder of its own avoids both.
  2. A socket needs write permission for the connecting uid. The gate creates its socket with the user's umask (srwxr-xr-x marko:marko under 022, which robotics cannot write), and the gate's code does not chmod it.

So, a folder for the gate alone, with the group robotics and no group membership for you (membership of robotics is root-equivalent, ADR-0013):

sudo install -d -o marko -g robotics -m 2750 /srv/robotics-lab/gate
namei -m /srv/robotics-lab/gate

then start the gate with its socket there and a umask that gives the group write ((umask 007; ...); the setgid bit makes the socket's group robotics). Check, once the gate runs:

ls -l /srv/robotics-lab/gate
sudo -u robotics python3 -c "import socket; s = socket.socket(socket.AF_UNIX); \
s.connect('/srv/robotics-lab/gate/duck-a-gate.sock'); print('robotics connects')"

The check is srw-rw---- marko robotics ... duck-a-gate.sock and robotics connects. This changes how the gate is started on this host (its socket path); the gate's own start command is not in this file. Until it runs there, the deploy says "NOT mounted ... start the gate, then deploy again" and Mission Control starts without the duck's gate; the Observatory is unaffected.

Install the file (the homelab's setup made /etc/robotics-staging, root:robotics 0750), then check that robotics reads it and that it parses:

sudo install -o root -g robotics -m 0640 ~/staging-installation.json \
  /etc/robotics-staging/installation.json
ls -l /etc/robotics-staging/installation.json
sudo -u robotics python3 -c "import json; \
d = json.load(open('/etc/robotics-staging/installation.json')); print(sorted(d))"
python3 -c "import json; json.load(open('$HOME/staging-installation.json')); print('json ok')"
grep -ciE "token|secret|password|key" ~/staging-installation.json

Check: mode -rw-r----- root robotics; the robotics read prints the key list; json ok; the grep count is 0 (no secret in the file). deploy.py itself checks the file's keys at the first up and names a wrong one.

Every path the file names, as seen by robotics (nothing may say Permission denied):

for p in /srv/robotics-lab/data /srv/robotics-lab/state/observatory \
  /srv/robotics-lab/robots/duck /srv/robotics-lab/gate; do
  sudo -u robotics namei -m $p | tail -1
done

3. Stop the old project, copy the data and the state

Mission Control and the Observatory write to the state while they run (SQLite with a write-ahead log), and host processes record runs into the data folder: stop all of them first, so the copy is whole. stop keeps the containers, so the old project starts again as it was.

cd ~/deploy/robotics-lab
docker --context default compose -p robotics-lab stop
docker --context default ps --filter label=com.docker.compose.project=robotics-lab
find /work/robotics-lab/data /work/robotics-lab/state -mmin -3 | head

Check: ps lists no container; the last find prints nothing (nothing written in the last 3 minutes). If it prints a path under data/runs, a host process is still recording a run: stop it and wait, then repeat the check. The ports 8070 and 8060 are free now (the stack was on the host's network), which the staging stack needs.

The copy (/. copies the folder's contents into the folder that exists already; cp -a keeps modes and times; --reflink=auto makes a cheap clone on the same btrfs where it can):

sudo cp -a --reflink=auto /work/robotics-lab/data/. /srv/robotics-lab/data/
sudo cp -a --reflink=auto /work/robotics-lab/state/miniview/. \
  /srv/robotics-lab/state/observatory/
sudo cp -a --reflink=auto /work/robotics-lab/state/control/. \
  /srv/robotics-lab/state/mission-control/
sudo cp -a --reflink=auto /work/robotics-lab/state/deploy/. /srv/robotics-lab/state/deploy/

If a target folder is not there (No such file or directory), make it first: sudo install -d -o robotics -g robotics -m 0750 <folder>.

Then the owners. The state stays robotics:robotics. The data is shared through the group robotics-data (you are in it, never in robotics): data and data-archive are robotics:robotics-data 2770 with default ACLs, so the host's recorders can write there as you. cp -a keeps the old group and modes, so set them on what was copied (data-archive is empty and needs nothing unless you copy into it):

sudo chown -R robotics:robotics /srv/robotics-lab/state
sudo chown -R robotics:robotics-data /srv/robotics-lab/data
sudo chmod -R g+rwX /srv/robotics-lab/data
sudo find /srv/robotics-lab/data -type d -exec chmod g+s {} +
sudo find /srv/robotics-lab/data -type d -exec setfacl -d -m g::rwx,m::rwx {} +
sudo find /srv/robotics-lab/state ! -user robotics | head
sudo find /srv/robotics-lab/data ! -group robotics-data | head
sudo find /srv/robotics-lab/data -type d ! -perm -2000 | head
sudo ls -ld /srv/robotics-lab/data /srv/robotics-lab/state/*
getfacl -p /srv/robotics-lab/data | grep default

Check: the three find lines print nothing; the state folders are robotics robotics, data is robotics robotics-data with drwxrws--- (the s, and a + for the ACL); the last line shows a default:group::rwx. For data-archive, the same four data commands with that path.

Verification: counts, then the sha256 manifest

mkdir -p ~/staging-cutover && cd ~/staging-cutover
for pair in data:data state/miniview:state/observatory state/control:state/mission-control \
  state/deploy:state/deploy; do
  old=/work/robotics-lab/${pair%%:*}; new=/srv/robotics-lab/${pair##*:}
  echo "$pair  old $(find $old | wc -l)  new $(sudo find $new | wc -l)"
done

Check: each line has the same count on both sides. A difference of a few entries in state/* means a file appeared or went away since the stop: find which with the manifest below.

for pair in data:data state/miniview:state/observatory state/control:state/mission-control \
  state/deploy:state/deploy; do
  name=$(echo "${pair%%:*}" | tr / -)
  old=/work/robotics-lab/${pair%%:*}; new=/srv/robotics-lab/${pair##*:}
  (cd $old && find . -type f -print0 | sort -z | xargs -0 -r sha256sum) > old-$name.sha
  sudo sh -c "cd $new && find . -type f -print0 | sort -z | xargs -0 -r sha256sum" > new-$name.sha
  if diff -q old-$name.sha new-$name.sha >/dev/null; then
    echo "SAME $name $(wc -l < old-$name.sha) files"
  else
    echo "DIFFER $name"; diff old-$name.sha new-$name.sha | head
  fi
done

Check: four SAME lines (hashing 2 GB takes a few minutes). Any DIFFER stops the cut-over: the old copy is untouched, so remove the new folder's contents (sudo rm -rf of the paths you named in the copy, nothing else), find the cause, copy again. Symlinks are in the count and not in the manifest; compare them with find ... -type l -printf '%p -> %l\n' on both sides if the count check passed and you want them too.

Keep ~/staging-cutover and the old folders: the old copy is the rollback.

4. The deploy and its first checks

Which commit: the one you tested on the dev engine, as a 40-hex sha that is on GitHub's main (the script refuses any other); without an argument it takes the head of main.

sudo -n /usr/local/libexec/robotics-staging-deploy up <40-hex sha>

The first up builds both images on the staging engine and takes minutes. The deploy's output is on this terminal (the one that ran sudo); the journal holds one line per call, not the output (journalctl -t robotics-staging-deploy -n 5 shows that the call was logged).

Check: the output ends DEPLOY PASS commit <sha12> project robotics-lab (the wrapper passes --no-browser, so the smoke inside it has no browser). It prints NOTE lines for what it could not mount (a gate that is not there); read them. If it ends DEPLOY FAIL the stack is up and recorded, and the way back is below.

sudo -n /usr/local/libexec/robotics-staging-deploy status

Check: the record's current.sha is the sha you deployed, previous.sha the one of step 0, and both containers of robotics-lab are listed healthy.

5. Smoke

sudo -n /usr/local/libexec/robotics-staging-deploy smoke

Check: every line PASS, the last SMOKE PASS. That is the health of both, the one origin, and /lib/, without the browser.

The browser smoke, as you, against 127.0.0.1 (it needs no engine access; it uses the Observatory's environment, make observatory-sync, in ~/deploy/robotics-lab):

cd ~/deploy/robotics-lab && make deploy-smoke

Check: SMOKE PASS, including the line "the pages load in headless Chromium with no console error and no failed request". Then open the Observatory at the tailnet address it already has (tailscale serve status lists 127.0.0.1:8070 under its port; nothing changes there) and check by eye that the runs list is the old one (the same count as before) and that the duck's page shows its body (the meshes of step 1).

Since e1df0fa, deploy.py mounts the host's resolver stub (/etc/resolv.conf, when every nameserver in it is loopback) into Mission Control, because the container could not resolve the tailnet's telemetry hosts. The staging engine runs on the same host, so it applies there as well; the dry-run output of up shows the mount. docker --context staging exec is not available to you (the socket is root:robotics), so check that telemetry arrives instead: in VictoriaMetrics, {__name__="robotics_lab.goals", "deployment.environment.name"="staging"} or any deployment.environment.name="staging" series, a minute or two after Mission Control started (the interval is 15 s; see TELEMETRY.md). No series after five minutes: the container cannot resolve or reach the endpoints.

If Mission Control reports tokens off (WARNING: no token exists), the token store was not copied: look in /srv/robotics-lab/state/mission-control/mission-control.sqlite.

6. After it

  • Point the host's recorders (the runner, the navigator, nxt-web, which run as you) at the staging data folder: their installation file's data becomes /srv/robotics-lab/data. They write there through the group robotics-data, which counts from a new login: log out and in (or start them from sg robotics-data) before they start, and check with id that the group is listed. Until then, new runs go to the old /work folder and the staging Observatory does not see them.
  • Keep the old project's stopped containers and the old folders until you are satisfied; removing them is your command, not a step here.

Rollback

To the shared engine, from the old project, which stop left whole.

The staging stack holds the host's ports 8070 and 8060. Stop it (the containers are kept):

sudo -n /usr/local/libexec/robotics-staging-deploy stop
sudo -n /usr/local/libexec/robotics-staging-deploy status
ss -ltn 'sport = :8070 or sport = :8060'

Check: status shows no container running; ss prints only its header (nothing listens on 8070 or 8060).

Then start the old project on the shared engine:

docker --context default compose -p robotics-lab start
docker --context default ps --filter label=com.docker.compose.project=robotics-lab
cd ~/deploy/robotics-lab && make deploy-smoke

Check: both containers healthy, then SMOKE PASS. start is the right command when the containers are still there (they are, after stop). If they were removed, redeploy the commit of step 0 (images observatory:<sha12> and mission-control:<sha12> are still on the shared engine): cd ~/deploy/robotics-lab && python3 scripts/deploy.py up --commit <sha of step 0> (no --context: the shared engine). That takes down nothing it should keep, and the deploy record in /work/robotics-lab/state/deploy is the old one, since the copy left it alone.

If runs were recorded into /srv/robotics-lab/data after the cut-over, they are not in the old folder: copy them back and restart the old Observatory so it indexes them:

sudo cp -a --reflink=auto -n /srv/robotics-lab/data/. /work/robotics-lab/data/
sudo chown -R marko:marko /work/robotics-lab/data

A rollback to the previous commit on staging itself (a bad deploy, not a bad engine) is sudo -n /usr/local/libexec/robotics-staging-deploy rollback, then step 5's smoke.

Not verified

  • Every command here: none was run. The folder names (miniview, control, deploy), the sha, the sizes and the counts were read on 2026-11-24; /srv/robotics-lab held data, data-archive, home and state (owned by robotics, mode 0750) and no checkout yet, no robots, no gate (the setup has since been run: that listing is from before it).
  • That cp -a --reflink=auto clones across the two btrfs subvolumes here (cp copies in full when it cannot: only slower).
  • That the gate, started in /srv/robotics-lab/gate with umask 007, gets the group and mode above, and how this host starts the gate.
  • That the installed wrapper passes --robots-dir (the recipe says so; I read the recipe, not the script), and that its stop verb frees the ports.
  • That a recorder started with the robotics-data group writes into the copied runs' folders under the ACLs above.
  • That the staging engine builds both images on the first up (the base images are pulled; the maintenance window's fault is the reason builds wait).
  • The robots/ copy of step 1 against what the deploy mounts: the first up shows it.