Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(aeo): drop stale prompt failures and retry topics on the prompts tab (#122872)

Lucas Ricoy2e7bc2a60e78
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
index 6c8825a548a9..d3b233ae7203 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
@@ -2,6 +2,7 @@ import { useActions, useValues } from 'kea'
import {
LemonBanner,
+ LemonButton,
LemonCard,
LemonSelect,
LemonSkeleton,
@@ -38,10 +39,12 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
promptsPage,
promptsTopic,
promptTopics,
+ promptTopicsError,
+ promptTopicsLoading,
promptEngines,
showArchived,
} = useValues(contentAutopilotPromptsLogic)
- const { loadAeoPrompts, setPromptsPage, setPromptsTopic, setShowArchived } =
+ const { loadAeoPrompts, loadAeoPromptTopics, setPromptsPage, setPromptsTopic, setShowArchived } =
useActions(contentAutopilotPromptsLogic)
const { openPromptDetail } = useActions(contentAutopilotPromptDetailLogic)
@@ -85,6 +88,20 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
]}
data-attr="content-autopilot-prompts-topic-filter"
/>
+ {promptTopicsError ? (
+ <span className="flex items-center gap-1 text-danger text-sm">
+ Couldn't load topics.
+ <LemonButton
+ size="xsmall"
+ type="secondary"
+ onClick={loadAeoPromptTopics}
+ loading={promptTopicsLoading}
+ data-attr="content-autopilot-prompts-topics-retry"
+ >
+ Try again
+ </LemonButton>
+ </span>
+ ) : null}
<LemonSwitch
checked={showArchived}
onChange={setShowArchived}
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
index c7b393d74ceb..45a3cf389710 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
@@ -86,6 +86,51 @@ describe('contentAutopilotPromptsLogic', () => {
}
})
+ it('drops a stale prompts failure after a newer request resolved', async () => {
+ const settlers: { resolve: () => void; reject: () => void }[] = []
+ mockPromptsList.mockImplementation(
+ () =>
+ new Promise((resolve, reject) => {
+ settlers.push({
+ resolve: () => resolve({ count: 1, next: null, previous: null, results: [EXAMPLE_PROMPTS[0]] }),
+ reject: () => reject(new ApiError('Server error', 500)),
+ })
+ })
+ )
+ logic = contentAutopilotPromptsLogic()
+ logic.mount()
+ logic.actions.setPromptsTopic('pricing')
+ await expectLogic(logic).toDispatchActions(['loadAeoPrompts', 'loadAeoPrompts'])
+ expect(settlers).toHaveLength(2)
+
+ settlers[1].resolve()
+ await expectLogic(logic).toDispatchActions(['loadAeoPromptsSuccess'])
+ settlers[0].reject()
+ await expectLogic(logic)
+ .toFinishAllListeners()
+ .toNotHaveDispatchedActions(['loadAeoPromptsFailure'])
+ .toMatchValues({ promptsError: null, prompts: expect.objectContaining({ count: 1 }) })
+ })
+
+ it('flags a topics failure and clears it when a retry succeeds', async () => {
+ mockPromptsTopics.mockRejectedValueOnce(new ApiError('Server error', 500))
+ silenceKeaLoadersErrors()
+ try {
+ logic = contentAutopilotPromptsLogic()
+ logic.mount()
+ await expectLogic(logic)
+ .toFinishAllListeners()
+ .toMatchValues({ promptTopicsError: true, promptTopics: [], promptsError: null })
+
+ logic.actions.loadAeoPromptTopics()
+ await expectLogic(logic)
+ .toFinishAllListeners()
+ .toMatchValues({ promptTopicsError: false, promptTopics: EXAMPLE_PROMPT_TOPICS })
+ } finally {
+ resumeKeaLoadersErrors()
+ }
+ })
+
it.each([
['saves', true, false],
['rolls back', false, true],
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
index 65a3311e0763..1208b9c4024b 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
@@ -47,6 +47,7 @@ export interface contentAutopilotPromptsLogicValues {
promptActiveUpdating: Record<string, boolean>
promptEngines: string[]
promptTopics: AEOPromptTopicApi[]
+ promptTopicsError: boolean
promptTopicsLoading: boolean
prompts: PaginatedAEOPromptListApi | null
promptsError: ContentAutopilotPromptsError | null
@@ -153,14 +154,20 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
null as PaginatedAEOPromptListApi | null,
{
loadAeoPrompts: async (_, breakpoint) => {
- const response = await aeoPromptsList(String(values.currentTeamIdStrict), {
- limit: PROMPTS_PAGE_SIZE,
- offset: (values.promptsPage - 1) * PROMPTS_PAGE_SIZE,
- topic: values.promptsTopic ?? undefined,
- include_archived: values.showArchived || undefined,
- })
- breakpoint()
- return response
+ try {
+ const response = await aeoPromptsList(String(values.currentTeamIdStrict), {
+ limit: PROMPTS_PAGE_SIZE,
+ offset: (values.promptsPage - 1) * PROMPTS_PAGE_SIZE,
+ topic: values.promptsTopic ?? undefined,
+ include_archived: values.showArchived || undefined,
+ })
+ breakpoint()
+ return response
+ } catch (error) {
+ // A superseded request's failure must not show an error over the newer results
+ breakpoint()
+ throw error
+ }
},
},
],
@@ -212,6 +219,13 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
loadAeoPromptsFailure: (_, { errorObject }) => promptsErrorFrom(errorObject),
},
],
+ promptTopicsError: [
+ false,
+ {
+ loadAeoPromptTopicsSuccess: () => false,
+ loadAeoPromptTopicsFailure: () => true,
+ },
+ ],
}),
selectors({
promptEngines: [