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(mcp-analytics): force-refresh the onboarding poll so it flips instantly (#66460)

Lucas Faria4887f3b59f71
diff --git a/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.test.ts b/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.test.ts
new file mode 100644
index 000000000000..924004e4baf3
--- /dev/null
+++ b/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.test.ts
@@ -0,0 +1,51 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+
+import { initKeaTests } from '~/test/init'
+
+import { mcpAnalyticsOnboardingLogic } from './mcpAnalyticsOnboardingLogic'
+
+jest.mock('lib/api')
+
+const mockApi = api as jest.Mocked<typeof api>
+
+describe('mcpAnalyticsOnboardingLogic', () => {
+ beforeEach(() => {
+ jest.clearAllMocks()
+ initKeaTests()
+ })
+
+ function mountWith(results: unknown[][]): ReturnType<typeof mcpAnalyticsOnboardingLogic.build> {
+ jest.spyOn(mockApi, 'query').mockResolvedValue({ results } as any)
+ const logic = mcpAnalyticsOnboardingLogic()
+ logic.mount()
+ return logic
+ }
+
+ it('forces a fresh calculation so an ingestion-gap cached [0,0] never sticks', async () => {
+ const logic = mountWith([[1, 1]])
+ await expectLogic(logic).toFinishAllListeners()
+ // The onboarding poll must bypass the cache (force_blocking). Otherwise a
+ // pre-ingestion [0,0] cached during the capture->queryable gap keeps the page
+ // on "not onboarded" for a full cache cycle after events actually land.
+ expect(mockApi.query).toHaveBeenCalledWith(expect.anything(), { refresh: 'force_blocking' })
+ })
+
+ it.each([
+ [[[1, 1]], 'onboarded'],
+ [[[1, 0]], 'connected-no-calls'],
+ [[[0, 0]], 'not-instrumented'],
+ ])('maps signal row %j to state %s', async (results, expected) => {
+ const logic = mountWith(results)
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.onboardingState).toBe(expected)
+ expect(logic.values.isOnboarded).toBe(expected === 'onboarded')
+ })
+
+ it('treats a stringified "0" as false (no false-positive onboarding)', async () => {
+ const logic = mountWith([['0', '0']])
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.onboardingState).toBe('not-instrumented')
+ })
+})
diff --git a/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.ts b/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.ts
index b968896a2427..db974085d787 100644
--- a/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.ts
+++ b/products/mcp_analytics/frontend/mcpAnalyticsOnboardingLogic.ts
@@ -40,10 +40,21 @@ export const mcpAnalyticsOnboardingLogic = kea<mcpAnalyticsOnboardingLogicType>(
signals: {
__default: null as MCPOnboardingSignals | null,
loadSignals: async (_: void, breakpoint): Promise<MCPOnboardingSignals> => {
- const response = (await api.query({
- kind: NodeKind.HogQLQuery,
- query: ONBOARDING_SIGNAL_QUERY,
- })) as HogQLQueryResponse
+ // Force a fresh calculation instead of reading a cached result. The first
+ // events on a new project land a beat after capture returns 200, so a poll
+ // during that gap caches `[0,0]` — and with the default cache TTL the page
+ // would then keep serving that stale "not onboarded" answer for up to a
+ // minute after the data is actually queryable, dulling the "you're connected!"
+ // moment. Forcing keeps the flip near-instant. Polling stops as soon as we're
+ // onboarded (see loadSignalsSuccess), so this is bounded to the onboarding
+ // window, and the query itself is cheap (two event-name counts on the sort key).
+ const response = (await api.query(
+ {
+ kind: NodeKind.HogQLQuery,
+ query: ONBOARDING_SIGNAL_QUERY,
+ },
+ { refresh: 'force_blocking' }
+ )) as HogQLQueryResponse
breakpoint()
const row = (response?.results?.[0] as unknown[] | undefined) ?? []
// ClickHouse returns the `> 0` comparisons as 0/1; coerce numerically so a