Repository navigation
Description
Problem
The LLM-backed onboarding steps make a single round-trip with no retry, so one transient failure drops the whole step. A user hit this on the Competitors step recently — the model returned nothing and they were left with an empty list and a bare error toast.
Three steps call the LLM:
- Topics —
server/src/routes/topics.js(generateText+generateObject) - Prompts —
server/src/routes/prompts.js(generateObject) - Competitors —
server/src/routes/competitors.js(two-phase:generateTextwith search grounding →generateObject, schema.min(3).max(10))
None are wrapped in a retry. The AI SDK's built-in maxRetries only covers provider-classified transient errors (429/5xx/network) — it does not retry a schema-validation miss (e.g. the model returns fewer than 3 competitors) or a NoObjectGeneratedError. Those throw immediately, the route returns 500, and the frontend (web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx) just shows a toast with an empty suggestion list.
This is made worse by #377/#378: the Competitors CTA is now disabled until at least one competitor exists, so a failed suggestion hard-blocks the step unless the user manually types one — with no clear prompt telling them to.
Desired behavior
Server (retry):
- Wrap the LLM calls in the three onboarding routes with a bounded retry (3 attempts, exponential backoff). A shared helper already exists at
server/src/lib/audit/retry.js(withRetry(fn, { attempts, baseDelayMs })) — promote it to a shared location (e.g.server/src/lib/retry.js) and reuse it. - For Competitors, wrap the whole two-phase op so a Phase-2 schema miss (
< 3results / malformed object) also re-runs, not just Phase 1. - After 3 failed attempts, return the error as today (
500with a clear message).
Frontend (graceful fallback):
- When suggestions fail after the server has exhausted its retries, do not leave the user stuck. Replace the bare error toast with an inline message on the step, e.g. "Couldn't fetch suggestions right now — add your own below."
- Keep the manual add path fully usable in that state (it already exists for competitors; make sure the empty-suggestion + disabled-CTA combo still lets the user add manually and continue).
Acceptance criteria
- Each onboarding LLM call retries up to 3 times with backoff before failing.
- A single transient LLM failure (429/5xx/timeout/empty or under-count structured output) is recovered automatically without the user noticing.
- After 3 genuine failures, the step shows a clear "add your own" message and the manual-entry form remains usable — the user can finish onboarding without suggestions.
- The shared retry helper is used by all three routes (no duplicated retry logic).
Notes
- Do not retry our own input-validation
400s (e.g. missingbrandName) — those return before the LLM call and are correct as-is. - Presentation/reliability only; no change to what the suggestions contain when they succeed.
Activity
Sam-syntax35 commentedon Jul 9, 2026
hey @gkhngyk !plz assign this to me
fix(onboarding): retry LLM suggestion calls and fall back to manual e…
fix(prompts): stop suggestion refresh failing on high-volume estimates (