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.

perf(engineering-analytics): count pr pushes in one runs scan (#109348)

Raúl Negrón-Oteroa7eca617415c
diff --git a/products/engineering_analytics/backend/logic/queries/_curated.py b/products/engineering_analytics/backend/logic/queries/_curated.py
index 20faebf2bf6c..fd3828b84f4e 100644
--- a/products/engineering_analytics/backend/logic/queries/_curated.py
+++ b/products/engineering_analytics/backend/logic/queries/_curated.py
@@ -384,8 +384,8 @@ class CuratedGitHubSource:
Only the LAST switch counts: for a merged PR the newest transition is necessarily the ready
that preceded the merge (a draft can't merge); an open PR goes false while re-drafted. The
event id breaks same-second ties (GitHub timestamps are second-coarse). Keyed on
- ``pr_number`` alone, unlike ``runs_by_pr``: a run's association can list the fork network's
- PRs (which is why that rollup needs the repo qualifier), whereas every row of a resolved
+ ``pr_number`` alone, unlike the push-activity query in ``pull_request_list``: a run's association
+ can list the fork network's PRs (which is why that query needs the repo qualifier), whereas every row of a resolved
issue-events table belongs to that one repo by table construction.
The events table and the pull requests table sync independently, so a timestamp here can run
@@ -437,21 +437,19 @@ class CuratedGitHubSource:
return f"({query})"
def runs_cte(self) -> str:
- """CTE materializing the curated workflow-runs source once.
+ """CTE naming the curated workflow-runs source for ``ci_rollup``.
- ``ci_rollup`` and ``runs_by_pr`` both derive from the same runs source; reading them from
- this shared CTE keeps the (JSON- and timestamp-parsing) source to a single scan per query
- instead of inlining — and re-parsing — it once per rollup.
+ ClickHouse inlines a CTE at every reference, so each extra reader of ``runs`` scans and
+ parses the whole runs source again.
"""
return f"runs AS {self.run_source()}"
def _pr_scope_cte(self, pr_scope_where: str) -> str:
"""CTE: the number and head SHA of PRs matching ``pr_scope_where`` (a predicate over
- unqualified curated PR columns), read once and shared by both runs rollups below —
- the same one-scan-per-query reasoning as ``runs_cte``, applied to the PR source.
+ unqualified curated PR columns).
- The runs rollups only ever join back to PRs the consuming query keeps, so they
- prefilter the runs scan to this set. Unscoped, they aggregate the team's whole
+ The CI rollup only ever joins back to PRs the consuming query keeps, so it
+ prefilters the runs scan to this set. Unscoped, it aggregates the team's whole
run history — millions of ``(head_sha, workflow)`` groups on a busy repo — and
the query runs out of memory before the join discards almost all of it.
"""
@@ -497,67 +495,18 @@ class CuratedGitHubSource:
)
"""
- def pr_rollup_query(self, select: str, *, pr_scope_where: str) -> str:
+ def pr_rollup_query(
+ self, select: str, *, pr_scope_where: str, ready: ReadyToMergeSql = READY_TO_MERGE_UNOBSERVABLE
+ ) -> str:
"""Compose a pull-requests query that reads ``FROM __PR_SOURCE__ AS pr LEFT JOIN ci_rollup``.
- Prefixes ``select`` with the ``pr_scope`` and CI rollup CTEs and fills its
- ``__PR_SOURCE__`` placeholder with the curated pull-requests source — the steps the
- cards and PR-list queries always do together. ``pr_scope_where`` must keep every PR the
- ``select`` reads CI for (it prunes the rollup scan, see ``_pr_scope_cte``); a PR outside
- it joins as if it had no runs.
+ Prefixes ``select`` with the ``pr_scope`` and CI rollup CTEs, and the CTE of the ``ready``
+ measure when ``select`` reads it, and fills its ``__PR_SOURCE__`` placeholder with the
+ curated pull-requests source. The cards and PR-list queries always do these steps together.
+ ``pr_scope_where`` must keep every PR the ``select`` reads CI for (it prunes the rollup scan,
+ see ``_pr_scope_cte``); a PR outside it joins as if it had no runs.
"""
- return self._compose_pr_query(
- [self.runs_cte(), self._pr_scope_cte(pr_scope_where), self.ci_rollup_cte()], select
- )
-
- def runs_by_pr_cte(self) -> str:
- """CTE: per-PR activity from the workflow runs attributed to each PR. Scoped to the
- ``pr_scope`` CTE the composing query adds (see ``_pr_scope_cte``); the scope is a
- prefilter — the repo-qualified join below still decides correctness.
-
- A run records the PR(s) it ran for in ``pull_requests``; the curated run source surfaces
- the first as ``pr_number``. ``pushes`` counts the distinct head SHAs that triggered CI
- (CI triggers), ``rerun_cycles`` the runs that were a 2nd+ attempt. Fork-PR runs have no
- association (``pr_number = 0``) and are excluded.
-
- Merge-queue gate runs are excluded too, even though the runs builder credits them to the PR
- they were landing. This rollup measures what the *author* did to the PR, and a gate branch's
- head SHA is a rebase the queue made — counting it would report a push nobody made, once per
- merge attempt. Cost and CI-health surfaces keep the gate run; they measure spend and outcomes,
- not authoring activity.
-
- Keyed on ``(repo_owner, repo_name, pr_number)``, not ``pr_number`` alone: PR numbers
- restart per repository, so the PR-list join is qualified by repo to stay correct — as
- repo-safe as the head-SHA join in ``ci_rollup_cte``. A resolved source is a single repo
- today (the warehouse GitHub source syncs one ``owner/repo``), so the qualifier is a no-op
- now; it keeps the rollup correct if a source ever spans repos, instead of silently
- cross-attributing runs to a same-numbered PR in another repo.
- """
- return f"""
- runs_by_pr AS (
- SELECT
- repo_owner,
- repo_name,
- pr_number,
- count(DISTINCT head_sha) AS pushes,
- countIf(run_attempt > 1) AS rerun_cycles
- FROM runs AS r
- WHERE {_PUSH_RUN_PREDICATE}
- AND pr_number IN (SELECT number FROM pr_scope)
- GROUP BY repo_owner, repo_name, pr_number
- )
- """
-
- def pr_list_rollup_query(self, select: str, *, pr_scope_where: str, ready: ReadyToMergeSql) -> str:
- """``pr_rollup_query`` plus the per-PR runs rollup and the CTE of the ``ready`` measure that
- ``select`` reads. ``pr_scope_where`` scopes both runs rollups via the shared ``pr_scope`` CTE
- (see ``pr_rollup_query``)."""
- ctes = [
- self.runs_cte(),
- self._pr_scope_cte(pr_scope_where),
- self.ci_rollup_cte(),
- self.runs_by_pr_cte(),
- ]
+ ctes = [self.runs_cte(), self._pr_scope_cte(pr_scope_where), self.ci_rollup_cte()]
if ready.cte:
ctes.append(ready.cte)
return self._compose_pr_query(ctes, select)
diff --git a/products/engineering_analytics/backend/logic/queries/pr_cost.py b/products/engineering_analytics/backend/logic/queries/pr_cost.py
index d0ffc5f7da61..ffe118a308b5 100644
--- a/products/engineering_analytics/backend/logic/queries/pr_cost.py
+++ b/products/engineering_analytics/backend/logic/queries/pr_cost.py
@@ -220,11 +220,13 @@ _PR_COSTS_CACHE_SECONDS = 300
# The cache stores the SQL row, not a PRCostAggregate, because the cache key covers the SQL but not
# the Python classes that read the row.
_CostRow = tuple[str, str, float | None, float | None, int | None, int | None, int | None]
+# (repo_owner, repo_name, pr_number). PR numbers restart per repository, so the number alone is not a key.
+PullRequestKey = tuple[str, str, int]
def query_pr_costs(
*, curated: CuratedGitHubSource, pr_numbers: list[int], run_from: datetime | None = None
-) -> dict[tuple[str, str, int], PRCostAggregate]:
+) -> dict[PullRequestKey, PRCostAggregate]:
"""Per-PR billable cost across the given PR numbers' runs, keyed by (repo_owner, repo_name, pr_number).
Empty when the jobs source isn't synced or no PR numbers are given. One grouped pass over the cost
diff --git a/products/engineering_analytics/backend/logic/queries/pull_request_list.py b/products/engineering_analytics/backend/logic/queries/pull_request_list.py
index 0859892d4338..54c9935e0296 100644
--- a/products/engineering_analytics/backend/logic/queries/pull_request_list.py
+++ b/products/engineering_analytics/backend/logic/queries/pull_request_list.py
@@ -11,6 +11,8 @@ from datetime import datetime
from posthog.hogql import ast
+from posthog.dataclasses import frozen
+
from products.engineering_analytics.backend.facade.contracts import (
AttentionPullRequestList,
Author,
@@ -29,7 +31,7 @@ from products.engineering_analytics.backend.logic.queries._curated import (
)
from products.engineering_analytics.backend.logic.queries._workflow_filters import DECISIVE_FAILURE_CONCLUSIONS_SQL
from products.engineering_analytics.backend.logic.queries.ci_cards import FAILING_CI_SQL, OPEN_PR_SQL, stuck_pr_sql
-from products.engineering_analytics.backend.logic.queries.pr_cost import query_pr_costs
+from products.engineering_analytics.backend.logic.queries.pr_cost import PullRequestKey, query_pr_costs
_LIMIT = 1000
_ATTENTION_LIMIT = 15
@@ -62,14 +64,10 @@ _SELECT = f"""
coalesce(ci.failing, 0) AS failing,
coalesce(ci.pending, 0) AS pending,
coalesce(ci.inconclusive, 0) AS inconclusive,
- ci.failing_workflows AS failing_workflows,
- coalesce(rp.pushes, 0) AS pushes,
- coalesce(rp.rerun_cycles, 0) AS rerun_cycles
+ ci.failing_workflows AS failing_workflows
__EXTRA_COLUMNS__
FROM __PR_SOURCE__ AS pr
LEFT JOIN ci_rollup AS ci ON ci.head_sha = pr.head_sha
- LEFT JOIN runs_by_pr AS rp
- ON rp.repo_owner = pr.repo_owner AND rp.repo_name = pr.repo_name AND rp.pr_number = pr.number
__READY_JOIN__
WHERE __ROWS__
ORDER BY __ORDER_BY__
@@ -77,55 +75,72 @@ _SELECT = f"""
"""
-# Per-push CI rounds for the visible PRs, for the push-history sparkline. Verdicts collapse like
-# ``ci_rollup``: latest run per (push, workflow) via argMax, then any decisive failure turns the
-# round red and any not-yet-completed run marks it pending. Wall time is the round's earliest run
-# start to its latest completed run end (``updated_at`` is the end time the duration column uses).
+# Per-push CI rounds for the visible PRs, for the push-history sparkline, plus each PR's ``pushes`` and
+# ``rerun_cycles``. Verdicts collapse like ``ci_rollup``: latest run per (push, workflow) via argMax,
+# then any decisive failure turns the round red and any not-yet-completed run marks it pending. Wall
+# time is the round's earliest run start to its latest completed run end (``updated_at`` is the end
+# time the duration column uses).
#
-# Merge-queue gate runs are excluded for the same reason as ``runs_by_pr`` (see its docstring), and
-# for one specific to here: they are the newest rounds a PR has, since they happen at merge time, so
-# leaving them in would push the author's real pushes out of the capped window below.
+# Merge-queue gate runs are excluded. A gate branch's head SHA is a rebase the queue made, not a push
+# the author made. Gate runs are also a PR's newest rounds, so they would push the author's real pushes
+# out of the capped window below.
#
# ``LIMIT __PUSH_HISTORY_LIMIT__ BY (repo_owner, repo_name, pr_number)`` bounds the scan to the most
# recent N pushes per PR *in ClickHouse* (rows are ordered newest-first, so the cap keeps the newest),
# rather than fetching every push and slicing in Python — a PR with hundreds of pushes never ships more
-# than the sparkline shows. The trailing ``LIMIT`` is the overall ceiling (≤ 1000 PRs × N); without it
-# HogQL applies its default 100-row limit and silently truncates the whole result.
-_PUSH_HISTORY_SELECT = """
+# than the sparkline shows. The window functions run before ``LIMIT BY``, so ``pushes`` and
+# ``rerun_cycles`` count every push. The trailing ``LIMIT`` is the overall ceiling (≤ 1000 PRs × N);
+# without it HogQL applies its default 100-row limit and silently truncates the whole result.
+_PUSH_ACTIVITY_SELECT = """
SELECT
- repo_owner, repo_name, pr_number, head_sha,
- min(first_start) AS started_at,
- if(countIf(last_end IS NOT NULL) = 0, NULL, dateDiff('second', min(first_start), max(last_end))) AS wall_seconds,
- countIf(s = 'completed' AND c IN (__DECISIVE_FAILURES__)) > 0 AS failed,
- countIf(s IS NULL OR s != 'completed') > 0 AS pending
+ repo_owner, repo_name, pr_number, head_sha, started_at, wall_seconds, failed, pending,
+ countIf(head_sha IS NOT NULL) OVER (PARTITION BY repo_owner, repo_name, pr_number) AS pushes,
+ sum(rerun_runs) OVER (PARTITION BY repo_owner, repo_name, pr_number) AS rerun_cycles
FROM (
SELECT
- repo_owner, repo_name, pr_number, head_sha, workflow_name,
- min(run_started_at) AS first_start,
- max(if(status = 'completed', updated_at, NULL)) AS last_end,
- argMax(status, run_started_at) AS s,
- argMax(conclusion, run_started_at) AS c
- FROM __RUNS_SOURCE__ AS r
- WHERE pr_number IN {pr_numbers} AND NOT is_merge_queue
- GROUP BY repo_owner, repo_name, pr_number, head_sha, workflow_name
+ repo_owner, repo_name, pr_number, head_sha,
+ min(first_start) AS started_at,
+ if(countIf(last_end IS NOT NULL) = 0, NULL, dateDiff('second', min(first_start), max(last_end))) AS wall_seconds,
+ countIf(s = 'completed' AND c IN (__DECISIVE_FAILURES__)) > 0 AS failed,
+ countIf(s IS NULL OR s != 'completed') > 0 AS pending,
+ sum(rerun_runs) AS rerun_runs
+ FROM (
+ SELECT
+ repo_owner, repo_name, pr_number, head_sha, workflow_name,
+ min(run_started_at) AS first_start,
+ max(if(status = 'completed', updated_at, NULL)) AS last_end,
+ argMax(status, run_started_at) AS s,
+ argMax(conclusion, run_started_at) AS c,
+ countIf(run_attempt > 1) AS rerun_runs
+ FROM __RUNS_SOURCE__ AS r
+ WHERE pr_number IN {pr_numbers} AND NOT is_merge_queue
+ GROUP BY repo_owner, repo_name, pr_number, head_sha, workflow_name
+ )
+ GROUP BY repo_owner, repo_name, pr_number, head_sha
)
- GROUP BY repo_owner, repo_name, pr_number, head_sha
ORDER BY started_at DESC
LIMIT __PUSH_HISTORY_LIMIT__ BY (repo_owner, repo_name, pr_number)
LIMIT 100000
"""
-def query_pr_push_history(
+@frozen
+class PushActivity:
+ pushes: int
+ rerun_cycles: int
+ # Oldest first and capped to the most recent ``_PUSH_HISTORY_LIMIT`` pushes, while ``pushes`` counts every push.
+ history: list[PushCISample]
+
+
+def query_pr_push_activity(
*, curated: CuratedGitHubSource, pr_numbers: list[int]
-) -> dict[tuple[str, str, int], list[PushCISample]]:
- """Per-PR push rounds keyed by (repo_owner, repo_name, pr_number), oldest first, capped in
- ClickHouse to the most recent ``_PUSH_HISTORY_LIMIT`` per PR. Scoped to the visible PR numbers so
- the scan tracks the page (same shape as ``query_pr_costs``)."""
+) -> dict[PullRequestKey, PushActivity]:
+ """Per-PR push activity keyed by (repo_owner, repo_name, pr_number). Scoped to the visible PR
+ numbers so the scan tracks the page (same shape as ``query_pr_costs``). A PR with no CI has no entry."""
if not pr_numbers:
return {}
sql = (
- _PUSH_HISTORY_SELECT.replace("__RUNS_SOURCE__", curated.run_source())
+ _PUSH_ACTIVITY_SELECT.replace("__RUNS_SOURCE__", curated.run_source())
.replace("__PUSH_HISTORY_LIMIT__", str(_PUSH_HISTORY_LIMIT))
.replace("__DECISIVE_FAILURES__", DECISIVE_FAILURE_CONCLUSIONS_SQL)
)
@@ -134,9 +149,24 @@ def query_pr_push_history(
query_type="engineering_analytics.pr_push_history",
placeholders={"pr_numbers": ast.Constant(value=pr_numbers)},
)
- by_pr: dict[tuple[str, str, int], list[PushCISample]] = {}
- for repo_owner, repo_name, pr_number, head_sha, started_at, wall_seconds, failed, pending in response.results or []:
- by_pr.setdefault((repo_owner, repo_name, int(pr_number)), []).append(
+ activity: dict[PullRequestKey, PushActivity] = {}
+ for (
+ repo_owner,
+ repo_name,
+ pr_number,
+ head_sha,
+ started_at,
+ wall_seconds,
+ failed,
+ pending,
+ pushes,
+ rerun_cycles,
+ ) in response.results or []:
+ key = (repo_owner, repo_name, int(pr_number))
+ pr_activity = activity.setdefault(
+ key, PushActivity(pushes=int(pushes), rerun_cycles=int(rerun_cycles or 0), history=[])
+ )
+ pr_activity.history.append(
PushCISample(
head_sha=head_sha,
started_at=started_at,
@@ -147,7 +177,9 @@ def query_pr_push_history(
)
# The query returns newest-first (so the per-PR cap keeps the newest pushes); the contract is
# oldest-first, so reverse each PR's list back to chronological order.
- return {key: samples[::-1] for key, samples in by_pr.items()}
+ for pr_activity in activity.values():
+ pr_activity.history.reverse()
+ return activity
def _query_rows(
@@ -163,7 +195,7 @@ def _query_rows(
extra_columns: str = "",
) -> list[tuple]:
"""``scope_where`` is over unqualified curated PR columns and must keep every row ``rows_where``
- keeps, because it prunes the runs rollups (see ``pr_list_rollup_query``)."""
+ keeps, because it prunes the CI rollup (see ``pr_rollup_query``)."""
select = (
_SELECT.replace("__READY_TO_MERGE__", f"{ready.expr} AS ready_to_merge_seconds")
.replace("__READY_JOIN__", ready.join)
@@ -173,7 +205,7 @@ def _query_rows(
.replace("__LIMIT__", str(limit))
)
response = curated.run(
- curated.pr_list_rollup_query(select, pr_scope_where=scope_where, ready=ready),
+ curated.pr_rollup_query(select, pr_scope_where=scope_where, ready=ready),
query_type=query_type,
placeholders=placeholders,
)
@@ -186,9 +218,9 @@ def _enrich(*, curated: CuratedGitHubSource, rows: list[tuple]) -> list[PullRequ
pr_numbers = sorted({int(row[0]) for row in rows})
with curated.concurrent_reads() as reads:
costs_read = reads.submit(lambda: query_pr_costs(curated=curated, pr_numbers=pr_numbers))
- pushes_read = reads.submit(lambda: query_pr_push_history(curated=curated, pr_numbers=pr_numbers))
- cost_by_pr, pushes_by_pr = costs_read.result(), pushes_read.result()
- return [_map_row(row, cost_by_pr, pushes_by_pr) for row in rows]
+ activity_read = reads.submit(lambda: query_pr_push_activity(curated=curated, pr_numbers=pr_numbers))
+ cost_by_pr, activity_by_pr = costs_read.result(), activity_read.result()
+ return [_map_row(row, cost_by_pr, activity_by_pr) for row in rows]
def query_pull_request_list(
@@ -234,8 +266,8 @@ def query_attention_pull_requests(*, curated: CuratedGitHubSource) -> AttentionP
def _map_row(
row: tuple,
- cost_by_pr: dict[tuple[str, str, int], PRCostAggregate],
- pushes_by_pr: dict[tuple[str, str, int], list[PushCISample]],
+ cost_by_pr: dict[PullRequestKey, PRCostAggregate],
+ activity_by_pr: dict[PullRequestKey, PushActivity],
) -> PullRequestListItem:
(
number,
@@ -258,10 +290,9 @@ def _map_row(
pending,
inconclusive,
failing_workflows,
- pushes,
- rerun_cycles,
) = row
cost = cost_by_pr.get((repo_owner, repo_name, number))
+ activity = activity_by_pr.get((repo_owner, repo_name, number))
return PullRequestListItem(
number=number,
title=title,
@@ -289,9 +320,9 @@ def _map_row(
inconclusive=inconclusive,
failing_workflows=list(failing_workflows or []),
),
- pushes=pushes,
- rerun_cycles=rerun_cycles,
+ pushes=activity.pushes if activity else 0,
+ rerun_cycles=activity.rerun_cycles if activity else 0,
estimated_cost_usd=cost.estimated_cost_usd if cost else None,
billable_minutes=(cost.billable_seconds / 60) if cost else None,
- push_history=pushes_by_pr.get((repo_owner, repo_name, number), []),
+ push_history=activity.history if activity else [],
)
diff --git a/products/engineering_analytics/backend/logic/views/workflow_runs.py b/products/engineering_analytics/backend/logic/views/workflow_runs.py
index 03572f0c1531..ebfe5f56d90b 100644
--- a/products/engineering_analytics/backend/logic/views/workflow_runs.py
+++ b/products/engineering_analytics/backend/logic/views/workflow_runs.py
@@ -42,7 +42,7 @@ and wrong for a few. Ask what the number is being counted *for*:
``NOT is_merge_queue``. A gate branch's head SHA is a rebase the queue made, so counting it reports
activity nobody performed, once per merge attempt.
-Only ``runs_by_pr`` (``_curated``) and the push-history scan (``pull_request_list``) are in the second
+Only ``push_rows_select`` (``_curated``) and the push-activity query (``pull_request_list``) are in the second
group today. Getting this wrong is silent: the numbers stay plausible and just drift up.
``commit_pr_number`` is the complementary key: it is how a push run gets PR attribution at all,
diff --git a/products/engineering_analytics/backend/tests/_logic_helpers.py b/products/engineering_analytics/backend/tests/_logic_helpers.py
index 7fabe4feeb9a..3973eb703309 100644
--- a/products/engineering_analytics/backend/tests/_logic_helpers.py
+++ b/products/engineering_analytics/backend/tests/_logic_helpers.py
@@ -261,9 +261,17 @@ class _EndpointsWarehouseMixin(_WarehouseMixin):
_run_row(2001, "CI", "sha10", "completed", "failure", _ago(1), _ago(1), pr_number=10),
_run_row(2002, "CI", "sha11", "completed", "success", _ago(2), _ago(2), pr_number=11),
# A second push on PR 10 (new head SHA) that was re-run -> pushes=2, rerun_cycles=1.
- # A non-CI workflow so the CI workflow-health assertions stay at 2 runs.
+ # A non-CI workflow so the CI workflow-health assertions stay at 2 runs. It starts a
+ # minute before sha10, so a push-history cap of 1 drops this re-run push.
_run_row(
- 2003, "Deploy", "sha10b", "completed", "success", _ago(1), _ago(1), pr_number=10, run_attempt=2
+ 2003,
+ "Deploy",
+ "sha10b",
+ "completed",
+ "success",
+ *_ago_offset_with_duration(1, -60, 0),
+ pr_number=10,
+ run_attempt=2,
),
# PR 10 queued to merge: the gate run is credited to PR 10 (its branch names it) but
# its head SHA is a rebase the queue made, so it must not read as a third push.
diff --git a/products/engineering_analytics/backend/tests/test_logic_pull_requests.py b/products/engineering_analytics/backend/tests/test_logic_pull_requests.py
index 7a9073870ec3..1881de221bbf 100644
--- a/products/engineering_analytics/backend/tests/test_logic_pull_requests.py
+++ b/products/engineering_analytics/backend/tests/test_logic_pull_requests.py
@@ -187,14 +187,12 @@ class TestPullRequestEndpointMapping(BaseTest):
0,
1,
["E2E CI"],
- 5,
- 2,
)
# The query returns newest-first (its per-PR LIMIT BY keeps the most recent pushes); the mapper
# reverses to the oldest-first contract, so the mock is ordered newest-first to match.
push_rows = [
- ("PostHog", "posthog", 10, "sha-new", _dt("2026-01-11T10:00:00"), None, 0, 1),
- ("PostHog", "posthog", 10, "sha-old", _dt("2026-01-10T10:00:00"), 900, 1, 0),
+ ("PostHog", "posthog", 10, "sha-new", _dt("2026-01-11T10:00:00"), None, 0, 1, 5, 2),
+ ("PostHog", "posthog", 10, "sha-old", _dt("2026-01-10T10:00:00"), 900, 1, 0, 5, 2),
]
with mock.patch(_RUN_QUERY, side_effect=_pr_list_run([row], push_rows)):
result = api.list_pull_requests(team=self.team, date_from="-30d")
@@ -248,8 +246,6 @@ class TestPullRequestEndpointMapping(BaseTest):
0,
0,
list[str](),
- 0,
- 0,
)
with (
mock.patch(f"{_PR_LIST}._LIMIT", 2),
@@ -326,6 +322,10 @@ class TestPullRequestEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):
# its head SHA is a rebase the queue made, so it must not inflate the author's push count.
assert (by_number[10].pushes, by_number[10].rerun_cycles) == (2, 1)
assert {sample.head_sha for sample in by_number[10].push_history} == {"sha10", "sha10b"}
+ with mock.patch.object(pull_request_list, "_PUSH_HISTORY_LIMIT", 1):
+ capped = next(i for i in api.list_pull_requests(team=self.team).items if i.number == 10)
+ assert [sample.head_sha for sample in capped.push_history] == ["sha10"]
+ assert (capped.pushes, capped.rerun_cycles) == (2, 1) # counts include the push the cap dropped
assert (by_number[11].pushes, by_number[11].rerun_cycles) == (1, 0)
assert by_number[12].pushes == 0 # no runs attributed to this PR
assert by_number[10].estimated_cost_usd is None # no jobs source seeded here → no cost figure
@@ -644,7 +644,7 @@ class TestPullRequestEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):
def test_pull_request_list_rollup_is_repo_qualified(self) -> None:
# PR numbers restart per repo. Two repos share PR #10; the per-PR push / re-run rollup must
# attribute each repo's runs to its own PR, not merge them on number alone. (The head-SHA CI
- # rollup is already repo-safe; this proves the runs_by_pr join is too.) A resolved source is
+ # rollup is already repo-safe; this proves the push-activity rollup is too.) A resolved source is
# one repo today, so this is the defensive guarantee, exercised by seeding both into one.
self._create_table(
"github_pull_requests",
diff --git a/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts b/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts
index e25424548654..255f22d6337e 100644
--- a/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts
+++ b/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts
@@ -693,7 +693,7 @@ export const pullRequestDetailLogic = kea<pullRequestDetailLogicType>([
},
],
// Drops merge-queue gate attempts, whose head SHAs the author never pushed. Mirrors the
- // backend's `runs_by_pr` rollup, so push counts agree between the PR list and this page.
+ // backend's push-activity query (`pull_request_list.py`), so push counts agree between the PR list and this page.
authoredRuns: [
(s) => [s.prRuns],
(prRuns: WorkflowRunDetailApi[]): WorkflowRunDetailApi[] => prRuns.filter((run) => !run.is_merge_queue),