← Back to Pull requests

Fall back to a safe prompt when image moderation blocks a cover or portrait #2

Closed
unknown closed this pull request without merging on Nov 07, 2026 18:40 UTC
View on GitHub
unknown unknown commented on Nov 07, 2026 07:13 UTC
Author

Problem

A fresh library build can end in "Library building paused — Something went wrong." with no explanation, even though almost every artist was made (in the reported case, 106 of 110 artists were ready).

Root cause

OpenAI's Images endpoint blocks some cover prompts with:

HTTP 400  code: moderation_blocked  type: image_generation_user_error
moderation_details: { moderation_stage: "output", categories: ["sexual"] }

All four failures were posed dance-pop covers of a solo woman: a bodysuit or mini-dress, a hand on her hip. The block happens at the output stage, and the same prompt gets blocked on every try. So:

1. client.image threw a generic .http(400, …).
2. writeAll retried the whole artist 3 times, with the same cover prompt each time, then marked the artist failed.
3. run() set the batch to .failed but only filled in activity, not error. BuildingView and SidebarView show status.error ?? "Something went wrong.", so the real reason never reached the UI.

Try Again couldn't fix it either, because it sends the same prompt again.

Fix

  • ChatGPTError.moderationBlocked([String]), parsed from the Images endpoint's 400 body by ChatGPTError.from(status:body:). It is not retryable.

  • LibraryBuilder.paint(_:fallback:generate:): if a cover or portrait is blocked, it tries once more with a fallback prompt that has no people in it:

  • - covers: a typographic, abstract design that keeps the title, artist name, year and genre
    - portraits: a wide environmental shot with everyday clothes
  • A partly failed batch now sets error (and stores it on generationBatch.error), for example "4 artists couldn't be finished." It used to show a generic message. This also fixes "1 artists".
  • Verification

  • New ImageModerationTests (6 tests): parsing the real blocked response body, keeping the body for other 4xx errors, using the fallback only on a moderation block, the content of the safe prompt, and the partial-failure message. They were written first and failed to compile before the fix.

  • swift test in Packages/StandardKit: 53 tests in 14 suites passed.

  • Live check with sm-dev image: the original Plastic Tiara cover prompt reproduces moderation_blocked. The fallback prompt generated a cover for all 4 previously blocked albums (Plastic Tiara, Paradise at Full Volume, Pleasure Audit, Chrome Tempo), with names spelled correctly.
  • Libraries that are already affected recover with Try Again: resumeUnfinished(retryFailed:) → complete → paintCover now takes the fallback path.

    Diff: 323 lines (+242 / -81) across 4 files Reviewer: justin-schroeder Review duration: 686m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 323 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.346
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #2"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.0% (MEDIUM) · Higher = larger blast radius
    47.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.6% · Safe to merge
    18.6%