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): count external agent claims as the user's claim (#126159)

Georgiy Tarasov305bfe66d211
diff --git a/products/signals/backend/report_assignments.py b/products/signals/backend/report_assignments.py
index 7455c7f6c1d3..91234eed5300 100644
--- a/products/signals/backend/report_assignments.py
+++ b/products/signals/backend/report_assignments.py
@@ -36,6 +36,7 @@ from products.signals.backend.pull_requests import (
)
from products.signals.backend.report_claims import (
ReportClaim,
+ actor_can_release_claim,
actor_owns_claim,
actor_works_under_claim,
claim_from_artefact,
@@ -428,13 +429,13 @@ def claim_report(
before = assignment_snapshot(locked_report, assignment, include_pull_request=include_pull_request)
if claim_id and (assignment is None or str(assignment.claim_id) != claim_id):
raise ReportClaimConflict("This claim is no longer active.")
- if claim_id and assignment is not None and not actor_works_under_claim(assignment, actor):
+ if claim_id and assignment is not None and not release and not actor_works_under_claim(assignment, actor):
raise ReportClaimConflict("This claim belongs to another actor.")
if release:
if assignment is None:
return None
- if assignment.actor_kind and not actor_owns_claim(assignment, actor):
+ if assignment.actor_kind and not actor_can_release_claim(assignment, actor):
raise ReportClaimConflict("Only the current assignee can release this report.")
release_claim(assignment, actor)
assignment = None
diff --git a/products/signals/backend/report_claims.py b/products/signals/backend/report_claims.py
index aa684e31d307..0ec1a4492eb4 100644
--- a/products/signals/backend/report_claims.py
+++ b/products/signals/backend/report_claims.py
@@ -151,6 +151,15 @@ def actor_owns_claim(claim: ReportClaim, actor: ArtefactAttribution) -> bool:
)
+def actor_can_release_claim(claim: ReportClaim, actor: ArtefactAttribution) -> bool:
+ return actor_owns_claim(claim, actor) or (
+ actor.kind == "user"
+ and actor.user_id is not None
+ and claim.actor_kind == "agent"
+ and claim.actor_user_id == actor.user_id
+ )
+
+
def is_user_claim_of(claim: ReportClaim, user_id: int | None) -> bool:
"""Whether a person holds the claim directly, not through an agent or an internal task."""
return claim.actor_kind == "user" and user_id is not None and claim.actor_user_id == user_id
diff --git a/products/signals/backend/test/test_signal_report_assignment_api.py b/products/signals/backend/test/test_signal_report_assignment_api.py
index 17f7909a86aa..6faf37b09c05 100644
--- a/products/signals/backend/test/test_signal_report_assignment_api.py
+++ b/products/signals/backend/test/test_signal_report_assignment_api.py
@@ -742,7 +742,18 @@ class TestSignalReportAssignmentAPI(APIBaseTest):
assert pr.state == SignalReportAssignment.PrState.UNKNOWN
assert pr.state != "merged"
- def test_only_current_actor_can_release_and_pr_is_preserved(self):
+ @parameterized.expand(
+ [
+ ("claiming_agent", "claude-code", False, False, status.HTTP_200_OK),
+ ("responsible_user", None, False, False, status.HTTP_200_OK),
+ ("responsible_user_with_claim_id", None, False, True, status.HTTP_200_OK),
+ ("different_agent", "codex", False, True, status.HTTP_409_CONFLICT),
+ ("different_user", None, True, True, status.HTTP_409_CONFLICT),
+ ]
+ )
+ def test_only_current_actor_or_responsible_user_can_release_and_pr_is_preserved(
+ self, _name: str, agent: str | None, different_user: bool, include_claim_id: bool, expected_status: int
+ ) -> None:
report = self._create_report()
claim = self.client.post(
self._claim_url(report),
@@ -752,23 +763,24 @@ class TestSignalReportAssignmentAPI(APIBaseTest):
)
assert claim.status_code == status.HTTP_200_OK
- rejected = self.client.post(
- self._claim_url(report),
- data={"release": True},
- format="json",
- headers=self._agent_headers("codex"),
- )
- assert rejected.status_code == status.HTTP_409_CONFLICT
+ if different_user:
+ other_user = User.objects.create_and_join(self.organization, "[email protected]", None)
+ self.client.force_login(other_user)
released = self.client.post(
self._claim_url(report),
- data={"release": True},
+ data={"release": True, **({"claim_id": claim.json()["assignee"]["claim_id"]} if include_claim_id else {})},
format="json",
- headers=self._agent_headers("claude-code"),
+ headers=self._agent_headers(agent) if agent else {},
)
- assert released.status_code == status.HTTP_200_OK
+ assert released.status_code == expected_status
assignment = get_active_claim(team_id=self.team.id, report_id=report.id)
+ if expected_status == status.HTTP_409_CONFLICT:
+ assert assignment is not None
+ assert str(assignment.claim_id) == claim.json()["assignee"]["claim_id"]
+ assert not SignalReportArtefact.objects.filter(report=report, type="work_release").exists()
+ return
assert assignment is None
assert released.json()["implementation_pr_url"] == "https://github.com/PostHog/posthog/pull/123"
assert released.json()["implementation_pr_state"] == "unknown"
diff --git a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
index 8751ff0a6fe6..5514f681d45d 100644
--- a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
@@ -9,7 +9,7 @@ import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { myClaim, teammateClaim } from '../../__mocks__/inboxMocks'
+import { myAgentClaim, myClaim, teammateClaim } from '../../__mocks__/inboxMocks'
import { inboxFiltersLogic } from '../../logics/inboxFiltersLogic'
import { INBOX_SCOPE_ENTIRE_PROJECT, SignalReport, SignalReportStatus } from '../../types'
import { ReportContextMenu } from './ReportContextMenu'
@@ -153,6 +153,12 @@ describe('ReportContextMenu', () => {
item: 'Unclaim',
body: { release: true },
},
+ {
+ name: 'releases the claim made by the user through their agent',
+ report: makeReport({ assignee: myAgentClaim }),
+ item: 'Unclaim',
+ body: { release: true },
+ },
])('$name', async ({ report, item, body }) => {
openMenu(report)
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
index 090d8c8d2f14..a9d97d24b62a 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
@@ -350,7 +350,7 @@ describe('inboxReportDetailLogic', () => {
describe('claiming a report opened from an out-of-date list row', () => {
const claimBy = (
- kind: 'task' | 'user',
+ kind: 'task' | 'user' | 'agent',
claimId: string,
userUuid?: string
): NonNullable<SignalReport['assignee']> =>
@@ -359,7 +359,7 @@ describe('inboxReportDetailLogic', () => {
kind,
user: userUuid ? { id: 1, uuid: userUuid, first_name: 'Ada', email: '[email protected]' } : null,
task_id: kind === 'task' ? 'task-1' : null,
- agent: null,
+ agent: kind === 'agent' ? 'codex' : null,
claimed_at: '2026-01-01T00:00:00Z',
responsible_user: null,
}) as unknown as NonNullable<SignalReport['assignee']>
@@ -377,6 +377,12 @@ describe('inboxReportDetailLogic', () => {
expectedBodies: [{ takeover: false }],
expectedToast: 'Someone else is already working on this report.',
},
+ {
+ name: 'preserves a claim made by a person through their agent meanwhile',
+ serverAssignee: claimBy('agent', 'claim-agent', '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[] = []
diff --git a/products/signals/frontend/inbox/utils/reportClaim.test.ts b/products/signals/frontend/inbox/utils/reportClaim.test.ts
index 7d3bcba43faf..761fcdd2bd95 100644
--- a/products/signals/frontend/inbox/utils/reportClaim.test.ts
+++ b/products/signals/frontend/inbox/utils/reportClaim.test.ts
@@ -1,7 +1,7 @@
import type { SignalActorKindEnumApi, SignalReportAssigneeApi } from 'products/signals/frontend/generated/api.schemas'
import { SignalReportStatus } from '../types'
-import { isReportClaimable, reportClaimRequest } from './reportClaim'
+import { isReportClaimable, reportClaimant, reportClaimRequest } from './reportClaim'
describe('report claim', () => {
const assignee = (kind: SignalActorKindEnumApi): SignalReportAssigneeApi => ({
@@ -15,23 +15,39 @@ describe('report claim', () => {
})
it.each([
- { case: 'unclaimed', current: null, claimable: true, request: { takeover: false } },
- { case: 'held by a person', current: assignee('user'), claimable: false, request: { takeover: false } },
+ { case: 'unclaimed', current: null, claimable: true, claimant: null, request: { takeover: false } },
+ {
+ case: 'held by a person',
+ current: assignee('user'),
+ claimable: false,
+ claimant: assignee('user').user,
+ request: { takeover: false },
+ },
{
case: 'held by an agent',
current: assignee('agent'),
- claimable: true,
+ claimable: false,
+ claimant: assignee('agent').responsible_user,
+ request: { takeover: true, takeover_claim_id: 'claim-1' },
+ },
+ {
+ case: 'held by an agent without a responsible user',
+ current: { ...assignee('agent'), responsible_user: null },
+ claimable: false,
+ claimant: assignee('agent').user,
request: { takeover: true, takeover_claim_id: 'claim-1' },
},
{
case: 'held by a task',
current: assignee('task'),
claimable: true,
+ claimant: null,
request: { takeover: true, takeover_claim_id: 'claim-1' },
},
- ])('claims a report $case', ({ current, claimable, request }) => {
+ ])('claims a report $case', ({ current, claimable, claimant, request }) => {
const report = { assignee: current, status: SignalReportStatus.READY }
expect(isReportClaimable(report)).toBe(claimable)
+ expect(reportClaimant(report)).toEqual(claimant)
expect(reportClaimRequest(report, true)).toEqual(request)
})
diff --git a/products/signals/frontend/inbox/utils/reportClaim.ts b/products/signals/frontend/inbox/utils/reportClaim.ts
index 4084aa0c5cea..9672d67e06cc 100644
--- a/products/signals/frontend/inbox/utils/reportClaim.ts
+++ b/products/signals/frontend/inbox/utils/reportClaim.ts
@@ -18,6 +18,9 @@ const CLAIMABLE_STATUSES: ReadonlySet<SignalReportStatus> = new Set([
export function reportClaimant(report: Pick<SignalReport, 'assignee'>): _UserApi | null {
const assignee = report.assignee
+ if (assignee?.kind === 'agent') {
+ return assignee.responsible_user ?? assignee.user
+ }
return assignee?.kind === 'user' ? assignee.user : null
}