Skip to content

app/: snapshots by SHA-256 with the fingerprint optional; the server fingerprints new files; registration in a few queries (sc-8999) - #127

Merged
ndbroadbent merged 1 commit into
mainfrom
app-server-fingerprints
Dec 3, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
app-server-fingerprints

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Server side of sc-8999: snapshots are registered by their file's SHA-256 with the fingerprint optional, the server fingerprints new files itself, and the "already known" path is a constant handful of queries. Deployable on its own; the CLI change that stops decoding is a separate PR that needs this one live first.

Backwards compatibility (must stay until the new CLI is released and the docs move)

Production's CI and customers run published CLIs that send fingerprint for every snapshot. The server accepts both shapes:

  • fingerprint given: used exactly as today (snapshot rows, render lookup, groups). The golden files for the old path are unchanged.
  • fingerprint absent: taken from the blob if the server has computed it, else filled in during processing.

POST /builds/{id}/groups likewise keeps hashing image entries by pixel fingerprint unless the client sends image_hash: "sha256".

Design

What the API accepts. POST /api/v1/builds/{id}/snapshots: each snapshot needs sha256 (plus name, kind, size, content_type as before); fingerprint is optional and still validated as hex when present. Answer unchanged: upload_url per snapshot, null when the server has the file (or, for a PDF, a render of it).

Where fingerprints are computed.

  • Images: in processing, right after confirm_uploads, outside any transaction under the build's lock (processing::fill_image_fingerprints). Each blob without pixel_fingerprint is decoded once (blobs::image_info, which stores the fingerprint and size on the blob row in its own statement), then the build's snapshots get it in one UPDATE ... FROM (VALUES ...). Same in compare_now (early comparisons). An undecodable file fails its snapshot ("the image couldn't be read"), as comparing it would have.
  • PDFs: by the renderer, in its sandbox (docs/design.md: customer documents are parsed only on the render node). The renderer now sends document_fingerprint (visualci_core::pdf::fingerprint_bytes(..).document, exactly what the CLI computes) with the pages; renders::complete stores it on the source blob (blobs.pdf_fingerprint, new nullable column, written once). A PDF sent without a fingerprint whose blob has none is queued under its file's hash (same bytes always draw the same); when the renderer reports the fingerprint, that render moves to it unless the project already has a render there. An older renderer that reports nothing leaves the file's hash as the snapshot's fingerprint (what the CLI gives a PDF it can't parse).
  • Texts: the SHA-256, at registration.
  • Only server- or renderer-computed values go on blob rows, never a client's claim: blobs are shared by every project.

Re-encoded files. Same pixels (or same drawing) in new bytes: unknown hash, so it's uploaded once and kept as its own blob under its own sha256, with the same fingerprint stored. It compares unchanged, and later runs match it by hash with no upload and no decode. Nothing is merged or deleted.

The known path. snapshots::register_all registers a request in one batch: blobs upsert + one read back (blobs::register_many), one renders query for documents with a fingerprint (+ one mark_all_used when any are found), and one snapshots upsert with RETURNING name, platform to detect conflicts. Measured with db::listen over the whole request (auth included): 8 queries for 10 known images and 8 for 100; before, about 5 per snapshot plus the fixed part. Duplicate names within one request keep today's semantics (same file = retry, other file = 409), and are checked before anything is written. confirm_uploads (processing) now reads the build's blob rows in one query and only asks the store about unconfirmed files. MCP upload_snapshots goes through the same batch.

Also: approved_elsewhere and inherited ignore empty fingerprints, so a snapshot whose file never arrived can't match another.

Migration: 2026_12_03_000000_blob_pdf_fingerprints (ALTER TABLE blobs ADD COLUMN pdf_fingerprint text).

Tests (app/tests/fingerprints.rs)

  • sha256 only: a known blob gets no upload URL, an unknown one does; both get their fingerprints in processing, stored on the blobs.
  • the server computes and stores a new image's fingerprint, and the next run matches by hash (no upload, fingerprint filled at registration, unchanged).
  • a re-encoded image (RGB vs RGBA PNG, same pixels) is uploaded, kept as its own blob with the same fingerprint, compares unchanged; a third run matches it by hash with no upload.
  • PDFs through the real renderer API: drawn under the file's hash, renderer reports the fingerprint, blob/render/snapshot take it; the same file next run needs no upload and reuses the render; the same drawing in other bytes is uploaded, drawn once (the render stays under its hash since the project already has one under the fingerprint), unchanged; then matched by hash with no upload and no third render.
  • an older renderer that reports no fingerprint leaves the file's hash.
  • the old path (fingerprint given) still works; a non-hex fingerprint is still refused.
  • query count for registering 10 vs 100 known files is equal (8), and under 20.
  • groups with image_hash: sha256 match by file hash; without it the same entries don't; an unknown image_hash is refused.

Gates on agents-build-1: app cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings, cargo test --locked (all pass, golden files unchanged); workspace cargo fmt --all --check and clippy for visualci-renderer. Load test (20 unchanged builds of 331 text snapshots, tests/load.rs, same box): 22.6 s on this branch, 51.3 s on main (49aa4c1).

Rollout

Deploy order: this PR (server + renderer image, which CI rebuilds since crates/visualci-renderer changed; the renderer version and render cache keys are unchanged). Then the CLI PR, whose CI visual job uploads to production with the CLI it builds, so it needs this live. After that CLI is released, the docs' VISUALCI_VERSION lines move in their own commit. The old (fingerprint-sending) path stays supported until then.

Not changed: server/ (legacy Loco). MCP's classify still fingerprints uploaded files in-process (PDF parsing included); it could pass no fingerprint now and leave PDFs to the renderer, as a follow-up.

Shortcut: sc-8999

…fingerprints new files; registration in a few queries (sc-8999)

Server side of sc-8999, deployable before any CLI change.

- POST /api/v1/builds/{id}/snapshots: `fingerprint` is optional. Published CLIs send it and it's used as before. Without
  it, a snapshot takes the fingerprint stored on its blob (an image's pixel fingerprint, a PDF's renderer-reported one,
  a text's SHA-256), and a file the server hasn't fingerprinted yet gets it during processing.
- Registration is one batch (`snapshots::register_all`): the blobs' upsert and one read back, one renders query (and
  one noting those reused) for documents, and one snapshots upsert, whatever the number of snapshots. 8 queries for the
  whole request with 10 known images or 100 (before: about 5 per snapshot). Within-request duplicates and conflicts
  keep today's answers.
- Processing, outside any transaction under the build's lock: images without a fingerprint are decoded once per blob
  (`blobs::image_info`, stored on the blob) and the snapshots updated in one statement, before comparison and groups.
  `confirm_uploads` reads the build's blob rows in one query and asks the store only about unconfirmed files.
- PDFs: the renderer now reports `document_fingerprint` (visualci_core::pdf, computed in its sandbox) with the pages;
  it's kept on the blob (`blobs.pdf_fingerprint`, new column, set once). A PDF sent without a fingerprint whose blob has
  none is drawn under its file's hash, and that render moves to the fingerprint unless the project already has one
  there. An older renderer that reports none leaves the file's hash as the fingerprint.
- A re-encoded file (same pixels or same drawing, new bytes) is uploaded once and kept as its own blob with the same
  fingerprint, compares unchanged, and later runs match it by hash with no upload. Nothing is merged or deleted.
- POST /builds/{id}/groups takes `image_hash: sha256`: image entries then hash the file's SHA-256 on both sides, so the
  CLI's large-suite path needn't decode either.
- MCP upload_snapshots registers through the same batch.

Docs: design.md (pipeline, source fingerprints, sandbox), design-storage.md (blobs), the API reference.
@ndbroadbent
ndbroadbent force-pushed the app-server-fingerprints branch from 5774efb to 395362c Compare December 3, 2026 10:27
ndbroadbent added a commit that referenced this pull request Dec 3, 2026
…LI 0.2.19

Images go to POST /snapshots with sha256 and no fingerprint; the server fingerprints files it doesn't have. The group check hashes image entries by file SHA-256 and sends image_hash: sha256. PDFs keep their fingerprint, since their bytes change every run while the drawing doesn't. Needs #127 live in production first.
@ndbroadbent
ndbroadbent merged commit b8fafdb into main Dec 3, 2026
14 checks passed
@ndbroadbent
ndbroadbent deleted the app-server-fingerprints branch December 3, 2026 10:40
ndbroadbent added a commit that referenced this pull request Dec 3, 2026
…LI 0.2.19

Images go to POST /snapshots with sha256 and no fingerprint; the server fingerprints files it doesn't have. The group check hashes image entries by file SHA-256 and sends image_hash: sha256. PDFs keep their fingerprint, since their bytes change every run while the drawing doesn't. Needs #127 live in production first.
ndbroadbent added a commit that referenced this pull request Dec 3, 2026
…ess (sc-8999)

MCP's classify fingerprinted every uploaded file in the app process, PDFs included (lopdf on customer documents),
though docs/design.md says customer PDFs are parsed only on the render node. It now works out only the kind, the
content type and a text's SHA-256, and registers images and PDFs by their hash alone through #127's path: an image's
pixel fingerprint is computed in processing, and a PDF takes the fingerprint its renderer reports once it's drawn.
An undecodable image now fails its snapshot in processing ("the image couldn't be read") instead of failing the upload
call.
ndbroadbent added a commit that referenced this pull request Dec 3, 2026
…ess (sc-8999) (#131)

MCP's classify fingerprinted every uploaded file in the app process, PDFs included (lopdf on customer documents),
though docs/design.md says customer PDFs are parsed only on the render node. It now works out only the kind, the
content type and a text's SHA-256, and registers images and PDFs by their hash alone through #127's path: an image's
pixel fingerprint is computed in processing, and a PDF takes the fingerprint its renderer reports once it's drawn.
An undecodable image now fails its snapshot in processing ("the image couldn't be read") instead of failing the upload
call.
ndbroadbent added a commit that referenced this pull request Dec 3, 2026
…LI 0.2.19

Images go to POST /snapshots with sha256 and no fingerprint; the server fingerprints files it doesn't have. The group check hashes image entries by file SHA-256 and sends image_hash: sha256. PDFs keep their fingerprint, since their bytes change every run while the drawing doesn't. Needs #127 live in production first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant