Skip to content

Reliable AI categories + image fallback for source-less articles#17

Merged
nmbrthirteen merged 1 commit into
mainfrom
fix/category-reliability-and-image-fallback
Jul 7, 2026
Merged

Reliable AI categories + image fallback for source-less articles#17
nmbrthirteen merged 1 commit into
mainfrom
fix/category-reliability-and-image-fallback

Conversation

@nmbrthirteen

Copy link
Copy Markdown
Owner

Problem

A published post (Bangladesh anti-gambling law) surfaced two issues: no featured image, and filed under the default Blog category instead of a topical one. Both root-caused with evidence.

Category → "Blog" (intermittent)

The site categorizes most posts correctly, so this wasn't systemic. OpenAiProvider used loose JSON mode (response_format: json_object), which only guarantees valid JSON, not that required fields are present. When the model occasionally dropped category, $structured['category'] ?? '' was empty and the post silently fell to WordPress's default category with no log.

  • Switch OpenAI to strict Structured Outputs (json_schema, strict: true) so category and all required fields are always returned. Schema is transformed to the strict-compatible subset (all props required, additionalProperties: false, unsupported length constraints stripped). Falls back to JSON mode if the model rejects the schema.
  • PostFactory now logs when a post keeps the site default category, closing the silent-fallback gap.

Missing image (source gap + lazy-load blind spot)

The original source has no og:image/twitter:image and lazy-loads its hero: the raw <img src> is an SVG placeholder, the real URL sits in data-src/srcset. first_content_image only read src, saw the data: placeholder, and returned nothing.

  • ContentExtractor now reads data-src, data-lazy-src, data-original, and the first srcset URL.
  • New optional default featured image (Settings + WP media picker) applied only when an article has no image of its own, so no post is left image-less.

Testing

92 tests pass (added lazy-load extraction cases and strict-schema transform cases), lint clean.

Two issues surfaced on a published post (missing image, filed under the
default 'Blog' instead of a topical category).

Category: OpenAI used loose JSON mode, which does not guarantee required
fields, so the model occasionally dropped 'category' and the post silently
fell to WordPress's default category.
- OpenAiProvider now uses strict Structured Outputs (json_schema, strict:true)
  so category and all required fields are always returned; falls back to JSON
  mode if the model rejects the schema.
- PostFactory logs when a post keeps the site default category.

Image: the source exposed no og:image and lazy-loaded its hero (real URL in
data-src/srcset, src held an SVG placeholder), so extraction found nothing.
- ContentExtractor reads data-src/data-lazy-src/data-original/srcset.
- New optional default featured image (Settings + media picker) used only
  when an article has no image of its own.

92 tests pass.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@nmbrthirteen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9371e2e1-7a6d-4c53-8824-fe0b577e35c3

📥 Commits

Reviewing files that changed from the base of the PR and between 4d24ad5 and e2a4114.

📒 Files selected for processing (9)
  • src/Admin/Admin.php
  • src/Admin/views/settings.php
  • src/Ai/OpenAiProvider.php
  • src/Publish/ImageImporter.php
  • src/Publish/PostFactory.php
  • src/Settings.php
  • src/Source/ContentExtractor.php
  • tests/ContentExtractorTest.php
  • tests/OpenAiProviderTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/category-reliability-and-image-fallback

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nmbrthirteen
nmbrthirteen merged commit 2f8b2dd into main Jul 7, 2026
6 checks passed
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