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>
This commit is contained in:
Dan
2026-11-18 19:49:14 -08:00
co-authored by Claude Fable 5.2
parent 3d5691dfa3
commit e1c02d5266
43 changed files with 2104 additions and 227 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ Defined in `packages/contracts/src/errors.ts`. Codes are stable; a code is never
|---|---|---|
| `invalid_request`, `unsupported_schema_version`, `unsupported_media`, `payload_too_large` | The request was malformed. | no |
| `unauthorized`, `credential_expired`, `forbidden` | Credential missing, revoked or expired. | no |
| `pairing_invalid`, `pairing_locked` | Wrong code; too many wrong codes. | no |
| `pairing_invalid` | The pairing code was wrong, expired or already used. The answer is identical in all three cases. (`pairing_locked` is reserved and no longer returned.) | no |
| `not_found` | Unknown, or belongs to another device. | no |
| `request_id_conflict` | Request id reused for different content. | no |
| `conversation_busy` | A turn is still running in this conversation. | yes |
+1 -1
View File
@@ -40,7 +40,7 @@ exactly in `apps/even-client/package.json`.
| Fastify / @fastify/cors | 5.12.8 / 11.4.3 |
| better-sqlite3 | 13.2.0 |
| @huggingface/transformers (ONNX Runtime 1.30.0) | 4.3.2 |
| Speech model | `onnx-community/whisper-base`, `q8` |
| Speech model | `onnx-community/whisper-base` at commit `27a07b4b52b3a4c5886134bb4320e93e1a4bbc7c`, `q8`; alternative `onnx-community/whisper-tiny` at `ff4177021cc41f7db950912b73ea4fdf7d01d8e7`. Per-file SHA-256 in `services/bridge/models/`. |
| @sinclair/typebox | 0.34.52 |
| pino | 10.4.0 |
+16 -4
View File
@@ -29,7 +29,7 @@ weights:
| 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 on first start | about 80 MB (`base`), cached afterwards |
| 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
@@ -41,8 +41,8 @@ Suggested starting point, to be confirmed by measuring on the droplet: **2 GB RA
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=onnx-community/whisper-tiny`
(faster, less accurate) or, for English only, `onnx-community/whisper-base.en`.
If transcription is too slow on the droplet, set `STT_MODEL=whisper-tiny` (faster, less
accurate) and run `fetch-model` again.
## Steps
@@ -59,11 +59,22 @@ If transcription is too slow on the droplet, set `STT_MODEL=onnx-community/whisp
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` (the first start downloads the model).
`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:
@@ -80,6 +91,7 @@ If transcription is too slow on the droplet, set `STT_MODEL=onnx-community/whisp
- 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.
+2 -1
View File
@@ -101,7 +101,8 @@ a suspended stream. The microphone is never reopened without a new tap.
Decision (updated after Dan asked for speech-to-text to be built in and to run on a droplet):
the bridge runs OpenAI's Whisper model itself, on the CPU, through ONNX Runtime
(`@huggingface/transformers` 4.3.2, model `onnx-community/whisper-base`, 8-bit weights). No
(`@huggingface/transformers` 4.3.2, model `onnx-community/whisper-base` pinned to a commit and
verified by SHA-256, 8-bit weights; fetched ahead of time, never downloaded by the running bridge). No
provider account, and recordings never leave the bridge host. An adapter for any external
OpenAI-compatible transcription endpoint remains as an alternative.
+74
View File
@@ -0,0 +1,74 @@
# Handoff for Cody, Round 3
From: Claude (implementation). Date: 2026-11-18.
**Not reviewed.** Cody's Round 2 verdict (NEEDS CHANGES) applies to `3d5691d` only. Nothing below
is a claim that any finding is closed; that is Cody's call on the new SHA.
| Item | Value |
|---|---|
| Repository | `git@git.xylo.gg:Xylo-Digital/hermeven.git` |
| Branch | `cody/slice-1-review` |
| Reviewed in Round 2 | `3d5691dfa3e3015f7d0e4f760de60c588ffea0dc` |
| `main` | `0c9dcd864f16782097471e5bbf57cbd701c26616` (unchanged; nothing merged) |
| New head for Round 3 | the tip of `cody/slice-1-review` after this push; the exact SHA is in the push report, since a file cannot contain its own commit id |
## What was done for each finding
| Finding | Change | Where |
|---|---|---|
| CODY-001 | Bridge URL must be HTTPS; HTTP only for `localhost`, `127.x.x.x`, `[::1]` (exact match). Same rule in the manifest generator, which exits 1. URLs with embedded credentials are refused. | `net/bridgeClient.ts`, `scripts/write-manifest.mjs` |
| CODY-002 | The host-call queue advances only when the SDK call has actually settled; the caller's timeout is a separate, bounded answer. A start that times out queues a stop behind it. The controller stops unconditionally when a capture was abandoned while opening. | `device/evenAdapter.ts`, `core/controller.ts` |
| CODY-003 | The request id is stored before the first submit and cleared only on a terminal result, a definite rejection, or the bridge confirming it has no such turn. An undelivered cancel is remembered and retried at next start. The HUD says "not confirmed yet" instead of "has not been sent". | `core/controller.ts`, `core/hud.ts` |
| CODY-004 | `Devices.revoke` flags every non-terminal turn of the device in the same transaction that revokes it. `TurnEngine.revokeDevice` (HTTP path) applies the flags at once; a one-second sweep applies flags written by the CLI process. Workers abort transcription and ask Hermes to stop. | `devices.ts`, `turns.ts`, `server.ts`, `app.ts` |
| CODY-005 | Manifests pin a 40-character commit id and a SHA-256 and size per file (`services/bridge/models/`). `fetch-model` downloads and verifies; the worker verifies on every load, disables remote models, and loads only from the store. No unpinned configuration exists. | `stt/modelStore.mjs`, `stt/whisperWorker.mjs`, `config.ts`, `cli.ts`, `deploy/*` |
| CODY-006 | Database file is created 0600 before SQLite opens it, in a 0700 directory; WAL and SHM inherit. Unit sets `UMask=0077` and a 0700 state directory. | `db.ts`, `deploy/hermeven-bridge.service`, `docs/deploy-droplet.md` |
| CODY-007 | `credential_expired` is handled like `unauthorized` on every runtime path (submit, poll, cancel, status refresh, renew, conversation create). | `core/controller.ts` |
| CODY-008 | `approval_started_at` is written once, when the approval is first seen (it was previously rewritten on every poll). The agent deadline is stored in a new column and updated in the same write that ends an approval wait. Both are restored after a restart. Schema migration v2. | `turns.ts`, `db.ts` |
| CODY-009 | One in-flight create per conversation epoch, shared by the menu action and the lazy first-turn path; creates are sent strictly in sequence; a result for a replaced conversation is dropped before persistence. A second "new conversation" while one is pending does nothing. | `core/controller.ts`, `core/reducer.ts` |
| CODY-010 | Wrong guesses no longer count against the outstanding code. Brute force is bounded by 49 bits of entropy, a 5-minute lifetime and the per-address limit. Wrong, expired and used codes return the same response. `pairing_locked` is reserved and no longer returned. | `devices.ts`, `server.ts` |
The tests for each are listed in `docs/test-evidence.md` under "Round 3".
## Check results
| Check | Result |
|---|---|
| `npm run typecheck` | exit 0 |
| `npm test` | 182 passed, 0 failed |
| `npm run client:build` | built |
| `npm run test:real-stt` | 11 passed, 0 failed |
| `npm run test:real-hermes` | 9 passed, 0 failed |
| `npm run test:simulator` | 6 passed, 0 failed |
| `git diff --check` | clean |
No check was omitted.
## Decisions made while fixing, for Cody to judge
- **CODY-010 uses entropy and a per-address limit, with no global cap.** A global cap would let a
flood block the owner's own pairing, which is the same denial of service by another route. The
arithmetic is in `docs/security.md`.
- **CODY-009 keys the result check to a conversation epoch, not the turn generation.** A question
asked while the conversation is being created bumps the turn generation; a strict generation
check would throw away the conversation that question is waiting for.
- **CODY-005 removes the automatic first-start download entirely**, including for development.
- **CODY-004 through the CLI is honoured within the sweep interval (1 s)**, not instantly, because
the CLI is a separate process with no channel to the running bridge other than the database.
- **CODY-003: after a restart, a voice question that never reached the bridge cannot be resent**,
because the recording lived only in memory. The user is told to ask again, and only after the
bridge has confirmed it has no record of the request.
## Things the author is unsure about
- `whisperWorker.mjs` and `modelStore.mjs` are plain JavaScript, typed only through a hand-written
declaration file.
- Between verifying the model files and loading them there is a short window; a read-only model
directory closes it, and that is a deployment setting, not something the code enforces.
- The CODY-006 test observes permissions at each `chmod` call, not continuously.
- A device revoked through the CLI while its turn is still being submitted to Hermes relies on the
poll loop noticing the flag after admission.
## Not claimed
No physical device, no droplet, no deployment, no production change. Nothing merged to `main`.
+13 -5
View File
@@ -24,8 +24,9 @@ devices. Not reviewed by anyone but its author yet; see `docs/handoff/`.
| Threat | Control | Tested |
|---|---|---|
| Hermes key or STT key leaks through the client | Neither is in the client code, bundle or any API response. The production bundle was searched for them. | yes |
| Stolen device credential | Scoped to one device and one profile; cannot name a Hermes session; expires in 7 days; pairing ends at 90 days; revocable from the phone or the bridge host; stored on the bridge as SHA-256 only. | yes |
| Guessing a pairing code | 10 characters from a 31-symbol alphabet (about 49 bits); valid 5 minutes; single use; a new code voids the old one; 5 wrong guesses burn every outstanding code; 5 attempts per minute per client address. | yes |
| Stolen device credential | Scoped to one device and one profile; cannot name a Hermes session; expires in 7 days; pairing ends at 90 days; revocable from the phone or the bridge host; stored on the bridge as SHA-256 only. Revoking also cancels every turn the device has in flight and asks Hermes to stop it, from the HTTP route and from the CLI alike. | yes |
| Credential or recordings sent in clear text | The app refuses any bridge address that is not HTTPS, except HTTP to loopback; the manifest generator refuses to package one. | yes |
| Guessing a pairing code | 10 characters from a 31-symbol alphabet (8.2 x 10^14 values, about 49 bits); valid 5 minutes; single use; a new code voids the old one; 5 attempts per minute per client address. At that rate one address gets 25 guesses per code: a 3 in 10^14 chance. Even a million guesses in the 5 minutes would be about 1 in 10^9. Wrong guesses do not consume the code, so nobody can void the owner's code by guessing; every failure returns the same answer. | yes |
| Client picks someone else's agent session or profile | Requests with unknown fields are rejected. The Hermes session id is generated by the bridge and never leaves it. A device is valid only for the profile it was paired under. | yes |
| One device reads or cancels another's turn | Every lookup is scoped to the authenticated device; a foreign id answers 404, not 403. | yes |
| Duplicate or replayed submit runs a tool twice | Client request id is the bridge's idempotency key; the bridge forwards a derived key to Hermes. | yes, including against real Hermes |
@@ -34,6 +35,8 @@ devices. Not reviewed by anyone but its author yet; see `docs/handoff/`.
| Request flooding | Per-device turn limit, per-address pairing limit, general per-device limit. | yes |
| Cross-origin browser abuse | CORS allows only exact configured origins and sends no credentials mode. CORS is not treated as authentication: every route still needs the bearer credential. | yes |
| Secrets or content in logs | Logs carry ids, states, codes and timings. Request logging is off, a redaction list backs it up, and Hermes's own diagnostic text is never relayed or logged. | yes |
| Substituted speech-model files | The model is pinned to a commit id with a SHA-256 for every file. Files are fetched ahead of time and verified; the bridge re-verifies on every load, never downloads at run time, and reads from a directory that can be read-only. There is no unpinned mode. | yes, including with no network at all |
| State files readable by other users | The database is created owner-only before SQLite opens it (so its WAL and SHM files inherit that), in a 0700 directory; the systemd unit sets `UMask=0077`. | yes, under umask 0022 |
| Recordings retained | Audio exists only in memory for the length of one transcription call and is never written to disk by the bridge. | by construction; not independently audited |
| Agent approves its own privileged action | The bridge never calls Hermes's approval endpoint. | yes |
| Markup injection from an agent answer into the phone page | The page is built with `textContent` only. | by construction |
@@ -48,14 +51,19 @@ Stated so they are not mistaken for protections.
encrypted, and the public SDK offers nothing better. The mitigation is that the credential is
narrow, expiring and revocable, not that it is safe at rest. Anyone with the unlocked phone, or
with developer access to the app's storage, can use it until it is revoked.
1a. **Pairing brute force is bounded by entropy and a per-address limit, not by a lockout.** A
distributed attacker is limited only by how fast the bridge answers. That is still far short
of a useful chance (see the table), but it is a deliberate trade against letting anyone
cancel the owner's code.
2. **Renewal needs only the current token.** A thief who renews before the owner notices keeps
access until revoked or until the 90-day pairing lifetime ends.
3. **Audio leaves the phone for the bridge host.** With the default built-in speech model it
goes no further. With `STT_PROVIDER=openai-compatible` it is sent to that provider, whose
retention is outside our control.
3a. **The built-in model's files are downloaded from the Hugging Face hub on first start** and
are not pinned to a revision or checked against a known hash. A compromised hub account or
path could serve different weights. Pinning a revision is a follow-up.
3a. **The pinned hashes are only as trustworthy as the moment they were recorded.** They were
taken from the hub on 2026-11-18. They prove the files have not changed since; they do not
prove the files were benign then. The verified-then-loaded sequence also has a small window
between check and use, which a read-only model directory closes.
3b. **The speech model runs in a worker thread of the bridge process**, not a separate
sandboxed process. It no longer stalls the bridge (measured 3 ms), but a crash inside the
native runtime could still take the bridge down; systemd restarts it and in-flight turns are
+6 -2
View File
@@ -1,14 +1,18 @@
# Setup
Requirements: Node.js 22.13 or later and a Hermes install with the API server enabled. Speech
recognition is built into the bridge (Whisper on the CPU, about 0.8 GB of memory); the first
start downloads about 80 MB of model files into `data/models`.
recognition is built into the bridge (Whisper on the CPU, about 0.8 GB of memory). The model is
pinned and verified, and the bridge never downloads it by itself: fetch it once (79 MB).
```sh
npm ci
cp .env.example .env # then edit: HERMES_API_KEY at minimum
npm run bridge:cli -- fetch-model # downloads and verifies the pinned speech model
```
The bridge address entered in the app must be `https://`. Plain `http://` is accepted only for
this machine (`localhost`, `127.x.x.x`), which is what the simulator and browser preview use.
## 1. Hermes
Enable the API server for the profile you want to use (see Hermes's "API Server" docs):
+59
View File
@@ -253,3 +253,62 @@ unauthenticated `/v1/device` answered 401, `bridge:cli -- pair` printed a code,
- Selecting a contextual-menu item.
The checklist for the hardware items is `docs/device-test-plan.md`.
## Round 3: after Cody's review (2026-11-18)
Cody reviewed `3d5691d` and returned NEEDS CHANGES with ten findings. This section records what
was run after the fixes. Everything above this heading describes the code before them; where a
number differs, this section is the current one.
```
$ npm run typecheck exit 0
$ npm test Test Files 10 passed (10) Tests 182 passed (182) (4 consecutive runs)
$ npm run client:build built; the development pairing hook is absent from the bundle
$ npm run test:real-stt Tests 11 passed (11)
$ npm run test:real-hermes Tests 9 passed (9)
$ npm run test:simulator Tests 6 passed (6) (3 consecutive runs)
$ git diff --check clean
```
No check was omitted. The offline speech test needs unprivileged network namespaces
(`unshare -rn`); they were available here and the test ran. Where they are not, that test prints
"OFFLINE CHECK NOT RUN" rather than passing silently.
### Regression tests added, by finding
| Finding | Test (file) | What it proves |
|---|---|---|
| CODY-001 | `tests/integration/clientSecurity.test.ts` | 15 public, private-LAN and look-alike HTTP addresses rejected; HTTPS accepted; HTTP accepted only for `localhost`, `127.x.x.x`, `[::1]`; the HTTP client refuses a remote HTTP base URL; manifest generation exits 1 and writes nothing for remote HTTP |
| CODY-002 | same file, fake timers and a host whose calls settle on command | Start times out, host opens the microphone late: a stop follows and the microphone ends closed; at most one host call in flight throughout; stop requested during a pending start waits its turn; calls queued behind a stuck call are sent one at a time |
| CODY-003 | `tests/integration/client-bridge.test.ts` | Every reply dropped after the bridge admitted the turn, then a client restart: one Hermes execution for that request, re-attached under the same request id, the HUD never said "not sent"; a request that truly never arrived is reported only after the bridge confirms it has no record; an undeliverable cancel is retried on the next start |
| CODY-004 | `tests/integration/bridge.test.ts` | Revoking over HTTP during a hanging run: one stop request reaches Hermes, the turn settles as cancelled, every later request is 401; the same through the CLI path (database only); revocation during transcription aborts it within 250 ms, in-process and via the sweep; another device's turn is untouched |
| CODY-005 | `services/bridge/test/modelStore.test.ts`, `tests/real-stt/realStt.test.ts` | Branch, tag and short revisions refused; unknown model without a manifest refused; a hub serving different bytes fails the fetch and leaves nothing behind; a changed or missing file refuses to load, with no network request; real pinned artifacts fetched from the real hub and verified; one flipped byte in the real model refuses to load; transcription from a read-only store; transcription inside a network namespace with no interfaces |
| CODY-006 | `services/bridge/test/units.test.ts` | In a child process under umask 0022: directory 0700, database, WAL and SHM 0600, and none of the three was group- or world-accessible at any point observed during creation |
| CODY-007 | `tests/integration/client-bridge.test.ts` | Credential expires during a live session: asking, waiting for an answer, status refresh, renew and new conversation each clear the stored pairing and return to the pairing screen; pairing again works |
| CODY-008 | `tests/integration/bridge.test.ts` | Restart before the original agent deadline: approval timeout still fires 700 ms after the approval was first seen, not after the restart; restart after the original agent deadline: still classified `approval_timeout`; approved after a restart: the paused deadline is stored and survives a second restart; a run that never finishes afterwards ends as `agent_timeout` |
| CODY-009 | `tests/integration/client-bridge.test.ts`, `apps/even-client/test/reducer.test.ts` | "New conversation" twice plus an immediate question with the reply delayed: one create, one stored id equal to the bridge's active conversation, the question succeeds; cancel-and-ask-again during a pending lazy create: one create; a reset during a pending create with the first reply arriving late: its result is dropped before persistence, the second create is not sent until the first settles, app and bridge agree |
| CODY-010 | `tests/integration/bridge.test.ts` | 40 wrong guesses, then the real code still pairs; every failure (wrong, expired, used) is byte-identical; a client is cut off after its 5 attempts per minute |
### Did the new tests have teeth?
Each fix was removed or broken in turn, 20 ways, and the default suite re-run. 16 were caught
at once. Two more exposed missing coverage (the CLI-path sweep during transcription; a database
file created loose and tightened a moment later); tests were added and both are now caught.
The remaining two are redundant safeguards whose removal changes nothing observable: the
directory `chmod` after `mkdir` with mode 0700 (a umask can only remove permissions), and the
final permission pass after a file that was already created owner-only.
### Real deployment sequence, run by hand on the development desktop
`verify-model` on an empty store exited 1 ("missing"). The bridge started without the model,
answered `/healthz`, and logged `stt.load_failed` with `reason: missing` and the command to run.
`fetch-model` downloaded 7 files (79 MB) from huggingface.co at the pinned commit in 4 s and
verified them. `verify-model` then exited 0, and the bridge logged `stt.ready` in 1.1 s. The
state directory was 700 and the database, WAL and SHM files 600.
This was not a droplet. `deploy/` and `docs/deploy-droplet.md` remain unrun.
### Still not tested
Unchanged from the list above: no physical G2, no audio from the glasses, no real model or tools
behind Hermes, no approval prompt from a real Hermes, no droplet, no HTTPS termination.