: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(ci): report failed repo checks in the depot relay (#107873)
Raúl Negrón-Otero70e01f8cbb91
diff --git a/.github/scripts/ci_backend_relay.py b/.github/scripts/ci_backend_relay.pyindex 4f6711942db2..7cc365b403bb 100644--- a/.github/scripts/ci_backend_relay.py+++ b/.github/scripts/ci_backend_relay.py@@ -56,6 +56,7 @@ API_ROOT = "https://api.github.com"PAGE_SIZE = 100# A 403 also covers a secondary rate limit, which clears, so a few refusals in a row are tolerated.MAX_REFUSALS = 5+PREREQUISITES = ("Repo checks (depot-ubuntu-24.04)", "Validate OpenAPI types")class ReadRefusedError(RuntimeError):@@ -98,6 +99,8 @@ class Progress:# The state of the check behind the phase, empty when there is none.state: str = ""details_url: str = ""+ root_failure: str = ""+ root_check_id: int = 0def wait_check_name(pr_number: int, event_at: str) -> str:@@ -236,6 +239,22 @@ def racing_wait(reader: CheckReader, event: Event, followed: set[str]) -> str |return None+def prerequisite_failure(reader: CheckReader, wait: CheckRun, current: Progress) -> Progress:+ for name in PREREQUISITES:+ latest = max(+ (+ check+ for check in reader.read(f"{DEPOT_WORKFLOW} / {name}")+ if check.depot_workflow == wait.depot_workflow+ ),+ key=lambda check: check.id,+ default=None,+ )+ if latest and latest.state == "failure":+ return Progress(Phase.FINISHED, "failure", current.details_url, name, latest.id)+ return current++def poll(reader: CheckReader,event: Event,@@ -259,6 +278,10 @@ def poll(wait = newest_live(reader.read(event_name))checks = reader.read(check_name) if wait and wait.state == "success" else []current = progress(wait, checks)+ # Depot cancels its own run only after a deterministic prerequisite failure. A gate that+ # failed without the cancel can follow a retryable one, so it keeps the retry options.+ if current.phase == Phase.CANCELLED and wait and wait.state == "success":+ current = prerequisite_failure(reader, wait, current)sys.stdout.write(f"Depot run for this event: {current.phase.value} {current.state}".rstrip() + "\n")elapsed = clock() - startif current.phase in (Phase.FINISHED, Phase.DECLINED):@@ -310,6 +333,11 @@ def relay_gate(result: Progress, event: Event, run_id: str) -> tuple[int, list[s"""The exit code and log lines of the `Django Tests Pass` relay for the gate's progress."""if result.phase == Phase.FINISHED and result.state == "success":return 0, []+ if result.root_failure:+ return 1, [+ f"::error::{result.root_failure} failed on Depot (check {result.root_check_id}). "+ "Push a fix; a retry will not help."+ ]if result.phase == Phase.FINISHED:return 1, [f"::error::Backend tests on Depot CI concluded {result.state}. This step's log lists the retry options.",diff --git a/.github/scripts/test_ci_backend_relay.py b/.github/scripts/test_ci_backend_relay.pyindex 4a574f741383..3c3bb198b874 100644--- a/.github/scripts/test_ci_backend_relay.py+++ b/.github/scripts/test_ci_backend_relay.py@@ -347,3 +347,76 @@ def test_reader_retries_interrupted_pages_without_reusing_a_stale_verdict(page:assert reader.read(relay.GATE_CHECK) == []assert reader.read(relay.GATE_CHECK) == []assert not answers++[email protected]("name", relay.PREREQUISITES)+ "state,workflow,newer",+ [+ ("failure", "live", None),+ ("failure", "other", None),+ ("success", "live", None),+ ("failure", "live", "pending"),+ ("failure", "live", "success"),+ ],+)+def test_cancelled_gate_reports_only_current_selected_prerequisite(+ name: str, state: str, workflow: str, newer: str | None+) -> None:+ roots = [run(2, state, workflow)]+ if newer:+ roots.append(run(3, newer, workflow))+ clock = FakeClock()+ result = relay.poll(+ FakeReader(+ [+ {+ EVENT_WAIT: [run(1, "success")],+ relay.GATE_CHECK: [run(5, "cancelled")],+ f"{relay.DEPOT_WORKFLOW} / {name}": roots,+ }+ ]+ ),+ EVENT,+ relay.GATE_CHECK,+ deadline_minutes=90,+ absent_minutes=15,+ clock=clock,+ sleep=clock.sleep,+ )+ code, lines = relay.relay_gate(result, EVENT, "123")+ assert code == 1+ if state == "failure" and workflow == "live" and newer is None:+ assert clock.now == 0+ assert lines == [f"::error::{name} failed on Depot (check 2). Push a fix; a retry will not help."]+ assert result.root_check_id == 2+ else:+ assert result.phase == relay.Phase.CANCELLED+ assert clock.now == 900++[email protected]("name", relay.PREREQUISITES)+def test_failed_gate_keeps_retry_options_after_a_prerequisite_failure(name: str) -> None:+ # Without Depot's self-cancel, the prerequisite may have failed on a retryable setup step.+ clock = FakeClock()+ result = relay.poll(+ FakeReader(+ [+ {+ EVENT_WAIT: [run(1, "success")],+ relay.GATE_CHECK: [run(5, "failure")],+ f"{relay.DEPOT_WORKFLOW} / {name}": [run(2, "failure")],+ }+ ]+ ),+ EVENT,+ relay.GATE_CHECK,+ deadline_minutes=90,+ absent_minutes=15,+ clock=clock,+ sleep=clock.sleep,+ )+ code, lines = relay.relay_gate(result, EVENT, "123")+ assert code == 1+ assert not result.root_failure+ assert not any("a retry will not help" in line for line in lines)