Skip to content

CLI: upload each distinct file once with jittered retries; PDF fingerprints ignore font subset timestamps (sc-9174, sc-9164) - #165

Open
ndbroadbent wants to merge 1 commit into
mainfrom
cli-dedupe-and-font-stamps
Open

ndbroadbent wants to merge 1 commit into
mainfrom
cli-dedupe-and-font-stamps

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Two CLI fixes, one version bump (0.2.24 → 0.2.25).

sc-9174: an upload with identical files fails on R2 429

WeasyPrint's build of 42 files held 14 identical .txt files. The server answers an upload URL for every snapshot whose file it lacks, and identical files share one content-addressed key, so the CLI PUT the same key up to 14 times in parallel. R2 lets one client write an object about once a second, and the retries from #128 (6 tries, 0.5 s → 8 s, no jitter) retried in lockstep, so the upload failed.

  • Dedupe: add_snapshots uploads each distinct SHA-256 once per run, across registration batches too. Every snapshot is still registered by name with its hash; the others point at the same blob. The registration request sends each snapshot once, as before; it's the upload list that asked for the same SHA twice, and that's deduplicated now.
  • Retries: extends CLI 0.2.19: snapshot uploads the store refuses are tried again #128's put_blob instead of adding a second layer. 429, 5xx and dropped connections still get 6 tries with exponential backoff (or Retry-After, at most 30 s), plus up to 50% random jitter so parallel uploads don't retry together.
  • Errors name the file: uploading out/sample-03.txt: the store refused it 6 times, the last with 429 Too Many Requests (an inline snapshot shows as name (from path)). The presigned URL no longer goes into the log.
  • Not changed: the server still returns a URL per duplicate snapshot, so older CLIs keep the old behaviour. A server-side dedupe in POST /snapshots (app/src/http/api/builds.rs) would cover them; I left app/ alone here.

sc-9164: PDF fingerprints change every run when font subsets carry a timestamp

fontTools stamps the time it saves each subset into head.modified, which changes head.checkSumAdjustment and the directory checksum for head. So every run of WeasyPrint, fpdf2 and similar tools got new fingerprints.

  • Normalisation (visualci-core::pdf): font programs under a font descriptor's FontFile2 or FontFile3 are decompressed (Flate etc. via lopdf), then normalize_sfnt zeroes head.modified, head.checkSumAdjustment and the head table-directory checksum before hashing. It parses the sfnt table directory and finds head by tag. It skips the font, leaving it to be hashed as it is, unless the version is 0x00010000, true or OTTO, the whole directory fits the data, the head record exists, the table holds at least 36 bytes in range (checked arithmetic) and the magic number is 0x5F0F3CF5. No indexing can panic. CFF (Type1C), Type 1 FontFile and collections are hashed as before. A font program the normalisation doesn't change hashes exactly as before: the referenced-stream path feeds R plus the stream's digest, the same as feed.
  • compare-runs: when two PDFs' fingerprints still differ and the PDFs are identical with every embedded font program left out (pdf::fingerprint_without_font_programs), it lists them under "same drawing, embedded fonts differ" with a note that this is usually a subsetter's timestamp, and suggests SOURCE_DATE_EPOCH. It doesn't list every page as differing. It still exits 1, because those PDFs would still re-render each run.
  • Docs: pdfs.md's Fingerprints section mentions the font timestamps and SOURCE_DATE_EPOCH. skills/ is regenerated and the plugin is bumped to 0.1.54.

Deploy impact (fingerprints are shared with the renderer)

  • ALGORITHM stays vci-pdf-1. I reworded its doc comment: bump it when a change could let PDFs that draw differently match. This change only makes fewer bytes count, so an old fingerprint can equal a new one only for PDFs that draw the same. Bumping would have re-rendered every PDF; this way only the affected ones re-render.
  • Affected PDFs: those that embed a TrueType/OpenType font with a valid head table. That's most PDFs with embedded TrueType subsets (WeasyPrint, Chrome/Skia, fpdf2, ReportLab TTF). checkSumAdjustment is never zero, so these get a new fingerprint once, whether or not their font had a timestamp. PDFs with only CFF/Type 1 or non-embedded fonts keep their fingerprints.
  • First run after customers upgrade the CLI: affected PDFs miss the render cache (renders is keyed by project, source fingerprint and renderer), so they upload, render and get charged rendered-page credits once. Their manifest groups (sc-8868) hash fingerprints, so those groups show as needed and are re-checked once. After that, timestamp-only runs match and stop re-rendering.
  • Baselines and review: no change. Comparison is by page image (base.image == head.image or the pixel fingerprint), so a re-render of the same drawing compares unchanged. Nothing shows as changed and nothing needs re-approving. The text-snapshot "variant" lookup uses text fingerprints, not PDF ones.
  • Renderer: its image rebuilds (its input hash covers visualci-core), and it reports document_fingerprint from the same fingerprint_bytes, so the CLI 0.2.25 and the renderer agree on any file. blobs.pdf_fingerprint is written only where it's NULL, so blobs already rendered keep the old value. That only matters when a PDF is registered by hash alone without a fingerprint (current CLIs always send one), and the worst case is one extra render.
  • CLIs before 0.2.25 keep sending old fingerprints. For affected PDFs those won't match renders keyed by new ones, so mixing CLI versions on one project costs re-renders, never wrong results.

Tests

  • identical_files_are_uploaded_once: 20 identical files through add_snapshots against a fake API and store → registered 20, exactly 1 PUT.
  • an_upload_the_store_refuses_once_succeeds_on_a_retry: a 429, then success → 2 PUTs.
  • an_upload_the_store_keeps_refusing_fails_naming_the_file: persistent 429 → 6 PUTs, and the error names sample-00.txt, "6 times" and 429.
  • ignores_the_time_a_font_subset_was_saved: a synthetic TrueType subset (generated in the test, with real table checksums and checkSumAdjustment) in a minimal PDF as Flate-compressed FontFile2. Two copies that differ only in head.modified and the two checksums get the same document and page fingerprints.
  • a_font_with_other_glyphs_still_changes_the_fingerprint: different glyf bytes → different fingerprint, and the fonts-left-out fingerprint still matches (the compare-runs case).
  • malformed_fonts_are_left_alone_without_panicking: empty data, a truncated header, directory or head table, a numTables that overruns, overflowing or out-of-range head offsets, a head that's too short, a bad magic number. Each is left unchanged, and the PDFs embedding them still fingerprint as drawn.
  • The existing CLI 0.2.19: snapshot uploads the store refuses are tried again #128 retry tests pass.

Gates on the build pool: cargo fmt --all --check, cargo clippy --locked --workspace --all-targets -- -D warnings, cargo test --locked --workspace --exclude visualci-app (all pass), and node scripts/skills.mjs --check. No app/ code changed.


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…rprints ignore font subset timestamps (sc-9174, sc-9164)

This branch has not been deployed

No deployments
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