Skip to content

fix(onboarding): retry LLM suggestion calls and add fallback - #385

Closed
Sam-syntax35 wants to merge 2 commits into
ansvisor:mainfrom
Sam-syntax35:fix/onboarding-llm-retry
Closed

Sam-syntax35 wants to merge 2 commits into
ansvisor:mainfrom
Sam-syntax35:fix/onboarding-llm-retry

Conversation

@Sam-syntax35

@Sam-syntax35 Sam-syntax35 commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR improves the reliability of onboarding LLM suggestion generation.

Backend

  • Added a shared withRetry helper in server/src/lib/retry.js.
  • Reused the helper across Topics, Prompts, and Competitors suggestion routes.
  • Wrapped the entire two-phase competitor suggestion flow in retries.

Frontend

  • Added inline fallback messaging when suggestion generation fails after retries.
  • Kept manual entry available so users can continue onboarding without AI-generated suggestions.

Related issue

Closes #379

Type of change

  • fix — Bug fix
  • feat — New feature
  • chore — Maintenance / dependencies
  • docs — Documentation only

Testing

  • Verified Topics suggestions still work.
  • Verified Prompts generation still works.
  • Verified Competitors manual entry remains usable after suggestion failure.

@Sam-syntax35
Sam-syntax35 force-pushed the fix/onboarding-llm-retry branch from e074e09 to 3341cc1 Compare July 9, 2026 15:41

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — the Topics and Competitors steps are wrapped correctly, the shared withRetry move is clean, and the inline fallback pattern is exactly right. One blocker before merge, though: the Prompts step targets the wrong route, so #379's most likely failure case is still unguarded.

The route onboarding actually calls is /from-topics, not /suggest.

  • Onboarding generates prompts via POST /api/prompts/from-topics (web/.../onboarding/page.tsx:651). There is zero reference to /api/prompts/suggest anywhere in web/src — /suggest is the dashboard "prompt suggestions" feature (it's even gated behind requireFeature('prompt_suggestions')), which onboarding never hits.
  • So the withRetry you added in prompts.js sits on a route onboarding doesn't use, while the real onboarding route (/from-topics, the generateObject at ~line 499) is still a bare call with no retry.
  • This matters because topicPromptSchema requires exactly 5 prompts per topic (z.array(...).length(5)). That's the strictest schema in the flow and the single most likely place to throw NoObjectGeneratedError and 500 without a retry — precisely the scenario in #379.

Two changes requested:

  1. Move the withRetry wrapper from the /suggest route to the /from-topics route (wrap the generateObject at ~line 499 with topicPromptSchema). Wrapping /suggest too is harmless, but /from-topics is the one that must be covered.
  2. Add the same inline fallback UI to the Prompts step. Right now that step still shows a bare toast.error('Failed to generate prompts from topics') (page.tsx:683) with no manual path forward — unlike the Topics/Competitors steps you fixed. After retries are exhausted the user should be able to continue (e.g. add prompts manually) instead of being stuck on the topics step.

Everything else looks good. Once the retry lands on /from-topics and the Prompts step gets the same fallback treatment, this is good to go.

@Sam-syntax35

Copy link
Copy Markdown
Contributor Author

I updated the retry logic and moved it to /from-topics. For the frontend, I now show an inline error and navigate to the prompt review step when generation fails. I noticed the onboarding prompt review doesn't currently have a manual prompt entry UI when there are no prompts. Would you like me to add manual prompt creation to that step as part of this PR?

@gkhngyk

gkhngyk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Thanks — pushing those changes will let me re-verify the /from-topics retry (the branch currently still shows the old state, so I think the commit isn't up yet).

And yes, please add manual prompt creation to the review step as part of this PR — that's exactly what closes #379 for the prompts path. Keep it minimal: when topicPrompts is empty, show a simple "add prompt" input (grouping entries under a single "Custom" topic is fine) so the user can proceed instead of being stuck on an empty list with Continue disabled. No need to rework the existing per-topic accordion.

@Sam-syntax35

Copy link
Copy Markdown
Contributor Author

done !! can you please check now?????

@gkhngyk

gkhngyk commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Just checking in — the /from-topics retry + prompts-step fallback you mentioned haven't landed on the branch yet (it still shows the earlier state). Still planning to finish this one? Happy to re-review as soon as it's pushed.

@gkhngyk

gkhngyk commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closing — the requested changes (/from-topics retry + prompts-step fallback) haven't landed after several check-ins, and #379 needs to move. Reopening #379 for a fresh implementation; happy to review a new PR if you get back to it.

@gkhngyk gkhngyk closed this Jul 16, 2026
gkhngyk added a commit that referenced this pull request Jul 16, 2026
…ntry (#443)

Closes #379. Supersedes the stalled #385.

Server: the shared withRetry helper moves from lib/audit to lib/retry
(audit imports updated) and now wraps every onboarding LLM call with 3
attempts + exponential backoff: topics /suggest and competitors
/suggest wrap their WHOLE two-phase flow (research + structuring), so a
Phase-2 schema miss like competitors' .min(3) under-count re-runs the
research too; prompts /suggest AND /from-topics — the generator the
onboarding prompts step actually uses, which the previous attempt
missed — get the same treatment. Input-validation 400s still return
before any LLM call and are never retried.

Web: when suggestions fail after the server exhausts its retries, the
bare error toasts are replaced with inline fallbacks that keep the
manual path usable. Topics and competitors steps show an amber
'add your own below' notice with a Try again button; a prompts-step
failure no longer strands the user on the topics step — they advance
with empty per-topic groups, an inline notice, and the existing
per-topic add inputs (Continue stays disabled until at least one
prompt exists).
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.

Onboarding: retry LLM suggestion calls, then fall back to manual entry when they fail

2 participants