Skip to content

fix(prompts): surface savePromptSet failures instead of the masked digest error - #536

Merged
gkhngyk merged 3 commits into
mainfrom
fix/prompt-save-limit-error
Jul 27, 2026
Merged

gkhngyk merged 3 commits into
mainfrom
fix/prompt-save-limit-error

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A new user got stuck on the onboarding prompt-review step: pressing Continue showed the production-masked toast An error occurred in the Server Components render… and the prompts were never saved. Supabase API logs show the request chain stopping right at the prompt-limit check — enforceLimit threw PlanLimitError, and since errors thrown from server actions are masked in production, the user never saw the real reason (over the plan's prompt cap after adding their own prompts on top of the generated ones).

Two layers of fix:

Server action (savePromptSet)

  • Now returns { promptSet } | { error, code? } instead of throwing for user-facing failures (plan limit, empty platform/model selection, DB errors) — same pattern as addPromptToBrand (Query fan-out: long hang then production-masked server error surfaced raw in the UI #427). Plan-limit failures carry code: 'plan_limit'.
  • The prompt cap check is explicit and inclusive: saving exactly maxPrompts (e.g. 50 on Starter) passes; only totals above the cap are rejected.
  • Dropped the duplicate getOrgPlan round-trip.
  • New getPromptCapacity(brandId) action exposes { maxPrompts, used } (used = prompts on the org's other brands, since a save replaces the brand's own set).

Review step UX (onboarding + brand setup wizard) — no error toasts at all

  • The step fetches capacity when it opens and shows X prompts total · up to N included in your plan.
  • Going over the cap disables Continue and shows an inline amber hint: "Your plan includes up to N prompts — remove X to continue." The user fixes it in place; the save is never even attempted.
  • If a save still fails (race/backend), the step renders an inline message instead of a toast: the plan-limit text verbatim (actionable), anything else as a friendly "We couldn't save your prompts — please try again." Raw error strings never reach the user on this step.
  • The brand prompts page (dashboard) keeps toasts but now gets the real message instead of the masked digest.

Related issue

Follow-up to #427 (same masking bug, different action).

Type of change

  • fix — Bug fix

How to test

  1. On cloud with a Starter-limited org (or an org still in onboarding), generate prompts on the review step and add manual prompts until the total exceeds 50.
  2. The counter reads 51 prompts total · up to 50 included in your plan, an inline hint says to remove 1, and Continue is disabled — no toast anywhere.
  3. Remove the extra prompt(s) so the total is exactly 50 → Continue enables and the wizard advances to competitors.
  4. Repeat on Dashboard → Brands → New brand (same wizard, other brands' prompts count against the cap).
  5. Brands → [brand] → Prompts: saving suggestions into a brand with no prompt set and adding a manual prompt still work; over-limit saves toast the real message there.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/)
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

gkhngyk added 3 commits July 27, 2026 12:20
…e real message

Errors thrown from a server action are masked in production (digest-only),
so a PlanLimitError from the onboarding prompt-review step surfaced as the
meaningless "Server Components render" toast and the save silently failed.

- savePromptSet now returns { promptSet } | { error } (same pattern as
  addPromptToBrand, #427); plan-limit, empty-selection and DB failures come
  back as values and are toasted verbatim.
- The prompt cap is checked explicitly and inclusively: saving exactly
  maxPrompts passes, and the error spells out how many prompts to remove.
- Call sites (onboarding, brand setup wizard, brand prompts page) handle the
  error value and stop instead of advancing.
The review step should never surface a technical toast. The wizards now
fetch the org's effective prompt capacity (getPromptCapacity) when the
step opens, show 'X prompts total - up to N included in your plan', and
disable Continue with an inline amber hint while over the cap. Save
failures render inline too: the plan-limit message verbatim (actionable),
everything else as a friendly retry line — never a raw error message.
The wizard runs before any plan is picked, so advertising a cap there is
confusing; the inline over-limit hint still appears when it matters.
@gkhngyk
gkhngyk merged commit 16385e5 into main Jul 27, 2026
3 checks passed
gkhngyk pushed a commit that referenced this pull request Jul 31, 2026
…566)

* fix(web): return invite/accept errors as values instead of throwing

inviteMember and acceptInvitation threw on common, user-reachable
failures (duplicate invite, wrong account, expired token, etc.). In
production a thrown server action surfaces as the masked digest
string, hiding the actionable message. Both now return `{ error }`
and the call sites branch on it, following the pattern from #536.

Closes #550

* style: apply prettier formatting to team.ts
gkhngyk added a commit that referenced this pull request Aug 3, 2026
#580)

Production masks errors thrown from server actions, so plan-limit and
validation failures from addPromptToSet reached users as the meaningless
digest toast (#427 pattern). Convert it to the same
{ prompt } | { error, code? } shape savePromptSet adopted in #536:

- addPromptToSet returns { prompt } | { error, code?: 'plan_limit' };
  PlanLimitError from enforceLimit maps to code 'plan_limit'
- addPromptToBrand and trackFanoutQuery drop their try/catch wrappers and
  forward the error value
- acceptSuggestion keeps its existing throwing contract, adapted to the
  new shape
- brand Prompts page (bulk suggestion save + manual add) shows the real
  message via toast; the bulk path also refreshes the list on partial
  failure so saved prompts appear

Closes #547
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.

1 participant