: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
fix(eng-analytics): hide depot gate hand-off shells (#118652)
Raúl Negrón-Otero4029b9f93b93
diff --git a/products/engineering_analytics/SPEC.md b/products/engineering_analytics/SPEC.mdindex a3113a4f8ff5..70c4e68f09dd 100644--- a/products/engineering_analytics/SPEC.md+++ b/products/engineering_analytics/SPEC.md@@ -199,7 +199,7 @@ Warehouse table (Depot source):- `depot_job_attempts`: one row per Depot CI job attempt, for the repository the Depot source names. Reads keep only that repository's rows, because a source moved to another repository keeps what it synced before. Depot CI is its own engine, so these runs never reach the GitHub tables. `logic/views/depot_ci.py` reshapes the attempts into rows of the GitHub runs and jobs contracts and unions them onto those tables, so every builder reads both engines. Each Depot workflow is one runs row. A run with one workflow decodes its id to the integer `GITHUB_RUN_ID` Depot CI gives its jobs, which joins them to the CI test spans; a run with several workflows keys each by its own decoded workflow id, so no join fans out. The PR number comes from the run's `refs/pull/<n>/merge` ref, and the run's branch and actor from that PR's snapshot (its head ref and author). A merge-queue gate run's PR is the gate PR the queue bot opened, so the run resolves through `logic/merge_queue.py` to the PR being landed, like a GitHub gate run (§6). Job rows carry no branch, because a PR snapshot lookup in the jobs builder would add two full PR scans to every jobs read; a read that joins a job to its run takes the branch through `workflow_jobs.branch`, which falls back to the run's. Depot numbers attempts per job, not per run, so a job's last attempt is listed again under each later attempt of its run, as GitHub lists a job it did not re-run; the jobs builder flags those rows as `is_rerun_copy`. Depot's API reports no `runs-on`, so every attempt is costed as the default `depot-ubuntu-24.04` sandbox. Optional, and reads degrade to GitHub-only CI when unsynced.- Depot ingestion replays seven days behind the creation-time watermark on every incremental sync and reconciles the schema's retained history weekly. The first sync after this policy deploys also reconciles retained history. The fixed `history_start` bounds new sources; a legacy source without that bound reconciles all available history. The durable reconciliation cursor advances only after extraction finishes and the pipeline makes the rows durable. Completed runs do not wait behind queued or stuck runs. Late retries older than the replay window can remain stale until the next reconciliation. Replayed attempts merge by `attempt_id`; append mode is unsupported, and an existing append sync stops before extraction with instructions to change its sync method. Depot's existing two-page-size pagination workaround still cannot guarantee recovery of every same-second cursor omission.- The shared CI sources assign `ci_engine` from the warehouse source: `github_actions` or `depot_ci`. Runner provider is independent: GitHub Actions can use Depot runners. Managed job-history and job-cost views append `ci_engine`, `native_run_id`, `native_workflow_run_id`, `native_job_id`, and `native_attempt_id`. GitHub's native workflow execution ID is its run ID; Depot's is its workflow ID. These additive string IDs preserve source identity while the existing integer IDs remain compatible with test traces and API consumers. CI job-to-run joins, failure attribution, job run shares, and timeline paging qualify integer IDs with `ci_engine`. The friction view consumes the same normalized sources and resolves a Depot job's default branch through its run. Run and job APIs append engine and source-native IDs; per-run costs and UI caches qualify compatible integers with the engine. Detail, job, and log lookups accept `ci_engine`; an unqualified integer that names both engines fails with a 400. New failure logs and test traces stamp the engine. Recovery evidence groups by engine, native workflow identity, and commit SHA; historical untagged telemetry remains unknown and cannot establish cross-engine identity. Legacy logs are read only for integer IDs unique to one engine in the selected source. Depot workflows without a hand-off job remain visible, including default-branch pushes; their branch and commit come from `ref` and `sha` when no PR head is present.- - While a workflow moves to Depot CI, GitHub Actions routes each pull request to one engine, and both engines record a run of the commit. The union suppresses a successful Depot workflow whose `wait-for-handoff` job ran alone. A GitHub run is suppressed only when it succeeded, its `Hand off backend tests to Depot CI` job succeeded, its latest `Django Tests Pass` job succeeded, no synced job attempt decisively failed, and a successful Depot workflow took the hand-off for the same PR number and `head_sha`. Missing association or replacement data leaves the GitHub run visible. Failed, cancelled and unsettled GitHub relays and Depot waits stay visible. A relay that recovered retains its earlier failure history. Suppression applies to both runs and jobs; raw source rows remain available for full runner-cost accounting. Curated estimates cover the visible execution jobs; suppressed hand-off and relay overhead is excluded. These figures are not total runner spend or invoice reconciliation.+ - While a workflow moves to Depot CI, GitHub Actions routes each pull request to one engine, and both engines record a run of the commit. The union suppresses a successful Depot workflow whose `wait-for-handoff` job ran alone. A GitHub run is suppressed only when it succeeded, its `Hand off backend tests to Depot CI` job succeeded, its latest `Django Tests Pass` job succeeded, no synced job attempt decisively failed, and a successful Depot workflow took the hand-off for the same PR number and `head_sha`. The PR number on both sides is the run's own association, because a merge-queue gate run's `pr_number` names the landed PR while Depot's ref names the gate PR. Missing association or replacement data leaves the GitHub run visible. Failed, cancelled and unsettled GitHub relays and Depot waits stay visible. A relay that recovered retains its earlier failure history. Suppression applies to both runs and jobs; raw source rows remain available for full runner-cost accounting. Curated estimates cover the visible execution jobs; suppressed hand-off and relay overhead is excluded. These figures are not total runner spend or invoice reconciliation.The Depot source is attempt-grained. A terminal run with no executed job attempts has no row here, sothe normalized run inventory cannot establish total run completeness. Vendor pagination can omit runsdiff --git a/products/engineering_analytics/backend/logic/views/depot_ci.py b/products/engineering_analytics/backend/logic/views/depot_ci.pyindex 3569e5cc64c0..4c0d9f90af52 100644--- a/products/engineering_analytics/backend/logic/views/depot_ci.py+++ b/products/engineering_analytics/backend/logic/views/depot_ci.py@@ -286,15 +286,16 @@ def _github_shells(jobs_table: str, runs_table: str, handoffs: str) -> str:) = 'success'AND countIf(conclusion IN ({DECISIVE_FAILURE_CONCLUSIONS_SQL})) = 0"""- # The runs builder parses JSON columns on every row, so the raw columns narrow its input first.- successful_relays = f"id >= {first_run} AND {SUCCESSFUL_RUN_CONDITION} AND id IN ({relays})"+ # Depot's PR is the run's association (see ASSOCIATION_PR_NUMBER). The raw columns come first, so+ # the JSON parse runs only on successful relays.return f"""- SELECT r.id- FROM ({workflow_runs.build_query(f"({_github_runs(runs_table, successful_relays)})")}) AS r- WHERE (r.head_sha, r.pr_number) IN (- SELECT head_sha, pr_number FROM {handoffs}- WHERE took_handoff AND pr_number > 0 AND workflow_status = 'finished'- )+ SELECT id+ FROM {runs_table}+ WHERE id >= {first_run} AND {SUCCESSFUL_RUN_CONDITION} AND id IN ({relays})+ AND (head_sha, {workflow_runs.ASSOCIATION_PR_NUMBER}) IN (+ SELECT head_sha, pr_number FROM {handoffs}+ WHERE took_handoff AND pr_number > 0 AND workflow_status = 'finished'+ )"""diff --git a/products/engineering_analytics/backend/logic/views/workflow_runs.py b/products/engineering_analytics/backend/logic/views/workflow_runs.pyindex 4c9624a4ff58..2450b1b16bfc 100644--- a/products/engineering_analytics/backend/logic/views/workflow_runs.py+++ b/products/engineering_analytics/backend/logic/views/workflow_runs.py@@ -105,6 +105,9 @@ _OWN_REPO_PR = """arrayFirst(AND JSONExtractInt(p, 'base', 'repo', 'id') = ifNull(JSONExtractInt(repository, 'id'), 0),JSONExtractArrayRaw(ifNull(pull_requests, '[]')))"""+# The PR number of that association, read off raw runs columns. A merge-queue gate run's association+# is the gate PR the queue opened, not the PR it lands, which ``pr_number`` names instead.+ASSOCIATION_PR_NUMBER = f"JSONExtractInt({_OWN_REPO_PR}, 'number')"# The squash-merge PR number off the head commit's subject: the fallback when the merge-commit# join can't resolve the run (see module docstring). Anchored to a line end ((?m), the squash@@ -185,7 +188,7 @@ def build_query(table_name: str, *, pull_requests_table: str | None = None, starstatus,conclusion,run_attempt,- JSONExtractInt({_OWN_REPO_PR}, 'number') AS association_pr_number,+ {ASSOCIATION_PR_NUMBER} AS association_pr_number,-- ``actor`` is read inline, not via an alias: an alias defined later in this same-- SELECT is not reliably resolvable as another expression's input (see the two-layer-- note above). It is the account GitHub recorded as triggering the run, which whoeverdiff --git a/products/engineering_analytics/backend/tests/test_views.py b/products/engineering_analytics/backend/tests/test_views.pyindex 0f148ad3ca60..5589f78d9ae4 100644--- a/products/engineering_analytics/backend/tests/test_views.py+++ b/products/engineering_analytics/backend/tests/test_views.py@@ -294,6 +294,21 @@ class TestEngineeringAnalyticsViews(ClickhouseTestMixin, BaseTest):(907, "abc123", 101991, "success", 1),(908, "abc123", 101991, "success", 2),)+ ]+ # A merge-queue gate for PR 101991, tested through gate PR 101993, handed its commit to Depot.+ + [+ _run_row(+ 909,+ "Backend CI",+ "gat123",+ "completed",+ "success",+ "2026-09-24 14:50:00",+ "2026-09-24 15:05:00",+ pr_number=101993,+ head_branch="trunk-merge/pr-101991/aaaa",+ actor="trunk-io[bot]",+ )],)jobs_table = self._create_table(@@ -326,13 +341,20 @@ class TestEngineeringAnalyticsViews(ClickhouseTestMixin, BaseTest):completed="2026-09-01 14:02:00",),_job_row(9083, 908, "Django Tests Pass", "success", head_sha="abc123", run_attempt=2),+ _job_row(9091, 909, "Hand off backend tests to Depot CI", "success", head_sha="gat123"),+ _job_row(9092, 909, "Django Tests Pass", "success", head_sha="gat123"),],)prs_table = self._create_table("github_pull_requests",PULL_REQUESTS_COLUMNS,- [_pr_row(101991, "octocat", "open", 0, "2026-09-24T14:00:00Z", head_ref="feature/depot")],+ [+ _pr_row(101991, "octocat", "open", 0, "2026-09-24T14:00:00Z", head_ref="feature/depot"),+ _pr_row(+ 101993, "trunk-io[bot]", "open", 1, "2026-09-24T14:30:00Z", head_ref="trunk-merge/pr-101991/aaaa"+ ),+ ],)def attempt(@@ -463,6 +485,25 @@ class TestEngineeringAnalyticsViews(ClickhouseTestMixin, BaseTest):workflow_status="failed",job_key="ci-backend.yml:wait-for-handoff",),+ *(+ attempt(+ attempt_id,+ 1,+ "finished",+ "2026-09-24T14:52:00.000Z",+ "2026-09-24T14:53:00.000Z",+ job_id=job_id,+ run_id="7777777777",+ workflow_id="8888888888",+ ref="refs/pull/101993/merge",+ head_sha="gat123",+ job_key=job_key,+ )+ for attempt_id, job_id, job_key in (+ ("g7h8j9k0l1", "g1h2j3k4l5", "ci-backend.yml:wait-for-handoff"),+ ("g7h8j9k0l2", "g1h2j3k4l6", "ci-backend.yml:turbo-tests:matrix-38"),+ )+ ),# Synced before the source moved to another repository, so no read of this one keeps it.attempt("k3w9v2rq8b",@@ -494,6 +535,16 @@ class TestEngineeringAnalyticsViews(ClickhouseTestMixin, BaseTest):(908, "Backend CI", "success", 101991, "main", 900, "PostHog", 2),(80213453736890, "Backend CI on Depot", "success", 101991, "feature/depot", 600, "PostHog", 2),(101808620689656, "Backend CI on Depot", "failure", 101991, "feature/depot", 600, "PostHog", 1),+ (+ 142532068965517,+ "Backend CI on Depot",+ "success",+ 101991,+ "trunk-merge/pr-101991/aaaa",+ 600,+ "PostHog",+ 1,+ ),(223978965517241, "Monitor", "success", 0, "master", 600, "PostHog", 1),(244340689655172, "Timing", "failure", 0, "master", 600, "PostHog", 1),]@@ -509,6 +560,7 @@ class TestEngineeringAnalyticsViews(ClickhouseTestMixin, BaseTest):(908,),(80213453736890,),(101808620689656,),+ (142532068965517,),(223978965517241,),(244340689655172,),]