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.

feat(eng-analytics): merge queue landing stats on repo overview (#86560)

Raúl Negrón-Oteroc34926fac689
diff --git a/products/engineering_analytics/backend/facade/contracts.py b/products/engineering_analytics/backend/facade/contracts.py
index 22a60186ef72..d332ee6152b1 100644
--- a/products/engineering_analytics/backend/facade/contracts.py
+++ b/products/engineering_analytics/backend/facade/contracts.py
@@ -1083,10 +1083,43 @@ class RepoOverview:
billable_minutes_prev: float | None
estimated_cost_usd: float | None
estimated_cost_usd_prev: float | None
+ # The window's estimated cost divided by its merged-PR count (all authors) — defined here so no
+ # consumer re-derives the ratio with different guards. None without cost data or merges.
+ cost_per_merge_usd: float | None
+ cost_per_merge_usd_prev: float | None
# The slice of billable_minutes spent on merge-queue batch branches, broken out so queue-settings
# changes show up as their own delta instead of hiding inside the total.
merge_queue_billable_minutes: float | None
merge_queue_billable_minutes_prev: float | None
+ # Merge-queue landing stats, over merged PRs with at least one corroborated gate run
+ # (logic/merge_queue.py). All authors, bots included: these measure the queue's mechanics,
+ # not author behavior.
+ merge_queue_merged_pr_count: int
+ merge_queue_merged_pr_count_prev: int
+ # Median seconds from a PR's first observed gate run starting to its merge, named for what is
+ # measured: pending time before gate testing starts is not observable in the GitHub source.
+ merge_queue_median_first_gate_to_merge_seconds: float | None
+ merge_queue_median_first_gate_to_merge_seconds_prev: float | None
+ merge_queue_p90_first_gate_to_merge_seconds: float | None
+ merge_queue_p90_first_gate_to_merge_seconds_prev: float | None
+ merge_queue_p95_first_gate_to_merge_seconds: float | None
+ merge_queue_p95_first_gate_to_merge_seconds_prev: float | None
+ merge_queue_p99_first_gate_to_merge_seconds: float | None
+ merge_queue_p99_first_gate_to_merge_seconds_prev: float | None
+ # Mean distinct gate attempts per queue-landed merge (distinct gate branches, bisection collapsed).
+ merge_queue_avg_attempts_per_merge: float | None
+ merge_queue_avg_attempts_per_merge_prev: float | None
+ # Fraction (0-1) of queue-landed merges that needed more than one gate attempt.
+ merge_queue_multi_attempt_merge_share: float | None
+ merge_queue_multi_attempt_merge_share_prev: float | None
+ # Fraction (0-1) of queue-landed merges with at least one failed gate run before merging: a
+ # CI-outcome proxy, not the queue's own eviction record.
+ merge_queue_failed_gate_merge_share: float | None
+ merge_queue_failed_gate_merge_share_prev: float | None
+ # Median wall clock for a push round to settle fully green over the window: the window-level
+ # twin of time_to_green_series, same population and exclusions. None when no fully green rounds.
+ median_time_to_green_seconds: float | None
+ median_time_to_green_seconds_prev: float | None
jobs_available: bool
# 'master' or 'main', picked by observed run volume in the current window.
default_branch: str
diff --git a/products/engineering_analytics/backend/logic/merge_queue.py b/products/engineering_analytics/backend/logic/merge_queue.py
index a4c3a583eefe..4a894c2f318b 100644
--- a/products/engineering_analytics/backend/logic/merge_queue.py
+++ b/products/engineering_analytics/backend/logic/merge_queue.py
@@ -105,3 +105,10 @@ def merge_queue_branch_expr(branch_column: str, *, queue_actor_column: str) -> s
cleanup we have today; misrecognizing one loses data.
"""
return f"{source_pr_number_expr(branch_column, queue_actor_column=queue_actor_column)} > 0"
+
+
+def gate_attempt_expr(branch_column: str) -> str:
+ """HogQL expression naming the gate attempt a run belongs to: the gate branch with Trunk's
+ ``-bisection`` suffix collapsed, so a flake-bisection probe groups with the attempt it
+ investigates instead of counting as an attempt of its own."""
+ return f"replaceRegexpOne({branch_column}, '-bisection$', '')"
diff --git a/products/engineering_analytics/backend/logic/queries/_workflow_filters.py b/products/engineering_analytics/backend/logic/queries/_workflow_filters.py
index b743675cced5..17a498e3ce2d 100644
--- a/products/engineering_analytics/backend/logic/queries/_workflow_filters.py
+++ b/products/engineering_analytics/backend/logic/queries/_workflow_filters.py
@@ -8,6 +8,8 @@ from datetime import datetime, timedelta
from posthog.hogql import ast
+from posthog.dataclasses import frozen
+
from products.engineering_analytics.backend.facade.contracts import WorkflowHealthRunScope
# Trunk's merge-queue batch branches. Trunk-specific and hardcoded like KNOWN_BOT_HANDLES;
@@ -106,6 +108,25 @@ def date_to_filter_clause(
return f"AND {column} <= {{date_to}}"
+@frozen
+class WindowPredicates:
+ current: str
+ previous: str
+
+
+def window_pair_predicates(column: str, *, date_to: datetime | None) -> WindowPredicates:
+ """The current/previous window predicates every with-prev aggregate splits on.
+
+ Half-open at ``{date_from}``: a row exactly on the boundary is current, never both. Callers
+ register ``{date_from}``/``{prev_from}`` (and ``{date_to}`` when set) themselves; the pair is
+ the one place the boundary semantics live, not the placeholder bookkeeping.
+ """
+ return WindowPredicates(
+ current=f"({column} >= {{date_from}}" + (f" AND {column} <= {{date_to}})" if date_to is not None else ")"),
+ previous=f"({column} >= {{prev_from}} AND {column} < {{date_from}})",
+ )
+
+
def non_default_branch_predicate(branch_column: str = "r.head_branch") -> str:
"""True when the branch expression names a branch other than the repo's default. The source
doesn't record which branch that is, so this excludes the common default names — the same
diff --git a/products/engineering_analytics/backend/logic/queries/merge_queue_overview.py b/products/engineering_analytics/backend/logic/queries/merge_queue_overview.py
new file mode 100644
index 000000000000..9016a2f67507
--- /dev/null
+++ b/products/engineering_analytics/backend/logic/queries/merge_queue_overview.py
@@ -0,0 +1,193 @@
+"""Curated query: merge-queue landing stats for the repo hub landing page.
+
+Gate-run attribution rides the runs builder's gate detection (SPEC §6, ``logic/merge_queue.py``):
+``is_merge_queue`` marks actor-corroborated gate runs, ``pr_number`` is already re-keyed to the
+source PR, and ``gate_attempt_expr`` names the attempt a run belongs to, so this module adds no
+branch parsing of its own. The population is merged PRs with at
+least one corroborated gate run: all authors, bots included, because these figures measure the
+queue's mechanics, not author behavior (the locked bots/drafts recipe governs cycle-time medians,
+a different question). ``had_failed_gate`` is a CI-outcome proxy for eviction: the queue's own
+records are not in the GitHub source.
+"""
+
+from dataclasses import dataclass
+from datetime import datetime, timedelta
+
+from posthog.hogql import ast
+
+from products.engineering_analytics.backend.logic.merge_queue import gate_attempt_expr
+from products.engineering_analytics.backend.logic.queries._curated import CuratedGitHubSource, opt_float
+from products.engineering_analytics.backend.logic.queries._workflow_filters import (
+ date_to_filter_clause,
+ run_started_floor_constant,
+ window_pair_predicates,
+)
+
+# Gate runs start minutes-to-hours before their merge; reach this far behind the previous window so
+# a PR merged just inside it keeps its first attempt. Dwell beyond this truncates honestly: the
+# first observed gate run anchors the measure.
+_GATE_LOOKBACK = timedelta(days=7)
+
+# Three layers so no SELECT reads an alias it defines: the inner select groups gate runs per source
+# PR, the middle names the per-PR measure, the outer splits the current and previous windows on
+# merge time. ``r.run_started_at <= merged_at`` keeps post-merge bisection runs out of both the
+# first-gate anchor and the attempt count; a cancelled gate run counts as an attempt but not a
+# failure (an attempt evicted by a neighbor's failure is not this PR's failure).
+_MERGE_QUEUE_SELECT = """
+ SELECT
+ countIf(__CUR__) AS merged_cur,
+ countIf(__PREV__) AS merged_prev,
+ quantileIf(0.5)(gate_to_merge_seconds, __CUR__) AS median_cur,
+ quantileIf(0.5)(gate_to_merge_seconds, __PREV__) AS median_prev,
+ quantileIf(0.9)(gate_to_merge_seconds, __CUR__) AS p90_cur,
+ quantileIf(0.9)(gate_to_merge_seconds, __PREV__) AS p90_prev,
+ quantileIf(0.95)(gate_to_merge_seconds, __CUR__) AS p95_cur,
+ quantileIf(0.95)(gate_to_merge_seconds, __PREV__) AS p95_prev,
+ quantileIf(0.99)(gate_to_merge_seconds, __CUR__) AS p99_cur,
+ quantileIf(0.99)(gate_to_merge_seconds, __PREV__) AS p99_prev,
+ avgIf(attempts, __CUR__) AS avg_attempts_cur,
+ avgIf(attempts, __PREV__) AS avg_attempts_prev,
+ countIf(attempts > 1 AND __CUR__) / nullIf(countIf(__CUR__), 0) AS multi_attempt_share_cur,
+ countIf(attempts > 1 AND __PREV__) / nullIf(countIf(__PREV__), 0) AS multi_attempt_share_prev,
+ countIf(had_failed_gate AND __CUR__) / nullIf(countIf(__CUR__), 0) AS failed_gate_share_cur,
+ countIf(had_failed_gate AND __PREV__) / nullIf(countIf(__PREV__), 0) AS failed_gate_share_prev
+ FROM (
+ SELECT
+ pr_number,
+ merged_at,
+ dateDiff('second', first_gate_started_at, merged_at) AS gate_to_merge_seconds,
+ attempts,
+ had_failed_gate
+ FROM (
+ SELECT
+ r.pr_number AS pr_number,
+ any(pr.merged_at) AS merged_at,
+ min(r.run_started_at) AS first_gate_started_at,
+ count(DISTINCT __GATE_ATTEMPT__) AS attempts,
+ max(r.status = 'completed' AND r.conclusion IN ('failure', 'timed_out')) AS had_failed_gate
+ FROM __RUNS_SOURCE__ AS r
+ INNER JOIN __PR_SOURCE__ AS pr ON pr.number = r.pr_number
+ WHERE r.is_merge_queue
+ AND r.run_started_at >= {gate_from}
+ AND pr.merged_at IS NOT NULL
+ AND r.run_started_at <= pr.merged_at
+ AND pr.merged_at >= {prev_from} __DATE_TO_MERGED__
+ GROUP BY r.pr_number
+ )
+ )
+"""
+
+
+@dataclass(frozen=True, kw_only=True)
+class MergeQueueWindowStats:
+ """Landing stats over merged PRs with at least one corroborated gate run, for a window and its
+ previous twin. The percentiles measure first gate run start to merge, the observable anchor
+ for enqueue-to-merge; pending time before gate testing starts is not visible in this data."""
+
+ merged_pr_count: int
+ merged_pr_count_prev: int
+ median_first_gate_to_merge_seconds: float | None
+ median_first_gate_to_merge_seconds_prev: float | None
+ p90_first_gate_to_merge_seconds: float | None
+ p90_first_gate_to_merge_seconds_prev: float | None
+ p95_first_gate_to_merge_seconds: float | None
+ p95_first_gate_to_merge_seconds_prev: float | None
+ p99_first_gate_to_merge_seconds: float | None
+ p99_first_gate_to_merge_seconds_prev: float | None
+ avg_attempts_per_merge: float | None
+ avg_attempts_per_merge_prev: float | None
+ multi_attempt_merge_share: float | None
+ multi_attempt_merge_share_prev: float | None
+ failed_gate_merge_share: float | None
+ failed_gate_merge_share_prev: float | None
+
+
+_EMPTY_STATS = MergeQueueWindowStats(
+ merged_pr_count=0,
+ merged_pr_count_prev=0,
+ median_first_gate_to_merge_seconds=None,
+ median_first_gate_to_merge_seconds_prev=None,
+ p90_first_gate_to_merge_seconds=None,
+ p90_first_gate_to_merge_seconds_prev=None,
+ p95_first_gate_to_merge_seconds=None,
+ p95_first_gate_to_merge_seconds_prev=None,
+ p99_first_gate_to_merge_seconds=None,
+ p99_first_gate_to_merge_seconds_prev=None,
+ avg_attempts_per_merge=None,
+ avg_attempts_per_merge_prev=None,
+ multi_attempt_merge_share=None,
+ multi_attempt_merge_share_prev=None,
+ failed_gate_merge_share=None,
+ failed_gate_merge_share_prev=None,
+)
+
+
+def query_merge_queue_overview(
+ *,
+ curated: CuratedGitHubSource,
+ date_from: datetime,
+ date_to: datetime | None,
+ prev_from: datetime,
+) -> MergeQueueWindowStats:
+ """Merge-queue landing stats for [date_from, date_to] and [prev_from, date_from], one scan.
+
+ The population keys on ``merged_at`` like every merge median; gate runs are scanned from
+ ``prev_from - _GATE_LOOKBACK`` so a merge near the previous window's start keeps its early
+ attempts.
+ """
+ gate_from = prev_from - _GATE_LOOKBACK
+ windows = window_pair_predicates("merged_at", date_to=date_to)
+ placeholders: dict[str, ast.Expr] = {
+ "date_from": ast.Constant(value=date_from),
+ "prev_from": ast.Constant(value=prev_from),
+ "gate_from": ast.Constant(value=gate_from),
+ "run_started_floor": run_started_floor_constant(gate_from),
+ }
+ date_to_merged_clause = date_to_filter_clause(date_to, placeholders, column="pr.merged_at")
+ sql = (
+ _MERGE_QUEUE_SELECT.replace("__CUR__", windows.current)
+ .replace("__PREV__", windows.previous)
+ .replace("__RUNS_SOURCE__", curated.run_source(started_floor=True))
+ .replace("__PR_SOURCE__", curated.pr_source())
+ .replace("__GATE_ATTEMPT__", gate_attempt_expr("r.head_branch"))
+ .replace("__DATE_TO_MERGED__", date_to_merged_clause)
+ )
+ response = curated.run(sql, query_type="engineering_analytics.merge_queue_overview", placeholders=placeholders)
+ if not response.results:
+ return _EMPTY_STATS
+ (
+ merged_cur,
+ merged_prev,
+ median_cur,
+ median_prev,
+ p90_cur,
+ p90_prev,
+ p95_cur,
+ p95_prev,
+ p99_cur,
+ p99_prev,
+ avg_attempts_cur,
+ avg_attempts_prev,
+ multi_share_cur,
+ multi_share_prev,
+ failed_share_cur,
+ failed_share_prev,
+ ) = response.results[0]
+ return MergeQueueWindowStats(
+ merged_pr_count=int(merged_cur or 0),
+ merged_pr_count_prev=int(merged_prev or 0),
+ median_first_gate_to_merge_seconds=opt_float(median_cur),
+ median_first_gate_to_merge_seconds_prev=opt_float(median_prev),
+ p90_first_gate_to_merge_seconds=opt_float(p90_cur),
+ p90_first_gate_to_merge_seconds_prev=opt_float(p90_prev),
+ p95_first_gate_to_merge_seconds=opt_float(p95_cur),
+ p95_first_gate_to_merge_seconds_prev=opt_float(p95_prev),
+ p99_first_gate_to_merge_seconds=opt_float(p99_cur),
+ p99_first_gate_to_merge_seconds_prev=opt_float(p99_prev),
+ avg_attempts_per_merge=opt_float(avg_attempts_cur),
+ avg_attempts_per_merge_prev=opt_float(avg_attempts_prev),
+ multi_attempt_merge_share=opt_float(multi_share_cur),
+ multi_attempt_merge_share_prev=opt_float(multi_share_prev),
+ failed_gate_merge_share=opt_float(failed_share_cur),
+ failed_gate_merge_share_prev=opt_float(failed_share_prev),
+ )
diff --git a/products/engineering_analytics/backend/logic/queries/pr_cost.py b/products/engineering_analytics/backend/logic/queries/pr_cost.py
index 55c93aa0b611..cda53a331d2a 100644
--- a/products/engineering_analytics/backend/logic/queries/pr_cost.py
+++ b/products/engineering_analytics/backend/logic/queries/pr_cost.py
@@ -51,6 +51,7 @@ from products.engineering_analytics.backend.logic.queries._workflow_filters impo
date_to_filter_clause,
merge_queue_branch_predicate,
run_scope_filter_clause,
+ window_pair_predicates,
)
# The billable-tier predicate over the cost source's classified columns — defined once in logic.cost
@@ -380,22 +381,24 @@ def query_workflow_window_costs_with_prev(
"date_from": ast.Constant(value=date_from),
"prev_from": ast.Constant(value=prev_from),
}
- cur = "(c.run_started_at >= {date_from}" + (" AND c.run_started_at <= {date_to})" if date_to else ")")
- # Half-open: a run starting exactly at date_from is current, not both windows.
- prev = "(c.run_started_at >= {prev_from} AND c.run_started_at < {date_from})"
+ windows = window_pair_predicates("c.run_started_at", date_to=date_to)
date_to_clause = ""
if date_to is not None:
date_to_clause = "AND c.run_started_at <= {date_to}"
placeholders["date_to"] = ast.Constant(value=date_to)
+ # The prefix predicate deliberately counts all queue-shaped spend, including branch shapes
+ # logic/merge_queue.py cannot resolve to a PR (e.g. trunk-merge/gr-*). The per-PR landing stats
+ # in merge_queue_overview.py use the narrower corroborated population; the two answer different
+ # questions, so don't unify them casually.
queue = merge_queue_branch_predicate("c.head_branch")
queue_agg = (
- f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {cur}) AS queue_billable_seconds, "
- f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {prev}) AS queue_billable_seconds_prev"
+ f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {windows.current}) AS queue_billable_seconds, "
+ f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {windows.previous}) AS queue_billable_seconds_prev"
)
sql = (
_WINDOW_COST_WITH_PREV_SELECT.replace("__COST_SOURCE__", cost_source)
- .replace("__CUR_AGG__", _cost_aggregates(when=cur))
- .replace("__PREV_AGG__", _cost_aggregates(when=prev, suffix="_prev"))
+ .replace("__CUR_AGG__", _cost_aggregates(when=windows.current))
+ .replace("__PREV_AGG__", _cost_aggregates(when=windows.previous, suffix="_prev"))
.replace("__QUEUE_AGG__", queue_agg)
.replace("__DATE_TO__", date_to_clause)
)
diff --git a/products/engineering_analytics/backend/logic/queries/repo_overview.py b/products/engineering_analytics/backend/logic/queries/repo_overview.py
index fe7ec125850e..778a4e2a498c 100644
--- a/products/engineering_analytics/backend/logic/queries/repo_overview.py
+++ b/products/engineering_analytics/backend/logic/queries/repo_overview.py
@@ -34,12 +34,19 @@ from products.engineering_analytics.backend.logic.queries._buckets import (
window_buckets,
)
from products.engineering_analytics.backend.logic.queries._curated import CuratedGitHubSource, opt_float
-from products.engineering_analytics.backend.logic.queries._workflow_filters import run_started_floor_constant
+from products.engineering_analytics.backend.logic.queries._workflow_filters import (
+ run_started_floor_constant,
+ window_pair_predicates,
+)
+from products.engineering_analytics.backend.logic.queries.merge_queue_overview import query_merge_queue_overview
from products.engineering_analytics.backend.logic.queries.pr_cost import (
query_cost_per_merge_series,
query_workflow_window_costs_with_prev,
)
-from products.engineering_analytics.backend.logic.queries.workflow_health import query_time_to_green_series
+from products.engineering_analytics.backend.logic.queries.workflow_health import (
+ query_time_to_green_series,
+ query_time_to_green_window,
+)
_RUNS_SELECT = """
SELECT
@@ -327,8 +334,7 @@ def query_repo_overview(
end = date_to or datetime.now(tz=date_from.tzinfo)
prev_from = date_from - (end - date_from)
date_to_clause = "AND run_started_at <= {date_to}" if date_to is not None else ""
- cur = "(run_started_at >= {date_from}" + (" AND run_started_at <= {date_to})" if date_to is not None else ")")
- prev = "(run_started_at >= {prev_from} AND run_started_at < {date_from})"
+ run_windows = window_pair_predicates("run_started_at", date_to=date_to)
placeholders: dict[str, ast.Expr] = {
"date_from": ast.Constant(value=date_from),
@@ -341,8 +347,8 @@ def query_repo_overview(
placeholders["date_to"] = ast.Constant(value=date_to)
runs_sql = (
- _RUNS_SELECT.replace("__CUR__", cur)
- .replace("__PREV__", prev)
+ _RUNS_SELECT.replace("__CUR__", run_windows.current)
+ .replace("__PREV__", run_windows.previous)
.replace("__RUNS_SOURCE__", curated.run_source(started_floor=True))
.replace("__DATE_TO__", date_to_clause)
)
@@ -353,15 +359,14 @@ def query_repo_overview(
run_count, run_count_prev, success_rate, success_rate_prev, reruns, reruns_prev, master_runs, main_runs = row
default_branch = "main" if (main_runs or 0) > (master_runs or 0) else "master"
- pr_cur = "(merged_at >= {date_from}" + (" AND merged_at <= {date_to})" if date_to is not None else ")")
- pr_prev = "(merged_at >= {prev_from} AND merged_at < {date_from})"
+ merge_windows = window_pair_predicates("merged_at", date_to=date_to)
ready = curated.ready_to_merge_sql()
pr_sql = ready.with_clause + (
- _PR_SELECT.replace("__READY_MEDIAN_CUR__", ready.median(scope=f"{pr_cur} AND {_HUMAN_MERGES}"))
- .replace("__READY_MEDIAN_PREV__", ready.median(scope=f"{pr_prev} AND {_HUMAN_MERGES}"))
+ _PR_SELECT.replace("__READY_MEDIAN_CUR__", ready.median(scope=f"{merge_windows.current} AND {_HUMAN_MERGES}"))
+ .replace("__READY_MEDIAN_PREV__", ready.median(scope=f"{merge_windows.previous} AND {_HUMAN_MERGES}"))
.replace("__READY_JOIN__", ready.join)
- .replace("__CUR_MERGED__", pr_cur)
- .replace("__PREV_MERGED__", pr_prev)
+ .replace("__CUR_MERGED__", merge_windows.current)
+ .replace("__PREV_MERGED__", merge_windows.previous)
.replace("__PR_SOURCE__", curated.pr_source())
)
pr_response = curated.run(pr_sql, query_type="engineering_analytics.repo_overview_prs", placeholders=placeholders)
@@ -370,6 +375,10 @@ def query_repo_overview(
)
jobs_available = curated.jobs_source() is not None
+ queue = query_merge_queue_overview(curated=curated, date_from=date_from, date_to=date_to, prev_from=prev_from)
+ time_to_green = query_time_to_green_window(
+ curated=curated, date_from=date_from, date_to=date_to, prev_from=prev_from
+ )
costs = query_workflow_window_costs_with_prev(
curated=curated, date_from=date_from, date_to=date_to, prev_from=prev_from
)
@@ -382,6 +391,8 @@ def query_repo_overview(
# The queue slice mirrors billable_minutes' null gating so both go null together.
queue_minutes = costs.merge_queue_billable_seconds / 60 if cost_cur else None
queue_minutes_prev = costs.merge_queue_billable_seconds_prev / 60 if cost_prev else None
+ cost_per_merge = cost_usd / int(merged_cur) if cost_usd is not None and merged_cur else None
+ cost_per_merge_prev = cost_usd_prev / int(merged_prev) if cost_usd_prev is not None and merged_prev else None
return RepoOverview(
run_count=run_count,
@@ -400,8 +411,28 @@ def query_repo_overview(
billable_minutes_prev=billable_seconds_prev / 60 if billable_seconds_prev is not None else None,
estimated_cost_usd=opt_float(cost_usd),
estimated_cost_usd_prev=opt_float(cost_usd_prev),
+ cost_per_merge_usd=opt_float(cost_per_merge),
+ cost_per_merge_usd_prev=opt_float(cost_per_merge_prev),
merge_queue_billable_minutes=queue_minutes,
merge_queue_billable_minutes_prev=queue_minutes_prev,
+ merge_queue_merged_pr_count=queue.merged_pr_count,
+ merge_queue_merged_pr_count_prev=queue.merged_pr_count_prev,
+ merge_queue_median_first_gate_to_merge_seconds=queue.median_first_gate_to_merge_seconds,
+ merge_queue_median_first_gate_to_merge_seconds_prev=queue.median_first_gate_to_merge_seconds_prev,
+ merge_queue_p90_first_gate_to_merge_seconds=queue.p90_first_gate_to_merge_seconds,
+ merge_queue_p90_first_gate_to_merge_seconds_prev=queue.p90_first_gate_to_merge_seconds_prev,
+ merge_queue_p95_first_gate_to_merge_seconds=queue.p95_first_gate_to_merge_seconds,
+ merge_queue_p95_first_gate_to_merge_seconds_prev=queue.p95_first_gate_to_merge_seconds_prev,
+ merge_queue_p99_first_gate_to_merge_seconds=queue.p99_first_gate_to_merge_seconds,
+ merge_queue_p99_first_gate_to_merge_seconds_prev=queue.p99_first_gate_to_merge_seconds_prev,
+ merge_queue_avg_attempts_per_merge=queue.avg_attempts_per_merge,
+ merge_queue_avg_attempts_per_merge_prev=queue.avg_attempts_per_merge_prev,
+ merge_queue_multi_attempt_merge_share=queue.multi_attempt_merge_share,
+ merge_queue_multi_attempt_merge_share_prev=queue.multi_attempt_merge_share_prev,
+ merge_queue_failed_gate_merge_share=queue.failed_gate_merge_share,
+ merge_queue_failed_gate_merge_share_prev=queue.failed_gate_merge_share_prev,
+ median_time_to_green_seconds=time_to_green.median_seconds,
+ median_time_to_green_seconds_prev=time_to_green.median_seconds_prev,
jobs_available=jobs_available,
default_branch=default_branch,
cost_series=series.cost,
diff --git a/products/engineering_analytics/backend/logic/queries/workflow_health.py b/products/engineering_analytics/backend/logic/queries/workflow_health.py
index 6f857f6809b3..152e7573b6c0 100644
--- a/products/engineering_analytics/backend/logic/queries/workflow_health.py
+++ b/products/engineering_analytics/backend/logic/queries/workflow_health.py
@@ -16,6 +16,7 @@ so the trend sparkline keeps a readable number of points — per-day buckets are
for a 24h window and far too many for a year.
"""
+from dataclasses import dataclass
from datetime import datetime
from posthog.hogql import ast
@@ -46,6 +47,7 @@ from products.engineering_analytics.backend.logic.queries._workflow_filters impo
run_duration_percentile_expr,
run_scope_filter_clause,
run_started_floor_constant,
+ window_pair_predicates,
)
from products.engineering_analytics.backend.logic.queries.pr_cost import query_workflow_window_costs
@@ -129,7 +131,7 @@ _BUCKET_SELECT = f"""
# workflows a draft never ran) stretches the wall, because the round really wasn't green until it
# passed, so the wall then also covers the hours the PR sat in draft. Distinguishing that from a
# slow queue would need a re-fire gap threshold, which is a number nobody can defend.
-_TIME_TO_GREEN_SELECT = f"""
+_TIME_TO_GREEN_CTES = f"""
WITH workflows_on_push AS (
SELECT
repo_owner,
@@ -144,7 +146,7 @@ _TIME_TO_GREEN_SELECT = f"""
)) AS first_green_end,
countIf(status = 'completed' AND conclusion = 'success') > 0 AS has_success
FROM __RUNS_SOURCE__ AS r
- WHERE run_started_at >= {{date_from}} __DATE_TO__
+ WHERE run_started_at >= {{scan_from}} __DATE_TO__
AND NOT r.is_merge_queue
AND {non_default_branch_predicate()}
GROUP BY repo_owner, repo_name, head_sha, workflow_name
@@ -159,6 +161,11 @@ _TIME_TO_GREEN_SELECT = f"""
AND countIf(first_green_end IS NULL) = 0
AND countIf(has_success) > 0
)
+"""
+
+_TIME_TO_GREEN_SELECT = (
+ _TIME_TO_GREEN_CTES
+ + f"""
SELECT
__BUCKET_FN__ AS bucket_start,
quantile(0.5)(wall_seconds) AS p50_seconds
@@ -166,6 +173,17 @@ _TIME_TO_GREEN_SELECT = f"""
GROUP BY bucket_start
LIMIT {_BUCKET_LIMIT}
"""
+)
+
+_TIME_TO_GREEN_WINDOW_SELECT = (
+ _TIME_TO_GREEN_CTES
+ + """
+ SELECT
+ quantileIf(0.5)(wall_seconds, __CUR__) AS p50_cur,
+ quantileIf(0.5)(wall_seconds, __PREV__) AS p50_prev
+ FROM green_rounds
+"""
+)
def query_time_to_green_series(
@@ -180,7 +198,7 @@ def query_time_to_green_series(
rounds are samples (``_TIME_TO_GREEN_SELECT`` has the exclusions and the one known overstatement);
an empty bucket carries ``p50_seconds`` None (a gap, not instant CI)."""
placeholders: dict[str, ast.Expr] = {
- "date_from": ast.Constant(value=date_from),
+ "scan_from": ast.Constant(value=date_from),
"run_started_floor": run_started_floor_constant(date_from),
}
date_to_clause = date_to_filter_clause(date_to, placeholders)
@@ -200,6 +218,43 @@ def query_time_to_green_series(
]
+@dataclass(frozen=True, kw_only=True)
+class TimeToGreenWindow:
+ """Median wall clock for a fully green push round over a window and its previous twin — the
+ same population and exclusions as the time-to-green series."""
+
+ median_seconds: float | None
+ median_seconds_prev: float | None
+
+
+def query_time_to_green_window(
+ *,
+ curated: CuratedGitHubSource,
+ date_from: datetime,
+ date_to: datetime | None,
+ prev_from: datetime,
+) -> TimeToGreenWindow:
+ """Window-level time-to-green medians for [date_from, date_to] and [prev_from, date_from], one
+ scan, keyed on the bucketless equivalent of the series' round_start."""
+ windows = window_pair_predicates("round_start", date_to=date_to)
+ placeholders: dict[str, ast.Expr] = {
+ "scan_from": ast.Constant(value=prev_from),
+ "date_from": ast.Constant(value=date_from),
+ "prev_from": ast.Constant(value=prev_from),
+ "run_started_floor": run_started_floor_constant(prev_from),
+ }
+ date_to_clause = date_to_filter_clause(date_to, placeholders)
+ sql = (
+ _TIME_TO_GREEN_WINDOW_SELECT.replace("__RUNS_SOURCE__", curated.run_source(started_floor=True))
+ .replace("__DATE_TO__", date_to_clause)
+ .replace("__CUR__", windows.current)
+ .replace("__PREV__", windows.previous)
+ )
+ response = curated.run(sql, query_type="engineering_analytics.time_to_green_window", placeholders=placeholders)
+ p50_cur, p50_prev = response.results[0] if response.results else (None, None)
+ return TimeToGreenWindow(median_seconds=opt_float(p50_cur), median_seconds_prev=opt_float(p50_prev))
+
+
def query_workflow_health(
*,
curated: CuratedGitHubSource,
diff --git a/products/engineering_analytics/backend/presentation/serializers/workflows.py b/products/engineering_analytics/backend/presentation/serializers/workflows.py
index 266dd8924da9..9792850e0d61 100644
--- a/products/engineering_analytics/backend/presentation/serializers/workflows.py
+++ b/products/engineering_analytics/backend/presentation/serializers/workflows.py
@@ -416,6 +416,16 @@ class RepoOverviewSerializer(DataclassSerializer):
"help_text": "Estimated cost over the previous window; null when the job-level source isn't synced.",
"allow_null": True,
},
+ "cost_per_merge_usd": {
+ "help_text": "estimated_cost_usd divided by merged_pr_count — the window's CI cost per merged "
+ "PR. Null when the job-level source isn't synced or nothing merged.",
+ "allow_null": True,
+ },
+ "cost_per_merge_usd_prev": {
+ "help_text": "The same ratio over the previous window. Null when the job-level source isn't "
+ "synced or nothing merged.",
+ "allow_null": True,
+ },
"merge_queue_billable_minutes": {
"help_text": "Slice of billable_minutes spent on merge-queue batch branches (trunk-merge/**); "
"null when the job-level source isn't synced.",
@@ -426,6 +436,84 @@ class RepoOverviewSerializer(DataclassSerializer):
"source isn't synced.",
"allow_null": True,
},
+ "merge_queue_merged_pr_count": {
+ "help_text": "PRs merged in the window with at least one corroborated merge-queue gate run — "
+ "the population behind every merge_queue_* landing stat. All authors, bots included."
+ },
+ "merge_queue_merged_pr_count_prev": {"help_text": "Queue-landed merges over the previous window."},
+ "merge_queue_median_first_gate_to_merge_seconds": {
+ "help_text": "Median seconds from a PR's first observed merge-queue gate run starting to the PR "
+ "merging. Pending time before gate testing starts is not included. Null when no queue-landed "
+ "merges.",
+ "allow_null": True,
+ },
+ "merge_queue_median_first_gate_to_merge_seconds_prev": {
+ "help_text": "The same median over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p90_first_gate_to_merge_seconds": {
+ "help_text": "p90 of the same first-gate-run-to-merge measure — the tail, where queue pain "
+ "concentrates. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p90_first_gate_to_merge_seconds_prev": {
+ "help_text": "The same p90 over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p95_first_gate_to_merge_seconds": {
+ "help_text": "p95 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p95_first_gate_to_merge_seconds_prev": {
+ "help_text": "The same p95 over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p99_first_gate_to_merge_seconds": {
+ "help_text": "p99 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_p99_first_gate_to_merge_seconds_prev": {
+ "help_text": "The same p99 over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_avg_attempts_per_merge": {
+ "help_text": "Mean distinct gate attempts (distinct gate branches, flake-bisection branches "
+ "collapsed) per queue-landed merge. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_avg_attempts_per_merge_prev": {
+ "help_text": "The same mean over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_multi_attempt_merge_share": {
+ "help_text": "Fraction (0-1) of queue-landed merges that needed more than one gate attempt. "
+ "Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_multi_attempt_merge_share_prev": {
+ "help_text": "The same fraction over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_failed_gate_merge_share": {
+ "help_text": "Fraction (0-1) of queue-landed merges with at least one failed gate run before "
+ "merging. Derived from CI run conclusions, not the queue's own eviction records. Null when no "
+ "queue-landed merges.",
+ "allow_null": True,
+ },
+ "merge_queue_failed_gate_merge_share_prev": {
+ "help_text": "The same fraction over the previous window. Null when no queue-landed merges.",
+ "allow_null": True,
+ },
+ "median_time_to_green_seconds": {
+ "help_text": "Median wall clock for a PR push round to settle fully green over the window — the "
+ "window-level twin of time_to_green_series, same population and exclusions. Null when no fully "
+ "green rounds.",
+ "allow_null": True,
+ },
+ "median_time_to_green_seconds_prev": {
+ "help_text": "The same median over the previous window. Null when no fully green rounds.",
+ "allow_null": True,
+ },
"jobs_available": {"help_text": "Whether the job-level source is synced (cost and queue figures exist)."},
"default_branch": {"help_text": "'master' or 'main', picked by observed run volume in the window."},
"cost_series_granularity": {
diff --git a/products/engineering_analytics/backend/presentation/views/workflows.py b/products/engineering_analytics/backend/presentation/views/workflows.py
index 064c5a25d98b..be1ec4770e5b 100644
--- a/products/engineering_analytics/backend/presentation/views/workflows.py
+++ b/products/engineering_analytics/backend/presentation/views/workflows.py
@@ -359,8 +359,10 @@ class WorkflowActionsMixin(EngineeringAnalyticsViewSetBase):
description=(
"Repo-level headline aggregates over a window (default -30d): run count, success rate, re-run "
"cycles, merged-PR count (bots included), median PR open-to-merge (bots and drafts excluded; "
- "coarse — draft and ready time fused), and billable minutes + estimated cost (with the merge-queue "
- "slice of billable minutes broken out) — each with its equal-length previous-window twin so a "
+ "coarse — draft and ready time fused), median time-to-green, billable minutes + estimated cost "
+ "(with the merge-queue slice of billable minutes broken out), and merge-queue landing stats "
+ "(queue-landed merges, first-gate-to-merge median and p90, gate attempts, failed-gate share) — "
+ "each with its equal-length previous-window twin so a "
"caller can render honest deltas. Also carries the "
"detected default branch and its completed-run history series (skippable via include_series=false). "
"Cost figures are null until the job-level source is synced."
diff --git a/products/engineering_analytics/backend/tests/test_logic_workflows.py b/products/engineering_analytics/backend/tests/test_logic_workflows.py
index e6c37cae9222..3c2bbb43087e 100644
--- a/products/engineering_analytics/backend/tests/test_logic_workflows.py
+++ b/products/engineering_analytics/backend/tests/test_logic_workflows.py
@@ -265,6 +265,7 @@ class TestWorkflowEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):
assert overview.rerun_cycles == 1
assert overview.billable_minutes == pytest.approx(4.0) # two 120s jobs on a billable tier
assert overview.estimated_cost_usd == pytest.approx(0.032) # 4 min x $0.004 x 2 (4-core)
+ assert overview.cost_per_merge_usd == pytest.approx(0.016) # the window's cost over its 2 merges
assert overview.merge_queue_billable_minutes == pytest.approx(2.0) # only the trunk-merge/** job
assert overview.merge_queue_billable_minutes_prev is None # no prev-window jobs, like billable_minutes_prev
assert overview.median_ready_to_merge_seconds is None # issue events unsynced: not observed, never zero
@@ -358,6 +359,101 @@ class TestWorkflowEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):
observed = [b.p50_seconds for b in overview.time_to_green_series if b.p50_seconds is not None]
# Oldest first: late1's own wall, then the median of the round walls {2400, 300, 900}.
assert observed == [pytest.approx(7500.0), pytest.approx(900.0)]
+ # The window aggregate pools every round the series shows: median over {300, 900, 2400, 7500}.
+ assert overview.median_time_to_green_seconds == pytest.approx(1650.0)
+ assert overview.median_time_to_green_seconds_prev is None # no rounds in the previous window
+
+ def test_repo_overview_merge_queue_landing_stats(self) -> None:
+ # Guards the queue landing stats end to end: gate runs resolve their PR through the branch
+ # name only when the actor corroborates (a contributor-named trunk-merge/** branch must not
+ # enter the population), bisection branches collapse into their attempt, and the medians key
+ # on first gate start to merge.
+ self._create_table(
+ "github_pull_requests",
+ PULL_REQUESTS_COLUMNS,
+ [
+ _pr_row(80, "alice", "closed", 0, _ago(10), merged_at=_ago(2), head_sha="sha80"),
+ _pr_row(81, "bob", "closed", 0, _ago(9), merged_at=_ago(3), head_sha="sha81"),
+ _pr_row(82, "carol", "closed", 0, _ago(8), merged_at=_ago(4), head_sha="sha82"),
+ ],
+ )
+ self._create_table(
+ "github_workflow_runs",
+ WORKFLOW_RUNS_COLUMNS,
+ [
+ # PR 80: failed attempt, its bisection probe (same attempt), then a green attempt.
+ _run_row(
+ 9700,
+ "CI",
+ "g80a",
+ "completed",
+ "failure",
+ _ago(4),
+ _ago(4),
+ head_branch="trunk-merge/pr-80/aaaa",
+ actor="trunk-io[bot]",
+ ),
+ _run_row(
+ 9701,
+ "CI",
+ "g80ab",
+ "completed",
+ "failure",
+ _ago(4),
+ _ago(4),
+ head_branch="trunk-merge/pr-80/aaaa-bisection",
+ actor="trunk-io[bot]",
+ ),
+ _run_row(
+ 9702,
+ "CI",
+ "g80b",
+ "completed",
+ "success",
+ _ago(3),
+ _ago(3),
+ head_branch="trunk-merge/pr-80/bbbb",
+ actor="trunk-io[bot]",
+ ),
+ # PR 81: one clean attempt.
+ _run_row(
+ 9703,
+ "CI",
+ "g81",
+ "completed",
+ "success",
+ _ago(4),
+ _ago(4),
+ head_branch="trunk-merge/pr-81/cccc",
+ actor="trunk-io[bot]",
+ ),
+ # Gate-shaped branch pushed by a contributor: fails corroboration, PR 82 stays out.
+ _run_row(
+ 9704,
+ "CI",
+ "g82",
+ "completed",
+ "success",
+ _ago(5),
+ _ago(5),
+ head_branch="trunk-merge/pr-82/dddd",
+ actor="mallory",
+ ),
+ ],
+ )
+
+ overview = api.get_repo_overview(team=self.team, include_series=False)
+ assert overview.merge_queue_merged_pr_count == 2 # 80 and 81; 82's gate run is uncorroborated
+ assert overview.merge_queue_merged_pr_count_prev == 0
+ assert overview.merge_queue_avg_attempts_per_merge == pytest.approx(1.5) # 80: two, 81: one
+ assert overview.merge_queue_multi_attempt_merge_share == pytest.approx(0.5)
+ assert overview.merge_queue_failed_gate_merge_share == pytest.approx(0.5)
+ # PR 80: first gate at -4d, merged -2d (2 days); PR 81: -4d to -3d (1 day).
+ assert overview.merge_queue_median_first_gate_to_merge_seconds == pytest.approx(1.5 * 86400)
+ assert overview.merge_queue_p90_first_gate_to_merge_seconds == pytest.approx(1.9 * 86400)
+ assert overview.merge_queue_p95_first_gate_to_merge_seconds == pytest.approx(1.95 * 86400)
+ assert overview.merge_queue_p99_first_gate_to_merge_seconds == pytest.approx(1.99 * 86400)
+ assert overview.merge_queue_median_first_gate_to_merge_seconds_prev is None
def test_repo_overview_ready_to_merge_median_and_series(self) -> None:
# Guards the overview's ready_by_pr join: the headline must anchor on the last ready
diff --git a/products/engineering_analytics/backend/tests/test_presentation.py b/products/engineering_analytics/backend/tests/test_presentation.py
index 3c7c1307bf11..ed7fdb1b2d6c 100644
--- a/products/engineering_analytics/backend/tests/test_presentation.py
+++ b/products/engineering_analytics/backend/tests/test_presentation.py
@@ -139,8 +139,28 @@ def _repo_overview() -> contracts.RepoOverview:
billable_minutes_prev=90.0,
estimated_cost_usd=12.5,
estimated_cost_usd_prev=11.0,
+ cost_per_merge_usd=0.3,
+ cost_per_merge_usd_prev=0.275,
merge_queue_billable_minutes=30.0,
merge_queue_billable_minutes_prev=0.0,
+ merge_queue_merged_pr_count=38,
+ merge_queue_merged_pr_count_prev=35,
+ merge_queue_median_first_gate_to_merge_seconds=1920.0,
+ merge_queue_median_first_gate_to_merge_seconds_prev=2460.0,
+ merge_queue_p90_first_gate_to_merge_seconds=11280.0,
+ merge_queue_p90_first_gate_to_merge_seconds_prev=13500.0,
+ merge_queue_p95_first_gate_to_merge_seconds=15600.0,
+ merge_queue_p95_first_gate_to_merge_seconds_prev=17700.0,
+ merge_queue_p99_first_gate_to_merge_seconds=22200.0,
+ merge_queue_p99_first_gate_to_merge_seconds_prev=25200.0,
+ merge_queue_avg_attempts_per_merge=2.0,
+ merge_queue_avg_attempts_per_merge_prev=1.8,
+ merge_queue_multi_attempt_merge_share=0.42,
+ merge_queue_multi_attempt_merge_share_prev=0.38,
+ merge_queue_failed_gate_merge_share=0.34,
+ merge_queue_failed_gate_merge_share_prev=0.28,
+ median_time_to_green_seconds=780.0,
+ median_time_to_green_seconds_prev=540.0,
jobs_available=True,
default_branch="master",
cost_series=[],
@@ -332,6 +352,9 @@ class TestEngineeringAnalyticsAPI(APIBaseTest):
assert data["merged_pr_count"] == 42
assert data["merged_pr_count_prev"] == 40
assert data["merge_queue_billable_minutes"] == 30.0 # the digest's queue row reads this key
+ assert data["merge_queue_merged_pr_count"] == 38
+ assert data["merge_queue_median_first_gate_to_merge_seconds"] == 1920.0
+ assert data["median_time_to_green_seconds"] == 780.0
assert data["cost_series"] == []
def test_repo_overview_400_on_bad_include_series(self) -> None:
diff --git a/products/engineering_analytics/frontend/generated/api.schemas.ts b/products/engineering_analytics/frontend/generated/api.schemas.ts
index 3eb6099a54cd..e3f91dae536d 100644
--- a/products/engineering_analytics/frontend/generated/api.schemas.ts
+++ b/products/engineering_analytics/frontend/generated/api.schemas.ts
@@ -947,6 +947,16 @@ export interface RepoOverviewApi {
* @nullable
*/
estimated_cost_usd_prev: number | null
+ /**
+ * estimated_cost_usd divided by merged_pr_count — the window's CI cost per merged PR. Null when the job-level source isn't synced or nothing merged.
+ * @nullable
+ */
+ cost_per_merge_usd: number | null
+ /**
+ * The same ratio over the previous window. Null when the job-level source isn't synced or nothing merged.
+ * @nullable
+ */
+ cost_per_merge_usd_prev: number | null
/**
* Slice of billable_minutes spent on merge-queue batch branches (trunk-merge/**); null when the job-level source isn't synced.
* @nullable
@@ -957,6 +967,90 @@ export interface RepoOverviewApi {
* @nullable
*/
merge_queue_billable_minutes_prev: number | null
+ /** PRs merged in the window with at least one corroborated merge-queue gate run — the population behind every merge_queue_* landing stat. All authors, bots included. */
+ merge_queue_merged_pr_count: number
+ /** Queue-landed merges over the previous window. */
+ merge_queue_merged_pr_count_prev: number
+ /**
+ * Median seconds from a PR's first observed merge-queue gate run starting to the PR merging. Pending time before gate testing starts is not included. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_median_first_gate_to_merge_seconds: number | null
+ /**
+ * The same median over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_median_first_gate_to_merge_seconds_prev: number | null
+ /**
+ * p90 of the same first-gate-run-to-merge measure — the tail, where queue pain concentrates. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p90_first_gate_to_merge_seconds: number | null
+ /**
+ * The same p90 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p90_first_gate_to_merge_seconds_prev: number | null
+ /**
+ * p95 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p95_first_gate_to_merge_seconds: number | null
+ /**
+ * The same p95 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p95_first_gate_to_merge_seconds_prev: number | null
+ /**
+ * p99 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p99_first_gate_to_merge_seconds: number | null
+ /**
+ * The same p99 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p99_first_gate_to_merge_seconds_prev: number | null
+ /**
+ * Mean distinct gate attempts (distinct gate branches, flake-bisection branches collapsed) per queue-landed merge. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_avg_attempts_per_merge: number | null
+ /**
+ * The same mean over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_avg_attempts_per_merge_prev: number | null
+ /**
+ * Fraction (0-1) of queue-landed merges that needed more than one gate attempt. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_multi_attempt_merge_share: number | null
+ /**
+ * The same fraction over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_multi_attempt_merge_share_prev: number | null
+ /**
+ * Fraction (0-1) of queue-landed merges with at least one failed gate run before merging. Derived from CI run conclusions, not the queue's own eviction records. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_failed_gate_merge_share: number | null
+ /**
+ * The same fraction over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_failed_gate_merge_share_prev: number | null
+ /**
+ * Median wall clock for a PR push round to settle fully green over the window — the window-level twin of time_to_green_series, same population and exclusions. Null when no fully green rounds.
+ * @nullable
+ */
+ median_time_to_green_seconds: number | null
+ /**
+ * The same median over the previous window. Null when no fully green rounds.
+ * @nullable
+ */
+ median_time_to_green_seconds_prev: number | null
/** Whether the job-level source is synced (cost and queue figures exist). */
jobs_available: boolean
/** 'master' or 'main', picked by observed run volume in the window. */
diff --git a/products/engineering_analytics/frontend/generated/api.ts b/products/engineering_analytics/frontend/generated/api.ts
index 8c8da30388ac..a10c9a24cb35 100644
--- a/products/engineering_analytics/frontend/generated/api.ts
+++ b/products/engineering_analytics/frontend/generated/api.ts
@@ -564,7 +564,7 @@ export const getEngineeringAnalyticsRepoOverviewUrl = (
}
/**
- * Repo-level headline aggregates over a window (default -30d): run count, success rate, re-run cycles, merged-PR count (bots included), median PR open-to-merge (bots and drafts excluded; coarse — draft and ready time fused), and billable minutes + estimated cost (with the merge-queue slice of billable minutes broken out) — each with its equal-length previous-window twin so a caller can render honest deltas. Also carries the detected default branch and its completed-run history series (skippable via include_series=false). Cost figures are null until the job-level source is synced.
+ * Repo-level headline aggregates over a window (default -30d): run count, success rate, re-run cycles, merged-PR count (bots included), median PR open-to-merge (bots and drafts excluded; coarse — draft and ready time fused), median time-to-green, billable minutes + estimated cost (with the merge-queue slice of billable minutes broken out), and merge-queue landing stats (queue-landed merges, first-gate-to-merge median and p90, gate attempts, failed-gate share) — each with its equal-length previous-window twin so a caller can render honest deltas. Also carries the detected default branch and its completed-run history series (skippable via include_series=false). Cost figures are null until the job-level source is synced.
*/
export const engineeringAnalyticsRepoOverview = async (
projectId: string,
diff --git a/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx b/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx
index 67a7352df304..f4681eea014b 100644
--- a/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx
+++ b/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx
@@ -36,9 +36,29 @@ const OVERVIEW: RepoOverviewApi = {
billable_minutes_prev: 4890,
estimated_cost_usd: 412.5,
estimated_cost_usd_prev: 361.0,
+ cost_per_merge_usd: 7.37,
+ cost_per_merge_usd_prev: 7.37,
// A slice of billable_minutes above, not an addition to it.
merge_queue_billable_minutes: 1180,
merge_queue_billable_minutes_prev: 940,
+ merge_queue_merged_pr_count: 48,
+ merge_queue_merged_pr_count_prev: 41,
+ merge_queue_median_first_gate_to_merge_seconds: 32 * 60,
+ merge_queue_median_first_gate_to_merge_seconds_prev: 41 * 60,
+ merge_queue_p90_first_gate_to_merge_seconds: 3 * 3600 + 8 * 60,
+ merge_queue_p90_first_gate_to_merge_seconds_prev: 3 * 3600 + 45 * 60,
+ merge_queue_p95_first_gate_to_merge_seconds: 4 * 3600 + 20 * 60,
+ merge_queue_p95_first_gate_to_merge_seconds_prev: 4 * 3600 + 55 * 60,
+ merge_queue_p99_first_gate_to_merge_seconds: 6 * 3600 + 10 * 60,
+ merge_queue_p99_first_gate_to_merge_seconds_prev: 7 * 3600,
+ merge_queue_avg_attempts_per_merge: 2.0,
+ merge_queue_avg_attempts_per_merge_prev: 1.8,
+ merge_queue_multi_attempt_merge_share: 0.417,
+ merge_queue_multi_attempt_merge_share_prev: 0.38,
+ merge_queue_failed_gate_merge_share: 0.337,
+ merge_queue_failed_gate_merge_share_prev: 0.28,
+ median_time_to_green_seconds: 13 * 60,
+ median_time_to_green_seconds_prev: 9 * 60,
jobs_available: true,
default_branch: 'master',
cost_series_granularity: 'day',
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index d8a98567d3e3..7879637ba3e2 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -71479,6 +71479,16 @@ export namespace Schemas {
* @nullable
*/
estimated_cost_usd_prev: number | null;
+ /**
+ * estimated_cost_usd divided by merged_pr_count — the window's CI cost per merged PR. Null when the job-level source isn't synced or nothing merged.
+ * @nullable
+ */
+ cost_per_merge_usd: number | null;
+ /**
+ * The same ratio over the previous window. Null when the job-level source isn't synced or nothing merged.
+ * @nullable
+ */
+ cost_per_merge_usd_prev: number | null;
/**
* Slice of billable_minutes spent on merge-queue batch branches (trunk-merge/**); null when the job-level source isn't synced.
* @nullable
@@ -71489,6 +71499,90 @@ export namespace Schemas {
* @nullable
*/
merge_queue_billable_minutes_prev: number | null;
+ /** PRs merged in the window with at least one corroborated merge-queue gate run — the population behind every merge_queue_* landing stat. All authors, bots included. */
+ merge_queue_merged_pr_count: number;
+ /** Queue-landed merges over the previous window. */
+ merge_queue_merged_pr_count_prev: number;
+ /**
+ * Median seconds from a PR's first observed merge-queue gate run starting to the PR merging. Pending time before gate testing starts is not included. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_median_first_gate_to_merge_seconds: number | null;
+ /**
+ * The same median over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_median_first_gate_to_merge_seconds_prev: number | null;
+ /**
+ * p90 of the same first-gate-run-to-merge measure — the tail, where queue pain concentrates. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p90_first_gate_to_merge_seconds: number | null;
+ /**
+ * The same p90 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p90_first_gate_to_merge_seconds_prev: number | null;
+ /**
+ * p95 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p95_first_gate_to_merge_seconds: number | null;
+ /**
+ * The same p95 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p95_first_gate_to_merge_seconds_prev: number | null;
+ /**
+ * p99 of the same first-gate-run-to-merge measure. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p99_first_gate_to_merge_seconds: number | null;
+ /**
+ * The same p99 over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_p99_first_gate_to_merge_seconds_prev: number | null;
+ /**
+ * Mean distinct gate attempts (distinct gate branches, flake-bisection branches collapsed) per queue-landed merge. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_avg_attempts_per_merge: number | null;
+ /**
+ * The same mean over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_avg_attempts_per_merge_prev: number | null;
+ /**
+ * Fraction (0-1) of queue-landed merges that needed more than one gate attempt. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_multi_attempt_merge_share: number | null;
+ /**
+ * The same fraction over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_multi_attempt_merge_share_prev: number | null;
+ /**
+ * Fraction (0-1) of queue-landed merges with at least one failed gate run before merging. Derived from CI run conclusions, not the queue's own eviction records. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_failed_gate_merge_share: number | null;
+ /**
+ * The same fraction over the previous window. Null when no queue-landed merges.
+ * @nullable
+ */
+ merge_queue_failed_gate_merge_share_prev: number | null;
+ /**
+ * Median wall clock for a PR push round to settle fully green over the window — the window-level twin of time_to_green_series, same population and exclusions. Null when no fully green rounds.
+ * @nullable
+ */
+ median_time_to_green_seconds: number | null;
+ /**
+ * The same median over the previous window. Null when no fully green rounds.
+ * @nullable
+ */
+ median_time_to_green_seconds_prev: number | null;
/** Whether the job-level source is synced (cost and queue figures exist). */
jobs_available: boolean;
/** 'master' or 'main', picked by observed run volume in the window. */