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.

fix(devex): let a depot relay re-run retry cancelled runs (#113760)

Julian Bez45e431fc633b
diff --git a/.agents/skills/debugging-ci-failures/SKILL.md b/.agents/skills/debugging-ci-failures/SKILL.md
index c94d40adc200..9b7b77ce49b9 100644
--- a/.agents/skills/debugging-ci-failures/SKILL.md
+++ b/.agents/skills/debugging-ci-failures/SKILL.md
@@ -251,7 +251,8 @@ history, hand off to `fixing-flaky-tests`, which covers the `search-test` and
A PR can route its backend tests to Depot CI.
Then the GitHub Actions run holds only the relay: `Django Tests Pass` fails with "Backend tests on Depot CI concluded failure", and the GitHub run logs show nothing more.
-A re-run of that job is not read-only: it retries the failed Depot jobs and reports the new verdict, so the rule against re-running CI applies to it.
+A re-run of that job is not read-only: it retries the failed and cancelled Depot jobs and reports the new verdict, so the rule against re-running CI applies to it.
+A run that Depot still shows as running past its job timeouts is stuck. A re-run waits on it, so cancel it with `depot ci cancel` first.
The log of the `Relay the Depot verdict` step prints the Depot run URL, each failed step with its log lines, and the label that sends the PR back to GitHub Actions.
Read more of the failure from Depot with the `depot` CLI, which the flox environment installs.
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 934fbd6861c0..afbfdc676c3d 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -13,7 +13,8 @@
# `Django Tests Pass` gate then relays this workflow's gate verdict. Its first step posts the
# `Depot run started` check that canonical's router waits for. Neither the router, the
# hand-off job, nor the relay has a counterpart here. A GitHub rerun does not restart this
-# workflow, so a re-run of the relay job retries this workflow's failed jobs with `depot ci retry`.
+# workflow, so a re-run of the relay job retries this workflow's failed and cancelled jobs with
+# `depot ci retry`.
# The relay's failure log prints the label that sends the PR back to GitHub Actions, and each
# failed step and its log lines, read with `depot ci diagnose`, because Depot's own checks
# carry no output.
diff --git a/.github/scripts/cancel_superseded_depot_runs.py b/.github/scripts/cancel_superseded_depot_runs.py
index 5972b34bd593..ea8bddc07c1a 100644
--- a/.github/scripts/cancel_superseded_depot_runs.py
+++ b/.github/scripts/cancel_superseded_depot_runs.py
@@ -65,8 +65,9 @@ def superseded(own_workflow_id: str, active_workflows: Sequence[Workflow], runs:
def depot(*args: str) -> list[dict[str, str]]:
+ # stderr passes through, so a failed call explains itself in the job log.
result = subprocess.run(
- ["depot", "ci", *args], check=True, capture_output=True, text=True, timeout=CLI_TIMEOUT_SECONDS
+ ["depot", "ci", *args], check=True, stdout=subprocess.PIPE, text=True, timeout=CLI_TIMEOUT_SECONDS
)
# `depot ci run list` prints `null` when nothing matches.
return json.loads(result.stdout) or []
@@ -95,8 +96,10 @@ def main() -> int:
]
targets = superseded(match[1], workflows, runs)
except (subprocess.SubprocessError, KeyError, ValueError) as error:
- sys.stdout.write(f"::warning::Could not read this PR's Depot runs, so no run was cancelled: {error!r}\n")
- return 0
+ # A missed cancel leaves a stuck run alive, so the step fails where people see it. Both
+ # callers set continue-on-error, so the failure does not block the pull request.
+ sys.stdout.write(f"::error::Could not read this PR's Depot runs, so no run was cancelled: {error!r}\n")
+ return 1
for workflow in targets:
sys.stdout.write(f"Cancelling superseded run {workflow.run_id} (workflow {workflow.workflow_id})\n")
try:
diff --git a/.github/scripts/ci_backend_relay.py b/.github/scripts/ci_backend_relay.py
index 1be10119e087..99c864d713b1 100644
--- a/.github/scripts/ci_backend_relay.py
+++ b/.github/scripts/ci_backend_relay.py
@@ -473,14 +473,16 @@ def gate_verdict(
) -> Progress:
"""The gate verdict that this attempt of the relay job reports.
- A GitHub re-run starts nothing on Depot. So when a re-run finds a gate that already failed,
- the relay retries the failed Depot jobs and reports the new verdict. A failed prerequisite
- is not retried, because it fails the same way until a commit fixes it.
+ A GitHub re-run starts nothing on Depot. So when a re-run finds a gate that already failed
+ or was cancelled, the relay retries the failed and cancelled Depot jobs and reports the new
+ verdict. A cancel is not a test verdict, so the re-run asks for the tests again. A failed
+ prerequisite is not retried, because it fails the same way until a commit fixes it.
"""
if rerun:
settled = poll(reader, event, GATE_CHECK, deadline_minutes=0, absent_minutes=0)
target = DEPOT_RUN_URL.match(settled.details_url)
- if target and settled.phase == Phase.FINISHED and settled.state != "success" and not settled.root_failure:
+ failed = settled.phase == Phase.FINISHED and settled.state != "success"
+ if target and (failed or settled.phase == Phase.CANCELLED) and not settled.root_failure:
retried = retry(*target.groups())
if retried:
return retried
@@ -535,7 +537,7 @@ def relay_gate(result: Progress, event: Event, run_id: str) -> tuple[int, list[s
if result.phase == Phase.CANCELLED:
return 1, [
f"::error::Depot CI cancelled its run for this event of {event.sha} and started no replacement.",
- *retry_instructions(event, result.details_url),
+ *retry_instructions(event, result.details_url, run_id),
]
if result.phase == Phase.DECLINED:
return 1, [f"::error::Depot declined the hand-off for {event.sha} (wait job: {result.state})"]
diff --git a/.github/scripts/test_ci_backend_relay.py b/.github/scripts/test_ci_backend_relay.py
index fca19bffe1d7..70e171c8950a 100644
--- a/.github/scripts/test_ci_backend_relay.py
+++ b/.github/scripts/test_ci_backend_relay.py
@@ -414,6 +414,7 @@ def test_retry_relays_only_the_verdict_of_the_new_execution(
pytest.param(True, [run(10, "failure")], [], "success", "success", 1, id="a failed gate is retried"),
pytest.param(True, [run(10, "success")], [], "failure", "success", 0, id="a passed gate is relayed"),
pytest.param(True, [run(10, "failure")], [], None, "failure", 1, id="Depot unreachable"),
+ pytest.param(True, [run(10, "cancelled")], [], "success", "success", 1, id="a cancelled gate is retried"),
pytest.param(True, [None, run(10, "success")], [], "failure", "success", 0, id="a running gate is awaited"),
pytest.param(
True,
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 486c6718f609..3ee40817e5b3 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -4290,7 +4290,8 @@ jobs:
EVENT_AT: ${{ github.event.pull_request.updated_at }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_REF: ${{ github.head_ref }}
- run: python3 .github/scripts/ci_backend_relay.py gate
+ # Unbuffered, so each poll shows in the live log instead of all at once when the step ends.
+ run: python3 -u .github/scripts/ci_backend_relay.py gate
- name: Summarize dependency results
if: needs.changes.outputs.engine != 'depot'
run: |