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(devex): stop owners:fmt aborting below a glob owners file (#100166)

Georges-Antoine Assia5ff651827f1
diff --git a/tools/owners/posthog_owners/fmt.py b/tools/owners/posthog_owners/fmt.py
index d468f1daed90..9471aaee2959 100644
--- a/tools/owners/posthog_owners/fmt.py
+++ b/tools/owners/posthog_owners/fmt.py
@@ -162,7 +162,13 @@ class CanonicalPlacer:
by_dir.setdefault(d, []).append((path, owners))
return by_dir
- def _label_tree(self, node: _Node, by_dir: dict[str, list[tuple[str, OwnerSet]]]) -> None:
+ def _label_tree(
+ self,
+ node: _Node,
+ by_dir: dict[str, list[tuple[str, OwnerSet]]],
+ enclosing_glob_label: OwnerSet = None,
+ under_glob_file: bool = False,
+ ) -> None:
"""Bottom-up labeling that minimizes boundaries. Each dir takes the owner set
held by the most of its *immediate* children and direct files — each becomes a
boundary only if it disagrees, so this is the local min-boundary choice.
@@ -171,7 +177,12 @@ class CanonicalPlacer:
manifest, a glob file) and do not vote in their parent, so a manifest at
``products/foo`` keeps ownership there instead of floating a rule up the tree."""
for child in node.children.values():
- self._label_tree(child, by_dir)
+ if node.frozen:
+ self._label_tree(child, by_dir, node.pinned_label, True)
+ elif node.pinned:
+ self._label_tree(child, by_dir, None, False)
+ else:
+ self._label_tree(child, by_dir, enclosing_glob_label, under_glob_file)
# A frozen dir labels itself from its own file too: its direct files are
# glob-served and excluded from voting, so deriving the label from children
@@ -181,6 +192,13 @@ class CanonicalPlacer:
node.label = node.pinned_label
return
+ # Below a frozen dir the visible files are only those a nearer carrier serves, so
+ # they cannot speak for the glob-served ones beside them. A label derived from
+ # them lands in a carrier nearer than the frozen file and shadows its globs.
+ if under_glob_file:
+ node.label = enclosing_glob_label
+ return
+
votes: dict[OwnerSet, int] = {}
for child in node.children.values():
if child.pinned or child.frozen:
diff --git a/tools/owners/tests/test_owners.py b/tools/owners/tests/test_owners.py
index 462f715a1ac6..08869c767584 100644
--- a/tools/owners/tests/test_owners.py
+++ b/tools/owners/tests/test_owners.py
@@ -528,6 +528,33 @@ def test_fmt_leaves_glob_files_untouched(tmp_path: Path) -> None:
assert plan.is_canonical
+def test_fmt_keeps_a_nested_carrier_from_claiming_its_glob_served_parent(tmp_path: Path) -> None:
+ # `d` is frozen by its `ml-*` glob, so only `costs` is left to vote up the chain. A
+ # dir-statement built from that vote sits nearer than `d/owners.yaml`, shadows it,
+ # and moves `d/sub/a.py` off team-a, which the proof catches by aborting.
+ plan = _fmt_plan(
+ tmp_path,
+ {
+ "owners.yaml": "version: 1\nowners: [team-root]\n",
+ "r1.py": "x",
+ "r2.py": "x",
+ "d/owners.yaml": (
+ "version: 1\nowners: []\nrules:\n"
+ " - match: '/sub/'\n owners: [team-a]\n"
+ " - match: '/sub/ml-*/'\n owners: [team-c]\n"
+ ),
+ "d/sub/ml-one/z.py": "x",
+ "d/sub/a.py": "x",
+ "d/sub/b.py": "x",
+ "d/sub/pipe/ai/costs/owners.yaml": "version: 1\nowners: [team-b]\n",
+ "d/sub/pipe/ai/costs/g.py": "x",
+ "d/sub/pipe/ai/costs/h.py": "x",
+ },
+ )
+ assert plan.creations == []
+ assert plan.deletions == []
+
+
def test_fmt_reports_top_level_owner_edits(tmp_path: Path) -> None:
# Canonical placement here rewrites the root file's `owners:` ([] -> [team-a])
# while deleting both children. A plan that only printed the deletions would