{"record":{"id":"6d66a52afb2445bb","repo":"moeru-ai/airi","slug":"replicate-returned-an-empty-output-array","errorCode":null,"errorMessage":"Replicate returned an empty output array.","messagePattern":"Replicate returned an empty output array\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/main/services/airi/widgets/providers/replicate.ts","lineNumber":171,"sourceCode":"        else if (typeof first === 'object' && first !== null && 'url' in first && typeof (first as any).url === 'string') {\n          imageUrl = (first as any).url\n        }\n        // Case 3: Simple string (the URL itself)\n        else if (typeof first === 'string') {\n          imageUrl = first\n        }\n\n        if (imageUrl && (imageUrl.startsWith('http') || imageUrl.startsWith('data:'))) {\n          log.log(`[Replicate] EXTRACTED IMAGE: ${imageUrl.startsWith('data:') ? 'DATA_URL' : imageUrl}`)\n          this.updateStatus(jobId, { status: 'succeeded', progress: 100, imageUrl })\n        }\n        else {\n          log.error(`[Replicate] Failed to extract URL from output: ${JSON.stringify(first)}`)\n          throw new Error('Output does not contain a recognizable image URL.')\n        }\n      }\n      else {\n        throw new Error('Replicate returned an empty output array.')\n      }\n    }\n    catch (error: any) {\n      const errorMessage = error.message || (typeof error === 'object' ? JSON.stringify(error) : String(error))\n      log.error(`[Replicate] Generation Failed for ${jobId}: ${errorMessage}`)\n      this.updateStatus(jobId, {\n        status: 'failed',\n        error: errorMessage,\n        actionLabel: `Error: ${errorMessage.slice(0, 50)}${errorMessage.length > 50 ? '...' : ''}`,\n      })\n    }\n    finally {\n      // Clean up callback and job result after completion to prevent memory leaks\n      setTimeout(() => {\n        this.callbacks.delete(jobId)\n        this.jobResults.delete(jobId)\n      }, 10000)\n    }","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/apps/stage-tamagotchi/src/main/services/airi/widgets/providers/replicate.ts#L153-L189","documentation":"Thrown when the output is an Array.isArray but items.length === 0. Replicate returned a structurally valid but empty output array — the prediction resolved with zero generated items. Sibling to [41] (null output) and [42] (unrecognizable item).","triggerScenarios":"An image model that normally returns multiple outputs returned none for this run; nsfw/safety filter blocked every output; model misconfigured with num_outputs=0 via extra options.","commonSituations":"Prompt tripped Replicate/model safety filters; model-specific `num_outputs` option set to 0 in request.extra; degenerate prediction on the platform.","solutions":["Retry with a different prompt to rule out a safety-filter block.","Inspect request.extra and the merged inputOptions to ensure no option forces zero outputs (e.g. num_outputs: 0).","Check the Replicate prediction page for the run to see if outputs were filtered.","If persistent, switch models — some community models intermittently return empty arrays."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isNonEmptyOutputArray(output: unknown): output is unknown[] {\n  return Array.isArray(output) && output.length > 0\n}","tryCatchPattern":"try {\n  await provider.runGeneration(jobId, model, inputOptions)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('empty output array')) {\n    // retry once with a sanitized prompt\n  } else throw e\n}","preventionTips":["Avoid prompts likely to trip safety filters.","Ensure request.extra does not set num_outputs to 0.","Retry once on empty-array outcomes."],"tags":["replicate","artistry","upstream","empty-result"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}