: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
feat(stamphog): derive size-gate limits from denial outcomes (#69230)
Julian Bez9a6dbd6fb11f
diff --git a/.stamphog/policy.yml b/.stamphog/policy.ymlindex a11722d0b838..fbe8a80e8cd3 100644--- a/.stamphog/policy.yml+++ b/.stamphog/policy.yml@@ -159,8 +159,8 @@ allow:- '.yaml'- '.yml'size_gate:- max_lines: 500- max_files: 20+ max_lines: 800+ max_files: 30tiers:t1_subclasses:T1a-trivial:diff --git a/tools/pr-approval-agent/README.md b/tools/pr-approval-agent/README.mdindex 2c3e86443211..ff5c34dab200 100644--- a/tools/pr-approval-agent/README.md+++ b/tools/pr-approval-agent/README.md@@ -62,10 +62,14 @@ Deny-list (hard gate)│▼Size ceiling (hard gate)- - >500 substantive lines or >20 substantive files → too large for auto-review+ - >800 substantive lines or >30 substantive files → too large for auto-review+ (limits derived from 90 days of denial outcomes: the friction cluster of+ denied-yet-merged-unchanged PRs sits at 500-750 substantive lines, and past+ ~800 the merged-unchanged rate collapses, so escalation is genuinely right)- Docs (.md/.txt/.rst anywhere; artifact-extension files under docs/),snapshots (.snap/.ambr, __snapshots__/), images,- `.lock`-extension files (e.g. `yarn.lock`), and generated/ artifacts+ `.lock`-extension files (e.g. `yarn.lock`), tests (test dirs and+ .test/.spec/_test files), and generated/ artifacts(regenerated-artifact extensions only: .ts/.tsx/.js/.jsx/.json/.md/.snap/.pyi/.txt)don't count toward the ceiling — they inflate diffs without adding reviewsurface. Note: `pnpm-lock.yaml` and `package-lock.json` are not `.lock`-extensiondiff --git a/tools/pr-approval-agent/gates.py b/tools/pr-approval-agent/gates.pyindex 8759ad0d5927..e54c5ae9b770 100644--- a/tools/pr-approval-agent/gates.py+++ b/tools/pr-approval-agent/gates.py@@ -473,8 +473,13 @@ def parse_conventional_commit(subject: str) -> dict:# ── File classification ──────────────────────────────────────────+# Directory matching is exact-segment only (__tests__/, test/, tests/, _tests/):+# suffix matching like `*_tests/` catches runtime packages that merely end in+# the word (destination_tests/ is API code, ingestion_acceptance_test/ is a+# Temporal worker). Files inside looser test-tree layouts are still covered by+# the filename branches (test_*.py, *.test.*, *_test.py)._TEST_FILE_RE = re.compile(- r"(?:^|/)(?:__tests__|tests?)/|[_.](?:test|spec)\.[^/]+$|_test\.py$",+ r"(?:^|/)(?:__tests__|tests?|_tests?)/|(?:^|/)test_[^/]+\.py$|[_.](?:test|spec)\.[^/]+$|_test\.py$",re.IGNORECASE,)@@ -652,11 +657,14 @@ def is_allow_listed_only(files: list[str]) -> bool:MAX_LINES = POLICY.size_gate.max_linesMAX_FILES = POLICY.size_gate.max_files-# Files that inflate a diff without adding review surface: prose docs,-# regenerated artifacts, and test snapshots. The size ceiling counts only the-# substantive remainder, so a 2000-line docs rewrite or type regen isn't-# auto-denied. Exempt files still count toward tier/subclass classification-# (which calibrates LLM scrutiny) and still appear in the diff the LLM reads.+# Files that inflate a diff without raising auto-approval risk: prose docs,+# regenerated artifacts, test snapshots, and tests (which cannot change+# production runtime behavior; counting them punished exactly the well-tested+# PRs the review philosophy waves through). The size ceiling counts only the substantive+# remainder, so a 2000-line docs rewrite, a type regen, or a fix arriving with+# extensive tests isn't auto-denied. Exempt files still count toward+# tier/subclass classification (which calibrates LLM scrutiny) and still+# appear in the diff the LLM reads.# Deliberately narrower than ALLOW_ONLY_EXTENSIONS: .json/.yaml/.toml configs# change runtime behavior, so they stay in the count.SIZE_EXEMPT_EXTENSIONS = {@@ -692,7 +700,11 @@ _SIZE_EXEMPT_PATH_RE = re.compile(def is_size_exempt(path: str) -> bool:- return Path(path).suffix.lower() in SIZE_EXEMPT_EXTENSIONS or bool(_SIZE_EXEMPT_PATH_RE.search(path))+ return (+ Path(path).suffix.lower() in SIZE_EXEMPT_EXTENSIONS+ or bool(_SIZE_EXEMPT_PATH_RE.search(path))+ or bool(_TEST_FILE_RE.search(path))+ )def substantive_size(files: list[dict]) -> tuple[int, int]:diff --git a/tools/pr-approval-agent/test_gates.py b/tools/pr-approval-agent/test_gates.pyindex 68e9980345ae..22e161f611f8 100644--- a/tools/pr-approval-agent/test_gates.py+++ b/tools/pr-approval-agent/test_gates.py@@ -347,7 +347,12 @@ def test_dwh_source_mixed_still_denies() -> None:pytest.param("docs/example-snippet.ts", True, id="docs-dir-artifact-extension"),pytest.param("posthog/api/test/__snapshots__/test_api.ambr", True, id="ambr-snapshot"),pytest.param("frontend/__snapshots__/scene.storyshot", True, id="storyshot-extension"),- pytest.param("posthog/test/__snapshots__/helper.py", False, id="executable-under-snapshots-counted"),+ # Outside a test dir, an executable under a snapshots dir still counts+ # (extension-only snapshot exemption). Inside a test dir it is exempt+ # like any test file: test-only PRs already gate-trust the same content+ # via T0, and the LLM still reads it in the diff.+ pytest.param("frontend/__snapshots__/helper.py", False, id="executable-under-snapshots-counted"),+ pytest.param("posthog/test/__snapshots__/helper.py", True, id="snapshots-inside-test-dir-exempt"),pytest.param("frontend/src/generated/core/api.schemas.ts", True, id="generated-dir"),pytest.param("products/tasks/frontend/generated/api.ts", True, id="product-generated-dir"),pytest.param("frontend/src/queries/schema/schema-general.ts", True, id="queries-schema"),@@ -363,6 +368,24 @@ def test_dwh_source_mixed_still_denies() -> None:pytest.param("frontend/src/generated/core/evil.py", False, id="generated-dir-executable-py"),pytest.param("frontend/src/generated/core/build.sh", False, id="generated-dir-executable-sh"),pytest.param("docs/generate_sidebar.py", False, id="docs-dir-executable-py"),+ pytest.param("posthog/api/test/test_insight.py", True, id="test-dir-exempt"),+ pytest.param("frontend/src/scenes/insights/Insight.test.tsx", True, id="dot-test-exempt"),+ pytest.param("posthog/personhog_client/test_interceptor.py", True, id="bare-pytest-file-exempt"),+ pytest.param(+ "common/ingestion/acceptance_tests/test_basic_capture.py", True, id="test-file-in-loose-test-tree-exempt"+ ),+ pytest.param("nodejs/src/cdp/_tests/helpers.ts", True, id="underscore-tests-dir-exempt"),+ pytest.param("posthog/tasks/protest.py", False, id="test-suffix-substring-counted"),+ pytest.param("posthog/latest/models.py", False, id="latest-dir-counted"),+ # Runtime packages that merely end in "_test(s)" must not classify as+ # tests: via the shared predicate that would open the T0 auto-approve+ # path, not just the size exemption.+ pytest.param(+ "products/batch_exports/backend/api/destination_tests/delta.py", False, id="runtime-dir-test-suffix-counted"+ ),+ pytest.param(+ "posthog/temporal/ingestion_acceptance_test/worker.py", False, id="runtime-worker-test-suffix-counted"+ ),],)def test_is_size_exempt(path: str, exempt: bool) -> None:@@ -370,8 +393,9 @@ def test_is_size_exempt(path: str, exempt: bool) -> None:def test_substantive_size_counts_only_non_exempt_files() -> None:- # A docs-heavy PR must not be size-denied for its prose, and a code-heavy- # PR must not slip under the ceiling by padding with docs.+ # A docs- or test-heavy PR must not be size-denied for its prose or its+ # tests, and a code-heavy PR must not slip under the ceiling by padding+ # with either.files = [{"filename": "docs/big-rewrite.md", "additions": 2000, "deletions": 500},{"filename": "frontend/src/generated/core/api.ts", "additions": 900, "deletions": 900},@@ -381,8 +405,8 @@ def test_substantive_size_counts_only_non_exempt_files() -> None:lines, file_count = substantive_size(files)- assert lines == 90- assert file_count == 2+ assert lines == 40+ assert file_count == 1# ── Dependency manifests without a lockfile ──────────────────────diff --git a/tools/pr-approval-agent/test_policy.py b/tools/pr-approval-agent/test_policy.pyindex a3658e95ec38..18886e0f2884 100644--- a/tools/pr-approval-agent/test_policy.py+++ b/tools/pr-approval-agent/test_policy.py@@ -150,8 +150,8 @@ OLD_ALLOW_PATH_PATTERNS = ["generated/","__snapshots__/",]-OLD_MAX_LINES = 500-OLD_MAX_FILES = 20+OLD_MAX_LINES = 800+OLD_MAX_FILES = 30OLD_DISMISS_TEST_RE = "(?:^|/)(?:__tests__|tests?|fixtures)/|(?:^|/)test_[^/]+\\.py$|_test\\.(py|go)$|\\.test\\.(ts|tsx|js|jsx)$|\\.spec\\.(ts|tsx|js|jsx)$|(?:^|/)conftest\\.py$"OLD_DISMISS_GENERATED_RE = "(?:^|/)generated/.*\\.(ts|tsx|js|jsx|json|md|snap|pyi|txt)$|\\.gen\\.(ts|tsx|js|jsx)$|\\.generated\\.(ts|tsx|js|jsx)$|^frontend/src/queries/schema/"diff --git a/tools/pr-approval-agent/version.py b/tools/pr-approval-agent/version.pyindex 1b925634809d..93770f86483b 100644--- a/tools/pr-approval-agent/version.py+++ b/tools/pr-approval-agent/version.py@@ -9,4 +9,4 @@ changes don't need a bump - they are tracked by the policy sha shown next tothe version in the verdict table."""-STAMPHOG_VERSION = "2.0.0b2"+STAMPHOG_VERSION = "2.0.0b3"