: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
chore(ci): review and label every agent infra change (#118003)
Charles Vien3233c0f4aa00
diff --git a/.agents/skills/owners.yaml b/.agents/skills/owners.yamlindex ca30252af6dc..07c0f5e80fcb 100644--- a/.agents/skills/owners.yaml+++ b/.agents/skills/owners.yaml@@ -1,5 +1,11 @@version: 1owners: []rules:+ - match:+ - '/auditing-llm-gateway-parity/'+ - '/finding-llm-gateway-migration-candidates/'+ - '/migrating-llm-gateway-callers/'+ owners: team-agent-infrastructure+ sensitive: true- match: '/ingestion-*/'owners: team-ingestiondiff --git a/.github/auto-assign-labels.json b/.github/auto-assign-labels.jsonindex 96204008d0c3..e368131b6f38 100644--- a/.github/auto-assign-labels.json+++ b/.github/auto-assign-labels.json@@ -1,5 +1,5 @@{- "_comment": "Maps a PR's conventional-commit scope (the part in parens of `type(scope): summary`) to labels the Auto Assign Labels workflow applies. Owned by @PostHog/team-feature-flags via owners.yaml, so mappings can change without editing the workflow or script. Scopes are matched case-insensitively. Labels must already exist in the repo. Add a new object to `rules` to map more scopes.",+ "_comment": "Maps a PR's conventional-commit scope (the part in parens of `type(scope): summary`) to labels the Auto Assign Labels workflow applies. Owned by @PostHog/team-feature-flags via owners.yaml, so mappings can change without editing the workflow or script. Scopes are matched case-insensitively. A rule can also list `paths` from the repo root: a PR that changes a matching file, either side of a rename, gets the rule's labels. A path that ends in `/` covers its directory, `*` matches within one path segment and `**` matches any number of directories. Labels must already exist in the repo. Add a new object to `rules` to map more scopes.","rules": [{"scopes": ["flags", "flag", "feature-flags", "feature-flag", "feature_flags", "feature_flag"],@@ -26,6 +26,25 @@"llm-gateway","ai-gateway"],+ "paths": [+ ".agents/skills/auditing-llm-gateway-parity/",+ ".agents/skills/finding-llm-gateway-migration-candidates/",+ ".agents/skills/migrating-llm-gateway-callers/",+ ".github/workflows/cd-agent-proxy-image.yml",+ ".github/workflows/cd-tasks-golden-snapshot.yml",+ ".github/workflows/ci-agent-proxy.yml",+ ".github/workflows/ci-llm-gateway.yml",+ ".github/workflows/llm-gateway-cd.yml",+ ".github/workflows/update-ai-costs.yml",+ "bin/start-llm-gateway",+ "nodejs/src/ingestion/pipelines/ai/costs/providers/",+ "nodejs/src/ingestion/pipelines/ai/costs/scripts/",+ "packages/agent/",+ "posthog/**/*llm_gateway*",+ "products/tasks/",+ "services/agent-proxy/",+ "services/llm-gateway/"+ ],"labels": ["feature/agent-infra"]}]diff --git a/.github/owners.yaml b/.github/owners.yamlindex 3f5164fd0fa5..330c53ba38f1 100644--- a/.github/owners.yaml+++ b/.github/owners.yaml@@ -26,8 +26,11 @@ rules:- '/workflows/llm-gateway-cd.yml'- '/workflows/update-ai-costs.yml'owners: [team-devex, team-agent-infrastructure]+ - match: ['/workflows/ci-llm-gateway.yml', '/workflows/llm-gateway-cd.yml']+ sensitive: true- match:- '/workflows/ci-agent-proxy.yml'- '/workflows/cd-agent-proxy-image.yml'- '/workflows/cd-tasks-golden-snapshot.yml'owners: team-agent-infrastructure+ sensitive: truediff --git a/.github/scripts/label-pr-from-title.js b/.github/scripts/label-pr-from-title.jsindex 587d63263535..0d4e0531dafc 100644--- a/.github/scripts/label-pr-from-title.js+++ b/.github/scripts/label-pr-from-title.js@@ -1,12 +1,12 @@#!/usr/bin/env node// Adds team/feature labels to a PR based on its conventional-commit scope-// (`type(scope): summary`), plus the `docs` label for docs-typed or Inkeep-bot+// (`type(scope): summary`) and the paths it changes, plus the `docs` label for docs-typed or Inkeep-bot// PRs, plus the feature flags team's `review/low-hanging-fruit` label (see the// feature flags team section below). Additive only — it never removes labels, so manual labels and the// ownership-based labeler (assign-reviewers.js) are left intact.//-// The scope -> labels mapping lives in .github/auto-assign-labels.json, OUTSIDE+// The scope and path -> labels mapping lives in .github/auto-assign-labels.json, OUTSIDE// this script, so the owning team can adjust mappings without changing (and// re-approving) the workflow or this script. The config is read from the master// checkout, never the PR, so a fork PR can't inject its own mappings, and the@@ -78,6 +78,77 @@ function labelsForTitle(title, rules) {return Array.from(labels)}+const PATH_PATTERN_TOKENS = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' }++function pathPatternToRegExp(pattern) {+ const source = pattern+ .split(/(\*\*\/|\*\*|\*)/)+ .map((part) => PATH_PATTERN_TOKENS[part] ?? part.replace(/[.+?^${}()|[\]\\]/g, '\\$&'))+ .join('')+ return new RegExp(`^${source}${pattern.endsWith('/') ? '' : '$'}`)+}++function labelsForFiles(files, rules) {+ const filenames = files.flatMap((file) =>+ file.status === 'renamed' && file.previous_filename ? [file.filename, file.previous_filename] : [file.filename]+ )+ const labels = new Set()++ for (const rule of rules) {+ const patterns = (rule.paths || []).map(pathPatternToRegExp)+ if (patterns.some((pattern) => filenames.some((filename) => pattern.test(filename)))) {+ for (const label of rule.labels || []) {+ labels.add(label)+ }+ }+ }++ return Array.from(labels)+}++const PR_FILES_PAGE_SIZE = 100++// The job applies every label after this request, and it has a five-minute+// timeout. A stalled request must give up well before that, so the team and+// docs labels still get applied.+const PR_FILES_REQUEST_TIMEOUT_MS = 10_000++// Returns null on failure, because a missing file list must not fail the job or+// apply the low-hanging-fruit label.+async function fetchPrFiles() {+ const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER } = process.env+ const files = []++ try {+ for (let page = 1; ; page++) {+ const response = await fetch(+ `https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=${PR_FILES_PAGE_SIZE}&page=${page}`,+ {+ headers: {+ Authorization: `token ${GITHUB_TOKEN}`,+ Accept: 'application/vnd.github.v3+json',+ },+ signal: AbortSignal.timeout(PR_FILES_REQUEST_TIMEOUT_MS),+ }+ )++ if (!response.ok) {+ console.warn(`⚠️ Could not list PR files: ${response.status} ${response.statusText}`)+ return null+ }++ const batch = await response.json()+ files.push(...batch)+ if (batch.length < PR_FILES_PAGE_SIZE) {+ return files+ }+ }+ } catch (error) {+ console.warn(`⚠️ Could not list PR files: ${error?.message ?? error}`)+ return null+ }+}+// Best-effort: a labeling failure must never fail the job. The workflow does// nothing but label, so a hard failure would only paint a non-blocking red ✗ on// the PR over a transient blip or config drift (e.g. a renamed label). We warn@@ -86,7 +157,7 @@ async function addLabels(labels) {const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER } = process.envif (labels.length === 0) {- console.info('ℹ️ Title has no labelable scope; nothing to do')+ console.info('ℹ️ No scope or path maps to a label; nothing to do')return}@@ -173,8 +244,7 @@ const FLAGS_QUICK_REVIEW_SHAPES = [{ maxFiles: 5, maxLines: 100, fileMatches: isFlagsUiFile },]-// GitHub's maximum page size for the "list pull request files" endpoint.-const FLAGS_FILES_PAGE_SIZE = 100+const FLAGS_FILE_LIMIT = 100// A small diff in these paths still needs a careful review: a migration changes// production data, and a workflow change runs with repository secrets.@@ -216,12 +286,10 @@ function flagsWithoutGeneratedFiles(files) {}}-// `files` is the first page of GitHub's "list pull request files" response.+// `files` is GitHub's "list pull request files" response.function isFlagsLowHangingFruit(files) {- // A full page means the PR has at least a page of files, and the files on- // later pages are not checked. So many files, even generated ones, is not a- // quick review, so a full page withholds the label.- if (files.length >= FLAGS_FILES_PAGE_SIZE) {+ // So many files, even generated ones, is not a quick review.+ if (files.length >= FLAGS_FILE_LIMIT) {return false}// Check the risky paths before the generated files are removed, because@@ -239,48 +307,12 @@ function isFlagsLowHangingFruit(files) {)}-// The job applies every label after this request, and it has a five-minute-// timeout. A stalled request must give up well before that, so the team and-// docs labels still get applied.-const FLAGS_FILES_REQUEST_TIMEOUT_MS = 10_000--// Fetches only the first page, because isFlagsLowHangingFruit() withholds the-// label when the page is full. Returns null on failure, because a missing size-// must not fail the job or apply the label.-async function fetchFlagsPrFiles() {- const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER } = process.env-- try {- const response = await fetch(- `https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=${FLAGS_FILES_PAGE_SIZE}`,- {- headers: {- Authorization: `token ${GITHUB_TOKEN}`,- Accept: 'application/vnd.github.v3+json',- },- signal: AbortSignal.timeout(FLAGS_FILES_REQUEST_TIMEOUT_MS),- }- )-- if (!response.ok) {- console.warn(`⚠️ Could not list PR files: ${response.status} ${response.statusText}`)- return null- }-- return await response.json()- } catch (error) {- console.warn(`⚠️ Could not list PR files: ${error?.message ?? error}`)- return null- }-}--// Returns the label to add, or null. `labels` are the labels the title rules-// computed for this PR, because the candidate check reads the team label.-async function flagsLowHangingFruitLabel(author, labels) {+// Returns the label to add, or null. `labels` are the labels computed for this+// PR, because the candidate check reads the team label.+function flagsLowHangingFruitLabel(author, labels, files) {if (!isFlagsLowHangingFruitCandidate(author, labels)) {return null}- const files = await fetchFlagsPrFiles()return files && isFlagsLowHangingFruit(files) ? FLAGS_LOW_HANGING_FRUIT_LABEL : null}@@ -301,11 +333,12 @@ async function main() {try {const rules = loadRules()- const labels = labelsForTitle(PR_TITLE, rules)+ const files = await fetchPrFiles()+ const labels = Array.from(new Set([...labelsForTitle(PR_TITLE, rules), ...labelsForFiles(files ?? [], rules)]))if (docsLabelApplies(PR_TITLE, PR_AUTHOR) && !labels.includes('docs')) {labels.push('docs')}- const flagsLabel = await flagsLowHangingFruitLabel(PR_AUTHOR, labels)+ const flagsLabel = flagsLowHangingFruitLabel(PR_AUTHOR, labels, files)if (flagsLabel) {labels.push(flagsLabel)}@@ -326,6 +359,7 @@ module.exports = {parseType,docsLabelApplies,labelsForTitle,+ labelsForFiles,loadRules,isFlagsLowHangingFruitCandidate,isFlagsLowHangingFruit,diff --git a/.github/scripts/label-pr-from-title.test.js b/.github/scripts/label-pr-from-title.test.jsindex 4b49addb7e49..79505c7680b3 100644--- a/.github/scripts/label-pr-from-title.test.js+++ b/.github/scripts/label-pr-from-title.test.js@@ -12,6 +12,7 @@ const {parseType,docsLabelApplies,labelsForTitle,+ labelsForFiles,loadRules,isFlagsLowHangingFruitCandidate,isFlagsLowHangingFruit,@@ -84,6 +85,74 @@ test('labelsForTitle', async (t) => {}})+const PATH_RULES = [+ {+ scopes: ['agent'],+ paths: ['packages/agent/', 'bin/start-agent', 'posthog/*agent_root*', 'products/**/*agent_any*'],+ labels: ['feature/agent-infra'],+ },+]++const LABELS_FOR_FILES_CASES = [+ {+ files: [+ { filename: 'posthog/api/survey.py', status: 'modified' },+ { filename: 'packages/agent/src/run.ts', status: 'modified' },+ ],+ expected: ['feature/agent-infra'],+ description: 'one of several files under a path prefix',+ },+ {+ files: [{ filename: 'elsewhere/run.ts', previous_filename: 'packages/agent/src/run.ts', status: 'renamed' }],+ expected: ['feature/agent-infra'],+ description: 'a rename out of a path prefix',+ },+ {+ files: [{ filename: 'elsewhere/run.ts', previous_filename: 'packages/agent/src/run.ts', status: 'copied' }],+ expected: [],+ description: 'a copy from a path prefix',+ },+ {+ files: [{ filename: 'packages/agentic/run.ts', status: 'modified' }],+ expected: [],+ description: 'a sibling directory that starts with the same name',+ },+ {+ files: [{ filename: 'bin/start-agent-old', status: 'modified' }],+ expected: [],+ description: 'a longer name than an exact file path',+ },+ {+ files: [{ filename: 'posthog/x_agent_root.py', status: 'modified' }],+ expected: ['feature/agent-infra'],+ description: 'a single star inside one segment',+ },+ {+ files: [{ filename: 'posthog/storage/x_agent_root.py', status: 'modified' }],+ expected: [],+ description: 'a single star does not cross directories',+ },+ {+ files: [{ filename: 'products/a/b/x_agent_any.py', status: 'modified' }],+ expected: ['feature/agent-infra'],+ description: 'a double star crosses directories',+ },+ {+ files: [{ filename: 'products/x_agent_any.py', status: 'modified' }],+ expected: ['feature/agent-infra'],+ description: 'a double star matches zero directories',+ },+ { files: [], expected: [], description: 'no files' },+]++test('labelsForFiles', async (t) => {+ for (const { files, expected, description } of LABELS_FOR_FILES_CASES) {+ await t.test(description, () => {+ assert.deepEqual(labelsForFiles(files, PATH_RULES), expected)+ })+ }+})+const PARSE_TYPE_CASES = [{ title: 'docs: add guide', expected: 'docs', description: 'type with no scope' },{ title: 'docs(internal): x', expected: 'docs', description: 'type with scope' },@@ -125,6 +194,10 @@ test('the shipped config loads into well-formed rules', () => {for (const rule of rules) {assert.ok(Array.isArray(rule.scopes) && rule.scopes.length > 0, 'rule missing scopes')assert.ok(Array.isArray(rule.labels) && rule.labels.length > 0, 'rule missing labels')+ assert.ok(+ (rule.paths || []).every((prefix) => typeof prefix === 'string' && prefix && !prefix.startsWith('/')),+ 'rule paths must be relative to the repo root'+ )}})@@ -178,6 +251,21 @@ for (const scope of [})}+for (const filename of [+ 'nodejs/src/ingestion/pipelines/ai/costs/providers/manual-providers.ts',+ 'packages/agent/src/run.ts',+ 'posthog/migrations/1225_team_llm_gateway_overspend_allowance_usd.py',+ 'posthog/tasks/team_llm_gateway_quota.py',+ 'products/tasks/backend/api.py',+ 'services/agent-proxy/src/main.rs',+ 'services/llm-gateway/src/app.py',+]) {+ test(`the shipped config maps a change to ${filename} to the agent infra label`, () => {+ const labels = labelsForFiles([{ filename, status: 'modified' }], loadRules())+ assert.ok(labels.includes('feature/agent-infra'), `${filename} does not map to feature/agent-infra`)+ })+}+test('the shipped config keeps labels from mixed desktop and agent infra scopes', () => {const labels = labelsForTitle('feat(desktop, tasks): x', loadRules())assert.ok(labels.includes('feature/desktop'))@@ -330,12 +418,12 @@ const FLAGS_LOW_HANGING_FRUIT_CASES = [{files: [...generatedFiles(98), file('a.tsx', 10)],expected: true,- description: 'generated files below a full page do not count',+ description: 'generated files below the file limit do not count',},{files: [...generatedFiles(99), file('a.tsx', 10)],expected: false,- description: 'a full page withholds the label, because later pages go unchecked',+ description: 'the file limit withholds the label, even when most files are generated',},]diff --git a/.github/workflows/auto-assign-labels.yml b/.github/workflows/auto-assign-labels.ymlindex db44e0740f25..ca9e98c7f3e5 100644--- a/.github/workflows/auto-assign-labels.yml+++ b/.github/workflows/auto-assign-labels.yml@@ -1,6 +1,6 @@name: Auto Assign Labels-# Adds team/feature labels to a PR based on its conventional-commit scope, e.g.+# Adds team/feature labels to a PR based on its conventional-commit scope and the paths it changes, e.g.# `feat(flags): …` -> `feature/feature-flags` + `team/feature-flags`. Small# feature flags PRs from the PostHog AI app also get `review/low-hanging-fruit`. The# scope -> label mappings live in .github/auto-assign-labels.json so the owning@@ -18,7 +18,7 @@ name: Auto Assign Labels# nosemgrep: semgrep.rules.github-actions-pull-request-targeton:pull_request_target:- types: [opened, edited, reopened, ready_for_review]+ types: [opened, edited, reopened, ready_for_review, synchronize]permissions:contents: read@@ -45,6 +45,11 @@ jobs:with:# MUST be `master` so we never execute untrusted PR code.ref: master+ sparse-checkout: |+ /.github/+ /.nvmrc+ .gitattributes+ sparse-checkout-cone-mode: false# No fork guard: pull_request_target runs in base context, so org# secrets are available even when the PR comes from a fork.diff --git a/owners.yaml b/owners.yamlindex 9e4723b3fb81..543aabec3803 100644--- a/owners.yaml+++ b/owners.yaml@@ -85,6 +85,7 @@ rules:owners: team-ingestion- match: '/bin/start-llm-gateway'owners: [team-devex, team-agent-infrastructure]+ sensitive: true- match: '/cli/'owners: team-error-tracking- match: '/docs/onboarding/ai-observability/'@@ -173,8 +174,6 @@ rules:owners: ai-research- match: '/posthog/test/test_feature_flag_analytics.py'owners: team-feature-flags- - match: '/services/llm-gateway/'- owners: team-agent-infrastructure- match:- '/packages/owners-yaml/'- '/tools/hogli-commands/'diff --git a/packages/agent/owners.yaml b/packages/agent/owners.yamlindex a849d13c540a..1d6248dc4950 100644--- a/packages/agent/owners.yaml+++ b/packages/agent/owners.yaml@@ -1,3 +1,4 @@version: 1owners:- team-agent-infrastructure+sensitive: truediff --git a/posthog/owners.yaml b/posthog/owners.yamlindex a7a5388553de..2de43abd6d05 100644--- a/posthog/owners.yaml+++ b/posthog/owners.yaml@@ -36,5 +36,8 @@ rules:owners: conversations- match: '/warehouse/'owners: team-data-stack+ - match: '*llm_gateway*'+ owners: team-agent-infrastructure+ sensitive: true- match: '*llm_prompt*.py'owners: team-experimentsdiff --git a/posthog/tasks/owners.yaml b/posthog/tasks/owners.yamlindex da838ca966f6..2007132eafa7 100644--- a/posthog/tasks/owners.yaml+++ b/posthog/tasks/owners.yaml@@ -26,3 +26,6 @@ rules:owners: conversations- match: ['/usage_report.py', '/test/test_usage_report.py']owners: team-billing+ - match: '*llm_gateway*'+ owners: team-agent-infrastructure+ sensitive: truediff --git a/products/canvas/product.yaml b/products/canvas/product.yamlindex f9ac42c37b95..075d7cbb29e8 100644--- a/products/canvas/product.yaml+++ b/products/canvas/product.yaml@@ -1,3 +1,3 @@name: Canvasowners:- - team-agent-infrastructure+ - team-surfacesdiff --git a/products/tasks/product.yaml b/products/tasks/product.yamlindex a8d16a19a9c8..5f8ff38f26d6 100644--- a/products/tasks/product.yaml+++ b/products/tasks/product.yaml@@ -1,3 +1,4 @@name: Tasksowners:- team-agent-infrastructure+sensitive: truediff --git a/services/agent-proxy/owners.yaml b/services/agent-proxy/owners.yamlindex a849d13c540a..1d6248dc4950 100644--- a/services/agent-proxy/owners.yaml+++ b/services/agent-proxy/owners.yaml@@ -1,3 +1,4 @@version: 1owners:- team-agent-infrastructure+sensitive: truediff --git a/services/llm-gateway/owners.yaml b/services/llm-gateway/owners.yamlnew file mode 100644index 000000000000..1d6248dc4950--- /dev/null+++ b/services/llm-gateway/owners.yaml@@ -0,0 +1,4 @@+version: 1+owners:+ - team-agent-infrastructure+sensitive: true