← Lesson library

Filter workflow runs by failure time, not creation time

When collecting workflow runs for a time window, do not exclude runs by creation time before the window, because a rerun can fail long after it was created. Gather candidates from a lookback that covers reruns, then apply the event-time cutoff on updated_at. Check truncation separately for each conclusion listing.

Compare the published fixtures

fixtures/bad/runs.py

def failures_since(runs, since):
    return [run for run in runs if run["conclusion"] == "failure" and run["created_at"] >= since]

fixtures/good/runs.py

def failures_since(runs, since):
    return [run for run in runs if run["conclusion"] == "failure" and run["updated_at"] >= since]