Correct the docs that Phase 2 made wrong

Both entry-point documents still described the server as a Phase 1 skeleton,
which is the kind of drift that costs someone an afternoon before they think
to distrust the README.

server/README.md opened with "There are no device endpoints yet". There are
eight, so it now lists them, checked against the mounted routes rather than
from memory. images.py joins the layout; api/ no longer says Phase 2 will
mount routes there one day.

TODO.md Phase 2 had every box unticked. Ticked with what was actually built,
and the three deviations from the plan written down where the plan was wrong:

  - /ingest was specified as "multipart image + JSON meta". The firmware
    sends a raw JPEG body with the metadata in headers. Multipart was a
    misreading of API.md, and the note now says so, because the next person
    to read the old line would implement the wrong endpoint.
  - "server_time in every response" is not compatible with /status being
    204, which API.md requires. The envelope goes on /heartbeat and /ingest.
  - Enroll accepts a device's own reenroll_secret as well as the shared
    bootstrap secret. Checking only the shared one, as the review's sample
    code did, locks out every device that has ever enrolled.

Two boxes stay open, and they are the honest ones: no gallery page, and no
end-to-end run against real hardware. The server half is proven only against
synthetic uploads, and the status table now says that rather than implying a
verified path.

Also recorded two deliberate deferrals that were living only in a
conversation, which is the same as not existing:

  - CORS, in Phase 3: not configured because Caddy serves the UI and the API
    from one origin, so there is no cross-origin request to permit and
    permissive headers would only weaken that.
  - The missing single-row constraint on firmware.is_target, in Phase 4
    beside the upload endpoint that will create the second target row.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 17:36:37 +02:00
1 parent 05f144ed98
commit c40072f644
2 files changed
+55 -19

No files matched your search

+34 -14
View File
@@ -26,10 +26,10 @@ Anything here that contradicts SPEC means SPEC needs an edit, not a workaround.
| Area | State |
|---|---|
| Firmware | Written, compiles, **never run on hardware**. Known gaps below. |
| Device↔server contract | Specified in full (`firmware/API.md`). Nothing implements the server half. |
| Data model | Designed (SPEC §3) + §0 additions. No migration written. |
| Server | Phase 1 skeleton in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units. Verified end to end on Python 3.14.7 against PostgreSQL 17: 12/12 tests, migrations applied, API serving, worker draining the queue. Not yet on the real host. |
| WebUI | **Nothing exists.** |
| Device↔server contract | Specified in full (`firmware/API.md`). Server half of the **device** endpoints implemented (Phase 2); the operator-facing half (firmware upload, device management) waits on user auth in Phase 3. |
| Data model | Designed (SPEC §3) + §0 additions, migration written and applied, guarded by a drift test. |
| Server | Phases 1 and 2 in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units, and every device endpoint the firmware calls. Verified on Python 3.14.7 against PostgreSQL 17: 194 tests, migrations applied, real HTTP ingest through the worker to a WebP thumbnail on disk. Not yet on the real host, and **never yet spoken to by real firmware**. |
| WebUI | **Nothing exists** beyond the Vite scaffold on `feature/UI_Basic_implementation`. |
---
@@ -89,7 +89,7 @@ written vs. what still needs doing on the real host:
- [ ] PostgreSQL 17 from the distro or PGDG repo; dedicated role + database; **loopback TCP with `scram-sha-256`, not a Unix socket** (see 1.2)
- [ ] Caddy DNS provider plugin build (`caddy add-package …`) and a real hostname
- [ ] Tailscale for remote access
- [ ] Image store at `/srv/poorbird/images/YYYY/MM/DD/<uuid>.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — paths configured, writer is Phase 2
- [x] Image store at `/srv/poorbird/images/YYYY/MM/DD/<uuid>.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — writer landed with Phase 2; writes are atomic (`.part` then `os.replace`) so a crash cannot leave a half-JPEG that a thumbnail job would then fail on
- [ ] journald log retention capped, disk usage alarmed
### 1.1 Schema — SPEC §3 plus the §0 additions
@@ -126,15 +126,27 @@ cheap today and most are the better native choice regardless.
The first milestone worth celebrating. Nothing below this line matters until a real
bird photo appears in a browser.
- [ ] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out.
- [x] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out.
**Re-enrolling a known `device_uid` must return the existing row with a fresh token, never a duplicate.**
- [ ] `POST /api/v1/ingest` — multipart image + JSON meta, honour `X-Pre-Trigger`, dedupe on sha256
- [ ] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status`
- [ ] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics
- [ ] Response envelope + `server_time` in **every** response (SPEC C7: `received_at` stays authoritative)
- [ ] Thumbnail job on ingest
- [ ] Minimal gallery page, no auth yet, purely to prove the path
- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser
Accepts the shared secret *or* that device's own `reenroll_secret`; checking only the
shared one would lock out every device already enrolled. Hardware facts (`mac`,
`hw_revision`, `fw_version`) refresh on every enrollment, the operator's `name` does not.
- [x] `POST /api/v1/ingest` — **raw JPEG body with metadata in headers, not multipart.**
`firmware/API.md` and `uploader.cpp` send the bytes directly; multipart was a
misreading. Honours `X-Pre-Trigger`, dedupes on sha256 per device.
- [x] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status`
- [x] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics.
Column-backed keys win over stale JSONB copies, so an operator rename actually reaches
the device; the device's own `config_version` never overwrites the server's.
- [x] Response envelope + `server_time` (SPEC C7: `received_at` stays authoritative).
On `/heartbeat` and `/ingest`. **Not** on `/status`, which is 204 with no body per
`firmware/API.md` — "every response" was not compatible with the firmware contract.
- [x] Thumbnail job on ingest — 400px WebP, decode kept off the request path
- [x] Device authentication, rate limiting, `POST /commands/{id}/ack`, `GET /firmware/{v}.bin`
— not in the original list, but the firmware calls them (see `docs/reviews/`)
- [ ] Minimal gallery page, no auth yet, purely to prove the path — **next, on `feature/UI_Basic_implementation`**
- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser.
Blocked on Phase 0: the server side is proven only against synthetic uploads.
---
@@ -149,6 +161,10 @@ bird photo appears in a browser.
- [ ] Auth: session cookies, Argon2id, CSRF, RBAC per SPEC §3.1 (viewer / editor / admin), `audit_log` on every mutation
- [ ] **Auth-checked image serving** — the app authorizes, Caddy serves the bytes. An unguessable URL is not access control
- [ ] Optional TOTP 2FA (see open Q14)
- [ ] **Revisit CORS.** Deliberately not configured in Phase 2: Caddy serves the built UI and the
API from one origin, so there is no cross-origin request to permit, and adding permissive
headers "for the UI" would only weaken that. Decide it properly if the UI is ever served
from somewhere else — *then* it matters.
### 3.1 Two things the UI must not get wrong
@@ -162,7 +178,11 @@ bird photo appears in a browser.
- [ ] Device list with live/awake state, last seen, RSSI, heap/PSRAM, ring depth
- [ ] Settings editor writing the `devices` settings surface → `apply_config` → `config_version`
- [ ] Command queue UI: `wake_and_hold`, `capture_now`, `apply_config`, `ota_update`, `stream_start`, `reboot`; commands ride along on the ingest response
- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout
- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout.
`GET /firmware/{version}.bin` already serves the bytes; the upload half was left out of
Phase 2 because it needs operator auth. **Constrain `firmware.is_target` to a single row
while doing this** — nothing enforces it today, and the lookup takes the first match, so
two target rows would pick non-deterministically between them.
- [ ] Verify the full OTA path on hardware: **trial boot and automatic rollback**. The camera is unreachable once mounted — this is the one feature with no recovery if it is broken
- [ ] Document that rotating the shared bootstrap secret server-side without shipping new firmware **removes the last-resort escape hatch**
+21 -5
View File
@@ -1,9 +1,24 @@
# poorBird server
Phase 1 skeleton: configuration, schema, health, job queue and scheduler.
There are **no device endpoints yet** — `/enroll`, `/ingest`, `/heartbeat`,
`/status` and `/config` are Phase 2. The contract they must satisfy is
[`../firmware/API.md`](../firmware/API.md).
Phases 1 and 2: configuration, schema, health, job queue, scheduler, and every
endpoint the camera calls.
```
POST /api/v1/enroll X-Enroll-Secret, returns a bearer token
POST /api/v1/ingest raw JPEG body, metadata in headers
POST /api/v1/heartbeat conditions in, envelope + commands out
POST /api/v1/status conditions in, 204 out
GET /api/v1/config ~40 optional keys the device merges
POST /api/v1/commands/{id}/ack 204
GET /api/v1/firmware/{version}.bin OTA image, exact Content-Length
GET /api/v1/health
```
[`../firmware/API.md`](../firmware/API.md) is the contract, and it wins over
anything here: it is what the firmware already does, and the camera is the side
that cannot be patched from a laptop once it is mounted outdoors. The operator
half — firmware *upload*, device management, the gallery — needs user auth and
arrives with Phase 3.
Stack per SPEC §6, deployed natively per [`../TODO.md`](../TODO.md) Phase 1.2:
FastAPI + PostgreSQL 17 + SQLAlchemy 2.0 + Alembic, run as systemd units
@@ -108,7 +123,8 @@ src/poorbird/
logging_setup.py stdout only; journald or a log driver catches it
db.py engine + session factory (sync, deliberately)
models/ SPEC §3 schema + the SPEC §0 additions
api/ FastAPI app; Phase 2 mounts device routes here
images.py JPEG sniffing, atomic writes, thumbnails
api/ FastAPI app, device routes, auth, rate limiting
worker/ queue (SKIP LOCKED), handlers, scheduler
cli.py serve | worker | migrate | check | enqueue
migrations/ Alembic