Skip to content

Fix CivitAI model browser failing when an image has null width or height - #1793

Open
deepratna-awale wants to merge 1 commit into
LykosAI:mainfrom
deepratna-awale:fix-civitai-null-image-dimensions
Open

deepratna-awale wants to merge 1 commit into
LykosAI:mainfrom
deepratna-awale:fix-civitai-null-image-dimensions

Conversation

@deepratna-awale

@deepratna-awale deepratna-awale commented Nov 6, 2026 •

Copy link
Copy Markdown

Fixes #1792

Problem

CivitAI sometimes returns "width": null, "height": null for model preview images. CivitImage.Width and Height were non-nullable int, so /api/v1/models failed to deserialize. The Model Browser then showed "CivitAI can't be reached right now (OK: OK)" and dropped the whole page, so infinite scroll stopped.

Reproduced on 2026-11-06 with live data: Illustrious and NoobAI, sorted Newest over a Week, NSFW on. Five models (3032697, 3032929, 3032961, 3032970, 3032979) had ordinary image entries with null dimensions. Requesting them through the app's ICivitApi Refit client, with the app's JSON options, threw the same JsonException ... Path: $.items[0].modelVersions[0].images[0].width as the issue.

Changes

  • CivitImage.Width and Height are now int?, following the 2.16.2 fix for null stats.
  • DownloadCivitWorkflowStep uses ?? 0 where it maps these values onto OpenArtThumbnail. This is the only consumer.
  • Added CivitImageTests, which deserializes an image with null dimensions and a models response where one item has them.

Impact of int → int?

  • Readers: the only code that reads CivitImage.Width/Height is the OpenArt thumbnail mapping in DownloadCivitWorkflowStep, which now falls back to 0. Downstream, those thumbnails only use the URL. The other CivitImage uses only touch Url, Type and NsfwLevel, and no XAML binds to these fields.
  • Persisted data: .cm-info.json doesn't store images. The Model Browser's LiteDB cache does. I checked a downgrade against LiteDB 5.0.21: a null written by this build reads back as 0 in a build where the field is int, so nothing crashes. Saved OpenArt workflow metadata still writes a plain int.
  • Side benefit: CivitModelVersionResponse, used by the by-hash lookup for metadata and model import, shares CivitImage, so it no longer fails on the same nulls.
  • Alternative: the 2.16.2 stats fix kept int and used NullToDefaultJsonConverter<int>. That would also work and would be consistent with it, but it turns "unknown" into 0. I chose int? to keep the null. Happy to switch to the converter if you'd rather match the stats fix; it's a two-line change.

Testing

  • dotnet build StabilityMatrix.Avalonia -r osx-arm64 builds with 0 errors.

  • The new tests pass, along with the existing JSON converter tests.

  • On the full suite, 772 tests pass. The 2 failures are LinkSafeFileSystemTests.GetRealPath_*, and they fail the same way on unmodified main on macOS because the temp dir resolves to /private/var.

  • The live API request for the affected models now returns all 5 items.

  • Headless UI check of the CivitAI Model Browser against the live API, searching "Gwenc League of Legends" (Model Type: All), with a clean cache for each build:

Before (main) After (this PR)
Before: "CivitAI can't be reached right now (OK: OK)" toast, search results not shown After: Gwenc model card loads, no toast

CivitAI returns null width/height for some images, which made the whole
/api/v1/models page fail to deserialize. Make CivitImage.Width/Height
nullable and default to 0 where they are mapped to OpenArt thumbnails.

Fixes LykosAI#1792
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot CLA Assistant bot All Contributors have signed the CLA.

@deepratna-awale

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@deepratna-awale
deepratna-awale marked this pull request as ready for review November 6, 2026 09:28

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.

CivitAI Model Browser: "CivitAI can't be reached right now (OK: OK)" when an image has null width

1 participant