Skip to content

fix(onboarding): retry LLM suggestion calls and fall back to manual entry - #443

Merged
gkhngyk merged 1 commit into
mainfrom
fix/onboarding-suggestion-retry
Jul 16, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/onboarding-suggestion-retry

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #379. Supersedes the stalled #385 (closed).

Server — bounded retry on every onboarding LLM call. The withRetry helper is promoted from lib/audit/retry.js to server/src/lib/retry.js (audit imports updated, log label generalized) and now wraps all four suggestion generators with 3 attempts + exponential backoff:

  • topics /suggest and competitors /suggest wrap their whole two-phase flow (search-grounded research → structuring), so a Phase-2 schema miss — e.g. the competitors schema's .min(3) under-count throwing NoObjectGeneratedError — re-runs the research too, giving the structuring phase fresh material.
  • prompts /suggest and prompts /from-topics — the generator the onboarding prompts step actually calls, which the previous attempt missed.
  • Input-validation 400s return before any LLM call and are never retried.

Web — graceful fallback when retries are exhausted. Bare error toasts are replaced with inline notices that keep the manual path usable:

  • Topics and Competitors steps show an amber "Couldn't fetch suggestions right now — add your own below" notice with a Try again button; the existing manual-add inputs stay fully usable.
  • A prompts-step failure no longer strands the user on the topics step: they advance to the review step with empty per-topic groups, an inline notice, and the existing per-topic add inputs. Continue stays disabled until at least one prompt exists, so nobody proceeds with an empty tracking list unknowingly.

Related Issue

Closes #379

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🧹 Chore / refactor
  • 📝 Documentation
  • 🚨 Breaking change

How to Test

  1. Normal path: run onboarding end to end — suggestions arrive as before (retries are invisible on success).
  2. Transient failure: make the first LLM attempt fail (e.g. temporarily point TOPIC_SUGGESTION_MODEL at an invalid model for one attempt, or drop the network briefly) → the step succeeds on a later attempt; server logs [retry] topic-suggest attempt 1/3 failed; retrying.
  3. Hard failure (kill the LLM provider key): Topics step shows the inline notice + Try again, and custom topics can still be added; Competitors step likewise, manual name/domain entry still works with the CTA gating from Onboarding: require at least one competitor before finishing the competitors step #377/fix(web): require competitor during onboarding #378; the prompts step advances with empty topic groups and manual prompt entry enables Continue.
  4. cd server && npm test (115) and cd web && npm test (45) pass.

Checklist

  • My code follows the project's style guidelines (Prettier clean)
  • I have performed a self-review of my code
  • npx tsc --noEmit passes
  • Server tests pass (115/115), web tests pass (45/45)
  • Manually exercised the three failure paths in the dashboard

…ntry

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).
@gkhngyk
gkhngyk merged commit 48e9f06 into main Jul 16, 2026
4 checks passed
gkhngyk added a commit that referenced this pull request Jul 17, 2026
…duplicating brands (#467)

The Add-a-new-brand flow had no recovery path when topic suggestion
failed: a transient toast, an empty suggestion list, and a disabled
continue button left the user stranded on step 3. Worse, the natural
retry — Back to step 2, Continue again — called createBrand
unconditionally and inserted a duplicate brand on every round-trip.

- Topic and competitor suggestion failures now show the onboarding-style
  amber inline banner with a Try again button (#443 pattern) plus copy
  pointing at the manual input as the fallback, replacing the toasts.
- handleCreateBrand is idempotent: once createdBrand exists, re-submitting
  step 2 updates the brand in place (updateBrand, extended with
  region/language) and syncs the domain row only when the website actually
  changed (syncDomains), then advances. The brand store is updated so the
  switcher reflects edits immediately.

Step gating is unchanged: no advancing past step 3 with 0 topics or past
step 4 with 0 prompts.

Closes #447
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

1 participant