: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(signals): stop repeating toast when inbox PR checks can't be fetched (#80949)
Chris Volzer4553573667fb
diff --git a/frontend/src/initKea.ts b/frontend/src/initKea.tsindex 45977aea6037..223df111efd8 100644--- a/frontend/src/initKea.ts+++ b/frontend/src/initKea.ts@@ -48,6 +48,8 @@ const ERROR_FILTER_ALLOW_LIST = ['loadDatasetItemVersions', // Dataset item modals render their own retry state'exportDataset', // Dataset scenes render their own retry state'loadToolDataEvents',+ 'loadPrChecks', // Polled in the Inbox report detail; the CI checks section renders its own error state+ 'loadPrComments', // The Inbox report detail's PR comments section renders its own error state]/*diff --git a/products/signals/frontend/inbox/components/detail/PrChecksSection.tsx b/products/signals/frontend/inbox/components/detail/PrChecksSection.tsxindex 5e70057507b1..f03fdb3dc540 100644--- a/products/signals/frontend/inbox/components/detail/PrChecksSection.tsx+++ b/products/signals/frontend/inbox/components/detail/PrChecksSection.tsx@@ -105,7 +105,8 @@ function CheckSummary({ variant, count }: { variant: CheckVariant; count: number/*** "CI checks" section for a report's implementation PR: the GitHub Actions check runs and legacy* commit statuses of the PR's head commit, polled every 15s by `inboxReportDetailLogic` while the- * detail is open. Read-only — each row links out to the check on GitHub.+ * detail is open (after repeated failures the poll backs off to a slow retry and the inline error+ * stays put until one succeeds). Read-only — each row links out to the check on GitHub.*/export function PrChecksSection({ report }: { report: SignalReport }): JSX.Element | null {const { prChecks, prChecksLoading, prChecksError } = useValues(diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.tsindex bb4b294753c3..0ea15499f61f 100644--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts@@ -1,5 +1,6 @@import { expectLogic } from 'kea-test-utils'+import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'@@ -8,59 +9,120 @@ import { inboxReportDetailLogic } from './inboxReportDetailLogic'const REPORT = { id: 'report-1', status: 'ready', title: 'Checkout errors spiked' } as unknown as SignalReport-describe('inboxReportDetailLogic feedback note submission', () => {- let logic: ReturnType<typeof inboxReportDetailLogic.build>- let notePosts: number- let bareRatingPosts: number-- beforeEach(() => {- notePosts = 0- bareRatingPosts = 0- useMocks({- get: {- '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },- '/api/projects/:team_id/signals/reports/:id/signals/': [],- '/api/projects/:team_id/signals/reports/available_reviewers/': [],- },- post: {- '/api/projects/:team_id/signals/reports/:id/feedback/': async ({ request }) => {- const body = (await request.json()) as { note?: string }- if (body.note) {- notePosts += 1- } else {- bareRatingPosts += 1- }- return [200, { forwarded: Boolean(body.note) }]+describe('inboxReportDetailLogic', () => {+ describe('feedback note submission', () => {+ let logic: ReturnType<typeof inboxReportDetailLogic.build>+ let notePosts: number+ let bareRatingPosts: number++ beforeEach(() => {+ notePosts = 0+ bareRatingPosts = 0+ useMocks({+ get: {+ '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },+ '/api/projects/:team_id/signals/reports/:id/signals/': [],+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],+ },+ post: {+ '/api/projects/:team_id/signals/reports/:id/feedback/': async ({ request }) => {+ const body = (await request.json()) as { note?: string }+ if (body.note) {+ notePosts += 1+ } else {+ bareRatingPosts += 1+ }+ return [200, { forwarded: Boolean(body.note) }]+ },},- },+ })+ initKeaTests()+ logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })+ logic.mount()+ })++ afterEach(() => {+ logic.unmount()})- initKeaTests()- logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })- logic.mount()- })- afterEach(() => {- logic.unmount()+ it('posts once on a double-click and lets a revised note through after re-rating', async () => {+ logic.actions.rateReport('positive')+ // A double-click dispatches submit twice before the first request settles.+ logic.actions.submitFeedbackNote('the repro steps were right')+ logic.actions.submitFeedbackNote('the repro steps were right')+ await expectLogic(logic).toFinishAllListeners()++ // The rating itself posts once (consumption evidence), the note once despite the double-click.+ expect(bareRatingPosts).toBe(1)+ expect(notePosts).toBe(1)+ expect(logic.values.feedbackNoteSubmitting).toBe(false)++ // Re-rating reopens the note flow; the guard must have reset or this submit is silently dropped.+ logic.actions.rateReport('negative')+ logic.actions.submitFeedbackNote('actually this was stale')+ await expectLogic(logic).toFinishAllListeners()++ expect(bareRatingPosts).toBe(2)+ expect(notePosts).toBe(2)+ })})- it('posts once on a double-click and lets a revised note through after re-rating', async () => {- logic.actions.rateReport('positive')- // A double-click dispatches submit twice before the first request settles.- logic.actions.submitFeedbackNote('the repro steps were right')- logic.actions.submitFeedbackNote('the repro steps were right')- await expectLogic(logic).toFinishAllListeners()-- // The rating itself posts once (consumption evidence), the note once despite the double-click.- expect(bareRatingPosts).toBe(1)- expect(notePosts).toBe(1)- expect(logic.values.feedbackNoteSubmitting).toBe(false)-- // Re-rating reopens the note flow; the guard must have reset or this submit is silently dropped.- logic.actions.rateReport('negative')- logic.actions.submitFeedbackNote('actually this was stale')- await expectLogic(logic).toFinishAllListeners()-- expect(bareRatingPosts).toBe(2)- expect(notePosts).toBe(2)+ describe('PR checks fetching', () => {+ const PR_REPORT = {+ id: 'report-2',+ status: 'ready',+ title: 'Checkout errors spiked',+ implementation_pr_url: 'https://github.com/example/repo/pull/1',+ } as unknown as SignalReport++ let logic: ReturnType<typeof inboxReportDetailLogic.build>+ let prChecksRequests: number++ beforeEach(() => {+ prChecksRequests = 0+ useMocks({+ get: {+ '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },+ '/api/projects/:team_id/signals/reports/:id/signals/': [],+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],+ '/api/projects/:team_id/signals/reports/:id/pr_checks/': () => {+ prChecksRequests += 1+ return [502, { error: 'GitHub could not return the checks for this pull request.' }]+ },+ '/api/projects/:team_id/signals/reports/:id/pr_comments/': { comments: [] },+ },+ })+ initKeaTests()+ silenceKeaLoadersErrors()+ logic = inboxReportDetailLogic({ reportId: PR_REPORT.id, report: PR_REPORT })+ logic.mount()+ })++ afterEach(() => {+ logic.unmount()+ resumeKeaLoadersErrors()+ })++ it('does not endlessly retry a failing checks fetch', async () => {+ await expectLogic(logic).toFinishAllListeners()+ expect(prChecksRequests).toBe(1)+ expect(logic.values.prChecksError).toBeTruthy()++ // The shell refreshes the report prop on its list poll; a failed load must not re-fire then.+ logic.actions.setReport(PR_REPORT)+ await expectLogic(logic).toFinishAllListeners()+ expect(prChecksRequests).toBe(1)++ // Two more failures (as the 15s poll would produce) reach the cap and back the poll off.+ logic.actions.loadPrChecks()+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.prChecksBackedOff).toBe(false)+ logic.actions.loadPrChecks()+ await expectLogic(logic).toFinishAllListeners()++ expect(prChecksRequests).toBe(3)+ expect(logic.values.prChecksBackedOff).toBe(true)+ expect(logic.values.prChecksError).toBeTruthy()+ })})})diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.tsindex 77bca0ddf168..9d368425b3e7 100644--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts@@ -106,6 +106,14 @@ const REPORT_TASKS_POLL_INTERVAL_MS = 5000// without hammering GitHub. Mirrors the desktop PR-review view's 15s poll.const PR_CHECKS_POLL_INTERVAL_MS = 15000+// Back off the checks poll after this many consecutive failures: a PR GitHub can't return+// checks for (deleted branch, lost integration access) re-fails on every 15s tick for nothing.+const PR_CHECKS_MAX_CONSECUTIVE_FAILURES = 3++// While backed off, still retry every Nth tick (20 × 15s = 5 min) so a transient GitHub outage+// heals the section without the report having to be closed and reopened.+const PR_CHECKS_FAILURE_BACKOFF_TICKS = 20+/** Extract the PR url from a task's latest run output, if present. Mirrors desktop `getTaskPrUrl`. */export function getTaskPrUrl(task: Task): string | null {const prUrl = task.latest_run?.output?.pr_url@@ -212,6 +220,8 @@ export interface inboxReportDetailLogicValues {optimisticReviewers: EnrichedReviewer[] | nullpostingThreadKey: string | nullprChecks: readonly PullRequestCheckApi[] | null+ prChecksBackedOff: boolean+ prChecksConsecutiveFailures: numberprChecksError: string | nullprChecksLoading: booleanprComments: readonly PullRequestCommentApi[] | null@@ -458,6 +468,7 @@ export interface inboxReportDetailLogicMeta {reportReviewers: (reportArtefacts: SignalReportArtefact[] | null) => EnrichedReviewer[] | nullisReportActive: (report: SignalReport | null) => booleanhasImplementationPr: (report: SignalReport | null) => boolean+ prChecksBackedOff: (prChecksConsecutiveFailures: number) => booleanhasPersonalGithub: (personalIntegrations: PersonalGitHubIntegration[]) => booleancurrentUserGithubLogin: (personalIntegrations: PersonalGitHubIntegration[]) => string | nullinlineThreadsByFile: (prComments: readonly PullRequestCommentApi[] | null) => Record<string, ReviewThread[]>@@ -795,14 +806,23 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([],// Human-readable PR checks/comments load failures (kea-loaders only exposes a boolean flag).// A failure usually means the branch/PR was deleted or the GitHub integration lost access.+ // Cleared only on success (not on load start), so the section keeps showing the error while+ // a backed-off retry is in flight instead of flashing back to the loading skeleton.prChecksError: [null as string | null,{- loadPrChecks: () => null,loadPrChecksSuccess: () => null,loadPrChecksFailure: () => "Couldn't load the PR checks from GitHub.",},],+ // Consecutive failed checks fetches — feeds `prChecksBackedOff`.+ prChecksConsecutiveFailures: [+ 0,+ {+ loadPrChecksSuccess: () => 0,+ loadPrChecksFailure: (state: number) => state + 1,+ },+ ],prCommentsError: [null as string | null,{@@ -867,6 +887,13 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([(s) => [s.report],(report: SignalReport | null): boolean => !!report?.implementation_pr_url,],+ // True once GitHub has failed enough consecutive times that the 15s cadence stops being worth+ // it — the poll tick then drops to a slow retry (see PR_CHECKS_FAILURE_BACKOFF_TICKS).+ prChecksBackedOff: [+ (s) => [s.prChecksConsecutiveFailures],+ (prChecksConsecutiveFailures: number): boolean =>+ prChecksConsecutiveFailures >= PR_CHECKS_MAX_CONSECUTIVE_FAILURES,+ ],// Whether the current user has a personal GitHub connection — required to post review comments// (they're attributed to the user's own GitHub identity, not the app's).hasPersonalGithub: [@@ -1339,11 +1366,13 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([// Load the PR checks/comments once the report has a shipped PR. The recurring checks poll// is registered once in `afterMount` (not here) so it isn't torn down and restarted every// time the shell hands us a fresh `report` prop — which would starve the 15s cadence.+ // A failed load leaves the value null, so gate on the error too: without it every prop+ // churn from the shell's list poll would re-fetch (and re-fail) a PR GitHub can't serve.if (values.hasImplementationPr) {- if (values.prChecks === null && !values.prChecksLoading) {+ if (values.prChecks === null && !values.prChecksLoading && values.prChecksError === null) {actions.loadPrChecks()}- if (values.prComments === null && !values.prCommentsLoading) {+ if (values.prComments === null && !values.prCommentsLoading && values.prCommentsError === null) {actions.loadPrComments()}}@@ -1365,14 +1394,22 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([// Seed the report from props so polling is gated on its status from the first tick.actions.setReport(props.report ?? null)// Register the PR-checks poll once for the lifetime of the mount — the tick re-checks whether- // the report has a PR, so it stays correct as the report prop churns without the interval ever- // being torn down and restarted (which would keep resetting the 15s cadence). Auto-disposed on- // unmount / hidden tab.+ // the report has a PR (and whether GitHub keeps failing), so it stays correct as the report+ // prop churns without the interval ever being torn down and restarted (which would keep+ // resetting the 15s cadence). Auto-disposed on unmount / hidden tab.cache.disposables.add(() => {+ let tick = 0const interval = setInterval(() => {- if (values.hasImplementationPr) {- actions.loadPrChecks()+ tick += 1+ if (!values.hasImplementationPr) {+ return+ }+ // While backed off, only every Nth tick retries — enough for a transient GitHub+ // outage to heal the section without hammering a permanently broken PR.+ if (values.prChecksBackedOff && tick % PR_CHECKS_FAILURE_BACKOFF_TICKS !== 0) {+ return}+ actions.loadPrChecks()}, PR_CHECKS_POLL_INTERVAL_MS)return () => clearInterval(interval)}, 'prChecksPoll')