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(engineering-analytics): stop reading by-design CI failures as flakes (#75600)

posthog[bot]348931e95e97
diff --git a/products/engineering_analytics/backend/logic/queries/workflow_flakiness.py b/products/engineering_analytics/backend/logic/queries/workflow_flakiness.py
index 9ced36436077..3f468354434b 100644
--- a/products/engineering_analytics/backend/logic/queries/workflow_flakiness.py
+++ b/products/engineering_analytics/backend/logic/queries/workflow_flakiness.py
@@ -11,10 +11,21 @@ from products.engineering_analytics.backend.logic.queries._curated import Curate
from products.engineering_analytics.backend.logic.queries._workflow_filters import run_started_floor_constant
# A job that failed in under this many seconds did no real work: it's a required-check aggregator
-# echoing a dependency's failure, which double-counts every real flake. Measured on PostHog/posthog,
-# aggregators settle in 3-5s and real jobs run 60s+. Run-level twin: NO_OP_RUN_MAX_SECONDS.
+# echoing a dependency's failure, which double-counts every real flake. The floor separates a job
+# that only reads its dependencies' results from one that runs anything. Run-level twin:
+# NO_OP_RUN_MAX_SECONDS.
NO_OP_JOB_MAX_SECONDS = 10
+# These jobs commit an artifact, then exit 1 so the merge waits for review. The rerun passes because
+# the commit already landed, and they run too long for NO_OP_JOB_MAX_SECONDS to drop them.
+# Repo-qualified because job names are free text. This hides a real flake in either job too.
+BY_DESIGN_FAILURES = (
+ # .github/actions/commit-snapshots exits 1 after committing; ci-backend.yml, ci-mcp.yml
+ "posthog/posthog/Commit snapshot changes",
+ # `vr run complete` exits 1 on detected visual changes; ci-storybook.yml, ci-e2e-playwright.yml
+ "posthog/posthog/Complete Visual Review run",
+)
+
_SELECT = """
SELECT
r.repo_owner,
@@ -31,6 +42,9 @@ _SELECT = """
-- created_at_raw is the unparsed string the scan can prune on; the parsed j.created_at filter
-- alone can't push down, so both floors keep the sweep off a full jobs+runs scan each hour.
WHERE j.created_at >= {date_from} AND j.created_at_raw >= {job_created_floor} AND j.head_sha != ''
+ -- concat yields NULL when j.name is NULL, which a bare NOT IN would drop.
+ AND ifNull(concat(lower(r.repo_owner), '/', lower(r.repo_name), '/', j.name), '')
+ NOT IN {by_design_failures}
GROUP BY r.repo_owner, r.repo_name, j.workflow_name, j.name, j.run_id, j.head_sha
HAVING failed_attempt > 0
AND passed_attempt > failed_attempt
@@ -71,6 +85,7 @@ def query_workflow_flakiness(
placeholders={
"date_from": ast.Constant(value=date_from),
"min_failed_duration_seconds": ast.Constant(value=min_failed_duration_seconds),
+ "by_design_failures": ast.Constant(value=list(BY_DESIGN_FAILURES)),
# Same date-only floor for both tables: prunes the runs subquery (run_started_floor) and
# the jobs scan (job_created_floor via created_at_raw).
"run_started_floor": run_started_floor_constant(date_from),
diff --git a/products/engineering_analytics/backend/tests/test_ci_signals.py b/products/engineering_analytics/backend/tests/test_ci_signals.py
index 61a15748943f..a9e7e3cf85e9 100644
--- a/products/engineering_analytics/backend/tests/test_ci_signals.py
+++ b/products/engineering_analytics/backend/tests/test_ci_signals.py
@@ -26,6 +26,7 @@ from products.engineering_analytics.backend.logic.ci_signals_config import (
update_ci_signals_config,
)
from products.engineering_analytics.backend.logic.queries._curated import CuratedGitHubSource
+from products.engineering_analytics.backend.logic.queries.workflow_flakiness import BY_DESIGN_FAILURES
from products.engineering_analytics.backend.logic.signals.contracts import (
SOURCE_PRODUCT,
SOURCE_TYPE_BROKEN_DEFAULT_BRANCH,
@@ -71,6 +72,8 @@ from products.warehouse_sources.backend.facade.models import (
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
from products.warehouse_sources.backend.test.utils import create_data_warehouse_table_from_csv
+_BY_DESIGN_JOB_NAMES = [entry.split("/", 2)[2] for entry in BY_DESIGN_FAILURES]
+
_COORDINATOR = "products.engineering_analytics.backend.logic.signals.coordinator"
_DETECT = "products.engineering_analytics.backend.logic.signals.detect"
_DETECTORS = "products.engineering_analytics.backend.logic.signals.detectors"
@@ -94,6 +97,7 @@ def _run_row(
head_branch: str = "main",
status: str = "completed",
default_branch: str = "main",
+ repository: str = "PostHog/posthog",
) -> dict[str, Any]:
started_s = _ts(started)
return {
@@ -108,7 +112,7 @@ def _run_row(
"updated_at": _ts(started + timedelta(seconds=duration_seconds)),
"run_attempt": run_attempt,
"pull_requests": None,
- "repository": json.dumps({"full_name": "PostHog/posthog", "default_branch": default_branch}),
+ "repository": json.dumps({"full_name": repository, "default_branch": default_branch}),
}
@@ -667,17 +671,38 @@ class TestCISignalDetectors(ClickhouseTestMixin, BaseTest):
assert findings[0].extra["run_id"] == 3
_assert_emittable(findings[0])
- def test_flaky_check_ignores_required_check_aggregators(self) -> None:
- # A `* Pass` gate fails only because a job it gates failed, so counting it emits a second
- # signal for every real flake. Real aggregators settle in 3-5s; real jobs run 60s+.
+ @parameterized.expand(
+ [
+ # A `* Pass` gate fails only because a job it gates failed, so counting it emits a second
+ # signal for every real flake. NO_OP_JOB_MAX_SECONDS drops this one.
+ ("Tests Pass", 3),
+ # 46s clears the duration floor, so only BY_DESIGN_FAILURES can drop these.
+ *[(name, 46) for name in _BY_DESIGN_JOB_NAMES],
+ ]
+ )
+ def test_flaky_check_ignores_excluded_jobs(self, job_name: str, duration_seconds: int) -> None:
now = datetime.now(UTC).replace(tzinfo=None)
rows = [_run_row(1, "CI", "shaG", "success", now - timedelta(hours=2), 60, run_attempt=2)]
jobs = [
_job_row(
- 200, 1, "Tests Pass", "shaG", "failure", now - timedelta(hours=3), run_attempt=1, duration_seconds=3
+ 200,
+ 1,
+ job_name,
+ "shaG",
+ "failure",
+ now - timedelta(hours=3),
+ run_attempt=1,
+ duration_seconds=duration_seconds,
),
_job_row(
- 201, 1, "Tests Pass", "shaG", "success", now - timedelta(hours=2), run_attempt=2, duration_seconds=3
+ 201,
+ 1,
+ job_name,
+ "shaG",
+ "success",
+ now - timedelta(hours=2),
+ run_attempt=2,
+ duration_seconds=duration_seconds,
),
_job_row(202, 1, "real-test-job", "shaG", "failure", now - timedelta(hours=3), run_attempt=1),
_job_row(203, 1, "real-test-job", "shaG", "success", now - timedelta(hours=2), run_attempt=2),
@@ -685,6 +710,20 @@ class TestCISignalDetectors(ClickhouseTestMixin, BaseTest):
findings = detect_flaky_checks(self._curated_over_runs(rows, jobs), min_flaky_runs=1)
assert {f.extra["job_name"] for f in findings} == {"real-test-job"}
+ @parameterized.expand([(name,) for name in _BY_DESIGN_JOB_NAMES])
+ def test_flaky_check_reports_by_design_job_names_in_another_repo(self, job_name: str) -> None:
+ # Every team runs this detector over its own repos, so the repo qualifier has to hold.
+ now = datetime.now(UTC).replace(tzinfo=None)
+ rows = [
+ _run_row(1, "CI", "shaS", "success", now - timedelta(hours=2), 60, run_attempt=2, repository="acme/webapp")
+ ]
+ jobs = [
+ _job_row(300, 1, job_name, "shaS", "failure", now - timedelta(hours=3), run_attempt=1, duration_seconds=46),
+ _job_row(301, 1, job_name, "shaS", "success", now - timedelta(hours=2), run_attempt=2, duration_seconds=46),
+ ]
+ findings = detect_flaky_checks(self._curated_over_runs(rows, jobs), min_flaky_runs=1)
+ assert {f.extra["job_name"] for f in findings} == {job_name}
+
def test_broken_default_branch_fires_only_on_failing_default_branch(self) -> None:
now = datetime.now(UTC).replace(tzinfo=None)
rows = [