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): retry report claim with the current claim after a conflict (#124422)

Dylan Martin846509eb12be
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
index 28de2f54d4bd..1d88a00b09a8 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
@@ -267,6 +267,79 @@ describe('inboxReportDetailLogic', () => {
})
})
+ describe('claiming a report opened from an out-of-date list row', () => {
+ const claimBy = (
+ kind: 'task' | 'user',
+ claimId: string,
+ userUuid?: string
+ ): NonNullable<SignalReport['assignee']> =>
+ ({
+ claim_id: claimId,
+ kind,
+ user: userUuid ? { id: 1, uuid: userUuid, first_name: 'Ada', email: '[email protected]' } : null,
+ task_id: kind === 'task' ? 'task-1' : null,
+ agent: null,
+ claimed_at: '2026-01-01T00:00:00Z',
+ responsible_user: null,
+ }) as unknown as NonNullable<SignalReport['assignee']>
+
+ it.each([
+ {
+ name: 'takes over the task claim the list row did not show',
+ serverAssignee: claimBy('task', 'claim-task'),
+ expectedBodies: [{ takeover: false }, { takeover: true, takeover_claim_id: 'claim-task' }],
+ expectedToast: null,
+ },
+ {
+ name: 'reports a person who claimed the report meanwhile',
+ serverAssignee: claimBy('user', 'claim-person', 'other-user'),
+ expectedBodies: [{ takeover: false }],
+ expectedToast: 'Someone else is already working on this report.',
+ },
+ ])('$name', async ({ serverAssignee, expectedBodies, expectedToast }) => {
+ const myClaim = claimBy('user', 'claim-mine', 'me')
+ const bodies: unknown[] = []
+ const claim = jest.fn(async ({ request }: MockResolverInfo): Promise<[number, unknown]> => {
+ const body = (await request.json()) as { takeover?: boolean }
+ bodies.push(body)
+ return body.takeover
+ ? [200, { ...REPORT, assignee: myClaim, updated_at: '2026-01-02T00:00:00Z' }]
+ : [409, { detail: 'This report already has an active claim.' }]
+ })
+ useMocks({
+ get: {
+ '/api/projects/:team_id/signals/reports/:id/feedback_state/': { sentiment: null, note: '' },
+ '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },
+ '/api/projects/:team_id/signals/reports/:id/signals/': { signals: [] },
+ '/api/projects/:team_id/signals/reports/:id/checks/': { results: [] },
+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],
+ '/api/projects/:team_id/signals/reports/:id/': { ...REPORT, assignee: serverAssignee },
+ },
+ post: { '/api/projects/:team_id/signals/reports/:id/claim/': claim },
+ })
+ initKeaTests()
+ const errorToast = jest.spyOn(lemonToast, 'error')
+ const logic = inboxReportDetailLogic({ reportId: REPORT.id, report: { ...REPORT, assignee: null } })
+ logic.mount()
+ try {
+ await expectLogic(logic).toFinishAllListeners()
+ logic.actions.setReportClaimed(true)
+ await waitFor(() => expect(logic.values.claimSaving).toBe(false))
+
+ expect(bodies).toEqual(expectedBodies)
+ if (expectedToast) {
+ expect(errorToast).toHaveBeenCalledWith(expectedToast)
+ } else {
+ expect(errorToast).not.toHaveBeenCalled()
+ expect(logic.values.report?.assignee).toEqual(myClaim)
+ }
+ } finally {
+ errorToast.mockRestore()
+ logic.unmount()
+ }
+ })
+ })
+
describe('reviewer updates', () => {
const reviewer: EnrichedReviewer = {
github_login: 'example-reviewer',
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
index 01ee1e0436a3..f0e87f4b8227 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
@@ -40,6 +40,7 @@ import {
signalsReportPrReviewCommentsCreate,
signalsReportPrReviewCommentUpdate,
signalsReportsClaim,
+ signalsReportsRetrieve,
signalsReportsFeedbackCreate,
signalsReportsFeedbackStateRetrieve,
signalsReportsSignalsRetrieve,
@@ -111,6 +112,26 @@ function prChecksErrorFrom(error: unknown): PrChecksError {
return { message: "Couldn't load the PR checks from GitHub.", remediationUrl: null }
}
+type FreshClaimAttempt = { fresh: SignalReportApi | null; updated: SignalReportApi | null }
+
+/** Claims again from the server's current record. The page can still show the list's copy, whose claim may be out of date. */
+async function claimFromFreshReport(teamId: string, reportId: string): Promise<FreshClaimAttempt> {
+ let fresh: SignalReportApi
+ try {
+ fresh = await signalsReportsRetrieve(teamId, reportId)
+ } catch {
+ return { fresh: null, updated: null }
+ }
+ if (!isReportClaimable({ status: fresh.status as SignalReportStatus, assignee: fresh.assignee })) {
+ return { fresh, updated: null }
+ }
+ try {
+ return { fresh, updated: await signalsReportsClaim(teamId, reportId, reportClaimRequest(fresh, true)) }
+ } catch {
+ return { fresh, updated: null }
+ }
+}
+
// The task↔report association is the `task_run` artefact log now (the legacy `/tasks/` endpoint is
// gone), and the activity timeline renders the whole log. Pull a generous page so early entries
// (the first task runs, repo selection) stay visible on reports with many findings — matching the
@@ -1613,7 +1634,7 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
surface: 'detail_pane',
})
const scene = inboxSceneLogic.findMounted()
- let updated: SignalReportApi
+ let updated: SignalReportApi | null = null
try {
updated = await signalsReportsClaim(
String(teamId),
@@ -1621,17 +1642,26 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
reportClaimRequest(currentReport, claimed)
)
} catch (error) {
- if (inboxReportDetailLogic.isMounted(props)) {
- actions.setClaimSaving(false)
- if (error instanceof ApiError && error.status === 409) {
- lemonToast.error('Someone else is already working on this report.')
- // Reload so the page shows who holds the claim now.
- scene?.actions.loadSelectedReport({ id: props.reportId })
- } else {
- lemonToast.error("Couldn't update who's working on this report. Try again.")
+ const conflict = error instanceof ApiError && error.status === 409
+ const retry = conflict && claimed ? await claimFromFreshReport(String(teamId), props.reportId) : null
+ updated = retry?.updated ?? null
+ if (!updated) {
+ if (inboxReportDetailLogic.isMounted(props)) {
+ actions.setClaimSaving(false)
+ if (!conflict) {
+ lemonToast.error("Couldn't update who's working on this report. Try again.")
+ } else if (!retry || (retry.fresh && reportClaimant(retry.fresh))) {
+ lemonToast.error('Someone else is already working on this report.')
+ } else {
+ lemonToast.error('This report changed. Check it and try again.')
+ }
+ if (conflict) {
+ // Reload so the page shows who holds the claim now.
+ scene?.actions.loadSelectedReport({ id: props.reportId })
+ }
}
+ return
}
- return
}
if (!inboxReportDetailLogic.isMounted(props)) {
return