Skip to content

fix(llm-analytics): show error state on sentiment API failure - #58405

Merged
carlos-marchal-ph merged 1 commit into
PostHog:masterfrom
okxint:fix/llm-sentiment-error-state
May 21, 2026
Merged

fix(llm-analytics): show error state on sentiment API failure#58405
carlos-marchal-ph merged 1 commit into
PostHog:masterfrom
okxint:fix/llm-sentiment-error-state

Conversation

@okxint

@okxint okxint commented May 13, 2026

Copy link
Copy Markdown
Contributor

Problem

When the sentiment generations endpoint (/api/environments/{id}/llm_analytics/sentiment/generations/) returns a 500 error, the kea loader dispatches loadGenerationsFailure but the generations state stays as []. The UI treats generations.length === 0 as "no data" and renders the empty-state copy ("No generations with user input found"), which misleads users into thinking there is simply nothing to show rather than signalling that something went wrong.

Closes #58341

Changes

llmAnalyticsSentimentLogic.ts — add generationsError reducer:

  • Set to true on loadGenerationsFailure
  • Reset to false on loadGenerations (new fetch started) and loadGenerationsSuccess

LLMAnalyticsSentiment.tsx — check generationsError before the empty-state branch:

  • Show "Failed to load generations — try refreshing the page" when the API call errored
  • Leave the existing empty-state and loading paths unchanged

How did you test this code?

Traced the kea loader lifecycle: loaders dispatch *Failure actions on thrown errors; kea does not expose a built-in error state on the generated selectors, so the new reducer is the standard kea pattern for this. Ran the frontend formatter (passed).

Publish to changelog?

No

Docs update

No docs change needed.

🤖 Agent context

Identified the gap by reading the loader definition and the UI branch: generations === [] covered both the "no data" and "load failed" cases with identical copy. Added a minimal reducer to distinguish the two states without touching the loader logic or the fetch function.

When the generations API returns a server error, the kea loader
dispatches loadGenerationsFailure but the generations state stays
as [], which the UI interprets as "no data" and shows a misleading
empty state message.

Add a generationsError reducer that is set on loadGenerationsFailure
and cleared on loadGenerations/loadGenerationsSuccess. Update the
sentiment component to render a distinct error message when the load
failed, so users know to refresh rather than think there is no data.

Closes PostHog#58341
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team May 13, 2026 17:39
@greptile-apps

greptile-apps Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(llm-analytics): show error state on ..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@github-actions github-actions Bot added the stale label May 21, 2026
@carlos-marchal-ph
carlos-marchal-ph enabled auto-merge (squash) May 21, 2026 15:04
@carlos-marchal-ph
carlos-marchal-ph merged commit de6e878 into PostHog:master May 21, 2026
156 checks passed
@deployment-status-posthog

deployment-status-posthog Bot commented May 21, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-21 15:53 UTC Run
prod-us ✅ Deployed 2026-05-21 16:10 UTC Run
prod-eu ✅ Deployed 2026-05-21 16:10 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: llma - sentiment panel returns '500', UI shows empty state

2 participants