Skip to content

Harden cron article generation with Gemini model fallback chain - #1

Draft
Parthakashyap with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cron-job-failure
Draft

Harden cron article generation with Gemini model fallback chain#1
Parthakashyap with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cron-job-failure

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown

The cron GitHub Actions job was failing because /api/cron/generate returned 500 {"error":"Failed to generate content"} when content generation failed on a single Gemini model. This change makes generation resilient to model-level failures instead of failing immediately.

  • Root-cause alignment

    • The cron workflow itself was functioning; failure occurred in lib/ai.ts where generation used one hardcoded model and threw on first provider/model error.
  • Generation fallback strategy

    • Added ordered model candidates in generateArticle:
      • process.env.GEMINI_MODEL (if set)
      • gemini-2.5-flash-lite
      • gemini-1.5-flash
    • Deduplicates candidates and attempts each model sequentially.
  • Failure handling behavior

    • Per-model errors are logged and retried with the next candidate.
    • Existing final behavior is preserved: if all candidates fail, the function throws Failed to generate content.
const modelCandidates = [
  process.env.GEMINI_MODEL,
  "gemini-2.5-flash-lite",
  "gemini-1.5-flash",
].filter((model, index, self): model is string => !!model && self.indexOf(model) === index);

for (const modelName of modelCandidates) {
  try {
    const model = genAI.getGenerativeModel({ model: modelName });
    const result = await model.generateContent(prompt);
    // parse/return response...
  } catch (error) {
    // log and continue to next model
  }
}
throw new Error("Failed to generate content");

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
genpost Ready Ready Preview, Comment Jul 16, 2026 12:30pm

Copilot AI changed the title [WIP] Fix failing GitHub Actions job cron Harden cron article generation with Gemini model fallback chain Jul 16, 2026
Copilot AI requested a review from Parthakashyap July 16, 2026 12:30
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.

2 participants