Skip to content

Alt text generation fails on decorative (or empty) image results in Media Library (single + bulk) #557

Description

@antoniomilev

Description

The ai/alt-text-generation ability can return { alt_text: "", is_decorative: true } when the AI determines an image is decorative. Two callers in the Media Library treat that response as a failure instead of as a valid decorative result, because they check the truthiness of alt_text (an empty string is falsy).

The shared utility src/utils/generate-alt-text.ts already returns both fields and the block-editor caller (src/experiments/alt-text-generation/components/AltTextControls.tsx:115-120) handles is_decorative correctly. The two Media Library entry points were never migrated to it. Therefore causing the frontend to display "Failed to generate alt text.".

  • src/experiments/alt-text-generation/media.ts:239if ( response?.alt_text ) throws "Failed to generate alt text." for a valid decorative response. The user sees a generic error and the alt textarea is not updated, even though the AI gave a usable answer (empty alt + decorative flag).
  • src/experiments/alt-text-generation/bulk.ts:112-116if ( ! altText ) throw new Error( 'Empty response received.' ) causes decorative attachments to be counted as failures and listed in the "Failed attachment IDs" notice. The empty alt is never written via wp/v2/media/{id}, so the user is told the image failed when it actually succeeded.

Expected behavior: when the response is decorative, write an empty alt_text (the WordPress convention for decorative images) and surface that to the user as a success — ideally via the existing generateAltText helper so behavior stays in sync with the block editor.

Step-by-step reproduction instructions

  1. Configure an AI Connector and enable the Alt Text Generation experiment.
  2. Upload an image the model is likely to mark decorative (e.g. a thin divider line, a solid color block, a purely ornamental flourish).
  3. Single image: open the attachment in the Media Library, click Generate in the alt text panel.
    • Observed: error notice "Failed to generate alt text."; alt textarea unchanged.
    • Expected: alt textarea cleared (empty alt = decorative) with a success message.

Screenshots, screen recording, code snippet

Image
// src/experiments/alt-text-generation/media.ts (current)
if ( response?.alt_text ) {           // empty string is falsy
    return response.alt_text;
}
throw new Error( __( 'Failed to generate alt text.', 'ai' ) );
// src/experiments/alt-text-generation/bulk.ts (current)
const altText = response?.alt_text;
if ( ! altText ) {                    // empty string is falsy
    throw new Error( __( 'Empty response received.', 'ai' ) );
}

Suggested direction: replace both call sites with generateAltText() from src/utils/generate-alt-text.ts (which already returns is_decorative) and branch on result.is_decorative the same way AltTextControls.tsx does.

Environment info

  • Wordpress 7.0-RC3
  • Chrome
  • AI plugin: develop @ commit 7888332

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions