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(ci): make the weekly flaky test report verifiable (#111972)

Raúl Negrón-Oteroac5178dbde0d
diff --git a/.github/scripts/weekly-flaky-report.mjs b/.github/scripts/weekly-flaky-report.mjs
index 26973470073b..6d16d4dc47a4 100644
--- a/.github/scripts/weekly-flaky-report.mjs
+++ b/.github/scripts/weekly-flaky-report.mjs
@@ -1,18 +1,16 @@
// Weekly flaky-test report, posted to #flakey-tests on Monday.
//
// PULL model, sibling of eng-analytics-weekly-digest.mjs: reads the
-// engineering_analytics flaky_tests endpoint for candidates, then one pytest-only
-// HogQL read of the product's ci_failures view joined to the synced runs table for
-// the rerun-rescue counts and failing-job evidence links the endpoint does not
-// carry yet. The product owns the flake signal; this owns cadence, owner
-// attribution, and the relay.
+// engineering_analytics flaky_tests endpoint for candidates and every count in the
+// table, then one pytest-only HogQL read of the product's ci_failures view for the
+// failing-job links the endpoint does not carry. The product owns the flake signal;
+// this owns cadence, owner attribution, and the relay.
//
// GHA cron ──> flaky_tests endpoint + one HogQL query ──> Slack
//
// Endpoint gaps inherited here (backend follow-ups): suites that don't ship junit
-// into the span pipeline are invisible, and rerun_passed_count only flows from
-// retry-enabled lanes. Master-burst breakage and branch-only tests are filtered
-// out client-side.
+// into the span pipeline are invisible. Master-burst breakage and branch-only tests
+// are filtered out client-side.
import { pathToFileURL } from 'node:url'
@@ -40,18 +38,17 @@ import {
const SOURCE_ID = process.env.ENG_ANALYTICS_SOURCE_ID || ''
// The synced runs table name carries the warehouse source prefix, which differs per project.
const RUNS_TABLE = process.env.ENG_ANALYTICS_RUNS_TABLE || 'eng_analyticsgithub_workflow_runs'
-const TRUNK_TABLE = process.env.TRUNK_QUARANTINE_TABLE || 'trunkio.quarantinedtests'
+const REPORT_WINDOW_DAYS = 7
const TOP_N = 10
const CANDIDATE_POOL = 40
const CLUSTER_MIN_TESTS = 5
const REPORT_RUNNERS = ['pytest', 'jest']
const RUNNER_LABELS = { pytest: 'pytest', jest: 'Jest' }
-// Two systems can suppress a failing test, and only one of them reaches the endpoint. The
-// quarantine file xfails the test, so the span records 'xfailed' and the item arrives already
-// marked. Trunk instead masks the job verdict and leaves a hard failure in the junit, so its
-// quarantines arrive as ordinary failures and have to be read separately.
+// Trunk quarantines a test by masking the job verdict. It leaves a hard failure in the junit, so
+// its quarantines arrive as ordinary failures and have to be read separately.
+// Expected failures (xfail), including file quarantines, are outside this Trunk report.
// Same two variables the CI uploaders read: uploads decide whether the synced Trunk state is
// current, masking decides whether a quarantine actually keeps a failure from failing CI.
const TRUNK_UPLOADS_ON = process.env.TRUNK_UPLOAD_ENABLED === 'true'
@@ -75,7 +72,7 @@ function endpointUrl(action, params = {}) {
// confirmed flakes with no master failure that rank below those rows.
function flakyTestsUrl(runner) {
return endpointUrl('flaky_tests', {
- date_from: '-7d',
+ date_from: `-${REPORT_WINDOW_DAYS}d`,
limit: 200,
repo: GITHUB_REPOSITORY,
runner,
@@ -86,11 +83,15 @@ function fetchFlakyTests(runner) {
return requestPosthog(flakyTestsUrl(runner), { headers: AUTH_HEADERS }, 'flaky_tests')
}
-// A same-commit recovery proves a flake, so only suppress likely one-merge bursts
-// when the endpoint has no recovery proof.
+// Xfail classification takes precedence over recovery, so use the recovery count directly.
+function hasRecovery(item) {
+ return item.same_commit_recovery_run_count > 0
+}
+
+// A known Trunk flake can fail repeatedly on master without a recorded recovery.
function isMasterBurst(item) {
return (
- item.classification === 'suspected_regression' &&
+ !item.knownFlake &&
item.failed_run_count > 0 &&
item.master_failed_run_count / item.failed_run_count >= 0.5 &&
item.failed_pr_count <= 3
@@ -100,7 +101,7 @@ function isMasterBurst(item) {
// A test with no file on master runs only on the branch that added it, so only that branch can fix
// it. The span scan is branch-agnostic by design, so the checkout is what tells the two apart.
function selectReportCandidates(items, runner, toRepoPaths) {
- const qualifying = items.filter((item) => item.runner === runner && !isMasterBurst(item))
+ const qualifying = items.filter((item) => item.runner === runner)
const onMaster = []
const branchOnly = []
for (const item of qualifying) {
@@ -150,8 +151,9 @@ function selectorVariants(selector) {
return variants.length > 0 ? variants : [selector]
}
-// Rescue counts (failed at attempt N, run green at a later attempt) and the two most
-// recent failing (run, job) pairs, from the product's ci_failures view.
+// The two most recent failing (run, job) pairs, from the product's ci_failures view. That view
+// holds fewer runs than the endpoint counts, so it supplies links and never a number. A run on
+// another CI engine has no page on GitHub, so only the runs GitHub synced get a link.
async function enrich(items, runHogql = hogql) {
const bySelector = new Map()
for (const item of items) {
@@ -160,7 +162,7 @@ async function enrich(items, runHogql = hogql) {
}
}
const selectors = [...bySelector.keys()]
- const empty = { runsRescued: null, evidence: [] }
+ const empty = { evidence: [] }
if (selectors.length === 0) {
return () => empty
}
@@ -168,24 +170,28 @@ async function enrich(items, runHogql = hogql) {
try {
const result = await runHogql(
`SELECT f.test_id AS test_id,
- uniqIf(f.run_id, r.run_attempt > f.run_attempt AND r.conclusion = 'success') AS runs_rescued,
- arraySlice(arrayReverseSort(x -> x.1, groupUniqArray(20)((toUnixTimestamp(f.timestamp), f.run_id, f.job_id))), 1, 6) AS recent
+ arraySlice(arraySort(x -> -x.1, groupUniqArray((toUnixTimestamp(f.timestamp), f.run_id, f.job_id))), 1, 6) AS recent
FROM engineering_analytics_ci_failures f
- LEFT JOIN ${RUNS_TABLE} r ON r.id = f.run_id
- WHERE f.timestamp >= now() - INTERVAL 7 DAY
+ WHERE f.timestamp >= now() - INTERVAL ${REPORT_WINDOW_DAYS} DAY
AND lower(f.repo) = lower({repository})
AND f.test_id IN {selectors}
- GROUP BY f.test_id`,
+ AND (f.ci_engine = 'github_actions' OR f.ci_engine IS NULL)
+ AND f.run_id IN (
+ SELECT id FROM ${RUNS_TABLE}
+ WHERE created_at >= toString(toDate(now() - INTERVAL 30 DAY))
+ )
+ GROUP BY f.test_id
+ LIMIT ${selectors.length}`,
{ repository: GITHUB_REPOSITORY, selectors }
)
rows = result.results || []
} catch (err) {
- // The table still works without these columns; degrade rather than skip the post.
- console.warn(`enrichment query failed — omitting rescue counts and job links: ${err.message}`)
+ // Counts come from the endpoint, so missing log links do not prevent the report.
+ console.warn(`enrichment query failed — omitting job links: ${err.message}`)
return () => empty
}
const enriched = new Map()
- for (const [testId, runsRescued, recent] of rows) {
+ for (const [testId, recent] of rows) {
const item = bySelector.get(testId)
if (!item) {
continue
@@ -202,7 +208,7 @@ async function enrich(items, runHogql = hogql) {
break
}
}
- enriched.set(item.selector, { runsRescued, evidence })
+ enriched.set(item.selector, { evidence })
}
return (item) => enriched.get(item.selector) || empty
}
@@ -214,51 +220,60 @@ async function enrichRunnerCandidates(runner, candidates, runHogql = hogql) {
runHogql
)
}
- const empty = { runsRescued: null, evidence: [] }
+ const empty = { evidence: [] }
return () => empty
}
-// Trunk keys a test by (file, classname, name) rather than by one id, and the two runners split
-// the name differently: pytest hides the class inside `classname` (the file's module plus the
-// class), while jest puts the whole title in `name`. Trimming the module prefix recovers the
-// pytest class; jest needs no reassembly, so file and name concatenate directly.
-//
-// `parent` carries the runner for pytest and the file path for jest, which is what separates the
-// two sets. The table has no repository column, so this cannot be repo-scoped. It does not need
-// to be: a row only annotates a selector the repo-scoped endpoint already returned.
-const TRUNK_QUARANTINED_QUERY = `
- SELECT concat(file, '::', if(cls = '', '', concat(cls, '::')), name) AS nodeid,
- quarantined_at
- FROM (
- SELECT file, name, quarantined_at,
- replaceAll(substring(file, 1, length(file) - 3), '/', '.') AS module,
- if({runner} = 'pytest' AND startsWith(classname, concat(module, '.')),
- replaceAll(substring(classname, length(module) + 2, length(classname)), '.', '::'),
- '') AS cls
- FROM __TRUNK_TABLE__
- WHERE if({runner} = 'pytest', parent = 'pytest', parent != 'pytest')
- )`
-
-// Uploads off, a missing table, or a query error all degrade to a report without Trunk state,
-// never to a failed run.
-async function fetchTrunkQuarantined(runner, runHogql = hogql, enabled = TRUNK_UPLOADS_ON) {
+function fetchTrunkQuarantine() {
+ return requestPosthog(
+ endpointUrl('trunk_quarantine', { repo: GITHUB_REPOSITORY }),
+ { headers: AUTH_HEADERS },
+ 'trunk_quarantine'
+ )
+}
+
+// Trunk does not expire quarantines; the TTL is the product's repair deadline.
+function trunkFixBy(quarantinedAt, ttlDays) {
+ const startedAt = Date.parse(quarantinedAt)
+ if (Number.isNaN(startedAt) || typeof ttlDays !== 'number' || !(ttlDays > 0)) {
+ return null
+ }
+ return new Date(startedAt + ttlDays * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)
+}
+
+// Uploads off, no synced Trunk source, a request error, or a cut-off page all degrade to a report
+// without Trunk state, never to a failed run. A partial list would read as "not quarantined".
+async function fetchTrunkQuarantined(runner, fetchQuarantine = fetchTrunkQuarantine, enabled = TRUNK_UPLOADS_ON) {
if (!enabled) {
return null
}
- let rows = []
+ let debt
try {
- const result = await runHogql(TRUNK_QUARANTINED_QUERY.replace('__TRUNK_TABLE__', TRUNK_TABLE), {
- runner,
- })
- rows = result.results || []
+ debt = await fetchQuarantine()
} catch (err) {
console.warn(`Trunk quarantine lookup failed — reporting without Trunk state: ${err.message}`)
return null
}
+ if (!debt?.available) {
+ console.warn('Trunk quarantine state is not available — reporting without Trunk state')
+ return null
+ }
+ if (debt.truncated) {
+ console.warn(`Trunk quarantine lookup was cut at ${debt.limit} rows — reporting without Trunk state`)
+ return null
+ }
const byVariant = new Map()
- for (const [nodeid, quarantinedAt] of rows) {
- for (const variant of selectorVariants(nodeid)) {
- byVariant.set(variant, { quarantinedAt })
+ for (const test of debt.tests || []) {
+ if (test.runner !== runner) {
+ continue
+ }
+ const entry = {
+ quarantinedAt: test.quarantined_at,
+ overdue: Boolean(test.overdue),
+ fixBy: trunkFixBy(test.quarantined_at, debt.ttl_days),
+ }
+ for (const variant of selectorVariants(test.nodeid)) {
+ byVariant.set(variant, entry)
}
}
return (item) =>
@@ -267,39 +282,56 @@ async function fetchTrunkQuarantined(runner, runHogql = hogql, enabled = TRUNK_U
.find(Boolean) || null
}
-// One question for both systems: is this failure suppressed, and since when? Suppressed tests
-// stay in the table with their suppression labeled, so masked failures remain visible.
+// The endpoint answers for every runner, so the runners share one request.
+function sharedTrunkLookup(fetchQuarantine = fetchTrunkQuarantine, enabled = TRUNK_UPLOADS_ON) {
+ let pending
+ return (runner) => fetchTrunkQuarantined(runner, () => (pending ??= fetchQuarantine()), enabled)
+}
+
+// Every later step reads these facts, so no step asks Trunk on its own.
+// `trunkFor` is null when Trunk state is unavailable.
+function resolveFacts(candidates, trunkFor) {
+ return candidates.map((item) => {
+ const trunk = trunkFor?.(item) || null
+ return {
+ ...item,
+ trunk,
+ // Failures with no recovery prove no flake. A quarantine is the other proof that a test
+ // is known to fail.
+ knownFlake: hasRecovery(item) || Boolean(trunk),
+ // The endpoint counts xfail separately; it does not distinguish its source.
+ expectedFailureOnly: !item.failed_run_count && !hasRecovery(item),
+ }
+ })
+}
+
+// Is this failure suppressed, and for how long? Suppressed tests stay in the table with their
+// suppression labeled, so masked failures remain visible.
//
// Trunk with masking off is marked but not suppressed: Trunk called the test flaky, CI still goes
// red on it, so it reads 'flagged' rather than a quarantine date.
-function quarantineStatusFor(trunkFor, masksCi = TRUNK_MASKS_CI) {
- return (item) => {
- // A cluster's bare file selector can never match a per-test quarantine, so the members'
- // statuses are counted at collapse time and the row reports how many are suppressed.
- if (item.cluster_size) {
- return item.quarantined_member_count ? `${item.quarantined_member_count}/${item.cluster_size}` : null
- }
- // Both counts are seven-day aggregates and the endpoint counts a quarantined run
- // separately from a failed one, so a park that ended inside the window leaves the
- // quarantined count set while CI fails on the test again. The unquarantined failures
- // decide: with any of them the test is red again and not suppressed.
- const quarantineFile = item.classification === 'quarantined' || item.quarantined_failed_run_count > 0
- if (quarantineFile && !item.failed_run_count) {
- return 'file'
- }
- const trunk = trunkFor?.(item)
- if (!trunk) {
- return null
- }
- if (!masksCi) {
- return 'flagged'
- }
- return (trunk.quarantinedAt || '').slice(0, 10) || 'yes'
+function quarantineStatusFor(item, masksCi = TRUNK_MASKS_CI) {
+ // A cluster's bare file selector can never match a per-test quarantine, so the members'
+ // statuses are counted at collapse time and the row reports how many are suppressed.
+ if (item.cluster_size) {
+ return item.quarantined_member_count ? `${item.quarantined_member_count}/${item.cluster_size}` : null
+ }
+ const { trunk } = item
+ if (!trunk) {
+ return null
+ }
+ if (!masksCi) {
+ return 'flagged'
+ }
+ if (trunk.fixBy) {
+ return `${trunk.overdue ? 'overdue since' : 'fix by'} ${trunk.fixBy}`
}
+ const since = (trunk.quarantinedAt || '').slice(0, 10)
+ return since ? `since ${since}` : 'yes'
}
// 5+ co-failing tests in one file are one shared-fixture incident, not N flakes.
-function collapseClusters(items, statusFor) {
+function collapseClusters(items, masksCi) {
const byFile = new Map()
for (const item of items) {
const file = item.selector.split('::')[0]
@@ -311,19 +343,18 @@ function collapseClusters(items, statusFor) {
const collapsed = []
for (const [file, group] of byFile) {
if (group.length >= CLUSTER_MIN_TESTS) {
+ const largest = (count) => Math.max(...group.map((item) => item[count]))
collapsed.push({
runner: group[0].runner,
selector: file,
cluster_size: group.length,
// 'flagged' members still fail CI, so only real suppressions count toward the fraction.
- quarantined_member_count: group.filter((item) => {
- const status = statusFor(item)
- return status && status !== 'flagged'
- }).length,
- failed_run_count: group.reduce((sum, item) => sum + item.failed_run_count, 0),
- // Members' PR sets can overlap, so the max is the provable floor rather than a sum.
- failed_pr_count: Math.max(...group.map((item) => item.failed_pr_count)),
- quarantined_failed_run_count: 0,
+ quarantined_member_count: masksCi ? group.filter((item) => item.trunk).length : 0,
+ // Members fail in the same runs and on the same PRs, so the max is the provable floor
+ // rather than a sum.
+ failed_run_count: largest('failed_run_count'),
+ same_commit_recovery_run_count: largest('same_commit_recovery_run_count'),
+ failed_pr_count: largest('failed_pr_count'),
})
} else {
collapsed.push(...group)
@@ -332,52 +363,58 @@ function collapseClusters(items, statusFor) {
return collapsed
}
-// A cluster's PR count is the max over members whose PR sets can overlap, so it is a
-// floor on the distinct PRs hit; the trailing + keeps it from reading as exact.
-function prCountCell(item) {
- if (item.failed_pr_count == null) {
+// A cluster's count is a floor over members whose runs and PRs can overlap; the trailing + keeps
+// it from reading as exact.
+function countCell(item, count) {
+ if (count == null) {
return '-'
}
- return item.cluster_size ? `${item.failed_pr_count}+` : String(item.failed_pr_count)
+ return item.cluster_size ? `${count}+` : String(count)
}
-// Rescued runs first (the strongest per-test signal), clusters and the rest by volume.
-function rankReportCandidates(items, extrasFor) {
- return items
- .map((item, index) => ({ item, index }))
- .sort(
- (left, right) =>
- (extrasFor(right.item).runsRescued ?? 0) - (extrasFor(left.item).runsRescued ?? 0) ||
- right.item.failed_run_count - left.item.failed_run_count ||
- left.index - right.index
- )
- .slice(0, TOP_N)
- .map(({ item }) => item)
+// Ranked on the endpoint's own counts, so the order and the numbers a reader sees agree.
+function rankByReportedCounts(items) {
+ return [...items].sort(
+ (left, right) =>
+ right.failed_run_count - left.failed_run_count ||
+ right.same_commit_recovery_run_count - left.same_commit_recovery_run_count
+ )
}
async function buildRunnerReports(
candidatePools,
getEnrichment = enrichRunnerCandidates,
- getTrunk = fetchTrunkQuarantined
+ getTrunk = sharedTrunkLookup(),
+ masksCi = TRUNK_MASKS_CI
) {
return Promise.all(
candidatePools.map(async ({ runner, candidates }) => {
const trunkFor = await getTrunk(runner)
- const statusFor = quarantineStatusFor(trunkFor)
- const candidatesWithTrunkStatus = trunkFor
- ? candidates.filter((item) => item.classification !== 'suspected_regression' || trunkFor(item))
- : candidates
- const queue = collapseClusters(candidatesWithTrunkStatus.slice(0, CANDIDATE_POOL), statusFor)
+ const facts = resolveFacts(candidates, trunkFor)
+ const expected = facts.filter((item) => item.expectedFailureOnly)
+ if (expected.length > 0) {
+ console.info(
+ `${runner}: dropped ${expected.length} test(s) with only expected failures (xfail): ${expected
+ .map((item) => item.selector)
+ .join(', ')}`
+ )
+ }
+ // Without Trunk state a quarantine cannot be told from an unproven failure, so all stay.
+ const knownFlakes = trunkFor ? facts.filter((item) => item.knownFlake) : facts
+ const ranked = rankByReportedCounts(
+ knownFlakes.filter((item) => !item.expectedFailureOnly && !isMasterBurst(item))
+ )
+ const queue = collapseClusters(ranked.slice(0, CANDIDATE_POOL), masksCi)
const extrasFor = await getEnrichment(runner, queue)
- return { runner, candidates: rankReportCandidates(queue, extrasFor), extrasFor, statusFor }
+ return { runner, candidates: rankByReportedCounts(queue).slice(0, TOP_N), extrasFor }
})
)
}
-function tableRows(items, ownerFor, extrasFor, statusFor = () => null) {
+function tableRows(items, ownerFor, extrasFor, statusFor = quarantineStatusFor) {
return items.map((item) => {
const { owner, repoPath } = ownerFor(item)
- const { runsRescued, evidence } = extrasFor(item)
+ const { evidence } = extrasFor(item)
const name = item.cluster_size
? `${item.selector.split('/').pop()} (${item.cluster_size} tests)`
: shortName(item.selector)
@@ -393,9 +430,9 @@ function tableRows(items, ownerFor, extrasFor, statusFor = () => null) {
cell(RUNNER_LABELS[item.runner] || item.runner),
cell(owner.replace(/^team-/, '')),
cell(statusFor(item) || '-'),
- cell(prCountCell(item)),
- cell(runsRescued == null ? '-' : String(runsRescued)),
- cell(String(item.failed_run_count)),
+ cell(countCell(item, item.failed_pr_count)),
+ cell(countCell(item, item.failed_run_count)),
+ cell(countCell(item, item.same_commit_recovery_run_count)),
logLinks.length > 0 ? linkedCell(logLinks) : cell('-'),
]
})
@@ -437,10 +474,10 @@ function flakyTable(rows) {
cell('test'),
cell('runner'),
cell('owner'),
- cell('quarantined'),
+ cell('quarantine'),
cell('PRs'),
- cell('rescued'),
- cell('fails'),
+ cell('failed runs'),
+ cell('recovered runs'),
cell('logs'),
],
...rows,
@@ -448,6 +485,22 @@ function flakyTable(rows) {
}
}
+const COLUMN_LEGEND = {
+ type: 'context',
+ elements: [
+ {
+ type: 'mrkdwn',
+ text: [
+ '*Failed runs* counts each CI run where the test failed, including runs that a quarantine kept green.',
+ '*Recovered runs* counts each run where the same commit failed and passed the test.',
+ '*Quarantine* shows the Trunk repair deadline (fix by), a missed deadline (overdue since), or the quarantine start date (since). Yes means quarantined with no date available. Quarantine continues until removed. Flagged means Trunk lists the test but CI failures are not masked. A fraction counts masked cluster members.',
+ 'A count with a + covers several tests in one file and is a minimum.',
+ 'Tests with only expected failures (xfail), including file quarantines, are omitted.',
+ ].join(' '),
+ },
+ ],
+}
+
function buildShadowBlocks({ owner, channel, rows }) {
return [
{
@@ -458,6 +511,7 @@ function buildShadowBlocks({ owner, channel, rows }) {
},
},
flakyTable(rows),
+ COLUMN_LEGEND,
]
}
@@ -468,10 +522,11 @@ function buildBlocks(now, rows) {
type: 'section',
text: {
type: 'mrkdwn',
- text: `*Weekly flaky tests - ${dateLabel}* _(CI, last 7 days, up to ${TOP_N} per runner)_`,
+ text: `*Weekly flaky tests - ${dateLabel}* _(CI, last ${REPORT_WINDOW_DAYS} days, up to ${TOP_N} per runner)_`,
},
},
flakyTable(rows),
+ COLUMN_LEGEND,
]
const editBlock = editWorkflowBlock()
if (editBlock) {
@@ -496,8 +551,8 @@ async function main() {
}
const ownerFor = resolveOwners(reportCandidates, toRepoPaths)
// Rendered once; the channel table and the per-team slices share the same rows.
- const entries = runnerReports.flatMap(({ candidates, extrasFor, statusFor }) => {
- const reportRows = tableRows(candidates, ownerFor, extrasFor, statusFor)
+ const entries = runnerReports.flatMap(({ candidates, extrasFor }) => {
+ const reportRows = tableRows(candidates, ownerFor, extrasFor)
return candidates.map((item, index) => ({ ...ownerFor(item), row: reportRows[index] }))
})
const blocks = buildBlocks(
@@ -552,6 +607,8 @@ export {
flakyTestsUrl,
quarantineStatusFor,
REPORT_RUNNERS,
+ resolveFacts,
selectReportCandidates,
+ sharedTrunkLookup,
tableRows,
}
diff --git a/.github/scripts/weekly-flaky-report.test.mjs b/.github/scripts/weekly-flaky-report.test.mjs
index 02fcec41d49a..b8a56d98c432 100644
--- a/.github/scripts/weekly-flaky-report.test.mjs
+++ b/.github/scripts/weekly-flaky-report.test.mjs
@@ -14,7 +14,9 @@ import {
flakyTestsUrl,
quarantineStatusFor,
REPORT_RUNNERS,
+ resolveFacts,
selectReportCandidates,
+ sharedTrunkLookup,
tableRows,
} from './weekly-flaky-report.mjs'
import { repoPathResolver, trackedTestPaths } from './weekly-report-common.mjs'
@@ -43,11 +45,11 @@ describe('weekly flaky report', () => {
quarantined_failed_run_count: 0,
failed_run_count: 4,
failed_pr_count: 3,
+ same_commit_recovery_run_count: 2,
},
],
() => ({ owner: 'team-devex', repoPath: 'posthog/test/test_example.py' }),
() => ({
- runsRescued: 2,
evidence: [
{ runId: 10, jobId: 20 },
{ runId: 11, jobId: 21 },
@@ -60,7 +62,7 @@ describe('weekly flaky report', () => {
assert.ok(table)
assert.deepEqual(
table.rows[0].map((tableCell) => tableCell.text),
- ['test', 'runner', 'owner', 'quarantined', 'PRs', 'rescued', 'fails', 'logs']
+ ['test', 'runner', 'owner', 'quarantine', 'PRs', 'failed runs', 'recovered runs', 'logs']
)
// The edit-workflow context block may still render when Actions env vars are set;
// only the action footer has to be gone.
@@ -87,6 +89,8 @@ describe('weekly flaky report', () => {
assert.deepEqual(rows[0][1], { type: 'raw_text', text: 'pytest' })
assert.deepEqual(rows[0][3], { type: 'raw_text', text: '-' })
assert.deepEqual(rows[0][4], { type: 'raw_text', text: '3' })
+ assert.deepEqual(rows[0][5], { type: 'raw_text', text: '4' })
+ assert.deepEqual(rows[0][6], { type: 'raw_text', text: '2' })
assert.deepEqual(rows[0][7], {
type: 'rich_text',
elements: [
@@ -151,7 +155,7 @@ describe('weekly flaky report', () => {
assert.deepEqual(
selectReportCandidates(items, 'pytest', onMasterResolver).map((candidate) => candidate.selector),
- ['test_proved.py::test_proved', 'test_pr_only.py::test_pr_only']
+ ['test_proved.py::test_proved', 'test_burst.py::test_burst', 'test_pr_only.py::test_pr_only']
)
assert.deepEqual(
selectReportCandidates(items, 'jest', onMasterResolver).map((candidate) => candidate.selector),
@@ -206,7 +210,8 @@ describe('weekly flaky report', () => {
)
})
- it('filters unproved regressions after an available Trunk lookup', async () => {
+ it('filters unproved regressions after an available Trunk lookup', async (context) => {
+ const logs = context.mock.method(console, 'info', () => {})
const common = {
runner: 'pytest',
classification: 'suspected_regression',
@@ -227,36 +232,51 @@ describe('weekly flaky report', () => {
classification: 'confirmed_flake',
same_commit_recovery_run_count: 1,
}
- const fileQuarantined = {
+ const expectedFailure = {
...common,
- selector: 'quarantined.py::test_quarantined',
+ selector: 'expected.py::test_marked_xfail_by_its_author',
classification: 'quarantined',
failed_run_count: 0,
failed_pr_count: 0,
quarantined_failed_run_count: 2,
}
- const master = { ...common, selector: 'master.py::test_master', master_failed_run_count: 1 }
- const getEnrichment = async () => () => ({ runsRescued: 0, evidence: [] })
+ const master = {
+ ...common,
+ selector: 'master.py::test_master',
+ failed_pr_count: 1,
+ master_failed_run_count: 4,
+ }
+ const trunkedMaster = { ...master, selector: 'trunked_master.py::test_trunked_master' }
+ const getEnrichment = async () => () => ({ evidence: [] })
const candidatePools = await fetchCandidatePools(['pytest'], onMasterResolver, async () => ({
- items: [...plainRegressions, trunked, confirmed, fileQuarantined, master],
+ items: [...plainRegressions, trunked, confirmed, expectedFailure, master, trunkedMaster],
}))
const [{ candidates }] = await buildRunnerReports(
candidatePools,
getEnrichment,
- async () => (item) => (item === trunked ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null)
+ async () => (item) =>
+ item === trunked || item === trunkedMaster ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null
)
assert.deepEqual(
- candidates.map((candidate) => candidate.selector),
- [trunked.selector, confirmed.selector, fileQuarantined.selector]
+ candidates.map((candidate) => [candidate.selector, candidate.failed_run_count]),
+ [
+ [confirmed.selector, 6],
+ [trunked.selector, 6],
+ [trunkedMaster.selector, 6],
+ ]
)
+ assert.ok(logs.mock.calls.some(({ arguments: [message] }) => message.includes(expectedFailure.selector)))
const [{ candidates: candidatesWithoutTrunk }] = await buildRunnerReports(
- [{ runner: 'pytest', candidates: [plainRegressions[0]] }],
+ [{ runner: 'pytest', candidates: [plainRegressions[0], expectedFailure, master] }],
getEnrichment,
async () => null
)
- assert.deepEqual(candidatesWithoutTrunk, [plainRegressions[0]])
+ assert.deepEqual(
+ candidatesWithoutTrunk.map((candidate) => candidate.selector),
+ [plainRegressions[0].selector]
+ )
})
it('ranks and limits each runner independently', async () => {
@@ -266,18 +286,20 @@ describe('weekly flaky report', () => {
runner,
selector: `${runner}-${index}`,
failed_run_count: index === 10 ? 20 : 5,
+ same_commit_recovery_run_count: index === 11 ? 3 : 1,
})),
}))
- const runnerReports = await buildRunnerReports(candidatePools, async () => (item) => ({
- runsRescued: item.selector.endsWith('-11') ? 1 : 0,
- evidence: [],
- }))
+ const runnerReports = await buildRunnerReports(
+ candidatePools,
+ async () => () => ({ evidence: [] }),
+ async () => null
+ )
for (const { runner, candidates } of runnerReports) {
assert.equal(candidates.length, 10)
assert.deepEqual(
candidates.map((candidate) => candidate.selector),
- [`${runner}-11`, `${runner}-10`, ...Array.from({ length: 8 }, (_, index) => `${runner}-${index}`)]
+ [`${runner}-10`, `${runner}-11`, ...Array.from({ length: 8 }, (_, index) => `${runner}-${index}`)]
)
}
assert.deepEqual(
@@ -319,6 +341,7 @@ describe('weekly flaky report', () => {
classification: 'confirmed_flake',
quarantined_failed_run_count: 0,
failed_run_count: 3,
+ same_commit_recovery_run_count: 1,
}
const extrasFor = await enrichRunnerCandidates('jest', [item], async () => {
enrichmentRequested = true
@@ -332,17 +355,35 @@ describe('weekly flaky report', () => {
assert.equal(enrichmentRequested, false)
assert.deepEqual(row[1], { type: 'raw_text', text: 'Jest' })
- assert.deepEqual(row[5], { type: 'raw_text', text: '-' })
assert.deepEqual(row[7], { type: 'raw_text', text: '-' })
})
- it('scopes enrichment to the current repository', async () => {
+ it('scopes enrichment and links the latest distinct failing runs', async () => {
let request
- await enrich([{ selector: 'products/example/backend/test_report.py::test_report' }], async (query, values) => {
+ const item = { selector: 'products/example/backend/test_report.py::test_report' }
+ const extrasFor = await enrich([item], async (query, values) => {
request = { query, values }
- return { results: [] }
+ return {
+ results: [
+ [
+ item.selector,
+ [
+ [100, 10, 20],
+ [300, 12, 22],
+ [250, 12, 23],
+ [200, 11, 21],
+ ],
+ ],
+ ],
+ }
})
+ assert.deepEqual(extrasFor(item), {
+ evidence: [
+ { runId: 12, jobId: 22 },
+ { runId: 11, jobId: 21 },
+ ],
+ })
assert.match(request.query, /lower\(f\.repo\) = lower\(\{repository\}\)/)
assert.equal(request.values.repository, 'PostHog/posthog')
// Every path suffix, so either side of the join can carry the longer prefix.
@@ -354,26 +395,49 @@ describe('weekly flaky report', () => {
})
it('distinguishes unavailable Trunk data from an empty result', async () => {
+ const otherRunnerOnly = {
+ available: true,
+ truncated: false,
+ ttl_days: 15,
+ tests: [{ runner: 'jest', nodeid: 'posthog/test/test_example.py::test_report', quarantined_at: null }],
+ }
const cases = [
{
label: 'uploads off',
enabled: false,
available: false,
- runHogql: () => assert.fail('must not query Trunk while uploads are disabled'),
+ fetchQuarantine: () => assert.fail('must not query Trunk while uploads are disabled'),
},
{
- label: 'table missing',
+ label: 'request fails',
enabled: true,
available: false,
- runHogql: async () => {
- throw new Error('Unknown table trunkio.quarantinedtests')
+ fetchQuarantine: async () => {
+ throw new Error('trunk_quarantine 503')
},
},
- { label: 'no rows', enabled: true, available: true, runHogql: async () => ({ results: [] }) },
+ {
+ label: 'no Trunk source synced',
+ enabled: true,
+ available: false,
+ fetchQuarantine: async () => ({ ...otherRunnerOnly, available: false, tests: [] }),
+ },
+ {
+ label: 'list is cut short, so rows may be missing',
+ enabled: true,
+ available: false,
+ fetchQuarantine: async () => ({ ...otherRunnerOnly, truncated: true, limit: 5000 }),
+ },
+ {
+ label: 'only another runner is quarantined',
+ enabled: true,
+ available: true,
+ fetchQuarantine: async () => otherRunnerOnly,
+ },
]
- for (const { label, enabled, available, runHogql } of cases) {
- const trunkFor = await fetchTrunkQuarantined('pytest', runHogql, enabled)
+ for (const { label, enabled, available, fetchQuarantine } of cases) {
+ const trunkFor = await fetchTrunkQuarantined('pytest', fetchQuarantine, enabled)
assert.equal(typeof trunkFor === 'function', available, label)
assert.equal(trunkFor?.({ selector: 'posthog/test/test_example.py::test_report' }) ?? null, null, label)
@@ -381,71 +445,88 @@ describe('weekly flaky report', () => {
})
it('matches Trunk rows to a product suite reported product-relative', async () => {
- const trunkFor = await fetchTrunkQuarantined(
- 'pytest',
- async () => ({
- results: [
- [
- 'products/example/backend/tests/test_migration.py::MigrationTest::test_backfill',
- '2026-07-29T09:14:22.000Z',
- ],
+ let requests = 0
+ const getTrunk = sharedTrunkLookup(async () => {
+ requests += 1
+ return {
+ available: true,
+ truncated: false,
+ ttl_days: 15,
+ tests: [
+ {
+ runner: 'pytest',
+ nodeid: 'products/example/backend/tests/test_migration.py::MigrationTest::test_backfill',
+ quarantined_at: '2026-07-29T09:14:22Z',
+ overdue: true,
+ },
+ {
+ runner: 'jest',
+ nodeid: 'src/scenes/example/exampleLogic.test.ts::exampleLogic loads the example',
+ quarantined_at: '2026-07-31T11:00:00Z',
+ overdue: false,
+ },
],
- }),
- true
+ }
+ }, true)
+ const pytestFor = await getTrunk('pytest')
+ const jestFor = await getTrunk('jest')
+
+ // The endpoint is not runner-specific, so a second request would repeat the first.
+ assert.equal(requests, 1)
+ assert.deepEqual(pytestFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_backfill' }), {
+ quarantinedAt: '2026-07-29T09:14:22Z',
+ overdue: true,
+ fixBy: '2026-08-13',
+ })
+ assert.equal(pytestFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_other' }), null)
+ assert.equal(
+ pytestFor({ selector: 'frontend/src/scenes/example/exampleLogic.test.ts::exampleLogic loads the example' }),
+ null
)
-
assert.equal(
- trunkFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_backfill' }).quarantinedAt,
- '2026-07-29T09:14:22.000Z'
+ jestFor({ selector: 'frontend/src/scenes/example/exampleLogic.test.ts::exampleLogic loads the example' })
+ .fixBy,
+ '2026-08-15'
)
- assert.equal(trunkFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_other' }), null)
})
- it('labels how each quarantine system suppresses a test instead of dropping it', () => {
- const quarantineFile = { runner: 'pytest', selector: 'file.py::test_file', classification: 'quarantined' }
- // Quarantined earlier in the window, un-quarantined since, and failing on its own now.
- const unparked = {
- runner: 'pytest',
- selector: 'expired.py::test_expired',
- classification: 'quarantined',
- quarantined_failed_run_count: 3,
- failed_run_count: 4,
- }
+ it('labels how Trunk suppresses a test instead of dropping it', () => {
const trunked = { runner: 'pytest', selector: 'masked.py::test_masked', failed_run_count: 9 }
+ const overdue = { runner: 'pytest', selector: 'overdue.py::test_overdue', failed_run_count: 7 }
+ const unlimited = { runner: 'pytest', selector: 'unlimited.py::test_unlimited', failed_run_count: 3 }
const undated = { runner: 'pytest', selector: 'undated.py::test_undated', failed_run_count: 2 }
const plain = { runner: 'pytest', selector: 'plain.py::test_plain', failed_run_count: 1 }
- const items = [quarantineFile, unparked, trunked, undated, plain]
+ const items = [trunked, overdue, unlimited, undated, plain]
const trunkRows = new Map([
- [trunked.selector, '2026-07-13T17:12:22.000Z'],
- [undated.selector, null],
+ [trunked.selector, { quarantinedAt: '2026-07-13T17:12:22Z', overdue: false, fixBy: '2026-07-28' }],
+ [overdue.selector, { quarantinedAt: '2026-06-20T08:00:00Z', overdue: true, fixBy: '2026-07-05' }],
+ [unlimited.selector, { quarantinedAt: '2026-07-13T17:12:22Z', overdue: false, fixBy: null }],
+ [undated.selector, { quarantinedAt: null, overdue: false, fixBy: null }],
])
- const trunkFor = (item) =>
- trunkRows.has(item.selector) ? { quarantinedAt: trunkRows.get(item.selector) } : null
+ const trunkFor = (item) => trunkRows.get(item.selector) || null
const cells = (masksCi) =>
tableRows(
- items,
+ resolveFacts(items, trunkFor),
() => ({ owner: 'team-devex', repoPath: null }),
- () => ({ runsRescued: null, evidence: [] }),
- quarantineStatusFor(trunkFor, masksCi)
+ () => ({ evidence: [] }),
+ (item) => quarantineStatusFor(item, masksCi)
).map((row) => row[3].text)
- assert.deepEqual(cells(true), ['file', '-', '2026-07-13', 'yes', '-'])
+ assert.deepEqual(cells(true), ['fix by 2026-07-28', 'overdue since 2026-07-05', 'since 2026-07-13', 'yes', '-'])
// Masking off leaves Trunk's failure reddening CI, so the date would overclaim.
- assert.deepEqual(cells(false), ['file', '-', 'flagged', 'flagged', '-'])
+ assert.deepEqual(cells(false), ['flagged', 'flagged', 'flagged', 'flagged', '-'])
})
it('keeps a Trunk-quarantined test in the report and counts suppressed cluster members', async () => {
const clustered = Array.from({ length: CLUSTER_MIN_TESTS }, (_, index) => ({
runner: 'pytest',
- // Two members parked via the quarantine file: suppressed whichever way TRUNK_* masking
- // resolves, so the count holds without pinning the env. A Trunk-marked member with
- // masking off is only 'flagged' and must not count as suppressed.
- classification: index < 2 ? 'quarantined' : 'confirmed_flake',
+ classification: 'confirmed_flake',
selector: `shared.py::test_${index}`,
- failed_run_count: index < 2 ? 0 : 2,
- quarantined_failed_run_count: index < 2 ? 3 : 0,
- same_commit_recovery_run_count: index < 2 ? 0 : 1,
+ // The first two members are listed in Trunk.
+ failed_run_count: index < 2 ? 3 : 2,
+ quarantined_failed_run_count: 0,
+ same_commit_recovery_run_count: 1,
master_failed_run_count: 0,
failed_pr_count: 1,
}))
@@ -459,31 +540,44 @@ describe('weekly flaky report', () => {
same_commit_recovery_run_count: 0,
quarantined_failed_run_count: 0,
}
- const [{ candidates, statusFor }] = await buildRunnerReports(
- [{ runner: 'pytest', candidates: [...clustered, trunked] }],
- async () => () => ({ runsRescued: null, evidence: [] }),
- async () => (item) =>
- item.selector === trunked.selector ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null
- )
+ const listed = new Set([trunked.selector, clustered[0].selector, clustered[1].selector])
+ const report = async (masksCi) => {
+ const [{ candidates }] = await buildRunnerReports(
+ [{ runner: 'pytest', candidates: [...clustered, trunked] }],
+ async () => () => ({ evidence: [] }),
+ async () => (item) =>
+ listed.has(item.selector) ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null,
+ masksCi
+ )
+ return candidates
+ }
+ const candidates = await report(true)
+ // Members share runs, so the cluster reports the largest member count and not the sum.
assert.deepEqual(
candidates.map((candidate) => [candidate.selector, candidate.failed_run_count]),
[
['masked.py::test_masked', 9],
- ['shared.py', 6],
+ ['shared.py', 3],
]
)
- assert.equal(statusFor(candidates[1]), `2/${CLUSTER_MIN_TESTS}`)
- // Truthy either way TRUNK_* masking resolves, so this holds without pinning the env.
- assert.ok(statusFor(trunked))
+ assert.deepEqual(
+ candidates.map((candidate) => quarantineStatusFor(candidate, true)),
+ ['since 2026-07-13', `2/${CLUSTER_MIN_TESTS}`]
+ )
+ // A Trunk-marked member with masking off is only 'flagged' and must not count as suppressed.
+ assert.deepEqual(
+ (await report(false)).map((candidate) => quarantineStatusFor(candidate, false)),
+ ['flagged', null]
+ )
const [clusterRow] = tableRows(
[candidates[1]],
() => ({ owner: 'team-devex', repoPath: null }),
- () => ({ runsRescued: null, evidence: [] }),
- statusFor
+ () => ({ evidence: [] })
)
- // The cluster PR count is a floor over overlapping member sets, never an exact count.
+ // The cluster counts are floors over overlapping member sets, never exact counts.
assert.deepEqual(clusterRow[4], { type: 'raw_text', text: '1+' })
+ assert.deepEqual(clusterRow[5], { type: 'raw_text', text: '3+' })
})
it('groups shadow digests by owning team and drops teams it cannot route', () => {
@@ -515,22 +609,28 @@ describe('weekly flaky report', () => {
const trunkFor = await fetchTrunkQuarantined(
'jest',
async () => ({
- results: [
- [
- 'src/lib/components/ActivityLog/activityLogLogic.person.test.tsx::the activity log logic humanizing persons can handle addition of a property',
- '2026-07-11T16:45:09.000Z',
- ],
+ available: true,
+ truncated: false,
+ // Without a time limit there is no fix-by date to report.
+ ttl_days: null,
+ tests: [
+ {
+ runner: 'jest',
+ nodeid: 'src/lib/components/ActivityLog/activityLogLogic.person.test.tsx::the activity log logic humanizing persons can handle addition of a property',
+ quarantined_at: '2026-07-11T16:45:09.000Z',
+ overdue: false,
+ },
],
}),
true
)
- assert.equal(
+ assert.deepEqual(
trunkFor({
selector:
'frontend/src/lib/components/ActivityLog/activityLogLogic.person.test.tsx::the activity log logic humanizing persons can handle addition of a property',
- }).quarantinedAt,
- '2026-07-11T16:45:09.000Z'
+ }),
+ { quarantinedAt: '2026-07-11T16:45:09.000Z', overdue: false, fixBy: null }
)
})
})
diff --git a/.github/workflows/weekly-flaky-report.yml b/.github/workflows/weekly-flaky-report.yml
index 803bb7459703..dd935c39cc2b 100644
--- a/.github/workflows/weekly-flaky-report.yml
+++ b/.github/workflows/weekly-flaky-report.yml
@@ -13,7 +13,7 @@ name: Weekly flaky test report
# warehouse source connected.
# - secrets.ENG_ANALYTICS_POSTHOG_API_KEY — a personal API key scoped to
# engineering_analytics:read + query:read for that project (the script also
-# reads the product's ci_failures view for rescue counts and job links).
+# reads the product's ci_failures view for job links).
# - secrets.SLACK_DEVEX_BOT_TOKEN — the existing DevEx Slack bot.
#
# Trunk state is optional on top of that: with the TRUNK_* variables below unset, the report
@@ -76,8 +76,6 @@ jobs:
# masked when Trunk is actually masking it. Unset means no Trunk state at all.
TRUNK_UPLOAD_ENABLED: ${{ vars.TRUNK_UPLOAD_ENABLED }}
TRUNK_QUARANTINE_ENABLED: ${{ vars.TRUNK_QUARANTINE_ENABLED }}
- # Optional: override the source-prefixed Trunk quarantine table name.
- TRUNK_QUARANTINE_TABLE: ${{ vars.TRUNK_QUARANTINE_TABLE }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
run: node .github/scripts/weekly-flaky-report.mjs