: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(devex): always request owners of sensitive paths in reviewer assignment (#113278)
Julian Bez9f94cefb622c
diff --git a/.agents/skills/establishing-code-ownership/SKILL.md b/.agents/skills/establishing-code-ownership/SKILL.mdindex 2fd5993a81c7..8fe1ff94a07d 100644--- a/.agents/skills/establishing-code-ownership/SKILL.md+++ b/.agents/skills/establishing-code-ownership/SKILL.md@@ -27,8 +27,8 @@ No hogli/flox available? The dependency-light fallback needs only pyyaml: `git lFor a path, it walks from the repo root down to the path collecting ownership files, then merges them **nearest-file-wins**:-1. **`owners.yaml` — the canonical, distributed source.** Each directory can carry one. Fields (`owners`, `status`, `inherit`, per-path `rules`) fall through to the nearest ancestor unless overridden. `inherit: false` cuts the walk (Gerrit's `set noparent`) — nothing above it contributes. Within a file, every matching rule applies in order, and each replaces only the fields it sets. `owners: null` means **unowned by design** (exempt from the coverage check), distinct from a directory with no file at all (genuinely unowned). `additions:` names the owners of _additions_ below a directory rather than the owners of the files in it (the consumer decides what counts as an addition); it never changes `owners`, and it adds up across the walk so a nested file cannot drop an ancestor's entry.-2. **`products/<name>/product.yaml` — an accepted alias.** The root `owners.yaml` enables this with `alias_files: [product.yaml]`. When a product dir has no `owners.yaml`, its `product.yaml` `owners:` list is read as the ownership for `products/<name>/**` (every other `product.yaml` field is ignored). A dir with both files is a lint error; `owners.yaml` wins.+1. **`owners.yaml` — the canonical, distributed source.** Each directory can carry one. Fields (`owners`, `status`, `inherit`, per-path `rules`) fall through to the nearest ancestor unless overridden. `inherit: false` cuts the walk (Gerrit's `set noparent`) — nothing above it contributes. Within a file, every matching rule applies in order, and each replaces only the fields it sets. `owners: null` means **unowned by design** (exempt from the coverage check), distinct from a directory with no file at all (genuinely unowned). `additions:` names the owners of _additions_ below a directory rather than the owners of the files in it (the consumer decides what counts as an addition); it never changes `owners`, and it adds up across the walk so a nested file cannot drop an ancestor's entry. `sensitive: true` marks paths where a small change matters (a CI baseline, an exemption list), so the reviewer assigner requests their owners for every change, whatever its size; it is nearest-wins like `status`, a `product.yaml` can set it too, and it never makes a review required.+2. **`products/<name>/product.yaml` — an accepted alias.** The root `owners.yaml` enables this with `alias_files: [product.yaml]`. When a product dir has no `owners.yaml`, its `product.yaml` `owners:` list is read as the ownership for `products/<name>/**`, and its `sensitive:` flag applies to that tree too (every other `product.yaml` field is ignored). A dir with both files is a lint error; `owners.yaml` wins.3. **`.github/CODEOWNERS` — blocking approvals, never part of the walk.** It keeps GitHub-native semantics, stays hand-maintained (mostly infra, e.g. `team-security`), and is enforced by GitHub itself. The resolver does **not** read it — when you need to know whether a blocking approval is additionally required, consult the file directly. It never changes the resolved `owners`, and nothing here writes to it.A tool that can only read CODEOWNERS gets a generated projection of the map instead, from `hogli owners:codeowners` (see [packages/owners-yaml/README.md](../../../packages/owners-yaml/README.md)); that projection covers test files and is never `.github/CODEOWNERS`.diff --git a/.github/scripts/assign-reviewers.js b/.github/scripts/assign-reviewers.jsindex 344ad4cb3213..e7179a42c923 100644--- a/.github/scripts/assign-reviewers.js+++ b/.github/scripts/assign-reviewers.js@@ -144,6 +144,8 @@ async function getChangedFiles() {additions: file.additions || 0,deletions: file.deletions || 0,status: file.status,+ // Set for a rename, so that a move out of a sensitive path still reaches its owners.+ previousFilename: file.previous_filename || null,})}@@ -259,6 +261,22 @@ function computeOwnerFootprints(resolutionByPath, changedFiles, config = CONFIG)// that directory as much as a new file does.const ADDED_FILE_STATUSES = new Set(['added', 'renamed', 'copied'])+// Adds `path` to the entry of `rawOwner` in `owners`, a Map of owner -> {type, name, owner, paths}.+function collectOwnerPath(owners, rawOwner, path) {+ const resolved = mapResolvedOwner(rawOwner)+ if (!resolved) {+ return+ }+ let entry = owners.get(resolved.owner)+ if (!entry) {+ entry = { ...resolved, paths: [] }+ owners.set(resolved.owner, entry)+ }+ if (!entry.paths.includes(path)) {+ entry.paths.push(path)+ }+}+// The resolver reads the master checkout, which does not hold the files a PR// adds. For such a file it reports `added`: the new directory above it (or the// file itself in an existing directory) and the owners of additions there. The@@ -277,17 +295,33 @@ function computeAdditionOwners(resolutionByPath, changedFiles, config = CONFIG)continue}for (const rawOwner of added.additions || []) {- const resolved = mapResolvedOwner(rawOwner)- if (!resolved) {+ collectOwnerPath(owners, rawOwner, added.path)+ }+ }+ return Array.from(owners.values())+}++// A rename changes the old path too, so a move out of a sensitive directory still counts as a+// change there. A copy leaves its source as it was.+function changedPaths(file) {+ return file.status === 'renamed' && file.previousFilename ? [file.filename, file.previousFilename] : [file.filename]+}++// A one-line edit to a sensitive path can turn a guard off, so `owners.yaml` marks such paths+// with `sensitive: true` and their owners are requested whatever the size of the change.+// Generated status does not skip a sensitive path: a tool writes a ratchet baseline, but one added+// line in it is a new exemption.+// Returns one entry per owner with the sensitive paths that pulled it in.+function computeSensitiveOwners(resolutionByPath, changedFiles, config = CONFIG) {+ const owners = new Map()+ for (const file of changedFiles) {+ for (const path of changedPaths(file)) {+ const resolution = resolutionByPath[path]+ if (!resolution || !resolution.sensitive || isExcludedFile(path, config.excludedPatterns)) {continue}- let entry = owners.get(resolved.owner)- if (!entry) {- entry = { ...resolved, additionPaths: [] }- owners.set(resolved.owner, entry)- }- if (!entry.additionPaths.includes(added.path)) {- entry.additionPaths.push(added.path)+ for (const rawOwner of resolution.owners || []) {+ collectOwnerPath(owners, rawOwner, path)}}}@@ -350,17 +384,34 @@ function classifyOwners(footprints, config = CONFIG) {return { requested, demoted }}-// Owners of additions decide whether a new directory belongs where the PR puts it,-// whatever the size of the change. So they are always requested, and the footprint-// rules and the team cap apply only to the other owners. An owner of additions that-// also owns changed files must not take one of the capped places.-function classifyOwnersWithAdditions(footprints, additionOwners, config = CONFIG) {- const additionOwnerSet = new Set(additionOwners.map((entry) => entry.owner))+// Owners of additions decide whether a new directory belongs where the PR puts it, and+// owners of a sensitive path must see every change to it, whatever the size of the change.+// So these pinned owners are always requested, and the footprint rules and the team cap+// apply only to the other owners. A pinned owner that also owns changed files must not+// take one of the capped places.+function classifyOwnersWithPinned(footprints, pinnedOwners, config = CONFIG) {+ const pinned = new Map()+ for (const entry of pinnedOwners) {+ if (!pinned.has(entry.owner)) {+ pinned.set(entry.owner, entry)+ }+ }+ // The other owners keep their review guarantees. A pinned owner can be the author's own+ // team, or a stale slug that GitHub rejects, so it does not replace an owner of the code.const { requested, demoted } = classifyOwners(- footprints.filter((footprint) => !additionOwnerSet.has(footprint.owner)),+ footprints.filter((footprint) => !pinned.has(footprint.owner)),config)- return { requested: [...requested, ...additionOwners], demoted }+ return { requested: [...requested, ...pinned.values()], demoted }+}++// The comment names only the owners of a sensitive path that the assignment without+// sensitivity would not request. The others are in the sidebar for their changes.+function sensitiveOwnersToExplain(sensitiveOwners, footprints, additionOwners, config = CONFIG) {+ const requestedAnyway = new Set(+ classifyOwnersWithPinned(footprints, additionOwners, config).requested.map((f) => f.owner)+ )+ return sensitiveOwners.filter((entry) => !requestedAnyway.has(entry.owner))}function formatPatterns(patterns, max = 3) {@@ -387,16 +438,16 @@ function sanitizePathForComment(path) {return path.replace(/[`\u0000-\u001f\u007f]/g, '?')}-function formatAdditionOwner(entry) {- return `- \`${entry.owner}\` (${formatPatterns(entry.additionPaths.map(sanitizePathForComment), 2)})`+function formatPinnedOwner(entry) {+ return `- \`${entry.owner}\` (${formatPatterns(entry.paths.map(sanitizePathForComment), 2)})`}// Produce the explanation comment body, or null if no owner was dropped and no-// owner of additions was requested. We only post when a reviewer would otherwise-// wonder why a team is (or is not) in GitHub's "Reviewers" sidebar, so the-// comment carries signal, not noise.-function buildReviewerComment(requested, demoted, additionOwners = [], config = CONFIG) {- if (demoted.length === 0 && additionOwners.length === 0) {+// owner was pinned. We only post when a reviewer would otherwise wonder why a team+// is (or is not) in GitHub's "Reviewers" sidebar, so the comment carries signal,+// not noise.+function buildReviewerComment(requested, demoted, additionOwners = [], sensitiveOwners = [], config = CONFIG) {+ if (demoted.length === 0 && additionOwners.length === 0 && sensitiveOwners.length === 0) {return null}@@ -407,7 +458,17 @@ function buildReviewerComment(requested, demoted, additionOwners = [], config ='These owners were selected because this PR adds a new path where `owners.yaml` names owners of additions. ' +'The path after each owner is the new path:','',- ...additionOwners.map(formatAdditionOwner),+ ...additionOwners.map(formatPinnedOwner),+ ''+ )+ }++ if (sensitiveOwners.length > 0) {+ lines.push(+ 'These owners were selected because this PR changes a path that `owners.yaml` marks as sensitive, ' ++ 'where a small change can matter. The path after each owner is the sensitive path:',+ '',+ ...sensitiveOwners.map(formatPinnedOwner),'')}@@ -645,14 +706,13 @@ async function main() {// Resolve ownership for the files that actually count (excluded ones can't// pull in a reviewer, so don't waste a resolver round-trip on them).- const relevantFilenames = changedFiles- .filter((file) => !isExcludedFile(file.filename))- .map((file) => file.filename)- const resolutionByPath = resolveOwners(relevantFilenames)+ const relevantFilenames = changedFiles.flatMap(changedPaths).filter((filename) => !isExcludedFile(filename))+ const resolutionByPath = resolveOwners([...new Set(relevantFilenames)])const footprints = computeOwnerFootprints(resolutionByPath, changedFiles)const additionOwners = computeAdditionOwners(resolutionByPath, changedFiles)- const { requested, demoted } = classifyOwnersWithAdditions(footprints, additionOwners)+ const sensitiveOwners = computeSensitiveOwners(resolutionByPath, changedFiles)+ const { requested, demoted } = classifyOwnersWithPinned(footprints, [...additionOwners, ...sensitiveOwners])const teams = requested.filter((f) => f.type === 'team').map((f) => f.name)const users = requested.filter((f) => f.type === 'user').map((f) => f.name)@@ -665,6 +725,7 @@ async function main() {console.info(`Users to request: ${users.join(', ') || 'none'}`)console.info(`Demoted to comment: ${demoted.map((f) => f.owner).join(', ') || 'none'}`)console.info(`Owners of additions: ${additionOwners.map((entry) => entry.owner).join(', ') || 'none'}`)+ console.info(`Owners of sensitive paths: ${sensitiveOwners.map((entry) => entry.owner).join(', ') || 'none'}`)console.info()if (!isExternal) {@@ -675,7 +736,12 @@ async function main() {await assignReviewers(toRequest, users)}- const commentBody = buildReviewerComment(requested, demoted, additionOwners)+ const commentBody = buildReviewerComment(+ requested,+ demoted,+ additionOwners,+ sensitiveOwnersToExplain(sensitiveOwners, footprints, additionOwners)+ )if (commentBody) {await upsertReviewerComment(commentBody)}@@ -697,9 +763,11 @@ module.exports = {partitionExternalTeams,computeOwnerFootprints,computeAdditionOwners,+ computeSensitiveOwners,+ sensitiveOwnersToExplain,isSubstantive,classifyOwners,- classifyOwnersWithAdditions,+ classifyOwnersWithPinned,buildReviewerComment,fileMatchesPattern,}diff --git a/.github/scripts/assign-reviewers.test.js b/.github/scripts/assign-reviewers.test.jsindex ce8e5ad81298..57084ae6f919 100644--- a/.github/scripts/assign-reviewers.test.js+++ b/.github/scripts/assign-reviewers.test.js@@ -11,9 +11,11 @@ const {partitionExternalTeams,computeOwnerFootprints,computeAdditionOwners,+ computeSensitiveOwners,+ sensitiveOwnersToExplain,isSubstantive,classifyOwners,- classifyOwnersWithAdditions,+ classifyOwnersWithPinned,buildReviewerComment,fileMatchesPattern,} = require('./assign-reviewers')@@ -316,25 +318,109 @@ test('computeAdditionOwners: collects owners of additions per new path, skippingassertMatchObject(owners[0], {owner: '@PostHog/team-devex',type: 'team',- additionPaths: ['products/new', 'tools/new.py'],+ paths: ['products/new', 'tools/new.py'],})- assertMatchObject(owners[1], { owner: '@someone', type: 'user', additionPaths: ['tools/new.py'] })+ assertMatchObject(owners[1], { owner: '@someone', type: 'user', paths: ['tools/new.py'] })})-test('classifyOwnersWithAdditions: requests owners of additions on top of a full team cap', () => {+test('computeSensitiveOwners: collects owners of sensitive paths, including generated ones and the old path of a rename but not of a copy', () => {+ const sensitive = (owners, extra = {}) => ({ ...resolved(owners, 'owners.yaml'), sensitive: true, ...extra })+ const resolution = {+ 'ci/allowlist.txt': sensitive(['team-devex']),+ 'ci/baseline.txt': sensitive(['team-devex'], { status: 'generated' }),+ 'guard/moved.py': sensitive(['team-guard', '@someone']),+ 'elsewhere/moved.py': resolved(['team-other'], 'owners.yaml'),+ 'elsewhere/template.txt': resolved(['team-other'], 'owners.yaml'),+ 'posthog/api/survey.py': resolved(['team-surveys'], 'posthog/owners.yaml'),+ 'guard/pnpm-lock.yaml': sensitive(['team-lock']),+ }+ const files = [+ file('ci/allowlist.txt', 1),+ file('ci/baseline.txt', 1),+ { ...file('elsewhere/moved.py'), status: 'renamed', previousFilename: 'guard/moved.py' },+ { ...file('elsewhere/template.txt'), status: 'copied', previousFilename: 'ci/allowlist.txt' },+ file('posthog/api/survey.py', 50),+ file('guard/pnpm-lock.yaml', 3),+ ]++ const owners = computeSensitiveOwners(resolution, files)++ assert.deepEqual(+ owners.map((entry) => [entry.owner, entry.type, entry.paths]),+ [+ ['@PostHog/team-devex', 'team', ['ci/allowlist.txt', 'ci/baseline.txt']],+ ['@PostHog/team-guard', 'team', ['guard/moved.py']],+ ['@someone', 'user', ['guard/moved.py']],+ ]+ )+})++test('sensitiveOwnersToExplain: names only the owners that the assignment without sensitivity leaves out', () => {+ const sensitiveOwners = [{ owner: '@PostHog/team-guard', paths: ['guard/list.txt'] }]+ const additionOwners = [{ owner: '@PostHog/team-guard', type: 'team', name: 'team-guard', paths: ['products/new'] }]+ const cases = [+ // The size rules request a substantive owner anyway.+ [[fp('@PostHog/team-guard', CONFIG.substantiveLines)], [], []],+ // Next to a larger owner, a minor owner is demoted.+ [[fp('@PostHog/team-guard', 1), fp('@PostHog/team-big', 50)], [], ['@PostHog/team-guard']],+ // Alone, a minor owner is requested anyway.+ [[fp('@PostHog/team-guard', 1)], [], []],+ // An owner of additions is in the sidebar anyway.+ [[fp('@PostHog/team-guard', 1), fp('@PostHog/team-big', 50)], additionOwners, []],+ ]++ for (const [footprints, pinned, expected] of cases) {+ assert.deepEqual(+ sensitiveOwnersToExplain(sensitiveOwners, footprints, pinned).map((entry) => entry.owner),+ expected+ )+ }+})++test('classifyOwnersWithPinned: a pinned owner keeps the review guarantee of the changed code', () => {+ const sensitiveOwners = computeSensitiveOwners(+ { 'ci/allowlist.txt': { ...resolved(['team-devex'], 'owners.yaml'), sensitive: true } },+ [file('ci/allowlist.txt', 1)]+ )++ const { requested, demoted } = classifyOwnersWithPinned(+ [fp('@PostHog/team-devex', 1), fp('@PostHog/team-foo', 1)],+ sensitiveOwners+ )++ assert.deepEqual(+ requested.map((f) => f.owner),+ ['@PostHog/team-foo', '@PostHog/team-devex']+ )+ assert.deepEqual(demoted, [])+})++test('classifyOwnersWithPinned: requests owners of additions and of sensitive paths on top of a full team cap', () => {const teams = Array.from({ length: CONFIG.maxTeamsRequested }, (_, i) => fp(`@PostHog/team-${i}`, 50 + i))- const footprints = [...teams, fp('@PostHog/team-devex', 200), fp('@PostHog/team-small', 1)]+ const footprints = [+ ...teams,+ fp('@PostHog/team-devex', 200),+ fp('@PostHog/team-guard', 1),+ fp('@PostHog/team-small', 1),+ ]const additionOwners = computeAdditionOwners({'products/new/a.py': { ...resolved([], null), added: { path: 'products/new', additions: ['team-devex'] } },},[{ ...file('products/new/a.py'), status: 'added' }])+ const sensitiveOwners = computeSensitiveOwners(+ {+ 'ci/allowlist.txt': { ...resolved(['team-guard', 'team-devex'], 'owners.yaml'), sensitive: true },+ },+ [file('ci/allowlist.txt', 1)]+ )- const { requested, demoted } = classifyOwnersWithAdditions(footprints, additionOwners)+ const { requested, demoted } = classifyOwnersWithPinned(footprints, [...additionOwners, ...sensitiveOwners])- assert.equal(requested.length, CONFIG.maxTeamsRequested + 1)+ assert.equal(requested.length, CONFIG.maxTeamsRequested + 2)assert.equal(requested.filter((f) => f.owner === '@PostHog/team-devex').length, 1)+ assert.equal(requested.filter((f) => f.owner === '@PostHog/team-guard').length, 1)for (const team of teams) {assert.ok(requested.some((f) => f.owner === team.owner))}@@ -368,15 +454,23 @@ test('buildReviewerComment: returns null when no owner was dropped', () => {})test('buildReviewerComment: names each owner of additions with its addition, even when nobody was skipped', () => {- const additionOwners = [{ owner: '@PostHog/team-devex', additionPaths: ['products/new'] }]+ const additionOwners = [{ owner: '@PostHog/team-devex', paths: ['products/new'] }]const body = buildReviewerComment(requested, [], additionOwners)assert.ok(body.includes(CONFIG.commentMarker))assert.ok(body.includes('- `@PostHog/team-devex` (`products/new`)'))assert.ok(!body.includes('soft owners were skipped'))})+test('buildReviewerComment: names each owner of a sensitive path with that path, even when nobody was skipped', () => {+ const sensitiveOwners = [{ owner: '@PostHog/team-devex', paths: ['ci/allowlist.txt'] }]+ const body = buildReviewerComment(requested, [], [], sensitiveOwners)+ assert.ok(body.includes('marks as sensitive'))+ assert.ok(body.includes('- `@PostHog/team-devex` (`ci/allowlist.txt`)'))+ assert.ok(!body.includes('soft owners were skipped'))+})+test('buildReviewerComment: keeps a PR-chosen addition path inside its code span', () => {- const additionOwners = [{ owner: '@PostHog/team-devex', additionPaths: ['products/x` @someone\n\n# hi'] }]+ const additionOwners = [{ owner: '@PostHog/team-devex', paths: ['products/x` @someone\n\n# hi'] }]const body = buildReviewerComment(requested, [], additionOwners)assert.ok(body.includes('- `@PostHog/team-devex` (`products/x? @someone??# hi`)'))})diff --git a/owners.yaml b/owners.yamlindex 8c7134526f2f..9e4723b3fb81 100644--- a/owners.yaml+++ b/owners.yaml@@ -58,11 +58,15 @@ rules:- AGENTS.md- '/.coderabbit.yaml'- '/.greptile/'- # 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+ # 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. A one-line edit changes who reviews+ # later PRs, so the path is sensitive. Sensitive stays on when a nearer file+ # names other owners, so a product's own owners.yaml goes to that product team.+ - match: owners.yaml+ owners: team-devex+ sensitive: true# Anchored: bare 'bin/' also matches Cargo's src/bin/, a crate's own binaries.- match:- '/bin/'@@ -116,8 +120,10 @@ rules: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.+ # closed, so the paths are sensitive and the reviewer assigner requests devex for every+ # change. Busy files that most PRs touch (lib/api.ts, pyproject.toml, the model crossing,+ # setup receivers and frozen dataclass baselines) stay out, so that the review requests+ # stay rare.- match:- '/.github/scripts/migration-deletion-allowlist.txt'- '/.semgrep/rules/devex/'@@ -147,9 +153,11 @@ rules:- '/products/README.md'- '/products/architecture.md'- '/products/isolation_baseline.txt'- - '/products/model_crossing_uses_baseline.txt'- '/tools/openapi-codegen/'owners: team-devex+ sensitive: true+ - match: '/products/model_crossing_uses_baseline.txt'+ owners: team-devex- match: '/posthog/management/commands/find_enum_collisions.py'owners: team-devex- match: '/posthog/settings/data_warehouse.py'diff --git a/posthog/owners.yaml b/posthog/owners.yamlindex 41ee1aae5234..a7a5388553de 100644--- a/posthog/owners.yaml+++ b/posthog/owners.yaml@@ -21,6 +21,9 @@ rules:owners: team-data-tools- match: '/management/migration_analysis/'owners: team-devex+ # Each line acknowledges a risky migration, so one added line lets that migration skip the check.+ - match: '/management/migration_analysis/*_acknowledged_migrations.txt'+ sensitive: true- match: '/queries/'owners: team-analytics-platform- match: '/rbac/'