Skip to content

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

Closed

Description

@gkhngyk

Bug

On the prompts page's Query Fan-out tab (and its two views, frequency / by-prompt), the tab can hang for a long time and then show this raw message in a toast — reproduced in production, also when promoting a sub-query with the Track (+) button:

An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance…

Both views die together because they share one load() path.

What's wrong (multiple compounding defects)

  1. Raw digest message reaches the user. web/src/app/[locale]/(dashboard)/dashboard/prompts/_fanout-tab.tsx catches the failed server action and does toast.error(err.message) — in production that message is Next's masked digest text, meaningless to users. It should map to a friendly "couldn't load fan-out" string (and the digest belongs in server logs, not the toast).

  2. getQueryFanout scans brand-wide and truncates silently. https://github.com/ansvisor/ansvisor/blob/main/web/src/lib/actions/fanout.ts fetches every prompt_results row for the brand in the window with the full search_queries jsonb and aggregates in JS. Two problems:

    • For busy brands this is slow and can push the server action toward the function time limit — matching the observed "long hang then error".
    • Supabase/PostgREST caps un-paginated selects at 1000 rows silently, so the aggregation is quietly incomplete on exactly the brands where fan-out matters most. Fix: paginate with .range() (or move the aggregation into an RPC like the insights surfaces from perf(insights): aggregate insights data in Postgres instead of pulling rows into Node #114).
  3. classifyFanoutIntents fetch has no timeout. The server action fetches ${API_BASE_URL}/api/prompts/fanout-intents, which classifies up to 200 cache-miss queries via LLM at concurrency 6 — minutes on a cold cache. If the express server is slow or hung, the action hangs until the platform kills it. The initial load races it against a 1.5s timeout (good), but the action itself should still carry an AbortController timeout (~20s) so it can never pin a function.

  4. Track (+) path: trackFanoutQuery → addPromptToSet chains 7+ sequential DB round-trips (set lookup, brand context, org prompt count, plan fetch, topic resolve, shopping-mode read, insert). Worth a look while in here, since the masked error also reproduces on Track.

Diagnosis needed

The Vercel function logs for the failing request contain the real error + digest — attaching that will pinpoint which of (2)/(3)/(4) actually fired in the reported case. The fixes above are worth doing regardless.

Acceptance criteria

  • Fan-out tab failures show a human-readable error, never the digest text.
  • getQueryFanout aggregates over all rows in the window (no silent 1000-row cap) without approaching function time limits on large brands.
  • classifyFanoutIntents cannot hang indefinitely (bounded fetch timeout, graceful fallback to no intent badges).
  • Track (+) completes or fails fast with a clear message.

Activity

  1. added
    bug
    on Jul 15, 2026
  2. self-assigned this
    on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions