: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(devex): put every paginator class on a bounded base (#126490)
Julian Bezf96ac33a8d9e
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 0ddb70da4c71..c9710d0d157a 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -7133,6 +7133,7 @@ export type PropertyDefinitionsListParams = {is_numerical?: boolean | null/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/posthog/api/advanced_activity_logs/test_pagination_schema.py b/posthog/api/advanced_activity_logs/test_pagination_schema.pyindex 30803f3dc09c..a8c2f3644f5b 100644--- a/posthog/api/advanced_activity_logs/test_pagination_schema.py+++ b/posthog/api/advanced_activity_logs/test_pagination_schema.py@@ -17,8 +17,8 @@ class TestActivityLogPaginationSchema(SimpleTestCase):def test_cursor_response_body_has_no_count(self):pagination = ActivityLogPagination()pagination.request = Request(APIRequestFactory().get("/"))- pagination.cursor_pagination.page = []- pagination.cursor_pagination.has_next = False- pagination.cursor_pagination.has_previous = False+ pagination.page = []+ pagination.has_next = False+ pagination.has_previous = Falseassert "count" not in pagination.get_paginated_response([]).datadiff --git a/posthog/api/advanced_activity_logs/viewset.py b/posthog/api/advanced_activity_logs/viewset.pyindex 457099c5d84a..a3a39c47dc33 100644--- a/posthog/api/advanced_activity_logs/viewset.py+++ b/posthog/api/advanced_activity_logs/viewset.py@@ -11,12 +11,13 @@ from django.db.models import Q, QuerySetfrom drf_spectacular.utils import extend_schemafrom rest_framework import mixins, serializers, viewsetsfrom rest_framework.decorators import action-from rest_framework.pagination import BasePagination, Cursor, CursorPagination, PageNumberPagination+from rest_framework.pagination import Cursorfrom rest_framework.permissions import BasePermissionfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom posthog.api.fields import JSONStringFilterField, JSONTolerantListField, OptionalBooleanField+from posthog.api.pagination import BoundedPageNumberPagination, StableCursorPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializerfrom posthog.constants import AvailableFeature@@ -155,7 +156,7 @@ class ActivityLogSerializer(serializers.ModelSerializer):return bookmark_date < obj.created_at.replace(microsecond=obj.created_at.microsecond // 1000 * 1000)-class TailFollowingCursorPagination(CursorPagination):+class TailFollowingCursorPagination(StableCursorPagination):"""Cursor pagination that can keep a forward cursor alive after the stream is exhausted.Stock DRF returns `next: null` on the final page, which leaves a polling client nothing to@@ -173,6 +174,8 @@ class TailFollowingCursorPagination(CursorPagination):timestamp-positioned cursor and matches DRF's behavior mid-stream."""+ # A follower polls this on every request, so a count would scan the activity log each time.+ include_count = Falsefollow = Falsedef get_next_link(self) -> Optional[str]:@@ -191,41 +194,45 @@ class TailFollowingCursorPagination(CursorPagination):return self.encode_cursor(Cursor(offset=0, reverse=False, position=position)) # type: ignore[arg-type]-class ActivityLogPagination(BasePagination):- def __init__(self):- self.page_number_pagination = PageNumberPagination()- self.cursor_pagination = TailFollowingCursorPagination()- self.page_number_pagination.page_size = 100- self.page_number_pagination.page_size_query_param = "page_size"- self.page_number_pagination.max_page_size = 1000- self.cursor_pagination.page_size = 100- self.cursor_pagination.page_size_query_param = "page_size"- self.cursor_pagination.max_page_size = 1000- # `created_at` is not unique, and DRF encodes only the first ordering field in the cursor,- # resolving ties with an offset. That offset is reproducible only when rows sharing a- # timestamp come back in a stable order, which Postgres does not otherwise guarantee.- self.cursor_pagination.ordering = ("-created_at", "-id")+class ActivityLogPageNumberPagination(BoundedPageNumberPagination):+ page_size = 100+ page_size_query_param = "page_size"+++class ActivityLogPagination(TailFollowingCursorPagination):+ """Cursor pages by default, and numbered pages when the request has a `page` parameter."""++ page_size = 100+ page_size_query_param = "page_size"+ max_page_size = 1000+ # `created_at` is not unique, and DRF encodes only the first ordering field in the cursor,+ # resolving ties with an offset. That offset is reproducible only when rows sharing a+ # timestamp come back in a stable order, which Postgres does not otherwise guarantee.+ ordering = ("-created_at", "-id")++ def __init__(self) -> None:+ super().__init__()+ self.page_number_pagination = ActivityLogPageNumberPagination()+ self.request: Optional[Request] = Nonedef paginate_queryset(self, queryset, request, view=None):self.request = requestif request.query_params.get("page"):return self.page_number_pagination.paginate_queryset(queryset, request, view)- else:- self.cursor_pagination.ordering = activity_log_ordering(request)- self.cursor_pagination.follow = request.query_params.get("follow") == "true"- return self.cursor_pagination.paginate_queryset(queryset, request, view)+ self.ordering = activity_log_ordering(request)+ self.follow = request.query_params.get("follow") == "true"+ return super().paginate_queryset(queryset, request, view)def get_paginated_response(self, data):if self.request and self.request.query_params.get("page"):return self.page_number_pagination.get_paginated_response(data)- else:- return self.cursor_pagination.get_paginated_response(data)+ return super().get_paginated_response(data)def get_paginated_response_schema(self, schema):# The paginator picks cursor or page-number mode per request, so the schema has to describe# both. Cursor responses (the default) carry no `count`, so it is documented as an optional# property rather than a required one.- cursor_schema = self.cursor_pagination.get_paginated_response_schema(schema)+ cursor_schema = super().get_paginated_response_schema(schema)page_number_schema = self.page_number_pagination.get_paginated_response_schema(schema)cursor_schema["properties"]["count"] = page_number_schema["properties"]["count"]return cursor_schemadiff --git a/posthog/api/event.py b/posthog/api/event.pyindex 12f43a19c1d3..3005d43d813e 100644--- a/posthog/api/event.py+++ b/posthog/api/event.py@@ -17,7 +17,6 @@ from opentelemetry import tracefrom prometheus_client import Counterfrom rest_framework import mixins, request, response, serializers, viewsetsfrom rest_framework.exceptions import NotFound-from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.renderers import BaseRendererfrom rest_framework.settings import api_settingsfrom rest_framework_csv import renderers as csvrenderers@@ -30,6 +29,7 @@ from posthog.hogql.property_utils import create_property_conditionsfrom posthog.hogql.query import execute_hogql_queryfrom posthog.api.documentation import PropertiesSerializer, extend_schema+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.property_value_metrics import PROPERTY_VALUES_DURATIONfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.utils import action@@ -154,7 +154,7 @@ class EventPropertyValuesResponseSerializer(serializers.Serializer):)-class UncountedLimitOffsetPagination(LimitOffsetPagination):+class UncountedLimitOffsetPagination(BoundedLimitOffsetPagination):"""the events api works with the default LimitOffsetPagination, but theresults don't have a count, so we need to override the pagination classdiff --git a/posthog/api/event_definition.py b/posthog/api/event_definition.pyindex 4663b283aa4f..f322ca9b4721 100644--- a/posthog/api/event_definition.py+++ b/posthog/api/event_definition.py@@ -550,7 +550,8 @@ class EventDefinitionViewSet(paginator = cast(CappedCountLimitOffsetPagination, self.paginator)query = EventDefinitionQuerySerializer(data=self.request.query_params)query.is_valid(raise_exception=True)- params["limit"] = query.validated_data["limit"]+ # The paginator builds `next` from its capped limit, so the SQL page has to use the same cap.+ params["limit"] = min(query.validated_data["limit"], paginator.max_limit)params["offset"] = query.validated_data["offset"]conditions = search_query + filter_querydiff --git a/posthog/api/health_issue.py b/posthog/api/health_issue.pyindex 9ed5e5c02d72..d2164d179717 100644--- a/posthog/api/health_issue.py+++ b/posthog/api/health_issue.py@@ -17,13 +17,13 @@ from drf_spectacular.utils import (from rest_framework import serializersfrom rest_framework.decorators import actionfrom rest_framework.mixins import ListModelMixin, RetrieveModelMixin-from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.permissions import BasePermissionfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom rest_framework.status import HTTP_202_ACCEPTED, HTTP_400_BAD_REQUESTfrom rest_framework.viewsets import GenericViewSet+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.event_usage import report_user_actionfrom posthog.exceptions_capture import capture_exception@@ -263,7 +263,7 @@ class HealthIssueDetailSerializer(HealthIssueSerializer):return {"human": remediation.human, "agent": remediation.agent}-class HealthIssuePagination(LimitOffsetPagination):+class HealthIssuePagination(BoundedLimitOffsetPagination):default_limit = 50max_limit = 250diff --git a/posthog/api/pagination.py b/posthog/api/pagination.pyindex e0ffc2283df0..f374fbdb0ff4 100644--- a/posthog/api/pagination.py+++ b/posthog/api/pagination.py@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any, Optional, castfrom django.core.exceptions import ImproperlyConfiguredfrom rest_framework import serializers-from rest_framework.pagination import CursorPagination, LimitOffsetPagination+from rest_framework.pagination import CursorPagination, LimitOffsetPagination, PageNumberPaginationfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom rest_framework.serializers import BaseSerializer@@ -82,13 +82,59 @@ class PageLinksSerializer(serializers.Serializer):)-class PrecountedLimitOffsetPagination(LimitOffsetPagination):+class BoundedLimitOffsetPagination(LimitOffsetPagination):+ """Limit/offset pages of at most `max_limit` rows.++ DRF has no upper bound by default, so `?limit=` could ask one request to read a whole table.+ A larger limit is cut to `max_limit`, and the schema states the maximum.+ """++ max_limit = 1000++ def get_schema_operation_parameters(self, view: Any) -> list[dict[str, Any]]:+ parameters = super().get_schema_operation_parameters(view)+ for parameter in parameters:+ if parameter["name"] == self.limit_query_param:+ parameter["schema"]["maximum"] = self.max_limit+ return parameters+++class DefaultLimitOffsetPagination(BoundedLimitOffsetPagination):+ """The project-wide default paginator: it caps `limit` at `max_limit` but leaves the schema as DRF writes it.++ Clients generated from the schema keep accepting a larger limit. The server answers with at most+ `max_limit` rows and a `next` link, so a client that follows `next` still reads every row.+ """++ def get_schema_operation_parameters(self, view: Any) -> list[dict[str, Any]]:+ return LimitOffsetPagination.get_schema_operation_parameters(self, view)+++class BoundedPageNumberPagination(PageNumberPagination):+ """Numbered pages with a cap on the page size that a client chooses.++ A subclass that lets clients choose the page size with `page_size_query_param` gets that size+ cut to `max_page_size`, and the schema states the maximum. A fixed `page_size` on the subclass+ is not cut.+ """++ max_page_size = 1000++ def get_schema_operation_parameters(self, view: Any) -> list[dict[str, Any]]:+ parameters = super().get_schema_operation_parameters(view)+ for parameter in parameters:+ if parameter["name"] == self.page_size_query_param:+ parameter["schema"]["maximum"] = self.max_page_size+ return parameters+++class PrecountedLimitOffsetPagination(BoundedLimitOffsetPagination):"""Pages a queryset that the view has already bounded with LIMIT and OFFSET.`LimitOffsetPagination` counts with `len(queryset)` and then slices the result in Python. A`RawQuerySet` answers both by fetching every row, so one page costs a read of the whole resultset. Views that page in SQL run their own count statement and hand the total over with- `set_count`. Without a count this behaves exactly like `LimitOffsetPagination`, so a view that+ `set_count`. Without a count this behaves exactly like `BoundedLimitOffsetPagination`, so a view thatalso returns unbounded querysets keeps working."""@@ -159,34 +205,6 @@ class CappedCountLimitOffsetPagination(PrecountedLimitOffsetPagination):return paginated-class BoundedLimitOffsetPagination(LimitOffsetPagination):- """Limit/offset pages of at most `max_limit` rows.-- DRF has no upper bound by default, so `?limit=` could ask one request to read a whole table.- A larger limit is cut to `max_limit`, and the schema states the maximum.- """-- max_limit = 1000-- def get_schema_operation_parameters(self, view: Any) -> list[dict[str, Any]]:- parameters = super().get_schema_operation_parameters(view)- for parameter in parameters:- if parameter["name"] == self.limit_query_param:- parameter["schema"]["maximum"] = self.max_limit- return parameters---class DefaultLimitOffsetPagination(BoundedLimitOffsetPagination):- """The project-wide default paginator: it caps `limit` at `max_limit` but leaves the schema as DRF writes it.-- Clients generated from the schema keep accepting a larger limit. The server answers with at most- `max_limit` rows and a `next` link, so a client that follows `next` still reads every row.- """-- def get_schema_operation_parameters(self, view: Any) -> list[dict[str, Any]]:- return LimitOffsetPagination.get_schema_operation_parameters(self, view)--class FacadeLimitOffsetPagination(BoundedLimitOffsetPagination):"""Builds the standard limit/offset response from a page that a facade read in SQL.@@ -231,6 +249,9 @@ class StableCursorPagination(CursorPagination):cursor does not store the primary key."""+ # A subclass can leave `count` out, because counting costs a full scan on large tables.+ include_count: bool = True+def get_ordering(self, request: Request, queryset: Any, view: Any) -> tuple[str, ...]:ordering = super().get_ordering(request, queryset, view)model = getattr(queryset, "model", None)@@ -245,6 +266,8 @@ class StableCursorPagination(CursorPagination):return super().paginate_queryset(queryset, request, view)def get_paginated_response(self, data: Any) -> Response:+ if not self.include_count:+ return super().get_paginated_response(data)return Response({"count": self.counted_rows.count(),@@ -256,6 +279,8 @@ class StableCursorPagination(CursorPagination):def get_paginated_response_schema(self, schema: dict) -> dict:paginated = super().get_paginated_response_schema(schema)+ if not self.include_count:+ return paginatedpaginated["required"] = ["count", "results"]paginated["properties"] = {"count": {"type": "integer", "example": 123},diff --git a/posthog/api/person.py b/posthog/api/person.pyindex 927e68d27167..49e283016f40 100644--- a/posthog/api/person.py+++ b/posthog/api/person.py@@ -25,7 +25,6 @@ from opentelemetry import tracefrom prometheus_client import Counterfrom rest_framework import request, response, serializers, viewsetsfrom rest_framework.exceptions import APIException, MethodNotAllowed, NotFound, ValidationError-from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.parsers import JSONParserfrom rest_framework.renderers import BaseRendererfrom rest_framework.response import Response@@ -41,6 +40,7 @@ from posthog.api.capture import CaptureInternalError, capture_internalfrom posthog.api.documentation import PersonPropertiesSerializerfrom posthog.api.fields import CoercedStringListFieldfrom posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.property_value_metrics import PROPERTY_VALUES_DURATIONfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.utils import action, paging_params, parse_actor_property_filters@@ -153,7 +153,7 @@ API_PERSON_LIST_SEARCH_COUNTER = Counter()-class PersonLimitOffsetPagination(LimitOffsetPagination):+class PersonLimitOffsetPagination(BoundedLimitOffsetPagination):def get_paginated_response_schema(self, schema):return {"type": "object",@@ -407,7 +407,7 @@ class DeletionStatusQueryParamsSerializer(serializers.Serializer):person_uuid = serializers.UUIDField(required=False)-class DeletionStatusPagination(LimitOffsetPagination):+class DeletionStatusPagination(BoundedLimitOffsetPagination):default_limit = 100@@ -832,6 +832,9 @@ class PersonViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):limit, offset = CSV_EXPORT_LIMIT, 0elif not limit:limit = DEFAULT_PAGE_LIMIT+ else:+ # The view reads `limit` itself, so it applies the cap that the paginator states in the schema.+ limit = min(limit, PersonLimitOffsetPagination.max_limit)from posthog.hogql import ast # noqa: PLC0415 — deferred to avoid a circular import at module loadfrom posthog.hogql.query import execute_hogql_query # noqa: PLC0415diff --git a/posthog/api/scim_request_log.py b/posthog/api/scim_request_log.pyindex 2be93b5a0991..8183d592f8e3 100644--- a/posthog/api/scim_request_log.py+++ b/posthog/api/scim_request_log.py@@ -2,9 +2,9 @@ from django.db.models import Q, QuerySetimport django_filtersfrom rest_framework import response, serializers-from rest_framework.pagination import PageNumberPaginationfrom rest_framework.request import Request+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.scim.utils import mask_email, mask_stringfrom posthog.models.scim_request_log import SCIMRequestLog@@ -50,7 +50,7 @@ class SCIMRequestLogQuerySerializer(serializers.Serializer):)-class SCIMRequestLogPagination(PageNumberPagination):+class SCIMRequestLogPagination(BoundedPageNumberPagination):page_size = 20page_size_query_param = "page_size"max_page_size = 100diff --git a/posthog/api/tagged_item.py b/posthog/api/tagged_item.pyindex 654ed9a15b82..0aceca572486 100644--- a/posthog/api/tagged_item.py+++ b/posthog/api/tagged_item.py@@ -8,9 +8,10 @@ from django.db import modelsfrom django.db.models import Prefetch, Q, QuerySet, prefetch_related_objectsfrom drf_spectacular.utils import OpenApiParameter, OpenApiTypes, extend_schema-from rest_framework import pagination, response, serializers, status, viewsets+from rest_framework import response, serializers, status, viewsetsfrom rest_framework.viewsets import GenericViewSet+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.utils import actionfrom posthog.helpers.impersonation import is_impersonated@@ -498,7 +499,7 @@ class TaggedItemViewSet(TeamAndOrgViewSetMixin, GenericViewSet):if search:tags = tags.filter(name__icontains=search)- paginator = pagination.LimitOffsetPagination()+ paginator = BoundedLimitOffsetPagination()paginator.default_limit = 100paginator.max_limit = 100page = paginator.paginate_queryset(tags, request, view=self)diff --git a/posthog/api/test/test_event_definition.py b/posthog/api/test/test_event_definition.pyindex 924188937adc..c6cb029b0ce1 100644--- a/posthog/api/test/test_event_definition.py+++ b/posthog/api/test/test_event_definition.py@@ -201,6 +201,16 @@ class TestEventDefinitionAPI(APIBaseTest):assert response.status_code == status.HTTP_200_OKassert response.json()["count"] == len(self.EXPECTED_EVENT_DEFINITIONS)+ def test_list_event_definitions_caps_the_limit_for_rows_and_next_link(self):+ with patch("posthog.api.event_definition.CappedCountLimitOffsetPagination.max_limit", 2):+ response = self.client.get("/api/projects/@current/event_definitions/?limit=5")++ body = response.json()+ assert response.status_code == status.HTTP_200_OK, body+ assert len(body["results"]) == 2+ assert "offset=2" in body["next"]+ assert "limit=2" in body["next"]+@parameterized.expand([("repeated", "names=installed_app&names=purchase&names=missing_event"),diff --git a/posthog/api/test/test_person.py b/posthog/api/test/test_person.pyindex d298a10ea07d..58073ec7a2c1 100644--- a/posthog/api/test/test_person.py+++ b/posthog/api/test/test_person.py@@ -27,7 +27,7 @@ from parameterized import parameterizedfrom rest_framework import statusfrom rest_framework.exceptions import ValidationError-from posthog.api.person import tag_client_query_id+from posthog.api.person import PersonLimitOffsetPagination, tag_client_query_idfrom posthog.clickhouse.client import sync_executefrom posthog.clickhouse.query_tagging import get_query_tag_value, reset_query_tagsfrom posthog.constants import AvailableFeature@@ -2311,6 +2311,11 @@ class TestPerson(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):self.assertEqual(len(paged), len(uuids)) # no person lost or repeated at a page boundaryself.assertEqual(set(paged), expected) # union of pages == full set, gapless and dup-free+ with mock.patch.object(PersonLimitOffsetPagination, "max_limit", 3):+ capped = self.client.get("/api/person/?limit=100").json()+ self.assertEqual(len(capped["results"]), 3)+ self.assertIsNotNone(capped["next"])+def test_retrieve_person(self):person = create_person( # creating without _create_person to guarentee created_at orderingteam=self.team, distinct_ids=["123456789"]diff --git a/products/alerts_platform/frontend/generated/api.schemas.ts b/products/alerts_platform/frontend/generated/api.schemas.tsindex 768f5dff8999..ce8a78e0ecd4 100644--- a/products/alerts_platform/frontend/generated/api.schemas.ts+++ b/products/alerts_platform/frontend/generated/api.schemas.ts@@ -1756,6 +1756,7 @@ export type PlatformAlertsListParams = {legacy_configuration_id?: string/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/products/annotations/backend/api/annotation.py b/products/annotations/backend/api/annotation.pyindex 26dae0b58731..d3148672f6f9 100644--- a/products/annotations/backend/api/annotation.py+++ b/products/annotations/backend/api/annotation.py@@ -3,9 +3,10 @@ from typing import Any, Literalfrom django.db.models import Q, QuerySet-from rest_framework import filters, pagination, serializers, viewsets+from rest_framework import filters, serializers, viewsetsfrom posthog.api.forbid_destroy_model import ForbidDestroyModel+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.scoped_related_fields import TeamScopedPrimaryKeyRelatedFieldfrom posthog.api.shared import UserBasicSerializer@@ -213,7 +214,7 @@ class AnnotationSerializer(serializers.ModelSerializer):return annotation-class AnnotationsLimitOffsetPagination(pagination.LimitOffsetPagination):+class AnnotationsLimitOffsetPagination(BoundedLimitOffsetPagination):default_limit = 1000diff --git a/products/annotations/frontend/generated/api.schemas.ts b/products/annotations/frontend/generated/api.schemas.tsindex cb00ce88237f..d92d27bb4b76 100644--- a/products/annotations/frontend/generated/api.schemas.ts+++ b/products/annotations/frontend/generated/api.schemas.ts@@ -286,6 +286,7 @@ export interface ChangeFeedApi {export type AnnotationsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/products/conversations/backend/api/tickets.py b/products/conversations/backend/api/tickets.pyindex 84b7b9316da5..70c1ad44e3eb 100644--- a/products/conversations/backend/api/tickets.py+++ b/products/conversations/backend/api/tickets.py@@ -24,7 +24,6 @@ from drf_spectacular.utils import (extend_schema_view,)from rest_framework import (- pagination,serializers,status as drf_status,viewsets,@@ -35,6 +34,7 @@ from rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Response+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.person import get_person_namefrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.tagged_item import (@@ -359,12 +359,12 @@ class BulkUpdateStatusResponseSerializer(serializers.Serializer):)-class TicketPagination(pagination.LimitOffsetPagination):+class TicketPagination(BoundedLimitOffsetPagination):default_limit = 100max_limit = 1000-class TicketMessagePagination(pagination.LimitOffsetPagination):+class TicketMessagePagination(BoundedLimitOffsetPagination):default_limit = 50max_limit = 200diff --git a/products/conversations/frontend/generated/api.schemas.ts b/products/conversations/frontend/generated/api.schemas.tsindex 4060de9c3c69..a84dd0a8f956 100644--- a/products/conversations/frontend/generated/api.schemas.ts+++ b/products/conversations/frontend/generated/api.schemas.ts@@ -1215,6 +1215,7 @@ export type ConversationsTicketsListParams = {emails?: string/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**@@ -1299,6 +1300,7 @@ export const ConversationsTicketsListSla = {export type ConversationsTicketsMessagesListParams = {/*** Number of results to return per page.+ * @maximum 200*/limit?: number/**diff --git a/products/data_modeling/backend/presentation/views/edge.py b/products/data_modeling/backend/presentation/views/edge.pyindex 71b682e7917f..4b2ef1b49a26 100644--- a/products/data_modeling/backend/presentation/views/edge.py+++ b/products/data_modeling/backend/presentation/views/edge.py@@ -1,8 +1,8 @@from typing import Anyfrom rest_framework import mixins, serializers, viewsets-from rest_framework.pagination import PageNumberPagination+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom products.data_modeling.backend.facade.api import delete_orphaned_table_nodes@@ -57,7 +57,7 @@ class EdgeSummarySerializer(serializers.ModelSerializer):read_only_fields = fields-class EdgePagination(PageNumberPagination):+class EdgePagination(BoundedPageNumberPagination):page_size = 5000diff --git a/products/data_modeling/backend/presentation/views/node.py b/products/data_modeling/backend/presentation/views/node.pyindex 4564f532c7eb..d21040dc707c 100644--- a/products/data_modeling/backend/presentation/views/node.py+++ b/products/data_modeling/backend/presentation/views/node.py@@ -9,8 +9,8 @@ from drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schemafrom rest_framework import filters, mixins, request, response, serializers, status, viewsetsfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDenied-from rest_framework.pagination import PageNumberPagination+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.models import Userfrom posthog.rbac.query_access import assert_user_can_read_query@@ -257,7 +257,7 @@ class NodeSerializer(serializers.ModelSerializer):return attrs-class NodePagination(PageNumberPagination):+class NodePagination(BoundedPageNumberPagination):page_size = 1000diff --git a/products/data_warehouse/backend/presentation/views/data_modeling_job.py b/products/data_warehouse/backend/presentation/views/data_modeling_job.pyindex f479cf8131e2..2d1ae4eab585 100644--- a/products/data_warehouse/backend/presentation/views/data_modeling_job.py+++ b/products/data_warehouse/backend/presentation/views/data_modeling_job.py@@ -4,10 +4,11 @@ import django_filtersfrom django_filters.rest_framework import DjangoFilterBackendfrom drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schema_view-from rest_framework import pagination, serializers, viewsets+from rest_framework import serializers, viewsetsfrom rest_framework.decorators import actionfrom rest_framework.response import Response+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.permissions import is_service_auth@@ -81,7 +82,7 @@ class DataModelingJobSerializer(serializers.ModelSerializer):read_only_fields = fields-class DataModelingJobPagination(pagination.LimitOffsetPagination):+class DataModelingJobPagination(BoundedLimitOffsetPagination):default_limit = 10max_limit = 100diff --git a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py b/products/data_warehouse/backend/presentation/views/saved_query/viewset.pyindex eee6f8ece24b..ba2ceae3c1d4 100644--- a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py+++ b/products/data_warehouse/backend/presentation/views/saved_query/viewset.py@@ -10,12 +10,12 @@ from asgiref.sync import async_to_syncfrom drf_spectacular.utils import OpenApiResponse, extend_schemafrom rest_framework import exceptions, filters, request, response, serializers, status, viewsetsfrom rest_framework.decorators import action-from rest_framework.pagination import PageNumberPaginationfrom rest_framework.response import Responsefrom posthog.hogql.database.database import Databasefrom posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.exceptions import Conflictfrom posthog.helpers.impersonation import is_impersonated@@ -75,7 +75,7 @@ class DependentsValidationError(serializers.ValidationError):self.extra = {"node_id": node_id}-class DataWarehouseSavedQueryPagination(PageNumberPagination):+class DataWarehouseSavedQueryPagination(BoundedPageNumberPagination):page_size = 1000diff --git a/products/data_warehouse/backend/presentation/views/saved_query_draft.py b/products/data_warehouse/backend/presentation/views/saved_query_draft.pyindex d02dd86434fc..7b47bca9a8db 100644--- a/products/data_warehouse/backend/presentation/views/saved_query_draft.py+++ b/products/data_warehouse/backend/presentation/views/saved_query_draft.py@@ -1,13 +1,14 @@import uuid-from rest_framework import pagination, serializers, viewsets+from rest_framework import serializers, viewsets+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom products.data_modeling.backend.facade.models import DataWarehouseSavedQuery, DataWarehouseSavedQueryDraft-class DataWarehouseSavedQueryDraftPagination(pagination.LimitOffsetPagination):+class DataWarehouseSavedQueryDraftPagination(BoundedLimitOffsetPagination):default_limit = 100diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.tsindex 75598af53ae3..3f350aab476e 100644--- a/products/data_warehouse/frontend/generated/api.schemas.ts+++ b/products/data_warehouse/frontend/generated/api.schemas.ts@@ -5679,6 +5679,7 @@ export type DataModelingJobsListParams = {engine?: DataModelingJobsListEngine/*** Number of results to return per page.+ * @maximum 100*/limit?: number/**@@ -6054,6 +6055,7 @@ export type WarehouseSavedQueriesListParams = {export type WarehouseSavedQueryDraftsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/products/mcp_registry/backend/presentation/views.py b/products/mcp_registry/backend/presentation/views.pyindex 77bc35b17c7c..832fcc37d2d5 100644--- a/products/mcp_registry/backend/presentation/views.py+++ b/products/mcp_registry/backend/presentation/views.py@@ -5,10 +5,10 @@ from drf_spectacular.utils import OpenApiParameter, extend_schemafrom rest_framework import viewsetsfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDenied, ValidationError-from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.request import Requestfrom rest_framework.response import Response+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.auth import OAuthAccessTokenAuthenticationfrom posthog.permissions import PostHogFeatureFlagPermission@@ -33,7 +33,7 @@ _DISCOVER_DEFAULT_LIMIT = 5_DISCOVER_MAX_LIMIT = 20-class MCPRegistryPagination(LimitOffsetPagination):+class MCPRegistryPagination(BoundedLimitOffsetPagination):default_limit = 50max_limit = 200diff --git a/products/mcp_registry/frontend/generated/api.schemas.ts b/products/mcp_registry/frontend/generated/api.schemas.tsindex 637cd55b0fe1..ed9197a2d11f 100644--- a/products/mcp_registry/frontend/generated/api.schemas.ts+++ b/products/mcp_registry/frontend/generated/api.schemas.ts@@ -231,6 +231,7 @@ export interface MCPRankingVersionApi {export type McpRegistryServersListParams = {/*** Number of results to return per page.+ * @maximum 200*/limit?: number/**diff --git a/products/messaging/backend/presentation/views/message_preferences.py b/products/messaging/backend/presentation/views/message_preferences.pyindex 152288b40bbe..d59f3071103e 100644--- a/products/messaging/backend/presentation/views/message_preferences.py+++ b/products/messaging/backend/presentation/views/message_preferences.py@@ -6,12 +6,12 @@ from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schefrom rest_framework import serializers, status, viewsetsfrom rest_framework.decorators import actionfrom rest_framework.exceptions import PermissionDenied-from rest_framework.pagination import PageNumberPaginationfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom posthog.api.documentation import _FallbackSerializerfrom posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.streaming import streaming_responsefrom posthog.plugins import plugin_server_api@@ -31,7 +31,7 @@ MAX_BULK_OPT_OUT_ENTRIES = 1000UNSAFE_FILENAME_CHARACTERS = re.compile(r"[^A-Za-z0-9_-]+")-class OptOutsPagination(PageNumberPagination):+class OptOutsPagination(BoundedPageNumberPagination):page_size = 20page_size_query_param = "page_size"max_page_size = 100diff --git a/products/messaging/backend/presentation/views/message_suppression.py b/products/messaging/backend/presentation/views/message_suppression.pyindex 4d7d7aa08754..2989e58c2cf1 100644--- a/products/messaging/backend/presentation/views/message_suppression.py+++ b/products/messaging/backend/presentation/views/message_suppression.py@@ -4,12 +4,12 @@ from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schefrom rest_framework import serializers, status, viewsetsfrom rest_framework.decorators import actionfrom rest_framework.exceptions import PermissionDenied-from rest_framework.pagination import PageNumberPaginationfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom posthog.api.documentation import _FallbackSerializerfrom posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom products.messaging.backend.facade.suppression import (@@ -21,7 +21,7 @@ from products.messaging.backend.facade.suppression import ()-class SuppressionPagination(PageNumberPagination):+class SuppressionPagination(BoundedPageNumberPagination):page_size = 20page_size_query_param = "page_size"max_page_size = 100diff --git a/products/notifications/backend/presentation/views.py b/products/notifications/backend/presentation/views.pyindex 748c82db6dcd..500f5c83fb75 100644--- a/products/notifications/backend/presentation/views.py+++ b/products/notifications/backend/presentation/views.py@@ -12,12 +12,12 @@ import posthoganalyticsfrom drf_spectacular.utils import OpenApiParameter, extend_schemafrom rest_framework import serializers as drf_serializersfrom rest_framework.exceptions import ValidationError-from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom rest_framework.viewsets import GenericViewSetfrom posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.pagination import BoundedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.utils import actionfrom posthog.models import User@@ -45,7 +45,7 @@ class BulkNotificationIdsRequestSerializer(drf_serializers.Serializer):)-class NotificationPagination(LimitOffsetPagination):+class NotificationPagination(BoundedLimitOffsetPagination):default_limit = 20max_limit = 100diff --git a/products/notifications/frontend/generated/api.schemas.ts b/products/notifications/frontend/generated/api.schemas.tsindex f54d2b5710ec..cb68cc4b300d 100644--- a/products/notifications/frontend/generated/api.schemas.ts+++ b/products/notifications/frontend/generated/api.schemas.ts@@ -103,6 +103,7 @@ export type NotificationsListParams = {created_before?: string/*** Number of results to return per page.+ * @maximum 100*/limit?: number/**diff --git a/products/persons/frontend/generated/api.schemas.ts b/products/persons/frontend/generated/api.schemas.tsindex 1fe81c755e22..40bff931419c 100644--- a/products/persons/frontend/generated/api.schemas.ts+++ b/products/persons/frontend/generated/api.schemas.ts@@ -4123,6 +4123,7 @@ export type PersonsListParams = {include_matched_fields?: boolean/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**@@ -4371,6 +4372,7 @@ export type PersonsDeletionStatusListParams = {format?: PersonsDeletionStatusListFormat/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/products/platform_features/frontend/generated/api.schemas.ts b/products/platform_features/frontend/generated/api.schemas.tsindex 38c4281fb253..81333cc5abcc 100644--- a/products/platform_features/frontend/generated/api.schemas.ts+++ b/products/platform_features/frontend/generated/api.schemas.ts@@ -1366,6 +1366,10 @@ export type RolesRoleMembershipsListParams = {}export type ActivityLogListParams = {+ /**+ * The pagination cursor value.+ */+ cursor?: string/*** Filter by the ID of the affected resource.* @minLength 1@@ -1835,6 +1839,10 @@ export type AdvancedActivityLogsListParams = {* Filter by API clients that generated the activity (the x-posthog-client header, or 'scout:<skill_name>' for a scout run).*/clients?: string[]+ /**+ * The pagination cursor value.+ */+ cursor?: string/*** JSON-encoded map of `detail` field paths to {operation, value} filters. Allowed operations: exact, contains, in.*/diff --git a/products/product_analytics/backend/presentation/insight_variable.py b/products/product_analytics/backend/presentation/insight_variable.pyindex 2a69c15b71e9..f0be7d9293ee 100644--- a/products/product_analytics/backend/presentation/insight_variable.py+++ b/products/product_analytics/backend/presentation/insight_variable.py@@ -2,11 +2,12 @@ import jsonfrom django_filters.rest_framework import DjangoFilterBackendfrom drf_spectacular.utils import extend_schema-from rest_framework import pagination, serializers, viewsets+from rest_framework import serializers, viewsetsfrom rest_framework.exceptions import PermissionDenied, ValidationErrorfrom posthog.schema import ProductKey+from posthog.api.pagination import BoundedPageNumberPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.auth import SharingAccessTokenAuthentication, SharingPasswordProtectedAuthentication@@ -180,7 +181,7 @@ class InsightVariableSerializer(serializers.ModelSerializer):return InsightVariable.objects.create(**validated_data)-class InsightVariablePagination(pagination.PageNumberPagination):+class InsightVariablePagination(BoundedPageNumberPagination):page_size = 500diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 457c5d6a6771..92b2a60e0663 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -419,15 +419,13 @@ def _agent_run_enabled(request, team) -> bool:class _SchemaAwareLimitOffsetPagination(PrecountedLimitOffsetPagination):- """LimitOffsetPagination subclass that surfaces `default_limit`/`max_limit` in the OpenAPI schema."""+ """LimitOffsetPagination subclass that surfaces `default_limit` and the bounds in the OpenAPI schema."""def get_schema_operation_parameters(self, view):parameters = super().get_schema_operation_parameters(view)for parameter in parameters:if parameter.get("name") == self.limit_query_param:parameter["schema"]["default"] = self.default_limit- if self.max_limit is not None:- parameter["schema"]["maximum"] = self.max_limitparameter["schema"]["minimum"] = 1elif parameter.get("name") == self.offset_query_param:parameter["schema"]["default"] = 0diff --git a/products/uptime_monitoring/frontend/generated/api.schemas.ts b/products/uptime_monitoring/frontend/generated/api.schemas.tsindex 1f3c32ebd507..e6cd314fbf6c 100644--- a/products/uptime_monitoring/frontend/generated/api.schemas.ts+++ b/products/uptime_monitoring/frontend/generated/api.schemas.ts@@ -120,6 +120,7 @@ export interface PatchedUpdateUptimeMonitorInputApi {export type UptimeMonitorsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**diff --git a/products/visual_review/backend/presentation/views.py b/products/visual_review/backend/presentation/views.pyindex 9680693780c7..bc7e8531b8cc 100644--- a/products/visual_review/backend/presentation/views.py+++ b/products/visual_review/backend/presentation/views.py@@ -163,6 +163,8 @@ class SnapshotsPagination(PrecountedLimitOffsetPagination):through the facade, then sets the total and `quarantined_count` on the paginatorinstance before rendering the response."""+ # The run scene loads every changed snapshot of a run in one request with `limit=10000`.+ max_limit = 10000quarantined_count = 0def get_paginated_response(self, data: object) -> Response:diff --git a/products/visual_review/frontend/generated/api.schemas.ts b/products/visual_review/frontend/generated/api.schemas.tsindex 5df77640c676..8b1862c2297f 100644--- a/products/visual_review/frontend/generated/api.schemas.ts+++ b/products/visual_review/frontend/generated/api.schemas.ts@@ -952,6 +952,7 @@ export type VisualReviewRunsSnapshotsListParams = {include_quarantined?: boolean/*** Number of results to return per page.+ * @maximum 10000*/limit?: number/**diff --git a/products/web_analytics/frontend/generated/api.schemas.ts b/products/web_analytics/frontend/generated/api.schemas.tsindex 5c41a73282d6..55c5a07506c8 100644--- a/products/web_analytics/frontend/generated/api.schemas.ts+++ b/products/web_analytics/frontend/generated/api.schemas.ts@@ -1975,6 +1975,7 @@ export type AeoPromptsListParams = {include_archived?: boolean/*** Number of results to return per page.+ * @maximum 1000*/limit?: number/**@@ -1997,6 +1998,7 @@ export type AeoPromptsChecksParams = {engine?: string/*** Number of results to return per page.+ * @maximum 100*/limit?: number/**diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex fd43aa60e533..a9c634612d4b 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -130238,6 +130238,10 @@ export namespace Schemas {* Filter by API clients that generated the activity (the x-posthog-client header, or 'scout:<skill_name>' for a scout run).*/clients?: string[];+ /**+ * The pagination cursor value.+ */+ cursor?: string;/*** JSON-encoded map of `detail` field paths to {operation, value} filters. Allowed operations: exact, contains, in.*/@@ -131356,6 +131360,10 @@ export namespace Schemas {} as const;export type ActivityLogListParams = {+ /**+ * The pagination cursor value.+ */+ cursor?: string;/*** Filter by the ID of the affected resource.* @minLength 1@@ -131827,6 +131835,10 @@ export namespace Schemas {* Filter by API clients that generated the activity (the x-posthog-client header, or 'scout:<skill_name>' for a scout run).*/clients?: string[];+ /**+ * The pagination cursor value.+ */+ cursor?: string;/*** JSON-encoded map of `detail` field paths to {operation, value} filters. Allowed operations: exact, contains, in.*/@@ -131932,6 +131944,7 @@ export namespace Schemas {include_archived?: boolean;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -131954,6 +131967,7 @@ export namespace Schemas {engine?: string;/*** Number of results to return per page.+ * @maximum 100*/limit?: number;/**@@ -132430,6 +132444,7 @@ export namespace Schemas {export type AnnotationsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -133619,6 +133634,7 @@ export namespace Schemas {emails?: string;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -133704,6 +133720,7 @@ export namespace Schemas {export type ConversationsTicketsMessagesListParams = {/*** Number of results to return per page.+ * @maximum 200*/limit?: number;/**@@ -134544,6 +134561,7 @@ export namespace Schemas {engine?: DataModelingJobsListEngine;/*** Number of results to return per page.+ * @maximum 100*/limit?: number;/**@@ -138142,6 +138160,7 @@ export namespace Schemas {kind?: string;/*** Number of results to return per page.+ * @maximum 250*/limit?: number;/**@@ -141194,6 +141213,7 @@ export namespace Schemas {export type McpRegistryServersListParams = {/*** Number of results to return per page.+ * @maximum 200*/limit?: number;/**@@ -141606,6 +141626,7 @@ export namespace Schemas {created_before?: string;/*** Number of results to return per page.+ * @maximum 100*/limit?: number;/**@@ -141665,6 +141686,7 @@ export namespace Schemas {include_matched_fields?: boolean;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -141919,6 +141941,7 @@ export namespace Schemas {format?: PersonsDeletionStatusListFormat;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -142007,6 +142030,7 @@ export namespace Schemas {legacy_configuration_id?: string;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -142161,6 +142185,7 @@ export namespace Schemas {is_numerical?: boolean | null;/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -144998,6 +145023,7 @@ export namespace Schemas {export type UptimeMonitorsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**@@ -146083,6 +146109,7 @@ export namespace Schemas {include_quarantined?: boolean;/*** Number of results to return per page.+ * @maximum 10000*/limit?: number;/**@@ -146178,6 +146205,7 @@ export namespace Schemas {export type WarehouseSavedQueryDraftsListParams = {/*** Number of results to return per page.+ * @maximum 1000*/limit?: number;/**diff --git a/services/mcp/src/generated/aeo/api.ts b/services/mcp/src/generated/aeo/api.tsindex 86c9457ff852..11c682607bb5 100644--- a/services/mcp/src/generated/aeo/api.ts+++ b/services/mcp/src/generated/aeo/api.ts@@ -21,6 +21,8 @@ export const AeoPromptsListParams = () => zod.object({})export const aeoPromptsListQueryIncludeArchivedDefault = false+export const aeoPromptsListQueryLimitMax = 1000+export const aeoPromptsListQueryTopicMax = 200export const AeoPromptsListQueryParams = () => zod.object({@@ -29,7 +31,7 @@ export const AeoPromptsListQueryParams = () => zod.object({.boolean().default(aeoPromptsListQueryIncludeArchivedDefault).describe('Also list archived prompts. Archived prompts are left out by default.'),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod.number().max(aeoPromptsListQueryLimitMax).optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),topic: zod.string()@@ -134,6 +136,8 @@ export const AeoPromptsChecksParams = () => zod.object({export const aeoPromptsChecksQueryEngineMax = 64+export const aeoPromptsChecksQueryLimitMax = 100+export const AeoPromptsChecksQueryParams = () => zod.object({engine: zod.string()@@ -141,7 +145,7 @@ export const AeoPromptsChecksQueryParams = () => zod.object({.max(aeoPromptsChecksQueryEngineMax).optional().describe("Only list checks from this answer engine, for example 'claude-web-search'."),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod.number().max(aeoPromptsChecksQueryLimitMax).optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),version: zod.number().min(1).optional().describe('Only list checks that ran this version of the prompt.'),})diff --git a/services/mcp/src/generated/annotations/api.ts b/services/mcp/src/generated/annotations/api.tsindex a46ea30d76f4..188e896ada41 100644--- a/services/mcp/src/generated/annotations/api.ts+++ b/services/mcp/src/generated/annotations/api.ts@@ -19,8 +19,10 @@ export const AnnotationsListParams = () => zod.object({),})+export const annotationsListQueryLimitMax = 1000+export const AnnotationsListQueryParams = () => zod.object({- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod.number().max(annotationsListQueryLimitMax).optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),search: zod.string().optional().describe('A search term.'),})diff --git a/services/mcp/src/generated/conversations/api.ts b/services/mcp/src/generated/conversations/api.tsindex 003df11de63f..5cfd20a29574 100644--- a/services/mcp/src/generated/conversations/api.ts+++ b/services/mcp/src/generated/conversations/api.ts@@ -41,6 +41,8 @@ export const ConversationsTicketsListParams = () => zod.object({),})+export const conversationsTicketsListQueryLimitMax = 1000+export const ConversationsTicketsListQueryParams = () => zod.object({ai_triage_result: zod.string()@@ -91,7 +93,11 @@ export const ConversationsTicketsListQueryParams = () => zod.object({.describe('Comma-separated list of email addresses to filter by, matched case-insensitively against `email_from` (max 100). When combined with `distinct_ids`, tickets matching either the distinct_ids or the emails are returned (OR).'),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod+ .number()+ .max(conversationsTicketsListQueryLimitMax)+ .optional()+ .describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),order_by: zod.string()@@ -232,8 +238,14 @@ export const ConversationsTicketsMessagesListParams = () => zod.object({),})+export const conversationsTicketsMessagesListQueryLimitMax = 200+export const ConversationsTicketsMessagesListQueryParams = () => zod.object({- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod+ .number()+ .max(conversationsTicketsMessagesListQueryLimitMax)+ .optional()+ .describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),})diff --git a/services/mcp/src/generated/health_issues/api.ts b/services/mcp/src/generated/health_issues/api.tsindex 882b4bee2dd9..3ead765708b3 100644--- a/services/mcp/src/generated/health_issues/api.ts+++ b/services/mcp/src/generated/health_issues/api.ts@@ -20,13 +20,15 @@ export const HealthIssuesListParams = () => zod.object({),})+export const healthIssuesListQueryLimitMax = 250+export const HealthIssuesListQueryParams = () => zod.object({dismissed: zod.boolean().optional().describe('Filter by dismissed state. Omit to include both dismissed and non-dismissed issues.'),kind: zod.string().optional().describe("Only return issues from this check kind (e.g. 'sdk_outdated')."),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod.number().max(healthIssuesListQueryLimitMax).optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),severity: zod.string()diff --git a/services/mcp/src/generated/persons/api.ts b/services/mcp/src/generated/persons/api.tsindex 2d7ebcd36f9d..bcf61c55a6a4 100644--- a/services/mcp/src/generated/persons/api.ts+++ b/services/mcp/src/generated/persons/api.ts@@ -19,6 +19,8 @@ export const PersonsListParams = () => zod.object({),})+export const personsListQueryLimitMax = 1000+export const personsListQueryPropertiesItemTypeDefault = `AND`export const personsListQueryPropertiesItemValuesItemOperatorDefault = `exact`export const personsListQueryPropertiesItemValuesItemTypeDefault = `event`@@ -39,7 +41,7 @@ export const PersonsListQueryParams = () => zod.object({.describe('Tag each search result with `matched_fields`, the searched fields the term was found in. A complete email address that exactly matches a distinct ID then returns that person first, followed by every person whose email or name property contains the address.'),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod.number().max(personsListQueryLimitMax).optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),properties: zod.array(diff --git a/services/mcp/src/generated/platform_features/api.ts b/services/mcp/src/generated/platform_features/api.tsindex 838c649caa30..86dfa5042f7c 100644--- a/services/mcp/src/generated/platform_features/api.ts+++ b/services/mcp/src/generated/platform_features/api.ts@@ -230,6 +230,7 @@ export const AdvancedActivityLogsListQueryParams = () => zod.object({.describe("Filter by API clients that generated the activity (the x-posthog-client header, or 'scout:<skill_name>' for a scout run)."),+ cursor: zod.string().optional().describe('The pagination cursor value.'),detail_filters: zod.string().optional()diff --git a/services/mcp/src/generated/visual_review/api.ts b/services/mcp/src/generated/visual_review/api.tsindex cf337857dff2..72384147ef08 100644--- a/services/mcp/src/generated/visual_review/api.ts+++ b/services/mcp/src/generated/visual_review/api.ts@@ -518,6 +518,8 @@ export const VisualReviewRunsSnapshotsListParams = () => zod.object({export const visualReviewRunsSnapshotsListQueryExcludeUnchangedDefault = falseexport const visualReviewRunsSnapshotsListQueryIncludeQuarantinedDefault = false+export const visualReviewRunsSnapshotsListQueryLimitMax = 10000+export const visualReviewRunsSnapshotsListQueryQuarantinedOnlyDefault = falseexport const VisualReviewRunsSnapshotsListQueryParams = () => zod.object({@@ -533,7 +535,11 @@ export const VisualReviewRunsSnapshotsListQueryParams = () => zod.object({.describe("Whether to include snapshots whose identifier is currently quarantined. Defaults to false: quarantined snapshots are excluded from results and reported in quarantined_count instead, since they are noise when reviewing real changes. This filter uses the quarantines active now. Each snapshot's `is_quarantined` flag holds the state when the run was gated, so for an older run pass true and read the flag."),- limit: zod.number().optional().describe('Number of results to return per page.'),+ limit: zod+ .number()+ .max(visualReviewRunsSnapshotsListQueryLimitMax)+ .optional()+ .describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),quarantined_only: zod.boolean()diff --git a/services/mcp/src/tools/generated/platform_features.ts b/services/mcp/src/tools/generated/platform_features.tsindex b874dc8791d2..b362d2094f81 100644--- a/services/mcp/src/tools/generated/platform_features.ts+++ b/services/mcp/src/tools/generated/platform_features.ts@@ -81,6 +81,7 @@ const advancedActivityLogsList = (): ToolBase<query: {activities: params.activities,clients: params.clients,+ cursor: params.cursor,detail_filters: params.detail_filters,end_date: params.end_date,follow: params.follow,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/advanced-activity-logs-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/advanced-activity-logs-list.jsonindex 71fbd5672279..043b0e568ad2 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/advanced-activity-logs-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/advanced-activity-logs-list.json@@ -17,6 +17,10 @@},"type": "array"},+ "cursor": {+ "description": "The pagination cursor value.",+ "type": "string"+ },"detail_filters": {"description": "JSON-encoded map of `detail` field paths to {operation, value} filters. Allowed operations: exact, contains, in.","type": "string"diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-checks-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-checks-list.jsonindex 62fd8f0b873a..27b088556995 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-checks-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-checks-list.json@@ -13,6 +13,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 100,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.jsonindex 129b5677e55f..9315c7a4098c 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json@@ -19,6 +19,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 1000,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/annotations-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/annotations-list.jsonindex 7a4d659dc9be..a83fdb30786b 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/annotations-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/annotations-list.json@@ -4,6 +4,7 @@"limit": {"default": 100,"description": "Number of annotations to return per page (default 100).",+ "maximum": 1000,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-list.jsonindex fc98d99ba969..85f05a1ea1ed 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-list.json@@ -46,6 +46,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 1000,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-messages-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-messages-retrieve.jsonindex f8f7ccef1593..bcdbd66c856e 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-messages-retrieve.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/conversations-tickets-messages-retrieve.json@@ -7,6 +7,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 200,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/health-issues-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/health-issues-list.jsonindex 9b417cf19eee..ad94120dd8bd 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/health-issues-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/health-issues-list.json@@ -11,6 +11,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 250,"type": "number"},"offset": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/persons-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/persons-list.jsonindex f8ffe246dcda..d8be963ef802 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/persons-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/persons-list.json@@ -15,6 +15,7 @@},"limit": {"description": "Number of results to return per page.",+ "maximum": 1000,"type": "number"},"offset": {