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(signals): resolve scratchpad report titles only for report keys (#118021)

posthog[bot]28393e0b134f
diff --git a/products/signals/frontend/inbox/components/scratchpad/ScratchpadLedger.tsx b/products/signals/frontend/inbox/components/scratchpad/ScratchpadLedger.tsx
index 754205ecc49d..1326c7f3f6ea 100644
--- a/products/signals/frontend/inbox/components/scratchpad/ScratchpadLedger.tsx
+++ b/products/signals/frontend/inbox/components/scratchpad/ScratchpadLedger.tsx
@@ -12,7 +12,7 @@ import type { ScratchpadEntryApi } from 'products/signals/frontend/generated/api
import { SCRATCHPAD_PAGE_SIZE, scratchpadLogic } from '../../logics/scratchpadLogic'
import { PIPELINE_WRITER_PREFIX, isPipelineWriter, stripScoutPrefix } from '../../utils/scoutRunsWindow'
-import { KIND_TAG_TYPE, isReportUuid, scratchpadKindOf, scratchpadTopicOf } from '../../utils/scratchpadKeys'
+import { KIND_TAG_TYPE, scratchpadKindOf, scratchpadReportIdOf } from '../../utils/scratchpadKeys'
// Below 52rem the six columns stop fitting, so every row collapses into one stacked cell. Broken
// on the container, not the viewport: the panel gets about 520 px once the nav and a side panel
@@ -140,14 +140,14 @@ function KeyCell({
entry: ScratchpadEntryApi
reportTitles: Record<string, string | null>
}): JSX.Element {
- const topic = scratchpadTopicOf(entry.key)
- if (topic && isReportUuid(topic)) {
- const title = reportTitles[topic]
+ const reportId = scratchpadReportIdOf(entry.key)
+ if (reportId) {
+ const title = reportTitles[reportId]
return (
<Tooltip title={entry.key}>
- <Link to={urls.inboxReport('reports', topic)} subtle className="truncate text-xs">
+ <Link to={urls.inboxReport('reports', reportId)} subtle className="truncate text-xs">
{/* Enough of the UUID to tell two apart while the title is loading, or gone. */}
- Report: {title || topic.slice(0, 8)}
+ Report: {title || reportId.slice(0, 8)}
</Link>
</Tooltip>
)
diff --git a/products/signals/frontend/inbox/logics/scratchpadLogic.test.ts b/products/signals/frontend/inbox/logics/scratchpadLogic.test.ts
index b228752e41ef..e46a2405155f 100644
--- a/products/signals/frontend/inbox/logics/scratchpadLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/scratchpadLogic.test.ts
@@ -11,6 +11,7 @@ import { initKeaTests } from '~/test/init'
import type { ScratchpadEntryApi } from 'products/signals/frontend/generated/api.schemas'
import { PANEL_LOAD_TIMEOUT_MS } from '../utils/panelLoadTimeout'
+import { forgetUnreachableReports } from '../utils/unreachableReports'
import {
SCRATCHPAD_FETCH_LIMIT,
SCRATCHPAD_PREVIEW_CHARS,
@@ -65,6 +66,7 @@ describe('scratchpadLogic', () => {
afterEach(() => {
logic.unmount()
jest.useRealTimers()
+ forgetUnreachableReports()
})
it('asks for previews rather than full bodies on the list read', async () => {
@@ -485,15 +487,20 @@ describe('scratchpadLogic', () => {
// A stored null asserts the report is gone and stops the key being asked for again, so a
// transient failure that stores one pins the row to its shortened UUID for the whole session.
// Only a 404 is terminal; anything else has to stay unresolved for a later pass to retry.
+ // The 404 also has to outlive the mount, or every page load asks for the same dead id.
it.each([
[404, true],
[500, false],
])('remembers a missing report title after status %s: %s', async (status, remembered) => {
const reportId = '01a0918c-5f5f-74c4-b539-c634a8cb990a'
+ let reportRequests = 0
useMocks({
get: {
[SCRATCHPAD_URL]: () => [200, [entry(`judged:${reportId}`, 'note')]],
- '/api/projects/:team_id/signals/reports/:id/': () => [status, {}],
+ '/api/projects/:team_id/signals/reports/:id/': () => {
+ reportRequests += 1
+ return [status, {}]
+ },
},
})
@@ -502,6 +509,13 @@ describe('scratchpadLogic', () => {
expect(Object.hasOwn(logic.values.reportTitles, reportId)).toBe(remembered)
expect(logic.values.unresolvedReportIds).toEqual(remembered ? [] : [reportId])
+
+ logic.unmount()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(reportRequests).toBe(remembered ? 1 : 2)
+ expect(Object.hasOwn(logic.values.reportTitles, reportId)).toBe(remembered)
})
// The harness writes every scout row under the canonical project, so a report a scratchpad key
diff --git a/products/signals/frontend/inbox/logics/scratchpadLogic.ts b/products/signals/frontend/inbox/logics/scratchpadLogic.ts
index 1b73bc3dc615..6de40b8ec7ff 100644
--- a/products/signals/frontend/inbox/logics/scratchpadLogic.ts
+++ b/products/signals/frontend/inbox/logics/scratchpadLogic.ts
@@ -1,7 +1,6 @@
import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { ApiError } from 'lib/api-error'
import { dayjs } from 'lib/dayjs'
import { teamLogic } from 'scenes/teamLogic'
@@ -10,7 +9,8 @@ import type { ScratchpadEntryApi } from 'products/signals/frontend/generated/api
import { withPanelLoadTimeout } from '../utils/panelLoadTimeout'
import { SCOUT_ROSTER_WINDOW_HOURS, isPipelineWriter } from '../utils/scoutRunsWindow'
-import { BOOKKEEPING_KINDS, isReportUuid, scratchpadKindOf, scratchpadTopicOf } from '../utils/scratchpadKeys'
+import { BOOKKEEPING_KINDS, scratchpadKindOf, scratchpadReportIdOf, scratchpadTopicOf } from '../utils/scratchpadKeys'
+import { isReportUnreachable, rememberUnreachableReport } from '../utils/unreachableReports'
// Search reruns the server-side ILIKE on every keystroke; debounce so typing doesn't
// fire a request per character.
@@ -712,9 +712,9 @@ export const scratchpadLogic = kea<scratchpadLogicType>([
(filteredEntries: ScratchpadEntryApi[] | null, reportTitles: Record<string, string | null>): string[] => {
const ids: string[] = []
for (const entry of filteredEntries ?? []) {
- const topic = scratchpadTopicOf(entry.key)
- if (topic && isReportUuid(topic) && !Object.hasOwn(reportTitles, topic) && !ids.includes(topic)) {
- ids.push(topic)
+ const reportId = scratchpadReportIdOf(entry.key)
+ if (reportId && !Object.hasOwn(reportTitles, reportId) && !ids.includes(reportId)) {
+ ids.push(reportId)
if (ids.length >= REPORT_TITLE_RESOLVE_CAP) {
break
}
@@ -865,11 +865,19 @@ export const scratchpadLogic = kea<scratchpadLogicType>([
if (!projectId || projectId === '@current' || ids.length === 0) {
return
}
- for (const reportId of ids) {
+ // A 404 from an earlier mount, or from the findings feed, is already terminal.
+ const fetchIds = ids.filter((reportId) => {
+ if (isReportUnreachable(reportId)) {
+ actions.setReportTitle(reportId, null)
+ return false
+ }
+ return true
+ })
+ for (const reportId of fetchIds) {
inFlight.add(reportId)
}
await Promise.all(
- ids.map(async (reportId) => {
+ fetchIds.map(async (reportId) => {
try {
const report = await signalsReportsRetrieve(String(projectId), reportId)
actions.setReportTitle(reportId, report.title ?? null)
@@ -878,7 +886,7 @@ export const scratchpadLogic = kea<scratchpadLogicType>([
// for again, so only a 404 earns one. Anything else is transient: leave the
// id unresolved, so the next pass asks again rather than pinning the row to
// its shortened UUID for the rest of the session.
- if (error instanceof ApiError && error.status === 404) {
+ if (rememberUnreachableReport(reportId, error)) {
actions.setReportTitle(reportId, null)
}
} finally {
diff --git a/products/signals/frontend/inbox/utils/scratchpadKeys.test.ts b/products/signals/frontend/inbox/utils/scratchpadKeys.test.ts
index 48fba3bcce0d..dd73ad6d86ab 100644
--- a/products/signals/frontend/inbox/utils/scratchpadKeys.test.ts
+++ b/products/signals/frontend/inbox/utils/scratchpadKeys.test.ts
@@ -1,4 +1,6 @@
-import { scratchpadKindOf, scratchpadTopicOf } from './scratchpadKeys'
+import { scratchpadKindOf, scratchpadReportIdOf, scratchpadTopicOf } from './scratchpadKeys'
+
+const UUID = '01a0918c-5f5f-74c4-b539-c634a8cb990a'
// The prefixes the scout memory contract defines for the fleet. One missing from the registry
// parses as a topic rather than a kind, so every key carrying it reports its prefix as its topic
@@ -30,4 +32,19 @@ describe('scratchpadKeys', () => {
expect(scratchpadKindOf('billing_spikes:34316')).toBeNull()
expect(scratchpadTopicOf('billing_spikes:34316')).toBe('billing_spikes')
})
+
+ // Every id the ledger takes for a report costs a request, and an id of anything else answers 404
+ // on every page load. Only the per-report bookkeeping kinds name a report in the topic.
+ it.each([
+ [`judged:${UUID}`, UUID],
+ [`followup:${UUID}:pr`, UUID],
+ [`report:${UUID}`, UUID],
+ [`${UUID}:pattern:cursor`, null],
+ [`noise:${UUID}:email`, null],
+ [`baseline:${UUID}:email`, null],
+ [`products:${UUID}`, null],
+ ['report:error_tracking:issue', null],
+ ])('reads the report id of %s as %s', (key, reportId) => {
+ expect(scratchpadReportIdOf(key)).toBe(reportId)
+ })
})
diff --git a/products/signals/frontend/inbox/utils/scratchpadKeys.ts b/products/signals/frontend/inbox/utils/scratchpadKeys.ts
index 3a70c0e6b8d6..267f357d97cb 100644
--- a/products/signals/frontend/inbox/utils/scratchpadKeys.ts
+++ b/products/signals/frontend/inbox/utils/scratchpadKeys.ts
@@ -65,10 +65,14 @@ export const BOOKKEEPING_KINDS = new Set([
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
-/** Whether a key segment is a report UUID, which the ledger resolves to that report's title. */
-export function isReportUuid(segment: string): boolean {
- return UUID_PATTERN.test(segment)
-}
+/**
+ * Kinds whose topic segment names a report: the per-report bookkeeping a scout or the pipeline
+ * writes. A UUID alone does not make a report reference, because other kinds also put a UUID in
+ * the topic (`noise:<uuid>:…` and `baseline:<uuid>:…` name other entities), and a key with no
+ * recognized kind can start with one (`<uuid>:pattern:…`). Each id the ledger takes for a
+ * report costs one request to the reports endpoint, which answers 404 for every other kind of id.
+ */
+const REPORT_TOPIC_KINDS = new Set(['judged', 'report', 'reported', 'followup', 'addressed', 'already_addressed'])
/** The note's kind, or null when the key's first segment is not one the fleet uses as a kind. */
export function scratchpadKindOf(key: string): string | null {
@@ -86,3 +90,13 @@ export function scratchpadTopicOf(key: string): string | null {
const topic = scratchpadKindOf(key) ? segments[1] : segments[0]
return topic || null
}
+
+/** The report a key belongs to, which the ledger resolves to that report's title, or null. */
+export function scratchpadReportIdOf(key: string): string | null {
+ const kind = scratchpadKindOf(key)
+ if (kind === null || !REPORT_TOPIC_KINDS.has(kind)) {
+ return null
+ }
+ const topic = scratchpadTopicOf(key)
+ return topic && UUID_PATTERN.test(topic) ? topic : null
+}