: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(devex): fail loudly when a durations segment has no artifacts (#83380)
Julian Bezbe79fcb3a719
diff --git a/.github/scripts/optimize_test_durations.py b/.github/scripts/optimize_test_durations.pyindex 6723b69ee8ca..0f0ab9587c4a 100644--- a/.github/scripts/optimize_test_durations.py+++ b/.github/scripts/optimize_test_durations.py@@ -638,6 +638,17 @@ def main():logger.info(" Filtering to segment: %s", args.segment)shards = ShardTimings.load_all(args.artifacts_dir, segment=args.segment)logger.info(" Loaded %d shards", len(shards))+ if not shards:+ # Same guard as run_merge_files/run_average_files: an empty durations file is+ # worse than no file. It contributes nothing to the union merge, so every+ # product the missing segment covers silently sizes to zero and gets packed+ # into a bucket it then runs straight past.+ logger.error(+ "No timing artifacts for segment %s in %s — refusing to write an empty durations file",+ args.segment or "all",+ args.artifacts_dir,+ )+ sys.exit(1)# Merge using outlier detection (not naive last-wins)logger.info("Merging with outlier detection...")diff --git a/.github/scripts/test_optimize_test_durations.py b/.github/scripts/test_optimize_test_durations.pyindex a055dca9ccc7..3605751b9010 100644--- a/.github/scripts/test_optimize_test_durations.py+++ b/.github/scripts/test_optimize_test_durations.py@@ -3,6 +3,7 @@Run with: uv run --with pytest --with defusedxml pytest .github/scripts/test_optimize_test_durations.py"""+import sysfrom pathlib import Pathimport pytest@@ -12,6 +13,7 @@ from optimize_test_durations import (MigrationTaxCorrector,_pick_outlier,average_durations,+ main,outlier_merge_durations,run_average_files,)@@ -118,6 +120,18 @@ class TestAverageDurations:sources = [{"test_a": 2.0}, {"test_b": 5.0}, {"test_a": 6.0}]assert average_durations(sources)["test_a"] == 4.0+ def test_segment_with_no_artifacts_refuses_to_write(self, tmp_path, monkeypatch):+ # A run whose artifacts failed to download must not produce an empty durations+ # file: it would contribute nothing to the union and drag a multi-run product+ # average toward zero, un-sizing every product in it.+ out = tmp_path / "products_durations"+ monkeypatch.setattr(+ sys, "argv", ["optimize_test_durations.py", str(tmp_path), str(out), "--segment", "Products"]+ )+ with pytest.raises(SystemExit):+ main()+ assert not out.exists()+def test_run_average_files_refuses_empty_result(self, tmp_path):# Newest (anchor) run scoped to nothing must not silently wipe the plan,# even when older runs still carry data — refuse to write, don't emit {}.