a9d5ce86e6dbfc3bef087dc175b7c3df29d8f61b
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ec9ef9b3a6 |
Add the thumbnail worker, and stop tests leaking jobs (Phase 2)
Captures now get a WebP thumbnail: 400px on the long edge, written to
thumbs/<uuid>_400.webp (SPEC 3.3). /ingest enqueues the job in the same
transaction as the capture row, so the worker never sees a job for a capture
that was rolled back, and decoding stays off the request path - it is the one
genuinely expensive part of a capture, and the device is waiting with a burst
still to upload.
api/images.py moves up to poorbird/images.py. Both sides use it now, and a
worker importing from api would be the wrong way round. The split by cost
stays: everything the ingest path touches still reads nine bytes of JPEG
header, and Pillow appears only in the thumbnail half.
Handler behaviour is about which failures are worth retrying:
- An undecodable frame returns rather than raises. The handler contract
makes a raise mean "retry", and a frame that will never decode should not
spend three attempts proving it. Logged, thumb_path left NULL.
- A missing source file raises, because it should be there and a mount that
has not come back yet is worth retrying for.
- A capture deleted between enqueue and run is not an error. Retention will
do that routinely in Phase 5.
- A malformed payload is validated with a Pydantic model and recorded, not
retried (SEC-003 applied to a job payload).
- Never upscales: blowing a 100px frame up to 400px produces a blurry lie.
- Fills in width/height when the ingest header parse could not. This is the
first full decode, so it is the chance to fix that.
Verified end to end against a real device row, a real HTTP ingest and the
real worker dispatch path - claim, _run_one, complete - not just the handler
called directly: 1600x1200 JPEG in, WEBP 400x300 on disk, job marked done.
That run is what caught the rest of this commit.
Tests were leaking jobs into the shared queue, which broke test_queue.py once
/ingest started enqueuing. Three separate causes, all the same shape as the
teardown bug fixed in
|
||
|
|
6223d960c4 |
Add POST /api/v1/ingest (Phase 2)
Raw JPEG body with metadata in headers, which is API.md's deliberate
deviation from SPEC 4.1: multipart would make the device assemble a second
buffer purely to add a wrapper the server strips immediately. REVIEW.AI.md's
reference code implemented the multipart version and would not have matched
the firmware at all. Returns the same envelope as /heartbeat, so a capture
that was going to happen anyway also drains the command queue.
api/images.py holds the storage helpers, with no imaging library. Reading
nine bytes of JPEG header for the dimensions beats decoding a frame on a
path that runs once per capture, and the same parse doubles as content
validation: the magic bytes decide whether this is a JPEG, not the
Content-Type header. Pillow belongs in the thumbnail worker, off the request
path, where the image has to be decoded anyway.
Ordering and failure:
- The file is written first, through a temp file in the same directory and
an atomic rename, so a half-written JPEG is never visible at its final
path. The row is inserted second, and the file is removed if the commit
fails. The reverse order would be worse: a row pointing at a missing
image is a broken gallery entry, while a stray file is invisible and
sweepable.
- A body that is not a JPEG is 400, never 401, so the device does not read
it as a credential problem and clear a good token. Unwritable storage is
503, because from the device's side it is transient.
- 12MB cap mirrors the Caddyfile, since a limit that only exists in the
proxy is not a limit in development.
Identical bytes from the same device are treated as a retry and return the
original capture, with the command queue still attached. The device cannot
tell a lost response from a real failure, and two genuine frames never
collide - sensor noise alone makes every capture unique. Checked in the
application rather than with a unique constraint, so a freak collision loses
a frame instead of raising.
X-Captured-At: 0 means the clock is unsynced and is stored as NULL. An epoch
date would bury the frame at the bottom of every chronological view forever.
received_at stays authoritative either way (SPEC C7), and is what dates the
YYYY/MM/DD path.
NOT included, and deliberately: the thumbnail job. An unknown job kind is
failed immediately by the worker (worker/main.py:35), so enqueuing one now
would produce a failed job per capture. thumb_path stays NULL, which the
gallery has to handle regardless - a capture is visible when it lands, not
once it is processed. Thumbnails are the next unit of work and need Pillow.
Tests: 122 -> 148. Verified by disabling dedup and by removing the
captured-at-zero guard: the two corresponding tests fail, as intended.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|