Repository navigation
perf(artwork): keep revisioned artwork URLs stable for a UTC day - #1376
Conversation
Clients and CDNs cache artwork by full URL, so every new URL for unchanged bytes costs a download the client already has. Local signed URLs rolled every 15 minutes. S3 presigned URLs carried the signing second and Cloudflare token URLs the issue second, so they changed on every resolve and differed between replicas. A revisioned key names immutable bytes: its path is the identity and its query only authorizes. At the default lifetime such a URL now holds for its UTC day. The local signer uses a day-long issuance bucket, and S3 presigns at the start of the day with X-Amz-Expires set to the day plus the TTL, shortened to fit the SigV4 seven-day limit. The WAF rule fixes a token's lifetime from its timestamp, so token timestamps are truncated to a quarter of the token TTL instead. Every replica mints the same URL for the same window. Mutable keys, short-lived capabilities such as avatars and chapter thumbnails, and job artifact downloads keep their current buckets. Over a simulated day of per-minute resolves through the production resolvers, distinct URLs for one revisioned key drop from 97 to 2 (local), 1440 to 2 (S3 presigned), and 1440 to 33 (three-hour Cloudflare token), and a second replica resolving 20 seconds later now always agrees. A leaked revisioned URL now works for up to a day plus the TTL instead of the TTL plus 15 minutes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Record that replica-identical presigned URLs rely on the shared static access key, that lowering s3.metadata_presign_expiry shortens the TTL but not the day window, and how the Cloudflare Token TTL sets how often token URLs change. Give the revisioned cache-policy test a few seconds of slack so a run that crosses midnight UTC cannot fail it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Client follow-ups filed: Silo-Server/silo-apple#406 and Silo-Server/silo-android#373 key the native image caches by the revisioned artwork path, so a re-signed URL stops re-downloading bytes the device already holds. |
Problem
Related issue: N/A
Validation tasks: none changed. #1210 C1 and #1211 C1 check artwork after it is edited; new artwork still gets a new URL immediately because its key carries a new revision.
Artwork URLs changed much more often than the images behind them. The web client, the Apple and Android apps (Nuke and Coil), and many third-party clients cache images by full URL. A new URL for the same poster means a new download, and on the web the card fades back to its placeholder until the download finishes.
X-Amz-Date). Every resolve produced a new URL, and each replica produced a different one.This affects every deployment. S3 and multi-node deployments see the most churn.
Approach
A revisioned key, whose filename carries a content revision such as
w500.<revision>.webp, names bytes that never change. The path identifies the image and the query only authorizes the request. At the default lifetime (s3.metadata_presign_expiry, 4 hours), such a URL now stays the same for its UTC day:X-Amz-Expiresset to the day plus the TTL. If the TTL is close to the SigV4 seven-day limit, the window shrinks and the TTL stays.is_timed_hmac_valid_v0) makes a token valid for the token TTL from its timestamp, so a day-long window would hand out expired URLs. The timestamp is truncated to a quarter of the token TTL instead, capped at a day: 45 minutes for the default 3 hours. Each URL stays valid for at least three quarters of the token TTL.Maintainer decision needed: the target was 1 or 2 token URLs a day. With the default 3-hour token TTL this change gives 33. Reaching the target needs a token TTL of at least 4 days (
345600), set in Silo and in the WAF rule, which gives 2 URLs a day and lets a leaked token URL work for up to 4 days. Please confirm the quarter-TTL cap, or say whether the default token TTL should change.docs/s3-storage-setup.mdnow describes this trade-off next to the Token TTL setting.Replicas compute the same URL for the same window because the signing inputs no longer include the current second. For S3 this also relies on every replica signing with the same key. The S3 client only uses the configured static access key (
credentials.NewStaticCredentialsProviderwith no session token), so that holds today. The resolver now reports each URL's real expiry instead ofnow + TTL.These cases keep their current behavior:
Cache headers: local revisioned responses already send
private, max-age=<remaining URL lifetime>, immutable, and mutable ones sendprivate, no-cachewith an ETag. A new test now covers the revisioned header. S3 uploads are unchanged. Browsers already apply heuristic freshness fromLast-Modifiedonce the URL is stable, and settingCache-Controlat upload time would only reach new objects.docs/architecture/blob-storage.mdnow records the "path is identity, query is authorization" rule and the windows.docs/images-api.mdtells clients what to expect and says they may key revisioned artwork by path.Alternatives considered:
min(1h, ttl/4)would limit the extra lifetime of a leaked URL to an hour. The maintainer chose one day.Client and compatibility follow-up: nothing is required in
silo-appleorsilo-android. Their poster caches key on the full URL, so they benefit without changes. Keying revisioned artwork by path is an optional later improvement that would also survive the daily rollover. Jellyfin-compatible image redirects use the same resolvers, so their targets become stable too.Before and after
TestRevisionedArtworkURLChurnOverADay: fake clock (testing/synctest), production resolvers, simulated day from 03:07 UTC; same test run on the base commit and on this branchnow + TTLThe count of 2 includes one rollover at midnight UTC. A day that starts at midnight gets 1. These counts are taken at the resolver. Before this change, the metadata layer's 5-minute cache of resolved URLs meant clients saw a new S3 URL from each replica about every 5 minutes. That figure is an estimate and was not measured.
Validation
All checks below ran after rebasing onto current
main, which applied cleanly. The branch changes no generated artifacts, migrations, workflows, settings, or/api/v2schema. Every check passed, so none needed a comparison run onmain.make embed-stub,go build ./...,go vet ./...: pass.gofmt -l .: no output.make lint-changed: 0 issues.GOFLAGS=-p=6 make test-go: pass, no failing packages.make verify-settings-bindings-all verify-playback-fixtures verify-route-inventory verify-migration-ledger verify-scenario-catalogs verify-offline-routes verify-apiv2-openapi verify-apiv2-contract verify-apiv2-fixtures verify-local-paths: all pass.go test -count=1 -run '^TestCommittedArtifactMatchesRouter$' ./internal/apiv2/: pass.TestRevisionedArtworkURLChurnOverADayre-run: 2 distinct URLs with local storage, 2 with S3 presigning, and 33 with Cloudflare tokens, and no replica disagreements in any mode. These match the table above, and the test's minimum-lifetime assertions pass.internal/artworkurl,internal/s3client,internal/blobstore, andinternal/apiv2pass under-race.TestArtworkRejectsInvalidSignaturesBeforeStoragebuilt its "expired" revisioned URL by signing 2 hours in the past. That URL is now still valid, so the test signs 26 hours back.X-Amz-Expiresof 28 hours returned 200 with the object bytes.X-Amz-Expiresof 168 hours, the SigV4 limit. That URL returned 200.DirectURLand avatar resolution do not use a database.web/is unchanged.Risks
s3.metadata_presign_expiryno longer brings a revisioned URL's lifetime below about a day; it shortens only the TTL part. Mutable keys, short-lived capabilities, and job artifacts are unchanged.X-Amz-Dateis up to a day old. That is standard SigV4 behavior, and MinIO accepted it in the live check above.X-Amz-Expiressays. That path does not exist today and was not tested.Checklist
AI Disclosure
mainas it stood then, ran the churn test there (97 / 1,440 / 1,440 distinct URLs, 0 / 1,440 / 1,440 replica disagreements), merged this branch ontomain(clean merge, build and focused tests pass, new tests pass under-race -count=3), read the vendored AWS SDK presign middleware to confirm the fixed signing time applies, and ran its own MinIO container: a day-oldX-Amz-Datereturned 200, an expired URL returned 403, and a URL over seven days returned 400. It approved with no blockers or majors. Its findings and how each was resolved:blob-storage.mdand the Risks section now state the dependency.docs/s3-storage-setup.md.s3.metadata_presign_expiryno longer shortens a revisioned URL below about a day. Added to the Security risk and toblob-storage.md.TestArtworkRevisionedCachePolicycould fail if a run crossed midnight UTC between signing and serving. The assertion now allows 5 seconds of slack.🤖 Generated with Claude Code