: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(dashboards): stop transient stream errors showing "dashboard not found" (#70207)
posthog[bot]013662015650
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 63853707cb1b..524de1b9d1f4 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -3551,8 +3551,11 @@ const api = {// If we can't read the response, just use the status}- // For any error, call onError and abort to prevent retries- onError(new Error(errorMessage))+ // Carry the real HTTP status so callers can classify the failure by status code+ // rather than string-matching the message (which misfires on transient/stream errors).+ const error = new Error(errorMessage) as Error & { status?: number }+ error.status = response.status+ onError(error)abortController.abort()return}diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex 0fd599862745..ca55593bc3b4 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -1161,6 +1161,90 @@ describe('dashboardLogic', () => {})})+ describe('tile streaming failure classification', () => {+ let lemonToastErrorSpy: jest.SpiedFunction<typeof lemonToast.error>++ beforeEach(silenceKeaLoadersErrors)+ afterEach(resumeKeaLoadersErrors)++ beforeEach(() => {+ lemonToastErrorSpy = jest.spyOn(lemonToast, 'error').mockImplementation(() => 'toast-id')+ logic = dashboardLogic({ id: 5 })+ logic.mount()+ })++ afterEach(() => {+ lemonToastErrorSpy.mockRestore()+ })++ // A genuine 404 from the stream's initial response is the only signal that flips the scene to+ // "Dashboard not found". A stream error whose message merely mentions 404 (e.g. a tile query that+ // failed upstream) carries no status and must stay a toast — string-matching '404' used to turn+ // these blips into a hard NotFound on valid, loaded dashboards.+ it('only marks NotFound on a real 404 status, not a message that mentions 404', async () => {+ await expectLogic(logic).toFinishAllListeners()++ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'Query failed with code 404 upstream' })+ }).toFinishAllListeners()+ expect(logic.values.error404).toBe(false)+ expect(logic.values.dashboardFailedToLoad).toBe(false)+ expect(lemonToastErrorSpy).toHaveBeenCalled()++ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'gone', status: 404 })+ }).toFinishAllListeners()+ expect(logic.values.error404).toBe(true)+ })++ it('routes a 403 status to access denied and other errors to a toast', async () => {+ await expectLogic(logic).toFinishAllListeners()++ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'forbidden', status: 403 })+ }).toFinishAllListeners()+ expect(logic.values.accessDeniedToDashboard).toBe(true)+ expect(logic.values.error404).toBe(false)++ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'HTTP 500: something broke', status: 500 })+ }).toFinishAllListeners()+ expect(lemonToastErrorSpy).toHaveBeenCalledWith(expect.stringContaining('something broke'))+ })++ // The failure that drove the reports: a transient stream error before any metadata arrives leaves+ // dashboard === null. The empty-state gate would then render "Dashboard not found"; instead the+ // load is marked failed so a load-error state shows, and it must NOT be classified as a 404.+ it('marks the load failed (not NotFound) when a transient error leaves no dashboard', async () => {+ // Dispatched before the initial load resolves (loaders breakpoint for 200ms), so dashboard is null.+ expect(logic.values.dashboard).toBeNull()++ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'network dropped mid-connect' })+ }).toDispatchActions(['setDashboardStreamFailed'])++ expect(logic.values.dashboardFailedToLoad).toBe(true)+ expect(logic.values.error404).toBe(false)+ })++ // fetchEventSource auto-retries transient failures, so the stream can recover on its own:+ // metadata arriving after a failure must clear the load-error state, not leave it latched+ // over a fully loaded dashboard.+ it('clears the failed state when a stream retry delivers metadata', async () => {+ await expectLogic(logic, () => {+ logic.actions.tileStreamingFailure({ message: 'network dropped mid-connect' })+ }).toDispatchActions(['setDashboardStreamFailed'])+ expect(logic.values.dashboardFailedToLoad).toBe(true)++ await expectLogic(logic, () => {+ logic.actions.loadDashboardMetadataSuccess(dashboardResult(5, []))+ }).toFinishAllListeners()++ expect(logic.values.dashboardFailedToLoad).toBe(false)+ expect(logic.values.dashboard).not.toBeNull()+ })+ })+describe('when a dashboard item API errors', () => {beforeEach(() => {logic = dashboardLogic({ id: 8 })diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex f5286fe3d2dd..c943d7a0fdea 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -717,6 +717,9 @@ export interface dashboardLogicActions {source: DashboardEventSource}}+ setDashboardStreamFailed: () => {+ value: true+ }setDataColorThemeId: (dataColorThemeId: number | null) => {dataColorThemeId: number | null}@@ -1170,6 +1173,8 @@ export const dashboardLogic = kea<dashboardLogicType>([tileStreamingComplete: true,/** Tile streaming failed. */tileStreamingFailure: (error: any) => ({ error }),+ /** A non-404 stream failure left no dashboard to render — show a load error, not "not found". */+ setDashboardStreamFailed: true,/** Expose additional information about the current dashboard load in dashboardLoadData. */loadingDashboardItemsStarted: (action: DashboardLoadAction) => ({ action }),/** Expose response size information about the current dashboard load in dashboardLoadData. */@@ -1768,8 +1773,13 @@ export const dashboardLogic = kea<dashboardLogicType>([dashboardFailedToLoad: [false,{+ loadDashboardStreaming: () => false,loadDashboardSuccess: () => false,+ // The stream auto-retries after transient errors; delivered metadata means it recovered,+ // so clear the load-error state instead of leaving it latched over a loaded dashboard.+ loadDashboardMetadataSuccess: () => false,loadDashboardFailure: () => true,+ setDashboardStreamFailed: () => true,},],dashboardLayouts: [@@ -3151,14 +3161,23 @@ export const dashboardLogic = kea<dashboardLogicType>([})},tileStreamingFailure: ({ error }) => {- if (error?.message?.includes('404') || error?.status === 404) {+ // Only a genuine HTTP status from the stream's initial response should flip the scene.+ // Transient network/stream errors carry no status, so a blip no longer masquerades as a+ // missing dashboard — it surfaces as a toast instead of a hard "Dashboard not found".+ if (error?.status === 404) {actions.dashboardNotFound()- } else if (error?.message?.includes('403') || error?.status === 403) {+ } else if (error?.status === 403) {actions.setAccessDeniedToDashboard()} else {// Show error toast for other errors (500s, network issues, etc.)const errorMessage = error?.message || 'Dashboard streaming failed'lemonToast.error(`Failed to load dashboard: ${errorMessage}`)+ // If the stream died before any metadata arrived there is no dashboard to render.+ // The empty-state gate would otherwise fall through to the "Dashboard not found" screen,+ // so mark the load as failed to show a load-error state instead.+ if (!values.dashboard) {+ actions.setDashboardStreamFailed()+ }}},