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): disable pr refunds for usage-based pricing (#130058)

Georgiy Tarasovea31c2690c63
diff --git a/docs/internal/signals-pr-lifecycle.md b/docs/internal/signals-pr-lifecycle.md
index 77bffbe831c9..bd7aa7b48f40 100644
--- a/docs/internal/signals-pr-lifecycle.md
+++ b/docs/internal/signals-pr-lifecycle.md
@@ -14,6 +14,8 @@ PR-driven dismissals emit `dismissal_cause=pr_closed_without_merge` when all lin
A person can resolve a report by recording a manual implementation or a useful finding that needs no action. Feedback from the state API, Slack, PR closures, report merges, refunds, and plan rollups saves its verdict so the activity log distinguishes resolutions from dismissals even after later state changes. Feedback predating recorded verdicts uses a neutral activity label.
The `no_action_needed` reason requires a resolved state. It leaves the report resolved, cancels its open follow-up checks, and is excluded from fixed outcomes in inbox ranking. Manual resolution closes an open implementation PR; the resulting GitHub close event preserves the resolved report status.
+PR refunds require `signals-pr-refunds` and are unavailable to organizations with `self-driving-ubp` enabled. The inbox hides the refund action for those organizations, and the refund API returns HTTP 403 before changing the report or creating a refund. If the pricing flag cannot be evaluated, the API returns HTTP 503 so the caller can retry without changing the report or creating a refund. Only a confirmed disabled `self-driving-ubp` result permits the existing refund eligibility rules to run.
+
Monitoring means implementation is complete and outcome verification is pending. With Monitoring enabled, Resolved means the report is finished and runs no follow-up checks. The organization-level `signals-report-monitoring` gate requires explicit enablement, including in local development, and treats missing definitions or evaluation failures as disabled. With Monitoring disabled, PR merges retain legacy resolution transitions, including archived reports.
Monitoring reports are excluded from Needs decision. Selecting Monitoring includes them in the inbox list, and clearing that selection removes them unless All statuses is selected.
diff --git a/products/signals/backend/test/test_dismissal_scout_notes.py b/products/signals/backend/test/test_dismissal_scout_notes.py
index ec37c4b67f6f..e6337d1d1ff8 100644
--- a/products/signals/backend/test/test_dismissal_scout_notes.py
+++ b/products/signals/backend/test/test_dismissal_scout_notes.py
@@ -282,7 +282,7 @@ class TestDismissalScoutNotes(APIBaseTest):
assert self._dismissal_notes_on(report) == ["context the scout should have"]
@time_machine.travel(_REFUND_NOW, tick=False)
- @patch("posthoganalytics.feature_enabled", return_value=True)
+ @patch("posthoganalytics.feature_enabled", side_effect=lambda key, *args, **kwargs: key != "self-driving-ubp")
def test_refund_feedback_reaches_the_authoring_scout(self, _flag) -> None:
self._create_scout_skill()
report = self._create_report()
@@ -305,7 +305,7 @@ class TestDismissalScoutNotes(APIBaseTest):
assert "pr_incorrect" in note.content
@time_machine.travel(_REFUND_NOW, tick=False)
- @patch("posthoganalytics.feature_enabled", return_value=True)
+ @patch("posthoganalytics.feature_enabled", side_effect=lambda key, *args, **kwargs: key != "self-driving-ubp")
def test_a_repeat_refund_does_not_forward_a_second_time(self, _flag) -> None:
self._create_scout_skill()
report = self._create_report()
@@ -323,7 +323,7 @@ class TestDismissalScoutNotes(APIBaseTest):
assert len(self._notes()) == 1
@time_machine.travel(_REFUND_NOW, tick=False)
- @patch("posthoganalytics.feature_enabled", return_value=True)
+ @patch("posthoganalytics.feature_enabled", side_effect=lambda key, *args, **kwargs: key != "self-driving-ubp")
def test_refund_without_a_note_forwards_nothing(self, _flag) -> None:
self._create_scout_skill()
report = self._create_report()
@@ -339,7 +339,7 @@ class TestDismissalScoutNotes(APIBaseTest):
assert self._dismissal_notes_on(report) == [None]
@time_machine.travel(_REFUND_NOW, tick=False)
- @patch("posthoganalytics.feature_enabled", return_value=True)
+ @patch("posthoganalytics.feature_enabled", side_effect=lambda key, *args, **kwargs: key != "self-driving-ubp")
def test_no_note_when_a_refund_leaves_a_merged_pr_report_resolved(self, _flag) -> None:
self._create_scout_skill()
report = self._create_report()
diff --git a/products/signals/backend/test/test_refunds.py b/products/signals/backend/test/test_refunds.py
index 31f58be876c7..ffa9091aa4fa 100644
--- a/products/signals/backend/test/test_refunds.py
+++ b/products/signals/backend/test/test_refunds.py
@@ -53,7 +53,7 @@ def _make_refund(
)
-@patch("posthoganalytics.feature_enabled", return_value=True)
+@patch("posthoganalytics.feature_enabled", side_effect=lambda key, *args, **kwargs: key != "self-driving-ubp")
class TestSignalReportRefundAPI(APIBaseTest):
def setUp(self):
super().setUp()
@@ -532,6 +532,43 @@ class TestSignalReportRefundAPI(APIBaseTest):
class TestSignalReportRefundFlagGate(APIBaseTest):
+ @parameterized.expand(
+ [
+ ("usage_based", True, status.HTTP_403_FORBIDDEN),
+ ("legacy", False, status.HTTP_200_OK),
+ ("unknown", None, status.HTTP_503_SERVICE_UNAVAILABLE),
+ ]
+ )
+ @time_machine.travel(_NOW, tick=False)
+ @patch("posthoganalytics.feature_enabled")
+ def test_refund_requires_legacy_pricing(self, _name, usage_based_pricing, expected_status, flag_mock):
+ flag_mock.side_effect = lambda key, *args, **kwargs: usage_based_pricing if key == "self-driving-ubp" else True
+ self.organization.usage = {"period": _PERIOD}
+ self.organization.save()
+ report = _make_report(self.team)
+ _make_pr_run(self.team, report, created_at=datetime(2026, 6, 15, 8, tzinfo=UTC))
+
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/signals/reports/{report.id}/refund/", {"reason": "other"}, format="json"
+ )
+
+ assert response.status_code == expected_status, response.json()
+ assert SignalReportRefund.objects.filter(report=report).exists() is (usage_based_pricing is False)
+ if usage_based_pricing is True:
+ assert response.json()["detail"] == "PR refunds are not available with usage-based pricing."
+ if usage_based_pricing is None:
+ assert response.json()["detail"] == "Unable to determine pricing. Please try again."
+ if usage_based_pricing is not False:
+ report.refresh_from_db()
+ assert report.status == SignalReport.Status.READY
+ org_id = str(self.organization.id)
+ flag_mock.assert_any_call(
+ "self-driving-ubp",
+ org_id,
+ groups={"organization": org_id},
+ group_properties={"organization": {"id": org_id}},
+ )
+
@patch("posthoganalytics.feature_enabled")
def test_refund_summary_available_with_only_enforcement_flag(self, flag_mock):
# The two flags roll out independently; an enforcement-only org still needs quota_limited
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index e25b59484f5f..5a73ec874f89 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -4799,7 +4799,9 @@ class SignalReportViewSet(
"the current billing period, or the report is system-marked never-billable."
)
),
+ 403: OpenApiResponse(description="PR refunds are not available with usage-based pricing."),
404: OpenApiResponse(description="Report not found, or refunds are not enabled for this organization."),
+ 503: OpenApiResponse(description="Pricing could not be determined. Retry the request."),
},
summary="Refund a report's implementation PR",
description=(
@@ -4818,6 +4820,20 @@ class SignalReportViewSet(
if not self._signals_pr_refunds_enabled():
raise NotFound("PR refunds are not enabled for this organization.")
+ org_id = str(self.organization.id)
+ usage_based_pricing = posthoganalytics.feature_enabled(
+ "self-driving-ubp",
+ org_id,
+ groups={"organization": org_id},
+ group_properties={"organization": {"id": org_id}},
+ )
+ if usage_based_pricing is True:
+ raise exceptions.PermissionDenied("PR refunds are not available with usage-based pricing.")
+ if usage_based_pricing is not False:
+ return Response(
+ {"detail": "Unable to determine pricing. Please try again."}, status=status.HTTP_503_SERVICE_UNAVAILABLE
+ )
+
report = cast(SignalReport, self.get_object())
data = request.validated_data
note = data.get("note") or ""
diff --git a/products/signals/frontend/inbox/components/cards/useReportRefund.test.ts b/products/signals/frontend/inbox/components/cards/useReportRefund.test.ts
new file mode 100644
index 000000000000..502c50305697
--- /dev/null
+++ b/products/signals/frontend/inbox/components/cards/useReportRefund.test.ts
@@ -0,0 +1,36 @@
+import { renderHook } from '@testing-library/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { makeReport } from '../../__mocks__/inboxMocks'
+import { useReportRefund } from './useReportRefund'
+
+describe('useReportRefund', () => {
+ beforeEach(() => {
+ initKeaTests()
+ featureFlagLogic.mount()
+ })
+
+ it.each([
+ { usageBasedPricing: true, refundsEnabled: true, canRefund: false },
+ { usageBasedPricing: false, refundsEnabled: true, canRefund: true },
+ { usageBasedPricing: undefined, refundsEnabled: true, canRefund: true },
+ { usageBasedPricing: false, refundsEnabled: false, canRefund: false },
+ ])(
+ 'offers refunds=$canRefund with usage-based pricing=$usageBasedPricing and refunds=$refundsEnabled',
+ ({ usageBasedPricing, refundsEnabled, canRefund }) => {
+ featureFlagLogic.actions.setFeatureFlags([], {
+ [FEATURE_FLAGS.SIGNALS_PR_REFUNDS]: refundsEnabled,
+ ...(usageBasedPricing === undefined ? {} : { [FEATURE_FLAGS.SELF_DRIVING_UBP]: usageBasedPricing }),
+ })
+ const report = makeReport({ implementation_pr_url: 'https://github.com/example/app/pull/1' })
+
+ const { result } = renderHook(() => useReportRefund({ report }))
+
+ expect(result.current.canRefund).toBe(canRefund)
+ }
+ )
+})
diff --git a/products/signals/frontend/inbox/components/cards/useReportRefund.ts b/products/signals/frontend/inbox/components/cards/useReportRefund.ts
index 805248045c22..fdaa9f248036 100644
--- a/products/signals/frontend/inbox/components/cards/useReportRefund.ts
+++ b/products/signals/frontend/inbox/components/cards/useReportRefund.ts
@@ -52,6 +52,7 @@ export function useReportRefund({
// without a PR was never billed either. One refund per report, ever.
const canRefund =
!!featureFlags[FEATURE_FLAGS.SIGNALS_PR_REFUNDS] &&
+ !featureFlags[FEATURE_FLAGS.SELF_DRIVING_UBP] &&
reportPullRequests(report).length > 0 &&
!report.refund &&
!report.billing_exempt_reason