Files
hermeven/docs/deploy-droplet.md
T
DanandClaude Fable 5.2 e1c02d5266 Address Cody review round 2: all ten findings (CODY-001 to CODY-010)
CODY-001 Bridge URL must be HTTPS (HTTP only to loopback), in the client and
         in manifest generation.
CODY-002 Even host calls stay serialised until the SDK call really settles;
         a microphone start that completes after its timeout is followed by
         a stop.
CODY-003 Request id is stored before the first submit and cleared only on a
         definitive answer; lost replies are treated as ambiguous and
         reconciled under the same id; HUD no longer claims "not sent".
CODY-004 Revoking a device cancels its in-flight turns, aborts
         transcription and asks Hermes to stop, from HTTP and CLI paths.
CODY-005 Speech model pinned to a commit with per-file SHA-256; fetched and
         verified ahead of time; verified on every load; never downloaded
         at run time; no unpinned configuration.
CODY-006 State directory 0700, database/WAL/SHM 0600 regardless of umask.
CODY-007 credential_expired handled like unauthorized on every path.
CODY-008 Approval wait start and paused agent deadline persisted and
         restored across restarts (schema v2).
CODY-009 Exactly one conversation create per epoch, sent in sequence, with
         stale results dropped before persistence.
CODY-010 Wrong pairing guesses no longer consume the outstanding code;
         failures are indistinguishable.

Checks: typecheck clean; npm test 182 passed; client build ok;
test:real-stt 11 passed (including with no network); test:real-hermes 9
passed; test:simulator 6 passed; git diff --check clean.

Not reviewed. No physical-device, droplet or production evidence.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 19:49:14 -08:00

102 lines
5.2 KiB
Markdown

# Running the bridge on a DigitalOcean droplet
**Status: written, not run.** These steps have not been executed on a droplet. The bridge, the
built-in speech model and the Hermes adapter have only been run on the development desktop.
Creating the droplet, pointing DNS at it and starting services are Dan's actions.
## What runs where
```
phone (Even app) --HTTPS--> Caddy :443 --> bridge 127.0.0.1:8787 --> Hermes 127.0.0.1:8642
|
built-in Whisper (in the bridge process)
```
The bridge listens on loopback only. Caddy is the only thing exposed, and it provides the
certificate. Speech is transcribed inside the bridge, so recordings never leave the droplet.
Hermes can run on the same droplet (shown above) or elsewhere; if elsewhere, `HERMES_BASE_URL`
must be `https://`.
## Sizing
Measured on the development desktop (Intel i7-13850HX), bridge with `whisper-base`, 8-bit
weights:
| Measurement | Value |
|---|---|
| Memory after loading the model | about 0.5 GB |
| Memory after transcribing | about 0.8 GB |
| 11 s of speech, process pinned to one core | about 1.7 s |
| Same, `whisper-tiny` | about 1.2 s, about 0.6 GB |
| Model download at deploy time (`fetch-model`) | 79 MB (`whisper-base`), 4 s on the desktop's connection |
| Longest pause of the bridge's event loop while transcribing | 3 ms (the model runs in a worker thread) |
Pinning to one core made no difference to speed, so extra cores will not help; a single droplet
vCPU is the relevant unit. **A shared droplet vCPU is slower than that desktop core by an amount
that has not been measured.** If it were three times slower, 11 s of speech would take about 5 s,
well inside the 30 s deadline.
Suggested starting point, to be confirmed by measuring on the droplet: **2 GB RAM, 1 to 2 vCPU**
for the bridge alone. 1 GB is likely too tight alongside the OS. If Hermes shares the droplet,
add whatever Hermes needs; that was not measured.
If transcription is too slow on the droplet, set `STT_MODEL=whisper-tiny` (faster, less
accurate) and run `fetch-model` again.
## Steps
1. **Droplet and DNS.** Ubuntu LTS. Point a hostname at it (for example `bridge.example.com`).
Firewall: allow 22, 80 and 443 only.
2. **Packages.** Node.js 22.13 or later, git, Caddy.
3. **User and directories.**
```sh
useradd --system --home /opt/hermeven --shell /usr/sbin/nologin hermeven
mkdir -p /opt/hermeven /var/lib/hermeven /etc/hermeven
chown hermeven:hermeven /var/lib/hermeven
```
4. **Code.** Clone the repository into `/opt/hermeven`, then `npm ci`. (The dev dependencies are
needed: the bridge runs through `tsx`.)
5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it
in, `chmod 600`, `chown hermeven`.
5a. **Speech model.** As root (not the service user), fetch and verify the pinned model into a
directory the service can read but not write:
```sh
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- fetch-model
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- verify-model
```
Every file is checked against the SHA-256 committed in `services/bridge/models/`. The running
service never downloads anything: it re-verifies these files each time it loads the model and
refuses to load if one is missing or different. This is the only step that needs outbound
access to huggingface.co.
6. **Hermes.** Enable its API server with a key, bound to `127.0.0.1`. Use a read-only or test
profile first.
7. **Service.** Copy `deploy/hermeven-bridge.service` to `/etc/systemd/system/`, then
`systemctl daemon-reload && systemctl enable --now hermeven-bridge`. Watch
`journalctl -u hermeven-bridge -f` for `stt.ready`. `stt.load_failed` with `reason: missing`
or `mismatch` means step 5a was skipped or the files changed.
8. **TLS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, reload
Caddy, then check `curl https://bridge.example.com/healthz`.
9. **App build.** On your own machine:
`HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`.
10. **Pair.** On the droplet, as the service user with the same environment:
```sh
sudo -u hermeven HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- pair
```
11. **Origin.** Open the phone page, read Diagnostics, "Page origin", put it in
`HERMEVEN_ALLOWED_ORIGINS`, restart the service.
## Things to check on the droplet and write down
- Time from `stt.loading` to `stt.ready`, and memory of the service after a few questions.
- `transcribe_ms` for a few real questions (the phone page shows it per question).
- That `curl http://<droplet-ip>:8787/healthz` from outside **fails** (bridge not exposed).
- `stat -c '%a' /var/lib/hermeven /var/lib/hermeven/hermeven.sqlite*` shows `700` and `600`.
- That the unit's hardening options do not stop the model loading. `ProtectSystem=strict` and
`MemoryMax` in particular are untested with ONNX Runtime.
## Not covered yet
Backups of `/var/lib/hermeven`, log rotation, upgrades, monitoring, and a compiled build that
would remove the need for dev dependencies on the droplet.