Barbara - Build, Simulate and Deploy
Five Layers Before the Real Home
Summary: Barbara runs on three machines (part 1), drives motors, and answers with a language model whose words change at each try. I can’t test her by hand after every change, so each change goes through five layers, from seconds to minutes: unit tests, a local simulation of the home, a robot simulator, a simulation of the deployment, and the real deployment, which ends by asking Barbara real questions. This part is my journal of how I built those layers, and of four incidents that taught me what each layer can and can’t see.
The Layers
| Layer | Runs on | Takes | Proves | Can’t see |
|---|---|---|---|---|
| Unit tests | laptop | about two minutes | the code’s logic | real models, real devices |
| Local simulation | laptop, Docker | seconds per sentence | routing, home calls, reply quality | the hardware |
| Robot simulator | laptop, Docker | minutes | timings and motor safety | real torque, real sound card |
| Deployment simulation | laptop, Docker | 1 to 5 minutes | the playbooks and their checks | GPU, robot, the real network |
| Real deployment | Orin and Pi | minutes; longer with training | the whole system | what no check asks |
Layer 1: Unit Tests
Barbara has about 1,800 unit tests, which run in about two minutes. A git hook runs them before each push, so a regression stops before it leaves my laptop. A separate coverage task fails below a floor (90% of the lines and branches of Barbara’s code), which I only ever raise.
Barbara is mostly about time: when a question ends, when a move starts, when a reminder rings. Waiting for real seconds would make the tests slow and flaky, so the timing tests run on a virtual clock: an event loop whose sleeps take no real time, because it jumps straight to the next timer. A test can play a 5 s sentence with its move, check that the move starts with the sentence, and finish in milliseconds. Its limit: a thread’s work takes no virtual time, so code run in threads can’t be timed this way.
Tests that need a simulator carry a marker: pytest -m sim plays the scenarios below, -m reachy_sim the robot checks, -m deploy_sim the double deployment. Without a simulator, they are skipped.
Layer 2: The Local Simulation
task sim:up starts three containers on my laptop: the router, Qwen3-0.6B on vLLM’s CPU image, and a fake Home Assistant. Barbara herself runs outside Docker, against them. The fake Home Assistant answers every endpoint Barbara calls with fixed data: a few lights, sensors, a forecast with sun today and rain tomorrow, a shopping list. It also fakes the other services: the metro times, a news feed, a calendar with fixed events, a reminders list. Lights and lists change with her calls, so a conversation has consequences.
task sim:say shows what she did, turn by turn:
you switch of the sofarouter <lights_sofa_off>home switch.turn_off switch.sofabarbara (silent) [0.07s]“switch of” is the speech recognition’s typo for “switch off” (part 2 explains why the router is trained on them). Her answer is silence: the light is the answer.
Two kinds of checks
Some answers are exact, others are written by a language model. They need different checks.
Scenarios are exact. A file of 51 turns is played in order from the initial home, and each turn checks the router’s action, the exact calls to the fake home, and the reply when code writes it:
[[turn]]say = "what time is it"action = "<time>"reply_contains = "By the way, you wanted to" # the due reminders, at the end
[[turn]]say = "not much" # the answer to her "what's up?": small talk, no light callaction = "<unknown>"The second turn replays a router mistake from part 2: “not much” once switched every light on. A bug that happened once gets a turn.
Reply cases score the language model. Each case is said several times, because the model samples, and a reply passes when it carries the module’s emotion, says one of the expected words, none of the avoided ones, and stays under 30 words:
[[case]]say = "will it rain tomorrow"emotion = "sad"expect = ["rain"]avoid = ["no rain", "won't rain", "not rain"]Keyword checks are crude: “Not raining yet, but it will by noon” fails avoid (“not rain”) while being right. So the score tells me whether a prompt change made things better or worse, and I still read the replies.
For experts: vLLM’s CPU image, with its defaults (bf16, all threads), wrote under 1 token per second on my laptop’s hybrid Intel CPU. In fp32 on 8 threads bound to the performance cores, it writes 24 tokens per second: slow, but enough to play a conversation. The first start downloads the model and compiles vLLM’s CPU code, about 3 minutes; the compiled code is cached for the next starts.
Layer 3: The Robot Simulator
Barbara’s motors are small and the robot is expensive to repair, so she follows rules I carried over from her earlier versions: every move starts with a glide of at least 0.8 s from where the head is, a recorded move never plays faster than recorded, and she returns to rest in 2 s. A bug that skips the glide makes the head jump.
Reachy Mini’s SDK ships a MuJoCo physics simulator of the robot. task robot:sim runs it headless in Docker, with Barbara’s own robot code beside it, a fake speech synthesis and a fake sound card that keep real timings. It plays a few replies (no emotion, one long sentence, a streamed reply, two emotions, one too short for any move, a dance) and fails when:
- a move’s glide doesn’t start within 0.1 s of its sentence being heard, or the last move doesn’t end within 0.1 s of the speech;
- a glide is shorter than 0.8 s, a rest isn’t 2 s, or a frame runs ahead of the recorded time;
- the robot isn’t back at rest, within 2 mm and 2°, 5 seconds after the reply.
The simulator found something I hadn’t looked for: four of the SDK’s recorded moves make the daemon warn of IK errors, even at their own speed. IK, inverse kinematics, computes the motor angles for a head pose; an error means a pose the mechanism can’t reach. The check now accepts that warning only from those four moves, so a new move that asks for an impossible pose fails.
What it can’t see: the simulator ignores torque, and the real sound card has its own delays. Whether a move looks in sync with the voice still needs the real robot and my eyes.
Layer 4: The Deployment Simulation
Deploying is code too, and it breaks like code. I deploy with Ansible, which runs a list of tasks (a playbook) on remote machines over SSH and describes the end state (“this file has this content”, “this service runs”) rather than the commands. task deploy:sim:up starts two containers that boot systemd, like real machines: an “Orin” on Ubuntu, with Docker inside, and a “Pi” on Debian. task deploy:sim runs the real playbooks against them over SSH, with every check.
What differs from production:
- Stubs instead of models. The real images need an ARM GPU with CUDA, so the simulated Orin runs small stand-ins behind the same APIs: a router that answers a few keywords, an LLM that streams a fixed reply, a training that publishes a placeholder model with the code’s labels and commit.
- Fake secrets, in clear.
- No robot: the daemon runs its mock-up, and the Pi gets a sound card with a silent microphone.
- Fewer checks: the speech, person and voice checks below are skipped, since their stand-ins only answer.
A test deploys twice and checks that the second run changes nothing. That property is idempotence: running the deployment again on a deployed machine must be a no-op, or every deploy restarts Barbara for nothing. The first run takes about 5 minutes, later ones about 1.
What it couldn’t see
The first real deployment, after a green simulation, still needed a day of fixes, all on the hardware:
- the Jetson’s PyTorch is built without
torch.distributed, which the Hugging Face Trainer’s checks expect; - that PyTorch needs NumPy 1, while my lock file had NumPy 2;
- Riva already used the ports I had picked for the router and the LLM, so they moved;
- the real sound card’s name needed escaping in a regular expression.
The simulation proves the playbooks’ logic. It can’t prove the hardware.
Layer 5: The Real Deployment
Three playbooks deploy Barbara:
- The commit, not my folder. Each playbook deploys the commit checked out on my laptop: uncommitted code is not deployed, so what runs at home always has a commit id, and each playbook ends by checking it.
- Secrets in a vault. Tokens live in an Ansible Vault file: encrypted, and opened with a password that stays out of the repository. A playbook stops at its first task when a secret it needs is missing.
- Training outlives the connection. A router training takes up to half an hour, the reply model’s hours, so training runs in a detached container. If my laptop loses the connection, the training goes on; the next run refuses to start a second one, and publishes the finished one if it trained the same commit. The deployment simulation covers that case.
Checks that ask real questions
A green “service started” proves little: a process can run and answer nothing. So each check gives a model a real input and checks its output:
| Model | Check |
|---|---|
| Router | ”what time is it” must give <time>, from the published run |
| LLM | answers a chat completion |
| Reply model | answers with an emotion token |
| Speech recognition | Riva’s voice says a question; the recognizer must write it |
| Person detector | finds the people in a photo |
| Voice fingerprints | two clips of one voice match, and Riva’s voice is told apart |
| Barbara, on the Pi | ”what time is it” (a reply written by code) and “tell me a joke” (router, then LLM), run as her service, in her sandbox (systemd’s limits on what a service may touch, see below) |
The speech check is my favourite: the text-to-speech tests the speech-to-text, so neither needs a recording.
On the Pi, the check runs barbara --prompt exactly as her service runs: same user, same settings, same sandbox:
- name: Ask Barbara, as her service would ansible.builtin.command: argv: >- {{ ['systemd-run', '--wait', '--pipe', '--uid=' ~ pi_user, '--property=EnvironmentFile=' ~ pi_env_file] + pi_barbara_sandbox | map('regex_replace', '^', '--property=') | list + [pi_venv_dir ~ '/bin/barbara', '--prompt', item.prompt] }} loop: - {prompt: "what time is it", action: "<time>", reply: "It's"} - {prompt: "tell me a joke", action: "<unknown>", reply: "[A-Za-z]"} failed_when: >- pi_prompts.rc != 0 or pi_prompts.stderr is not search('Router: ' ~ item.action) or pi_prompts.stdout is not search(item.reply)Simplified: the real task also checks music when it runs.
Four Incidents
A config key that silently changed the model
Missed by every layer; caught by a code review.
Transformer models need to know where each token sits in the sentence. Qwen3 uses RoPE, rotary position embeddings: it rotates each token’s vectors by an angle that depends on its position, with a base frequency, theta, of 1,000,000.
My reply model was trained with transformers 5, which saves theta only inside a new rope_parameters block of config.json. vLLM on the Orin reads configs with transformers 4, which looks for rope_theta at the top level, doesn’t find it, and uses the default: 10,000. No error, no warning: the model loads, answers, and every check passes, but it no longer sees positions as it was trained to. Its twin was loud: in the same save, the special tokens’ new format made vLLM refuse to start. That one I fixed in minutes; only a review found the silent one.
No check caught it. A code review of the save function did, before the model was served. The fix writes theta under both names, and a test pins it. The lesson: “it answers” doesn’t mean “it answers right”. A check that compares the served model’s outputs with the training’s on a few fixed inputs would catch this whole family of bugs.
A router that passed every check and was worse
Missed by every check: they test a threshold, not a comparison.
One day, a new router run passed every check of the training playbook: all its files, the code’s labels, a test macro-F1 of at least 0.9, the right commit. The playbook published it, replacing the served router and deleting it.
Its numbers were fine. Its errors were not: on the sentence groups that both runs held out (part 2 explains why only those compare), it made more wrong light and alarm actions than the served one. I chose not to serve it. But the served router’s files were gone; only the running container still had it in memory. Each training keeps its run folder, so I restored the files from there before anything restarted.
An absolute threshold says “good enough”, not “better than what runs”. The reply model already promotes through a gate: a candidate is published apart, served only if its test score is no worse than the served model’s, minus a small slack because their test sets differ, and the previous one is kept for rollback. The router will get the same gate, with one more rule: no more wrong real actions on the paired groups.
A clock jump after boot
Only the real Pi could show it.
After a reboot, the robot didn’t wake up: its daemon had failed with “time value is out of range [0,1]”.
The Pi keeps no time while it is off. At boot it restores the last saved time, and a few seconds later the network sets the real one. The daemon had started in between: a move computes its progress from the clock, as a value between 0 and 1, and the jump threw it out of range.
The fix: the daemon starts after time-sync.target, the point at boot when the clock has been set from the network, and the wait is capped at 90 s so the robot still starts without internet. A gotcha: that target waits for nothing unless systemd-time-wait-sync is enabled, so the playbook enables it. No simulation could have shown it: containers share my laptop’s clock, which never jumps. Barbara’s own long waits (reminders, wake-ups) were already capped at 5 minutes and recomputed from the clock, for the same reason: a correction after boot delays a ring by a few minutes at most.
Sandboxing: from 9.2 to 1.6
A risk no layer flagged, until I measured it on the Pi.
systemd can sandbox a service: a read-only system, no privileges, only the devices it needs, a filter on the system calls it may make, other services’ files hidden. systemd-analyze security sums up what is left open as an exposure score, from 0 (locked down) to 10 (wide open).
When I measured, Barbara and the robot’s daemon scored 9.2. Only the phone service, built later, scored 1.3. I used it as the model. Barbara now gets her home folder and the audio and camera devices she uses, nothing else; the daemon gets the robot’s connection only and can’t see her tokens or her processes. Both measure 1.6 on the Pi, and every other service of the Pi got the same treatment.
A sandbox fails silently: Barbara keeps running, deaf or mute. So the deployment:
- runs the questions above in her exact sandbox, and fails on “Operation not permitted”;
- fails when her journal says she couldn’t open the microphone array;
- fails when a service’s exposure goes above its threshold (the measured score plus 0.5, lowered to the Pi’s own measurement after deploying), and warns about any drop-in file, a small file that overrides part of a service’s settings, such as a forgotten emergency override.
The README keeps that emergency override: one file that lifts the sandbox in seconds, then a bisection order to find the directive that broke her.
What I Learned
- Each layer catches what the one before can’t, and none catches everything. The hardware, the clock and silent config drift only showed up on the real machines.
- Check outputs, not processes. Every useful check gives a real input and expects a real answer.
- A threshold is not a gate. A new model must be compared with the one it replaces, on the same examples.
- Every incident becomes a check: a scenario turn, a test, or a deployment task.
Next, part 4: architecture and modules.