Merge pull request #9882 from dotCooCoo/fix/cold-cache-clear-start-wait

CI: the cold cache clear fails on a late warm leg before its job times out
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 01:24:42 -08:00
commit cefcc8a955
3 files changed
+100 -18

No files matched your search

+5 -4
View File
@@ -89,14 +89,15 @@ jobs:
# 10 GB cache limit and get the corpus, SonarCloud and Windows ARM64 entries evicted. This deletes
# the old entries when the `cache warm` leg starts saving (scripts/ci-clear-rolling-cache.py).
# When the leg fails or is canceled, before its save or during it, this job fails too, so "Re-run
# failed jobs" runs it again beside the re-run leg. The script's 160-minute wait starts when the leg
# starts, which is after `gate / select legs` and a free runner, so this job's timeout leaves
# 40 minutes for that.
# failed jobs" runs it again beside the re-run leg. The leg starts after `gate / select legs` and a
# free runner: the script fails when the leg has not started within 120 minutes, and then waits
# up to 160 minutes from the leg's start. This job's timeout is longer than both together, so the
# script reports a leg that starts late with its own error before the job times out.
cold-cache-clear:
name: cold cache clear
if: github.event_name == 'schedule'
runs-on: ubuntu-24.04
timeout-minutes: 200
timeout-minutes: 290
permissions:
actions: write
steps:
+57 -6
View File
@@ -9,6 +9,7 @@ import importlib.util
import io
import os
from pathlib import Path
import re
import subprocess
import unittest
from unittest import mock
@@ -78,15 +79,49 @@ class Deadline(unittest.TestCase):
before_limit = clear.parse_time("2026-11-28T04:00:00Z") + timedelta(seconds=clear.GIVE_UP_SECONDS - 60)
after_limit = clear.parse_time("2026-11-28T04:00:00Z") + timedelta(seconds=clear.GIVE_UP_SECONDS + 60)
self.assertGreater((before_limit - self.began).total_seconds(), clear.GIVE_UP_SECONDS)
self.assertFalse(clear.gave_up(late, before_limit, self.began))
self.assertTrue(clear.gave_up(late, after_limit, self.began))
self.assertFalse(clear.gave_up(late, before_limit))
self.assertTrue(clear.gave_up(late, after_limit))
self.assertFalse(clear.start_overdue(late, after_limit, self.began))
def test_a_leg_that_never_starts_is_timed_from_the_script_start(self):
queued = warm_job("queued", started_at="2026-11-28T03:38:00Z")
later = self.began + timedelta(seconds=clear.GIVE_UP_SECONDS + 60)
self.assertFalse(clear.gave_up(None, self.began + timedelta(minutes=10), self.began))
self.assertTrue(clear.gave_up(None, later, self.began))
self.assertTrue(clear.gave_up(queued, later, self.began))
before_limit = self.began + timedelta(seconds=clear.START_SECONDS - 60)
after_limit = self.began + timedelta(seconds=clear.START_SECONDS + 60)
self.assertFalse(clear.start_overdue(None, before_limit, self.began))
self.assertTrue(clear.start_overdue(None, after_limit, self.began))
self.assertTrue(clear.start_overdue(queued, after_limit, self.began))
self.assertFalse(clear.gave_up(queued, after_limit))
def test_a_leg_that_starts_after_the_start_limit_fails(self):
at = lambda seconds: warm_job("in_progress", started_at=(self.began + timedelta(seconds=seconds)).isoformat())
self.assertTrue(clear.started_late(at(clear.START_SECONDS + 5), self.began))
self.assertFalse(clear.started_late(at(clear.START_SECONDS - 10), self.began))
self.assertFalse(clear.started_late(warm_job("queued"), self.began))
self.assertFalse(clear.started_late(None, self.began))
class Workflow(unittest.TestCase):
ci = (Path(__file__).resolve().parent.parent / ".github" / "workflows" / "ci.yml").read_text()
def timeout_minutes(self, job):
"""The first `timeout-minutes` under `job` in ci.yml."""
lines = self.ci.splitlines()
start = lines.index(f" {job}:") + 1
for line in lines[start:]:
if re.match(r" \S", line):
break
match = re.match(r"\s+timeout-minutes: (\d+)$", line)
if match:
return int(match.group(1))
self.fail(f"no timeout-minutes under {job}")
def test_the_job_outlasts_the_start_wait_and_the_save_wait(self):
# Five minutes are left for the steps before the script and for the deletion.
spare = self.timeout_minutes("cold-cache-clear") * 60 - clear.START_SECONDS - clear.GIVE_UP_SECONDS
self.assertGreaterEqual(spare, 5 * 60)
def test_the_save_wait_outlasts_the_gate(self):
self.assertGreater(clear.GIVE_UP_SECONDS, self.timeout_minutes("gate") * 60)
class Jobs(unittest.TestCase):
@@ -187,6 +222,22 @@ class AfterDeletion(unittest.TestCase):
canceled = warm_job("completed", "cancelled", [("Gate", "completed", "success"), ("Post Setup", "completed", "cancelled")])
self.assertEqual(self.run_main(canceled), 1)
def test_a_leg_that_starts_late_and_saves_deletes_nothing(self):
# Clock.now() is 04:00, so the leg starts 120 minutes 5 seconds after the script.
late = warm_job("in_progress", steps=self.SAVING, started_at="2026-11-28T06:00:05Z")
deleted = []
def run(args, **kwargs):
deleted.append(args[-1])
return subprocess.CompletedProcess(args, 0, "", "")
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
with mock.patch.object(clear, "gh", lambda url: {"jobs": ME + [late]}), mock.patch.object(clear.subprocess, "run", run), \
mock.patch.object(clear.time, "sleep"), mock.patch.object(clear, "datetime", Clock), mock.patch.dict(os.environ, env), \
contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(clear.main(), 1)
self.assertEqual(deleted, [])
def test_a_save_that_fails_after_the_deletion_exits_1(self):
failed = warm_job("completed", "failure", [("Gate", "completed", "success"), ("Post Setup", "completed", "failure")])
self.assertEqual(self.run_main(failed), 1)
+38 -8
View File
@@ -16,8 +16,8 @@ save step started saves nothing: its old entries stay, and this exits 1, so "Re-
runs it again beside the re-run leg. A save step that is canceled or fails after the old entries
were deleted leaves no rolling entry, so the next run starts cold, and this exits 1 too. A failure
in a later post step does not count once the save step has succeeded. This also exits 1 when the
leg has not reached its save, or its save has not finished, GIVE_UP_SECONDS after the leg started.
An absent warm leg is treated as finished only
leg has not started START_SECONDS after this script started, and when the leg has not reached its
save, or its save has not finished, GIVE_UP_SECONDS after the leg started. An absent warm leg is treated as finished only
when the most recent earlier attempt that lists it reports success and the current attempt lists
no `cache prune` job, which runs from the start of "Re-run all jobs". Otherwise this keeps polling
because reusable-workflow dependencies may still be scheduling it.
@@ -46,6 +46,12 @@ PAGE_SIZE = 100
# Longer than the gate's `timeout-minutes` in ci.yml and timed from the leg's own start, so a cold
# leg that starts late and runs to its limit still reaches its save before this gives up.
GIVE_UP_SECONDS = 160 * 60
# How long the leg may take to start, timed from this script's start: the leg waits for
# `gate / select legs` and then for a runner, which took 44 minutes on a push to main on
# 2026-11-28. The `cold-cache-clear` job's `timeout-minutes` in ci.yml is longer than
# START_SECONDS and GIVE_UP_SECONDS together, so this exits with its own error before the job
# times out.
START_SECONDS = 120 * 60
STOPPED = ('failure', 'cancelled', 'timed_out')
# Steps with continue-on-error in craft-common-actions .github/workflows/gate.yml.
TOLERATED_FAILURES = ('Trim the cache entry to this build',)
@@ -85,11 +91,28 @@ def save_finished(job):
return job.get('status') == 'completed' or (step is not None and step['status'] == 'completed')
def gave_up(job, now, began):
"""True once GIVE_UP_SECONDS have passed since the warm leg started, or since `began` (this
script's start) while the leg has not started."""
def started_at(job):
"""The warm leg's start time, or None while the leg has not started."""
started = job.get('started_at') if job and job.get('status') in ('in_progress', 'completed') else None
return (now - (parse_time(started) if started else began)).total_seconds() > GIVE_UP_SECONDS
return parse_time(started) if started else None
def start_overdue(job, now, began):
"""True once START_SECONDS have passed since `began` (this script's start) and the warm leg
has not started."""
return started_at(job) is None and (now - began).total_seconds() > START_SECONDS
def started_late(job, began):
"""True when the warm leg started more than START_SECONDS after `began` (this script's start)."""
started = started_at(job)
return started is not None and (started - began).total_seconds() > START_SECONDS
def gave_up(job, now):
"""True once GIVE_UP_SECONDS have passed since the warm leg started."""
started = started_at(job)
return started is not None and (now - started).total_seconds() > GIVE_UP_SECONDS
def all_caches(fetch):
@@ -150,6 +173,9 @@ def main():
while True:
jobs = gh(jobs_url) or {}
job = warm_job(jobs.get('jobs', []))
if started_late(job, began):
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
return 1
if job and saving(job):
break
if job is None:
@@ -171,7 +197,11 @@ def main():
return 1
print('the cache warm leg finished without a save step; nothing deleted')
return
if gave_up(job, datetime.now(timezone.utc), began):
now = datetime.now(timezone.utc)
if start_overdue(job, now, began):
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
return 1
if gave_up(job, now):
print('::error::the cache warm leg never reached its save; nothing deleted')
return 1
time.sleep(POLL_SECONDS)
@@ -190,7 +220,7 @@ def main():
print(result.stderr, end='', file=sys.stderr)
return result.returncode
while not save_finished(job):
if gave_up(job, datetime.now(timezone.utc), began):
if gave_up(job, datetime.now(timezone.utc)):
print(f'::error::{SAVE_LOST}')
return 1
time.sleep(POLL_SECONDS)