: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): anchor the bin/ owners rule and scope owners:lint --live (#71953)
Raúl Negrón-Oteroc1f787c64e3f
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 310ecd76e007..15987890df58 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -986,7 +986,10 @@ jobs:- name: Validate owners.yaml identities against GitHubenv:GH_TOKEN: ${{ steps.app-token.outputs.token }}- run: ./bin/hogli owners:lint --live+ CHANGED_FILES: ${{ needs.changes.outputs.product_yamls_files }}+ # Scoped to the diff: unscoped, one stale slug fails every owners.yaml PR.+ # xargs re-parses the paths-filter escape format, keeping escaped paths whole.+ run: printf '%s' "$CHANGED_FILES" | xargs -r ./bin/hogli owners:lint --live# Migration validation and OpenAPI type generation.# This job needs Docker + DB — it checks out master first to run baselinediff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 7bd9868faf84..8a5f1585e920 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -1192,7 +1192,10 @@ jobs:- name: Validate owners.yaml identities against GitHubenv:GH_TOKEN: ${{ steps.app-token.outputs.token }}- run: ./bin/hogli owners:lint --live+ CHANGED_FILES: ${{ needs.changes.outputs.product_yamls_files }}+ # Scoped to the diff: unscoped, one stale slug fails every owners.yaml PR.+ # xargs re-parses the paths-filter escape format, keeping escaped paths whole.+ run: printf '%s' "$CHANGED_FILES" | xargs -r ./bin/hogli owners:lint --live# Migration validation.# This job needs Docker + DB — it checks out master first to run baselinediff --git a/owners.yaml b/owners.yamlindex 2ae7cbddc2a2..1c3cc6237772 100644--- a/owners.yaml+++ b/owners.yaml@@ -6,6 +6,8 @@ owners: []teams:# GitHub team slugs that predate the 'team-' convention: the slug is right,# the channel just doesn't match it.+ ai-research:+ slack: '#team-ai-research'batch-exports:slack: '#team-batch-exports'clickhouse:@@ -33,13 +35,20 @@ rules:- tach.toml- CLAUDE.md- AGENTS.md- - bin/- greptile.json# Every owners.yaml routes to devex (unanchored: matches at any depth)# unless a nearer file or rule claims it — ownership-policy edits must# never go out for review unassigned.- owners.yamlowners: team-devex+ # Anchored: bare 'bin/' also matches Cargo's src/bin/, a crate's own binaries.+ - match:+ - '/bin/'+ - '/ee/bin/'+ - '/frontend/bin/'+ - '/nodejs/bin/'+ - '/rust/bin/'+ owners: team-devex- match: '/.agents/skills/manage-dashboard-widgets/'owners: team-analytics-platform- match: '/.claude/'diff --git a/posthog/owners.yaml b/posthog/owners.yamlindex 2002fef44b02..d270c9b28259 100644--- a/posthog/owners.yaml+++ b/posthog/owners.yaml@@ -5,6 +5,8 @@ rules:owners: team-analytics-platform- match: '/cdp/'owners: team-workflows+ - match: '/clickhouse/hcl/'+ owners: clickhouse- match: '/email.py'owners: team-platform-features- match: '/heatmaps/'diff --git a/rust/owners.yaml b/rust/owners.yamlindex 9b6d9000a01c..90e7c1152181 100644--- a/rust/owners.yaml+++ b/rust/owners.yaml@@ -29,4 +29,4 @@ rules:- match:- '/replay-anonymizer/'- '/replay-anonymizer-node/'- owners: team-ai-research+ owners: ai-researchdiff --git a/tools/owners/posthog_owners/cli.py b/tools/owners/posthog_owners/cli.pyindex b9a976b30e67..9ba0c2ed4ecb 100644--- a/tools/owners/posthog_owners/cli.py+++ b/tools/owners/posthog_owners/cli.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport sysimport jsonimport subprocess+from collections import defaultdictimport click@@ -159,14 +160,28 @@ def _consolidation_suggestions(owners_dirs: dict[str, bool], threshold: int = 3))+def _live_scope(owners_by_file: dict[str, set[str]], paths: tuple[str, ...]) -> set[str]:+ """Owners to validate: all of them, or only those declared in PATHS.++ Callers scope this to the diff's ownership files. Unscoped, one stale slug+ fails every PR that touches any owners.yaml, none of which can fix it. A+ path with nothing to contribute (deleted, not an ownership file) just misses.+ """+ if not paths:+ return {owner for owners in owners_by_file.values() for owner in owners}+ wanted = {normalize_path(p) for p in paths}+ return {owner for rel, owners in owners_by_file.items() if rel in wanted for owner in owners}++@click.command(name="owners:lint", help="Validate owners.yaml files, conflicts, dead globs, and coverage")@click.option("--live", is_flag=True, help="Also validate team slugs and @handles against the GitHub org")-def cmd_lint(live: bool) -> None:[email protected]("paths", nargs=-1)+def cmd_lint(live: bool, paths: tuple[str, ...]) -> None:resolver = OwnersResolver()repo_root = resolver.repo_rooterrors: list[str] = []warnings: list[str] = []- all_owners: set[str] = set()+ owners_by_file: defaultdict[str, set[str]] = defaultdict(set)owners_dirs: dict[str, bool] = {}tracked = resolver.tracked_files()@@ -193,7 +208,7 @@ def cmd_lint(live: bool) -> None:if directory in owners_yaml_dirs:errors.append(f"{directory or '<root>'}: has both product.yaml (with owners) and owners.yaml")if parsed and parsed.owners:- all_owners.update(normalize_product_owners(parsed.owners))+ owners_by_file[rel].update(normalize_product_owners(parsed.owners))continuefor err in entry.errors:@@ -202,7 +217,7 @@ def cmd_lint(live: bool) -> None:if parsed is None:continueif parsed.owners:- all_owners.update(parsed.owners)+ owners_by_file[rel].update(parsed.owners)if not parsed.rules:continue@@ -216,13 +231,13 @@ def cmd_lint(live: bool) -> None:# Slice paths relative to the file's directory once, not per rule.rel_paths = [p[len(directory) + 1 :] for p in under_dir] if directory else under_dirfor rule in parsed.rules:- all_owners.update(o for o in (rule.owners if isinstance(rule.owners, list) else []))+ owners_by_file[rel].update(rule.owners if isinstance(rule.owners, list) else [])matcher = compile_pattern(rule.match)if not any(matcher.test(rp) for rp in rel_paths):warnings.append(f"{rel}: rule '{rule.match}' matches zero tracked files (dead glob)")if live:- errors.extend(_validate_owners_live(all_owners))+ errors.extend(_validate_owners_live(_live_scope(owners_by_file, paths)))unowned = resolver.unowned(tracked)warnings.append(f"coverage: {len(unowned)} of {len(tracked)} tracked file(s) resolve to unowned")diff --git a/tools/owners/tests/test_owners.py b/tools/owners/tests/test_owners.pyindex 3a8b4858e2bb..64c20da807ab 100644--- a/tools/owners/tests/test_owners.py+++ b/tools/owners/tests/test_owners.py@@ -6,7 +6,7 @@ from pathlib import Pathimport pytestfrom posthog_owners import fmt as fmt_module-from posthog_owners.cli import _consolidation_suggestions, _reserved_location_error+from posthog_owners.cli import _consolidation_suggestions, _live_scope, _reserved_location_errorfrom posthog_owners.fmt import CanonicalPlacer, CanonicalPlanfrom posthog_owners.matcher import path_matches_patternfrom posthog_owners.resolver import OwnersResolver@@ -612,3 +612,28 @@ def test_fmt_equivalence_proof_catches_a_wrong_layout(tmp_path: Path) -> None:placer = CanonicalPlacer(OwnersResolver(repo_root=tmp_path))with pytest.raises(AssertionError):placer._prove({}, {"a/f.py": ("team-wrong",)})+++_OWNERS_BY_FILE = {+ "owners.yaml": {"team-devex", "team-billing"},+ "rust/owners.yaml": {"ai-research"},+ "ee/owners.yaml": {"team-bogus"},+}+++ "paths,expected",+ [+ ((), {"team-devex", "team-billing", "ai-research", "team-bogus"}),+ (("rust/owners.yaml",), {"ai-research"}),+ (("owners.yaml", "rust/owners.yaml"), {"team-devex", "team-billing", "ai-research"}),+ (("./rust/owners.yaml",), {"ai-research"}),+ (("posthog/owners.yaml",), set()),+ ],+)+def test_live_scope_limits_validation_to_the_given_files(paths: tuple[str, ...], expected: set[str]) -> None:+ assert _live_scope(_OWNERS_BY_FILE, paths) == expected+++def test_live_scope_ignores_stale_owners_outside_the_diff() -> None:+ assert "team-bogus" not in _live_scope(_OWNERS_BY_FILE, ("owners.yaml",))