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(tasks): Treat canceling seats as currently active in best-plan picker (#58558)

Charles Vien6c8bd38ee10c
diff --git a/products/tasks/backend/seat_api.py b/products/tasks/backend/seat_api.py
index 4b881380134f..2688dee9c390 100644
--- a/products/tasks/backend/seat_api.py
+++ b/products/tasks/backend/seat_api.py
@@ -30,7 +30,10 @@ PRO_PLAN_PREFIXES = ("posthog-code-200", "posthog-code-pro-")
def _seat_priority(seat: dict[str, Any]) -> tuple[bool, int, float]:
# Tuple comparison: active (True > False) first, then tier, then
# earliest created_at wins ties (oldest seat is the stable pick).
- active = seat.get("status") == "active"
+ # `canceling` is treated as currently active because the seat is still in
+ # effect until its `active_until` timestamp (notably during the alpha→free
+ # migration window where alpha seats are flipped to `canceling`).
+ active = seat.get("status") in ("active", "canceling")
plan_key = seat.get("plan_key") or ""
created_at = seat.get("created_at") or ""
try:
diff --git a/products/tasks/backend/tests/test_seat_api.py b/products/tasks/backend/tests/test_seat_api.py
index a9cb1653f26a..9b38f6a2ebe2 100644
--- a/products/tasks/backend/tests/test_seat_api.py
+++ b/products/tasks/backend/tests/test_seat_api.py
@@ -498,6 +498,25 @@ class TestSeatAPIBestPlan(BaseSeatAPITest):
assert response.json()["plan_key"] == "posthog-code-free-20260301"
assert response.json()["status"] == "active"
+ @patch("products.tasks.backend.seat_api.requests.request")
+ @patch("products.tasks.backend.seat_api.build_billing_token", return_value=MOCK_BILLING_TOKEN)
+ def test_canceling_pro_beats_active_free(self, _mock_token, mock_request, _mock_license):
+ canceling_pro = {
+ **MOCK_PRO_SEAT,
+ "status": "canceling",
+ "id": "seat_canceling_pro",
+ "active_until": "2026-06-04T00:00:00Z",
+ }
+ mock_request.side_effect = [
+ _billing_response({"seat": canceling_pro}),
+ _billing_response({"seat": MOCK_FREE_SEAT}),
+ ]
+ self._auth_as_member()
+ response = self.client.get("/api/seats/me/?product_key=posthog_code&best=true")
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()["plan_key"] == MOCK_PRO_SEAT["plan_key"]
+ assert response.json()["status"] == "canceling"
+
@patch("products.tasks.backend.seat_api.requests.request")
@patch("products.tasks.backend.seat_api.build_billing_token", return_value=MOCK_BILLING_TOKEN)
def test_future_exception_handled_gracefully(self, _mock_token, mock_request, _mock_license):