Skip to content

fix(artwork): cache SVG logos at full size instead of their tiny canvas - #5214

Merged
Quick104 merged 2 commits into
mainfrom
fix/blurry-logo-multi-server
Nov 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/blurry-logo-multi-server

Conversation

@Quick104

@Quick104 Quick104 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1210 C1 (an applied SVG logo is now cached at full size; the case's steps and expected results are unchanged)

Other clients: N/A (server-side fix; every client gets the corrected artwork without changes)

On servers that cache artwork, title logos from TMDB show up as a blur on title pages. TMDB serves most logos as SVGs, and the cache rasterized each one at its declared canvas. For these logos that canvas is a few dozen units wide, so the original and every rung were tiny. Back to the Future's logo declares a 53.921×24 viewBox, and every cached size of it was 54×24 px. The web detail page then draws that image about 280 px wide. Servers that don't cache artwork send clients the TMDB SVG directly, so they never showed the problem.

This change draws SVGs at the cache's full original size and repairs logos that were already cached the old way.

Approach

  • imageutil.Rasterize sends SVG sources to a small cgo function. It loads the SVG with libvips' svgload scale option, so the longest edge comes out at MaxCachedOriginalDimension (3840 px), and encodes a PNG. bimg has no way to pass that option. The scale and the decode-budget charge both come from the size libvips reports for that scale, not from bimg's declared size. bimg rounds a fractional canvas to whole pixels, which would make the charge differ from what libvips draws. HEIF and AVIF keep the existing path.
  • On a node with little memory, a square or tall SVG drawn 3840 px wide can need more pixels than the decode budget accepts at all. Such an SVG is drawn as large as the node allows instead of failing.
  • The admin artwork picker's SVG sidecar previews use a new RasterizeWithin, which draws at preview size instead of 3840 px.
  • A migration re-queues the cache job of every logo cached from an SVG (on media_items and media_item_localizations) where the job row still exists, including library-file sources that end in a ?v= fingerprint, so the image cache stores it again at full size. Logos from metadata providers also go back to their provider source path, so clients get the provider's SVG right after the upgrade, the same as on a server that doesn't cache artwork. Logos from library files and NFOs keep their cached path, because clients can't load those sources.
  • The jellycompat image routes serve the same cached objects, so the fix applies there too.

Validation

  • Real TMDB logo through Rasterize and GenerateVariants: before, original/w1280/w500 were all 54×24. After: 3840×1709 / 1280×570 / 500×223. Rendering takes about 0.65 s per logo, once.
  • New unit test: an SVG with only a viewBox, and one whose declared canvas is fractional, each rasterize to the requested size. The test asks for a size that fits any node's decode budget.
  • Migration SQL ran inside a rolled-back transaction on a development database. All three statements ran without errors.
  • Go gate: build, gofmt, go mod tidy -diff, vet, lint-changed, lint-router-recovery, verify-migrations, verify-local-paths, verify-size-ratchet and verify-bidi pass. make test-go passes on the first commit. After the review fixes, the imageutil, imagecache and metadata packages, vet, lint-changed and the silo_node build pass again. Four packages whose tests refuse group-writable temp directories failed under this machine's umask 002 and pass when re-run with umask 022. The API contract, settings binding and route inventory checks were not run because none of those files changed.
  • The web gate was not run because no web files changed.

Evidence

Checked with the Back to the Future logo from TMDB (7hXsyx9em5FhNdeEf0tehFmG06r.svg). Before this change, its cached w500 rung was 54×24 px. Scaled to the web detail page's logo height, it matched the blur users reported. With this change the w500 rung is 500×223 px and the logo is sharp at that size. The build was this branch at 42dd3c75b6.

Risks

  • Migration: cached SVG logos from providers show the provider's SVG until they are cached again. Re-queued jobs wait an hour so that, during a rolling upgrade, a node still on the old version doesn't claim one and cache the tiny image again. A cluster whose upgrade takes longer than that can still re-cache some logos the old way.
  • Pruned jobs: the image cache removes jobs that succeeded more than 30 days ago, so older logos have no job to re-queue. Those get cached again by "Backfill Metadata Images" or by the item's next metadata refresh. A library-file or NFO logo with no job left keeps its tiny cached image until the item is scanned or refreshed again.
  • If the provider plugin behind a logo's source (for example TMDB) is no longer installed, that logo can't be loaded and the title shows as text until the item's artwork is refreshed.
  • Rendering an SVG at 3840 px costs more CPU and memory than the old tiny raster: about 26 MB of pixels per logo while it renders, within the decode budget. It happens once per logo.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code, run inside T3 Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, at the maintainer's direction; maintainer review pending
  • Adversarial review: an independent Claude Code reviewer (claude-opus-5-5) that was not given these conclusions read the commit and the code it touches. It checked cgo memory and error handling, the build tags, libvips compatibility, the decode budget, other Rasterize callers, and the migration's SQL against the job table's constraints, the processor's success path and artwork GC. It found three problems, all fixed here: tall SVGs failed outright on small-memory nodes, the migration repointed library-file and NFO logos to sources clients can't load, and old nodes in a rolling upgrade could re-cache the tiny image. The Kody and CodeRabbit review bots then found four more, also fixed: SVG previews drawn at full size, library-file jobs missed because of their ?v= fingerprint, a test that depended on the machine's memory, and the budget charge for fractional SVG canvases.

🤖 Generated with Claude Code

Note

Fix SVG logo caching: rasterize at full size instead of tiny canvas

  • SVG rasterization previously used the SVG's declared canvas size, which is often tiny for logos. imageutil.Rasterize now renders SVGs at MaxCachedOriginalDimension on their longest edge via a new imageutil.RasterizeWithin function that accepts a caller-specified longest-edge limit (implemented in imageutil.go).
  • New libvips C bridges in svg.go measure and render SVGs at a chosen scale, clamping the pixel count to source and decode-budget limits. SVGs with only a viewBox or fractional dimensions are covered by tests.
  • LocalImagePreview in local_artwork_picker.go now rasterizes SVG/HEIF/AVIF sidecars to at most twice the preview width.
  • Migration 20261123160655_recache_svg_logos.sql requeues SVG logo cache jobs and moves cached logo paths to their provider SVG source paths.
  • Risk: Rasterize output size for SVGs changes, so anything relying on the old canvas-sized output must be checked; migration edits item/localization logo paths in place and cannot be undone (down migration is a no-op).

Macroscope summarized 42dd3c7.

The image cache drew an SVG at its declared canvas. TMDB logos declare
canvases a few dozen units wide, so a cached logo's original and every
rung were a 54px image, and title pages stretched it into a blur.

Rasterize now draws an SVG at the cache's 3840px original width through
libvips' SVG scale option, or as large as the node's decode budget
allows, and the budget is charged for that raster. A migration
re-queues the cache jobs of logos already cached from an SVG, an hour
out so old nodes in a rolling upgrade leave them alone, and points the
ones from metadata providers back at their provider source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 23, 2026
@silo-kody

silo-kody Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T16:58:45.659110Z 42dd3c7 New commits
🔒 Security Review ✅ Completed 2026-11-23T17:03:31.232782Z 42dd3c7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added bug Something isn't working impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

SVG inputs now use dimension-limited rasterization that respects the decode budget. Local artwork previews use a bounded rasterization size. A migration requeues qualifying logo jobs and updates qualifying cached logo paths.

Changes: SVG logo cache handling

Layer / File(s) Summary
SVG rasterization
internal/imageutil/imageutil.go, internal/imageutil/svg.go, internal/imageutil/imageutil_node.go, internal/imageutil/imageutil_test.go, internal/metadata/local_artwork_picker.go, docs/images-api.md
Rasterize delegates to RasterizeWithin, which applies a caller-selected dimension limit and routes SVG input through libvips. SVG rendering adjusts its scale to fit the dimension and pixel limits and reserves decode budget. Local previews use a limit of twice their display width. Tests check rendered dimensions, and the documentation describes the cached-original limit and SVG rendering size.
Logo cache repair
migrations/sql/20261123160655_recache_svg_logos.sql
The migration requeues qualifying succeeded or failed logo jobs and resets qualifying item and localization logo paths to their SVG source paths. The down migration performs no reversal.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: blurbery, rhainland

Merge Risk: Minimal · up to 42dd3

This change renders SVG title logos at up to 3840 px instead of their tiny declared canvas, keeps admin previews at preview size, and requeues affected logo cache jobs. No unresolved defects remain in the reviewed changes. The migration data repair cannot be reversed by the Down migration, which is documented and intentional.

Security architecture risk: Moderate · up to 42dd3

The new renderer limits the size of the image it produces, but the repair can send clients back to the original provider and does not restore the previous cached logo on rollback. During a rolling upgrade, some jobs can also be picked up by older workers before the intended delay ends, leaving the blurry logo cached.

Retained concerns

  • Medium · reliability · inferred: The migration's one-hour delay does not fence old workers. Reset local jobs qualify for existing early-claim paths because their attempt count is zero and their last error is empty. Routine workers can also claim the jobs after the delay regardless of version. If an old worker completes a repair for the same source, the usual source and lease checks accept its result and the job can finish with the old rasterization behavior.
  • Medium · reliability · observed: Provider-backed logo pointers are rewritten without requiring a surviving job or a successful replacement upload. A missing or failed job can therefore leave users dependent on provider delivery until refresh or backfill. The Down migration restores neither the prior pointers nor the queue state, so a database downgrade does not recover the previously cached delivery path.
  • Low · security · inferred: The SVG branch replaces the declared-canvas admission check with a rendered-pixel check. A source that exceeded the old canvas limit can now reach native rendering if its scaled dimensions fit. The shared reservation still bounds output pixels, but does not account for the newly added input copy and repeated header loads before reservation, or establish a bound on embedded-raster work. The incremental availability impact on the rendering process was not measured.
Security review details

Security Blast Radius

  • inferred — The renderer change applies to SVGs reaching the existing artwork cache and administrator preview, not just migrated logos. The database repair is narrower: it affects qualifying item and localization logos and their matching queue rows.

Security Findings and Attack Paths

  • inferred — Provider or library SVG bytes can reach the native renderer through existing artwork workflows. The changed admission check can expose the rendering process to inputs formerly rejected on canvas size, but the inspected call paths do not establish a new anonymous route or a demonstrated exhaustion outcome.

Trust Boundaries and Controls

  • observed — The migration restores provider delivery for previously cached qualifying logos but excludes known internal source schemes, including file, upload, and generated artwork. Provider-hosted delivery already exists for uncached artwork; the change extends that delivery mode to the migrated rows before recaching completes.

Resilience and Maintainability Implications

  • observed — The decode budget already documented that an SVG's embedded images can cost more to decode than the canvas suggests. That limitation predates this PR; charging the rendered output does not resolve it.

Hardening Proposals

  • proposed — Keep serving the previous cached logo until the replacement is ready, and activate repair jobs only once workers capable of the new render are eligible. If immediate provider fallback is required, preserve the prior pointers for an explicit recovery operation.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: SVG logos are now cached at full size instead of their small declared canvas. The changeset adds an SVG rasterization path in imageutil, a migration that re-queues SVG…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the problem (blurry TMDB SVG logos caused by rasterizing at the declared canvas size), the approach (libvips svgload scale to MaxCachedOriginalDimension, RasterizeWithin for the…
Full details: Title check

Explanation

The title names the main change: SVG logos are now cached at full size instead of their small declared canvas. The changeset adds an SVG rasterization path in imageutil, a migration that re-queues SVG logo cache jobs, and a test for full-size SVG rendering. The title is short, specific, and matches the primary fix.

Full details: Description check

Explanation

The description states the problem (blurry TMDB SVG logos caused by rasterizing at the declared canvas size), the approach (libvips svgload scale to MaxCachedOriginalDimension, RasterizeWithin for the admin picker, a migration that re-queues cache jobs and repoints provider logos), validation, and risks. It matches the changeset closely, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 70f2b6b5-2a38-4c1b-b88e-5a99a73cbdf7
Commits

Reviewing files that changed from the base of the PR and between 4243d3b and 42dd3c7.

Files selected for processing: 6

  • internal/imageutil/imageutil.go
  • internal/imageutil/imageutil_node.go
  • internal/imageutil/imageutil_test.go
  • internal/imageutil/svg.go
  • internal/metadata/local_artwork_picker.go
  • migrations/sql/20261123160655_recache_svg_logos.sql

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment thread internal/imageutil/imageutil.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebdcdbee-3dfb-4207-a851-339a31a04239
Commits

Reviewing files that changed from the base of the PR and between f02a521 and 4243d3b.

Files selected for processing: 5

  • docs/images-api.md
  • internal/imageutil/imageutil.go
  • internal/imageutil/imageutil_test.go
  • internal/imageutil/svg.go
  • migrations/sql/20261123160655_recache_svg_logos.sql

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment thread internal/imageutil/imageutil_test.go Resolved
Comment thread internal/imageutil/svg.go Resolved
bimg rounds an SVG's declared canvas to whole pixels, and libvips
scales the fractional canvas, so the decode budget could be charged
for a smaller raster than the one drawn. The scale and the reservation
now come from libvips' own header at each scale, which also lands the
cached original exactly on 3840px.

The admin artwork picker drew each SVG sidecar at 3840px only to
shrink it to a 300px preview; RasterizeWithin draws it at preview size.

The migration also re-queues jobs for library-file SVG logos, whose
sources end in a "?v=" fingerprint, and the full-size test no longer
depends on the machine's memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 23, 2026
@silo-kody

silo-kody Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit a62176b into main Nov 23, 2026
28 of 29 checks passed
@Quick104
Quick104 deleted the fix/blurry-logo-multi-server branch November 23, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant