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): treat a refused suggestions read as no access (#105705)

posthog[bot]617673d5eb4d
diff --git a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
index 218bac6b1e8f..b2144b113469 100644
--- a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
@@ -192,6 +192,78 @@ describe('scoutSuggestionsLogic', () => {
expect(logic.values.hasPicks).toBe(true)
})
+ // The 500 row is the point of this case: a guard wide enough to swallow it would leave a real
+ // suggestions outage looking identical to a project the member cannot read.
+ it.each([
+ [403, 'loadSuggestionsSuccess'],
+ [404, 'loadSuggestionsSuccess'],
+ [500, 'loadSuggestionsFailure'],
+ ])('resolves a %s from the batch read to %s', async (status, expectedAction) => {
+ mockList.mockRejectedValueOnce(new ApiError('nope', status))
+ logic = scoutSuggestionsLogic()
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions([expectedAction])
+ expect(logic.values.stripVisible).toBe(false)
+ })
+
+ // The members this guard serves send the read on every tab open, so leaving before the 403
+ // lands is routine and must not turn the refusal into a report.
+ it('reports nothing when a refusal lands after the strip unmounts', async () => {
+ let refuse: (error: ApiError) => void = () => {}
+ mockList.mockReturnValueOnce(
+ new Promise((_, reject) => {
+ refuse = reject
+ })
+ )
+ logic = scoutSuggestionsLogic()
+ logic.mount()
+
+ logic.unmount()
+ refuse(new ApiError('nope', 403))
+ await new Promise(setImmediate)
+
+ expect(posthog.captureException).not.toHaveBeenCalled()
+ })
+
+ // Access can go away between reads — a role change, or a project switch leaving a stale id in
+ // the URL. Every button on a pick would be refused, so the picks go with the access.
+ it('takes the strip away when a later read is refused', async () => {
+ await mountWithBatch()
+ expect(logic.values.stripVisible).toBe(true)
+
+ mockList.mockRejectedValueOnce(new ApiError('nope', 403))
+ logic.actions.loadSuggestions()
+
+ await expectLogic(logic).toDispatchActions(['loadSuggestionsSuccess'])
+ expect(logic.values.stripVisible).toBe(false)
+ })
+
+ // A refused read returns no batch, which the scan-settled check would otherwise read as a scan
+ // that found nothing (baseline set) or as a scan still running (no baseline).
+ it.each([
+ ['after an earlier scan', '2026-09-01T00:00:00Z'],
+ ['before any scan', null],
+ ])('stops waiting on a scan when a read during it is refused: %s', async (_name, generatedAt) => {
+ const info = jest.spyOn(lemonToast, 'info').mockReturnValue('toast-1')
+ const error = jest.spyOn(lemonToast, 'error').mockReturnValue('toast-1')
+ await mountWithBatch(suggestionSet({ generated_at: generatedAt }))
+ logic.actions.requestRefresh('strip')
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.isRefreshing).toBe(true)
+
+ mockList.mockRejectedValueOnce(new ApiError('nope', 403))
+ logic.actions.loadSuggestions()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.isRefreshing).toBe(false)
+ expect(logic.values.refreshScan).toBeNull()
+ expect(info).not.toHaveBeenCalled()
+ expect(error).not.toHaveBeenCalled()
+ info.mockRestore()
+ error.mockRestore()
+ })
+
// Whatever the batch row says, a batch with no picks has nothing to put on the roster.
it.each([
['never scanned', 'empty', null],
diff --git a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
index fe7860f0c6ba..96feebb2e8ca 100644
--- a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
+++ b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
@@ -333,7 +333,7 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
reportSuggestionsShown: (surface: ScoutSuggestionSurface) => ({ surface }),
}),
- loaders(({ values }) => ({
+ loaders(({ actions, values }) => ({
suggestionSet: [
null as ScoutSuggestionSetApi | null,
{
@@ -343,9 +343,30 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
if (!teamId || !values.suggestionsEnabled) {
return values.suggestionSet
}
- const set = await signalsScoutSuggestionsList(String(teamId))
- breakpoint()
- return set
+ try {
+ const set = await signalsScoutSuggestionsList(String(teamId))
+ breakpoint()
+ return set
+ } catch (error) {
+ // A member without resource-level scout access, or a stale project id left
+ // by a project switch, are expected — degrade to the empty batch instead of
+ // reporting them. Keeping the picks an earlier read returned would leave a
+ // strip whose every button is refused. Anything else, notably a 5xx, still
+ // throws so a real backend failure reaches error tracking.
+ if (error instanceof ApiError && (error.status === 403 || error.status === 404)) {
+ // The strip can unmount before the refusal lands, and a loader that
+ // resolves into a dead store is what reports next.
+ breakpoint()
+ // Without access the scan's batch can never be read. End the wait here,
+ // because the success listener would read the empty batch as the scan's
+ // result and show a false toast, or poll until the timeout.
+ if (values.isRefreshing) {
+ actions.refreshFinished()
+ }
+ return null
+ }
+ throw error
+ }
},
},
],