: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): align lead time card population (#103874)
Raúl Negrón-Otero218e378b7cdc
diff --git a/products/engineering_analytics/backend/facade/contracts.py b/products/engineering_analytics/backend/facade/contracts.pyindex 947d15c2d934..b5757d86f475 100644--- a/products/engineering_analytics/backend/facade/contracts.py+++ b/products/engineering_analytics/backend/facade/contracts.py@@ -1632,11 +1632,11 @@ class DeliveryLeadTime:"""Lead time to deploy for one scope against the repository, over the DORA deployed-PRpopulation (bots and drafts excluded, containment resolved through the deploy's head commit).- The distributions cover PRs whose first containing deploy succeeded in the window, so the- three stages compose. The coverage pair counts PRs merged in the window instead:- ``deployed_merged_pr_count`` of ``merged_pr_count`` reached a deploy. Deploy failure share and- recovery are per deploy and one deploy ships many PRs, so they are not attributable to an- author or a team and are not part of this type.+ The distributions cover PRs merged in the window whose first containing deploy succeeded by+ the window end, so the three stages compose. ``deployed_merged_pr_count`` of+ ``merged_pr_count`` reached such a deploy. Deploy failure share and recovery are per deploy and+ one deploy ships many PRs, so they are not attributable to an author or a team and are not part+ of this type."""deploy_data_available: booldiff --git a/products/engineering_analytics/backend/logic/queries/delivery_summary.py b/products/engineering_analytics/backend/logic/queries/delivery_summary.pyindex 47fa0c063c7a..510dc329b68a 100644--- a/products/engineering_analytics/backend/logic/queries/delivery_summary.py+++ b/products/engineering_analytics/backend/logic/queries/delivery_summary.py@@ -283,7 +283,9 @@ def _lead_time(def in_window(at: datetime) -> bool:return at >= date_from and (date_to is None or at <= date_to)- repo_rows = [row for row in deployed.rows if in_window(row.deployed_at)]+ repo_rows = [+ row for row in deployed.rows if in_window(row.merged_at) and (date_to is None or row.deployed_at <= date_to)+ ]scope_rows = [row for row in repo_rows if row.in_scope]def pair(stage: Callable[[DeployedPR], float]) -> ScopeRepoDistribution:@@ -296,12 +298,7 @@ def _lead_time(deploy_data_available=True,environment_scope=deployed.environment_scope,merged_pr_count=scope_merged_count,- # A deploy after the window end had not happened yet in the selected horizon.- deployed_merged_pr_count=sum(- 1- for row in deployed.rows- if row.in_scope and in_window(row.merged_at) and (date_to is None or row.deployed_at <= date_to)- ),+ deployed_merged_pr_count=len(scope_rows),open_to_deploy=pair(lambda row: row.open_to_deploy_seconds),open_to_merge=pair(lambda row: row.open_to_merge_seconds),merge_to_deploy=pair(lambda row: row.merge_to_deploy_seconds),diff --git a/products/engineering_analytics/backend/presentation/serializers/delivery.py b/products/engineering_analytics/backend/presentation/serializers/delivery.pyindex 39756b7a4c70..756bd6092991 100644--- a/products/engineering_analytics/backend/presentation/serializers/delivery.py+++ b/products/engineering_analytics/backend/presentation/serializers/delivery.py@@ -92,8 +92,8 @@ class DeliveryLeadTimeSerializer(DataclassSerializer):},"merged_pr_count": {"help_text": "PRs in scope merged in the window (bots and drafts excluded)."},"deployed_merged_pr_count": {- "help_text": "Of merged_pr_count, the PRs a successful in-scope deploy contains. The rest are "- "still waiting for a deploy or fall outside the scan."+ "help_text": "Of merged_pr_count, the PRs whose first successful in-scope deployment was observed "+ "by the window end. The rest are still waiting for a deploy or fall outside the scan."},}diff --git a/products/engineering_analytics/backend/tests/test_delivery.py b/products/engineering_analytics/backend/tests/test_delivery.pyindex 5f675607af2a..c2b83a3068af 100644--- a/products/engineering_analytics/backend/tests/test_delivery.py+++ b/products/engineering_analytics/backend/tests/test_delivery.py@@ -917,12 +917,21 @@ class TestDeliveryComparisonOnWarehouse(_WarehouseMixin):class TestDeliveryDeployWindow(_WarehouseMixin):def _seed(self) -> None:- # Two merges inside the window, each heading its own production deploy: one deploy lands- # inside the reported window, the other two days after it.self._create_table("github_pull_requests",PULL_REQUESTS_COLUMNS,[+ _pr_row(+ 30,+ "alice",+ "closed",+ 0,+ "2026-01-07 08:00:00",+ merged_at="2026-01-08 08:00:00",+ merge_commit_sha="sha-before",+ base_ref="main",+ default_branch="main",+ ),_pr_row(31,"alice",@@ -952,6 +961,7 @@ class TestDeliveryDeployWindow(_WarehouseMixin):"github_deployments",DEPLOYMENTS_COLUMNS,[+ _deployment_row(3, "sha-before", "prod", "2026-01-11 09:30:00", production=True),_deployment_row(1, "sha-inside", "prod", "2026-01-12 09:30:00", production=True),_deployment_row(2, "sha-after", "prod", "2026-01-14 09:30:00", production=True),],@@ -960,12 +970,13 @@ class TestDeliveryDeployWindow(_WarehouseMixin):"github_deployment_statuses",DEPLOYMENT_STATUSES_COLUMNS,[+ _status_row(31, 3, "success", "prod", "2026-01-11 10:00:00"),_status_row(11, 1, "success", "prod", "2026-01-12 10:00:00"),_status_row(21, 2, "success", "prod", "2026-01-14 10:00:00"),],)- def test_deployed_count_stops_at_the_report_end(self) -> None:+ def test_lead_time_population_matches_the_merged_count(self) -> None:self._seed()curated = CuratedGitHubSource.for_team(self.team)@@ -979,8 +990,8 @@ class TestDeliveryDeployWindow(_WarehouseMixin):lead_time = summary.lead_timeassert lead_time.deploy_data_available is Trueassert lead_time.merged_pr_count == 2- # The second PR's deploy is two days past the window end, so it is not deployed work yet,- # and the count has to agree with the distribution beside it.+ # One deploy follows the report end and another belongs to an earlier merge, so neither+ # belongs in the count or its adjacent distribution.assert lead_time.deployed_merged_pr_count == 1assert lead_time.open_to_deploy.scope.pr_count == 1diff --git a/products/engineering_analytics/frontend/components/LeadTimeComparisonCard.tsx b/products/engineering_analytics/frontend/components/LeadTimeComparisonCard.tsxindex 1c6f5291e28d..aa532593780a 100644--- a/products/engineering_analytics/frontend/components/LeadTimeComparisonCard.tsx+++ b/products/engineering_analytics/frontend/components/LeadTimeComparisonCard.tsx@@ -52,11 +52,11 @@ export function LeadTimeComparisonCard({title={<div className="flex flex-col gap-1"><div>- Merged pull requests (bots and drafts excluded), each matched once to the first- successful deploy that contains its merge, in the environments named under the headline.- Open to merge includes draft time. The three stages use the same pull requests. For each- one, open to merge and merge to deploy add up to open to deploy, but their medians do- not.+ Pull requests merged in the window (bots and drafts excluded), each matched once to the+ first successful deploy that contains its merge by the window end, in the environments+ named under the headline. Open to merge includes draft time. The three stages use the+ same pull requests. For each one, open to merge and merge to deploy add up to open to+ deploy, but their medians do not.</div><div>Box: the middle half of the pull requests. Line: median. Dot: mean. Whiskers: 5th todiff --git a/products/engineering_analytics/frontend/generated/api.schemas.ts b/products/engineering_analytics/frontend/generated/api.schemas.tsindex 3685db9b8101..03ce17059400 100644--- a/products/engineering_analytics/frontend/generated/api.schemas.ts+++ b/products/engineering_analytics/frontend/generated/api.schemas.ts@@ -385,7 +385,7 @@ export interface DeliveryLeadTimeApi {environment_scope: string/** PRs in scope merged in the window (bots and drafts excluded). */merged_pr_count: number- /** Of merged_pr_count, the PRs a successful in-scope deploy contains. The rest are still waiting for a deploy or fall outside the scan. */+ /** Of merged_pr_count, the PRs whose first successful in-scope deployment was observed by the window end. The rest are still waiting for a deploy or fall outside the scan. */deployed_merged_pr_count: number}diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex f922aa695a6b..ccf419d426ef 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -30500,7 +30500,7 @@ export namespace Schemas {environment_scope: string;/** PRs in scope merged in the window (bots and drafts excluded). */merged_pr_count: number;- /** Of merged_pr_count, the PRs a successful in-scope deploy contains. The rest are still waiting for a deploy or fall outside the scan. */+ /** Of merged_pr_count, the PRs whose first successful in-scope deployment was observed by the window end. The rest are still waiting for a deploy or fall outside the scan. */deployed_merged_pr_count: number;}