Skip to content

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

Merged
mohnjiles merged 4 commits into
LykosAI:mainfrom
deepratna-awale:fix-civitai-null-image-dimensions
Nov 17, 2026
Merged

mohnjiles merged 4 commits 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
Contributor

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
Contributor 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
@mohnjiles

Copy link
Copy Markdown
Member

Thanks for this, and for pinning the whole-page case in a test! I checked every reader of CivitImage.Width/Height. The OpenArt thumbnail mapping is the only one, and your ?? 0 covers it. Nothing else does size math on them, so int? is the right call over a null-to-default converter.

One small nit: the comments at CivitImageTests.cs:12 ("observed live 2026-11-06, issue #1792") and :50 ("used to fail the whole page") describe history. That context fits better in the PR body, where it already is, so the test comments can just say what's being pinned.

Good to go from my side.

Remove comment that should have been in PR instead
@deepratna-awale

Copy link
Copy Markdown
Contributor Author

@mohnjiles Done. Ready for merge.

@mohnjiles mohnjiles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@mohnjiles
mohnjiles enabled auto-merge November 17, 2026 01:55
@mohnjiles
mohnjiles merged commit 1386b80 into LykosAI:main Nov 17, 2026
2 of 3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

3 participants