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.

chore(devex): route guardrail edits to devex review (#109743)

Julian Bez827d6294825d
diff --git a/.stamphog/README.md b/.stamphog/README.md
index f2b9d86ecacd..a4cd934db600 100644
--- a/.stamphog/README.md
+++ b/.stamphog/README.md
@@ -13,6 +13,7 @@ It overrides `deny` and `allow`, and the differences are:
- `auth` and `billing` exempt `products/warehouse_sources/backend/temporal/data_imports/sources/`, because connector code does OAuth and talks to the Stripe API without touching PostHog's auth system or its billing.
- `infra_cicd` also matches `.github/pr-deploy`.
- `stamphog_policy` also matches `products/stamphog/backend/logic/policy_defaults/`, `packages/owners-yaml/`, `owners.yaml` and `product.yaml`, because those are gate inputs here.
+- `devex_guardrails` is an extra category. It matches the semgrep rules, ratchet baselines, invariant tests and lint code that guard the house patterns, so an edit to a guard always gets a human review.
- `allow` also lists `.github/CODEOWNERS`.
- Every `rationale` records the false positives that shaped the rule in this repository.
@@ -25,7 +26,8 @@ It differs from the default in six lines:
- The incidental-keyword example is a warehouse connector fix.
- The philosophy line says "We move fast" rather than "Move fast".
-There is no `steering.md`.
+`steering.md` tells the reviewer to refuse a diff that adds a suppression or an exemption for one of those guards.
+A path rule cannot see these, because the marker sits in product code or in a busy file.
`ownership` declares one `hogli-resolver` source at the repo root, so stamphog reads the same merged view the reviewer auto-assigner builds.
diff --git a/.stamphog/policy.yml b/.stamphog/policy.yml
index 209d577c5e44..17bca26ab791 100644
--- a/.stamphog/policy.yml
+++ b/.stamphog/policy.yml
@@ -132,8 +132,33 @@ deny:
# Transitional: branches that predate the move still carry the resolver here.
- 'tools/owners/'
- 'CODEOWNERS'
- - 'owners\.yaml'
- - 'product\.yaml'
+ - '(?:^|/)owners\.yaml$'
+ - '(?:^|/)product\.yaml$'
+ devex_guardrails:
+ description: 'The guards that keep the house patterns for API codegen, egress, ingress, product isolation, migrations, URLs and startup imports.'
+ rationale: 'These files define what CI blocks, so a small edit can turn a guard off. Most are .yaml, .md, .txt or test files, and without this category they ride the allow-list or the test-only rule to a T0 auto-approve. Busy files stay out on purpose, because most edits to them are routine: tach.toml, pyproject.toml, lib/api.ts, model_crossing_uses_baseline.txt and the setup receivers baseline. owners.yaml routes those to team-devex instead.'
+ match:
+ paths:
+ - '^\.github/scripts/migration-deletion-allowlist\.txt$'
+ - '^\.semgrep/rules/devex/'
+ - '^\.semgrep/rules/security/prefer-codegen-api\.'
+ - '^frontend/src/lib/api-ratchet-baseline\.txt$'
+ - '^posthog/(egress|ingress)/agents\.md$'
+ - '^posthog/egress/(limiter|observability|transport)/'
+ - '^posthog/ingress/(dispatch|observability|verify)/'
+ - '^posthog/ingress/views\.py$'
+ - '^posthog/management/migration_analysis/'
+ - '^posthog/migration_helpers/'
+ - '^posthog/product_urls\.py$'
+ - '^posthog/settings/nextgensquash\.py$'
+ - '^posthog/test/repo_invariants/(dataclass_secret_field_exemptions\.txt|setup_import_baseline\.txt)$'
+ - '^posthog/test/repo_invariants/test_(admin_url_conf|dataclass_secret_fields|generated_files_are_registered|migration_dependencies_share_a_database|migration_run_before|model_crossing_uses|model_enum_defaults|squash_partial_fallback|startup_import_budget)\.py$'
+ - '^products/(architecture\.md|isolation_baseline\.txt|readme\.md)$'
+ - '^docs/internal/django-startup-time\.md$'
+ - '^docs/published/handbook/engineering/type-system\.md$'
+ - '^tools/hogli-commands/hogli_commands/(api_ratchet|projections|tach_lint)\.py$'
+ - '^tools/hogli-commands/hogli_commands/product_structure\.yaml$'
+ - '^tools/hogli-commands/hogli_commands/product/(baseline|checks|crossings|isolation|reverse_accessors)\.py$'
allow:
path_patterns:
- 'docs/'
diff --git a/.stamphog/steering.md b/.stamphog/steering.md
new file mode 100644
index 000000000000..e6d964f43d70
--- /dev/null
+++ b/.stamphog/steering.md
@@ -0,0 +1,10 @@
+Suppressing a house-pattern guard is a team-devex decision, so refuse it.
+Refuse when the diff adds a suppression or an exemption for one of these guards:
+
+- a `nosemgrep` marker for a rule in `.semgrep/rules/devex/` or for `prefer-codegen-api`, or a bare `nosemgrep` with no rule id
+- a `# tach-ignore` marker
+- an `ignore_imports` entry in the `[tool.importlinter]` section of `pyproject.toml`
+- a new line in `products/model_crossing_uses_baseline.txt`, or a new `exposes` entry in `tach.toml`
+- a new name in `ENUM_NAME_OVERRIDES` in `posthog/settings/web.py`
+
+Removed lines and removed markers are fine: the guard got tighter.
diff --git a/owners.yaml b/owners.yaml
index c87e14d3d058..111b9d960867 100644
--- a/owners.yaml
+++ b/owners.yaml
@@ -112,9 +112,43 @@ rules:
owners: team-platform-features
- match: '/posthog/test/activity_logging/'
owners: team-platform-features
+ - match: '/posthog/api/test/test_playwright_setup.py'
+ owners: team-devex
+ # The guards behind the house patterns: semgrep rules, ratchet baselines, invariant tests,
+ # and the docs that state the rules. A small edit here can quietly reopen what a guard
+ # closed. Busy files that most PRs touch (lib/api.ts, pyproject.toml, the setup receivers
+ # and frozen dataclass baselines) stay out, so that the review requests stay rare.
- match:
- - '/posthog/api/test/test_playwright_setup.py'
- - '/posthog/test/test_startup_import_budget.py'
+ - '/.github/scripts/migration-deletion-allowlist.txt'
+ - '/.semgrep/rules/devex/'
+ - '/.semgrep/rules/security/prefer-codegen-api.*'
+ - '/docs/internal/django-startup-time.md'
+ - '/docs/published/handbook/engineering/type-system.md'
+ - '/ee/urls.py'
+ - '/frontend/src/lib/api-orval-mutator.ts'
+ - '/frontend/src/lib/api-ratchet-baseline.txt'
+ - '/frontend/src/lib/api-stream.ts'
+ - '/posthog/management/commands/analyze_migration_risk.py'
+ - '/posthog/migration_helpers/'
+ - '/posthog/openapi/'
+ - '/posthog/product_urls.py'
+ - '/posthog/settings/nextgensquash.py'
+ - '/posthog/test/repo_invariants/dataclass_secret_field_exemptions.txt'
+ - '/posthog/test/repo_invariants/setup_import_baseline.txt'
+ - '/posthog/test/repo_invariants/test_admin_url_conf.py'
+ - '/posthog/test/repo_invariants/test_dataclass_secret_fields.py'
+ - '/posthog/test/repo_invariants/test_generated_files_are_registered.py'
+ - '/posthog/test/repo_invariants/test_migration_dependencies_share_a_database.py'
+ - '/posthog/test/repo_invariants/test_migration_run_before.py'
+ - '/posthog/test/repo_invariants/test_model_crossing_uses.py'
+ - '/posthog/test/repo_invariants/test_model_enum_defaults.py'
+ - '/posthog/test/repo_invariants/test_squash_partial_fallback.py'
+ - '/posthog/test/repo_invariants/test_startup_import_budget.py'
+ - '/products/README.md'
+ - '/products/architecture.md'
+ - '/products/isolation_baseline.txt'
+ - '/products/model_crossing_uses_baseline.txt'
+ - '/tools/openapi-codegen/'
owners: team-devex
- match: '/posthog/management/commands/find_enum_collisions.py'
owners: team-devex
diff --git a/products/stamphog/packages/pr-approval-agent/test_gates.py b/products/stamphog/packages/pr-approval-agent/test_gates.py
index 4a057832643b..e12c62b8c2b8 100644
--- a/products/stamphog/packages/pr-approval-agent/test_gates.py
+++ b/products/stamphog/packages/pr-approval-agent/test_gates.py
@@ -108,6 +108,30 @@ from policy import OwnershipSource
["common/esbuilder/tsconfig.json"],
id="tsconfig-not-deps",
),
+ pytest.param(
+ ["frontend/src/lib/api.ts"],
+ id="busy-api-client-not-guardrail",
+ ),
+ pytest.param(
+ ["tach.toml"],
+ id="busy-tach-config-not-guardrail",
+ ),
+ pytest.param(
+ ["products/model_crossing_uses_baseline.txt"],
+ id="busy-crossings-baseline-not-guardrail",
+ ),
+ pytest.param(
+ ["posthog/test/repo_invariants/setup_receivers_baseline.txt"],
+ id="busy-receivers-baseline-not-guardrail",
+ ),
+ pytest.param(
+ ["posthog/egress/slack/client.py"],
+ id="egress-domain-not-guardrail",
+ ),
+ pytest.param(
+ ["tools/release/feature-product.yaml"],
+ id="product-yaml-suffix-not-manifest",
+ ),
],
)
def test_no_false_positive(files: list[str]) -> None:
@@ -235,6 +259,36 @@ def test_no_false_positive(files: list[str]) -> None:
"deps_toolchain",
id="manifest-with-lockfile",
),
+ pytest.param(
+ [".semgrep/rules/devex/url-naming.yaml"],
+ "devex_guardrails",
+ id="devex-semgrep-rule",
+ ),
+ pytest.param(
+ ["frontend/src/lib/api-ratchet-baseline.txt"],
+ "devex_guardrails",
+ id="api-ratchet-baseline",
+ ),
+ pytest.param(
+ ["posthog/egress/AGENTS.md"],
+ "devex_guardrails",
+ id="egress-agents-md-matches-lowercased",
+ ),
+ pytest.param(
+ ["posthog/ingress/verify/hmac.py"],
+ "devex_guardrails",
+ id="ingress-shared-verify",
+ ),
+ pytest.param(
+ ["posthog/test/repo_invariants/test_startup_import_budget.py"],
+ "devex_guardrails",
+ id="startup-budget-invariant-test",
+ ),
+ pytest.param(
+ ["tools/hogli-commands/hogli_commands/product/isolation.py"],
+ "devex_guardrails",
+ id="isolation-lint",
+ ),
],
)
def test_true_positive(files: list[str], expected_category: str) -> None:
diff --git a/products/stamphog/packages/pr-approval-agent/test_policy.py b/products/stamphog/packages/pr-approval-agent/test_policy.py
index adde7ed3a8b0..54f3ff1bf3e5 100644
--- a/products/stamphog/packages/pr-approval-agent/test_policy.py
+++ b/products/stamphog/packages/pr-approval-agent/test_policy.py
@@ -115,6 +115,30 @@ OLD_DENY_PATTERN_DEFS = {
"\\.nvmrc",
]
},
+ "devex_guardrails": {
+ "paths": [
+ "^\\.github/scripts/migration-deletion-allowlist\\.txt$",
+ "^\\.semgrep/rules/devex/",
+ "^\\.semgrep/rules/security/prefer-codegen-api\\.",
+ "^frontend/src/lib/api-ratchet-baseline\\.txt$",
+ "^posthog/(egress|ingress)/agents\\.md$",
+ "^posthog/egress/(limiter|observability|transport)/",
+ "^posthog/ingress/(dispatch|observability|verify)/",
+ "^posthog/ingress/views\\.py$",
+ "^posthog/management/migration_analysis/",
+ "^posthog/migration_helpers/",
+ "^posthog/product_urls\\.py$",
+ "^posthog/settings/nextgensquash\\.py$",
+ "^posthog/test/repo_invariants/(dataclass_secret_field_exemptions\\.txt|setup_import_baseline\\.txt)$",
+ "^posthog/test/repo_invariants/test_(admin_url_conf|dataclass_secret_fields|generated_files_are_registered|migration_dependencies_share_a_database|migration_run_before|model_crossing_uses|model_enum_defaults|squash_partial_fallback|startup_import_budget)\\.py$",
+ "^products/(architecture\\.md|isolation_baseline\\.txt|readme\\.md)$",
+ "^docs/internal/django-startup-time\\.md$",
+ "^docs/published/handbook/engineering/type-system\\.md$",
+ "^tools/hogli-commands/hogli_commands/(api_ratchet|projections|tach_lint)\\.py$",
+ "^tools/hogli-commands/hogli_commands/product_structure\\.yaml$",
+ "^tools/hogli-commands/hogli_commands/product/(baseline|checks|crossings|isolation|reverse_accessors)\\.py$",
+ ]
+ },
}
OLD_ALLOW_ONLY_EXTENSIONS = {
".txt",
@@ -646,8 +670,9 @@ def test_policy_file_only_pr_is_t2_never(path: str) -> None:
def test_reviewer_system_composes_guidance_and_scaffold() -> None:
# Wording changes are governed by human review (stamphog_policy deny), not a
# frozen snapshot; this only guards the composition seam itself.
- guidance = policy.review_guidance_path().read_text()
+ guidance = reviewer._load_review_guidance()
assert reviewer.REVIEWER_SYSTEM == guidance + reviewer._REVIEWER_SCAFFOLD_TAIL
+ assert guidance.startswith(policy.review_guidance_path().read_text())
assert "showstoppers" in guidance
assert "Verdicts:" in reviewer._REVIEWER_SCAFFOLD_TAIL