Skip to content

fix(fanout): complete aggregation, bounded fetches, real error messages - #428

Merged
gkhngyk merged 2 commits into
mainfrom
fix/fanout-hardening
Jul 15, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
fix/fanout-hardening

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #427. Root cause of the reported error is confirmed: the org was at its maxPrompts limit, and the PlanLimitError thrown inside the trackFanoutQuery server action reached production users as Next's masked digest message ("An error occurred in the Server Components render…"), surfaced verbatim in a toast.

Four fixes, three of them defects found during diagnosis:

  • Plan-limit failures return as values. Production masks every error thrown from a server action, so trackFanoutQuery now returns user-facing failures as { error } instead of throwing — the real message ("Plan limit reached: maximum 200 for maxPrompts. Upgrade to increase.") survives to the toast. Unexpected errors still throw.
  • No more silent 1000-row truncation. getQueryFanout / getPromptFanout page through prompt_results with .range() (deterministic created_at, id order, 50k-row safety ceiling). PostgREST's un-paginated cap meant busy brands aggregated an incomplete fan-out.
  • Bounded intent classification. classifyFanoutIntents carries AbortSignal.timeout(20s) so a slow/hung aeo-server can never pin the server action until the platform kills it; the tab already degrades to no intent badges.
  • Masked digests never reach users. The fan-out tab maps "An error occurred in the Server…" messages to friendly copy in both the load and Track paths, logs the raw error to console, and passes genuine messages through.

Deliberately out of scope: reducing the Track path's sequential DB round-trips (optimization with behavior-change risk; noted in #427).

Related Issue

Fixes #427

Type of Change

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

How to Test

  1. On an org at its maxPrompts limit, open Prompts → Query Fan-out and hit + on a sub-query → the toast shows the actual plan-limit message (in production too), not the digest text.
  2. On an org under the limit, + adds the prompt and flips the row to Tracked ✓.
  3. On a brand with >1000 prompt_results rows in 30 days, the fan-out list includes sub-queries that only appear in rows beyond the first 1000.
  4. Stop the aeo-server and load the tab → table renders within ~20s with no intent badges instead of hanging.

Checklist

  • My code follows the project's style guidelines (Prettier clean)
  • I have performed a self-review of my code
  • npx tsc --noEmit passes
  • npm test passes (45/45)
  • Reproduced locally and verified the root cause before fixing

gkhngyk added 2 commits July 15, 2026 13:33
…umanize errors

Fixes #427 (three of its four findings; the Track-path round-trip
reduction is intentionally left out as a separate optimization):

- getQueryFanout/getPromptFanout now page through prompt_results with
  .range() instead of one un-paginated select, which PostgREST silently
  capped at 1000 rows — busy brands were aggregating an incomplete
  fan-out. A 50k-row ceiling bounds the worst case.
- classifyFanoutIntents carries AbortSignal.timeout(20s) so a hung
  aeo-server can never pin the server action until the platform kills
  it; the tab already degrades to no intent badges on rejection.
- The fan-out tab no longer surfaces Next's production-masked digest
  message ('An error occurred in the Server Components render...') in
  toasts — masked errors map to friendly copy, real messages still
  pass through, and the raw error goes to console for debugging.
… the real reason

Confirmed root cause of the reported error: the org was at its
maxPrompts limit, and the PlanLimitError thrown by addPromptToSet
reached production users as Next's masked digest message. Thrown
server-action errors are always masked in production, so trackFanoutQuery
now returns user-facing failures ({ error }) instead of throwing —
plan-limit and no-prompt-set messages survive to the toast verbatim.
Unexpected errors still throw and fall back to the friendly copy.
@gkhngyk
gkhngyk merged commit 2fa4c40 into main Jul 15, 2026
5 checks passed
gkhngyk added a commit that referenced this pull request Jul 17, 2026
…kground chunks (#448)

The Query Fan-out tab requested intent classification for every observed
sub-query in a single call. On a cold cache that one request serialized
dozens of LLM waves (120 queries ~= 40s+), blew past the server action's
20s fetch timeout (#428), and the badges never arrived that session.

Classify progressively instead: the visible page's 10 queries go first
(one request, at most ~2 LLM waves), then the remainder in background
chunks of 20, each merged into state as it resolves. The table never
waits on classification, a failed chunk only leaves its own rows
unbadged, and a reload/brand switch cancels the stale chain via a run
counter. Already-classified queries are skipped on silent reloads.

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

Query fan-out: long hang then production-masked server error surfaced raw in the UI

1 participant