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:239 — if ( 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-116 — if ( ! 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
- Configure an AI Connector and enable the Alt Text Generation experiment.
- Upload an image the model is likely to mark decorative (e.g. a thin divider line, a solid color block, a purely ornamental flourish).
- 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
// 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.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.
Description
The
ai/alt-text-generationability 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 ofalt_text(an empty string is falsy).The shared utility
src/utils/generate-alt-text.tsalready returns both fields and the block-editor caller (src/experiments/alt-text-generation/components/AltTextControls.tsx:115-120) handlesis_decorativecorrectly. 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:239—if ( 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-116—if ( ! 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 viawp/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 existinggenerateAltTexthelper so behavior stays in sync with the block editor.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Suggested direction: replace both call sites with
generateAltText()fromsrc/utils/generate-alt-text.ts(which already returnsis_decorative) and branch onresult.is_decorativethe same wayAltTextControls.tsxdoes.Environment info
develop@ commit7888332Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.