CI: the cache warm on main builds its five shards in parallel

`cargo xtask ci warm` builds only shard GATE_SHARD of GATE_SHARDS when the gate sets them, and
every shard when neither is set; one set without the other, a non-number, a count other than the
shard count, or a shard out of range is an error. ci.yml turns on the gate's `warm-split`, so
main's warm runs as five `cache warm <k>/5` legs and a `cache warm` leg that saves the entry.

The cold-cache cleanup waits for the split legs before it times the saving leg's start, and fails
when a split leg fails. The cache-prune watch and both jobs' timeouts cover a split leg followed
by the saving leg.
This commit is contained in:
dotCooCoo committed 2026-11-29 06:09:05 -08:00
1 parent d4d8da4544
commit 3a617b1324
5 files changed
+222 -31

No files matched your search

+108 -3
View File
@@ -36,6 +36,11 @@ def earlier(conclusion):
return [{"name": WARM, "conclusion": conclusion}, {"name": "cold cache clear", "conclusion": "failure"}]
def split_job(shard, status, completed_at=None):
return {"name": f"gate / cache warm {shard}/5 (ubuntu-24.04)", "status": status,
"conclusion": "success" if status == "completed" else None, "completed_at": completed_at}
class SaveStep(unittest.TestCase):
def test_the_leg_is_saving_once_its_save_step_starts(self):
self.assertFalse(clear.saving(warm_job("in_progress", steps=[("Setup", "completed", "success"), ("Gate", "in_progress", None)])))
@@ -99,6 +104,34 @@ class Deadline(unittest.TestCase):
self.assertFalse(clear.started_late(warm_job("queued"), self.began))
self.assertFalse(clear.started_late(None, self.began))
def test_split_progress_suspends_the_start_deadline(self):
for status in ("queued", "in_progress"):
with self.subTest(status=status):
jobs = [split_job(1, "completed", "2026-11-28T06:00:00Z"), split_job(2, status)]
ready = clear.start_wait_began(jobs, self.began)
self.assertIsNone(ready)
now = self.began + timedelta(seconds=clear.START_SECONDS + 60)
self.assertFalse(clear.start_overdue(None, now, ready))
self.assertFalse(clear.started_late(warm_job("in_progress", started_at=now.isoformat()), ready))
def test_the_last_split_completion_starts_the_wait(self):
jobs = [split_job(1, "completed", "2026-11-28T08:00:00Z"),
split_job(2, "completed", "2026-11-28T07:00:00Z")]
ready = clear.start_wait_began(jobs, self.began)
self.assertEqual(ready, clear.parse_time("2026-11-28T08:00:00Z"))
self.assertFalse(clear.start_overdue(None, ready + timedelta(seconds=clear.START_SECONDS), ready))
self.assertTrue(clear.start_overdue(None, ready + timedelta(seconds=clear.START_SECONDS + 1), ready))
self.assertFalse(clear.started_late(warm_job("in_progress", started_at="2026-11-28T08:01:00Z"), ready))
late = warm_job("in_progress", started_at=(ready + timedelta(seconds=clear.START_SECONDS + 1)).isoformat())
self.assertTrue(clear.started_late(late, ready))
def test_without_split_legs_the_script_start_starts_the_wait(self):
self.assertEqual(clear.start_wait_began([], self.began), self.began)
self.assertEqual(clear.start_wait_began(ME + [warm_job("queued")], self.began), self.began)
def test_a_split_completion_without_a_timestamp_does_not_start_the_wait(self):
self.assertIsNone(clear.start_wait_began([split_job(1, "completed")], self.began))
class Workflow(unittest.TestCase):
ci = (Path(__file__).resolve().parent.parent / ".github" / "workflows" / "ci.yml").read_text()
@@ -116,10 +149,17 @@ class Workflow(unittest.TestCase):
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.
# Without split legs, five minutes remain for setup and deletion.
spare = self.timeout_minutes("cold-cache-clear") * 60 - clear.START_SECONDS - clear.GIVE_UP_SECONDS
self.assertGreaterEqual(spare, 5 * 60)
def test_the_job_allows_both_warm_builds_within_the_hosted_job_limit(self):
# Runner waits and the full start allowance may exceed the 360-minute job limit.
timeout = self.timeout_minutes("cold-cache-clear")
spare = timeout * 60 - self.timeout_minutes("gate") * 60 - clear.GIVE_UP_SECONDS
self.assertGreaterEqual(spare, 5 * 60)
self.assertEqual(timeout, 360)
def test_the_save_wait_outlasts_the_gate(self):
self.assertGreater(clear.GIVE_UP_SECONDS, self.timeout_minutes("gate") * 60)
@@ -148,6 +188,9 @@ class Jobs(unittest.TestCase):
self.assertTrue(clear.legs_stopped([done("gate / select legs", "success"), done("gate / build (ubuntu-24.04)", "cancelled")]))
self.assertFalse(clear.legs_stopped([done("gate / select legs", "success"), done("gate / build (${{ matrix.os }})", "skipped")]))
self.assertFalse(clear.legs_stopped([done("gate / test 1/5 (ubuntu-24.04)", "failure")]))
# With warm-split, the saving `cache warm (<os>)` leg also needs every `cache warm <k>/<N>` leg.
self.assertTrue(clear.legs_stopped([done("gate / cache warm 2/5 (ubuntu-24.04)", "failure")]))
self.assertFalse(clear.legs_stopped([done("gate / cache warm 2/5 (ubuntu-24.04)", "success")]))
class Caches(unittest.TestCase):
@@ -184,6 +227,60 @@ class Clock(datetime):
return datetime(2026, 11, 28, 4, 0, tzinfo=timezone.utc)
class BeforeSaving(unittest.TestCase):
def run_main(self, polls):
began = Clock.now()
current = began
remaining = iter(polls)
class PollClock(datetime):
@classmethod
def now(cls, tz=None):
return current
def gh(url):
nonlocal current
if "/jobs?" in url:
minutes, jobs = next(remaining)
current = began + timedelta(minutes=minutes)
return {"jobs": ME + jobs}
if "/caches?" in url:
return {"actions_caches": []}
return {"run_started_at": began.isoformat()}
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
with mock.patch.object(clear, "gh", gh), mock.patch.object(clear.time, "sleep"), \
mock.patch.object(clear, "datetime", PollClock), mock.patch.dict(os.environ, env), \
mock.patch.object(clear.subprocess, "run") as delete, contextlib.redirect_stdout(io.StringIO()):
status = clear.main()
delete.assert_not_called()
return status
def test_queued_and_running_split_legs_can_outlast_the_original_start_deadline(self):
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
saved = warm_job("completed", "success", [("Post Setup", "completed", "success")],
started_at="2026-11-28T07:50:00Z")
self.assertFalse(self.run_main([
(181, [split_job(1, "queued")]),
(201, [split_job(1, "in_progress"), warm_job("queued")]),
(220, [done, warm_job("queued")]),
(230, [done, saved]),
]))
def test_a_saving_leg_that_never_starts_expires_after_the_last_split_completion(self):
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
self.assertEqual(self.run_main([
(220, [done, warm_job("queued")]),
(401, [done, warm_job("queued")]),
]), 1)
def test_a_late_start_after_split_completion_is_rejected_even_if_already_saving(self):
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
late = warm_job("in_progress", steps=[("Post Setup", "in_progress", None)],
started_at="2026-11-28T10:40:01Z")
self.assertEqual(self.run_main([(401, [done, late])]), 1)
class AfterDeletion(unittest.TestCase):
SAVING = [("Gate", "completed", "success"), ("Post Setup", "in_progress", None)]
@@ -222,9 +319,17 @@ 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_saving_leg_skipped_after_a_failed_split_warm_leg_fails_this_job(self):
skipped = warm_job("completed", conclusion="skipped")
failed = {"name": "gate / cache warm 2/5 (ubuntu-24.04)", "status": "completed", "conclusion": "failure"}
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
with mock.patch.object(clear, "gh", lambda url: {"jobs": ME + [failed, skipped]}), 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)
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")
# Clock.now() is 04:00, so the leg starts 180 minutes 5 seconds after the script.
late = warm_job("in_progress", steps=self.SAVING, started_at="2026-11-28T07:00:05Z")
deleted = []
def run(args, **kwargs):
+32 -18
View File
@@ -16,8 +16,10 @@ 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 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
leg has not started START_SECONDS after the last split warm leg completed (or after this script
started when there are no split legs). The start deadline does not expire while a split leg is
queued or running. This 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
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.
@@ -33,9 +35,11 @@ import time
REF = 'refs/heads/main'
WARM_JOB = re.compile(r'^gate / cache warm \(')
SPLIT_WARM_JOB = re.compile(r'^gate / cache warm \d+/\d+ \(')
# The jobs the gate's legs need (craft-common-actions .github/workflows/gate.yml): when one of
# them fails or is canceled, the legs are skipped and no warm leg is listed.
NEEDED_JOBS = re.compile(r'^gate / (select legs$|build \()')
# them fails or is canceled, the legs are skipped and no warm leg is listed. With `warm-split` the
# saving leg also needs every `cache warm <k>/<N>` leg.
NEEDED_JOBS = re.compile(r'^gate / (select legs$|build \(|cache warm \d+/\d+ \()')
PRUNE_JOB = 'cache prune'
ROLLING = '-gate-crates-'
# The gate-setup action's post step, which saves the dependency cache (craft-common-actions
@@ -46,12 +50,11 @@ 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
# How long the saving leg may take to start after the last split warm leg completed, or after
# this script started when there are no split legs. Queued or running split legs suspend this
# deadline. The `cold-cache-clear` job's 360-minute timeout in ci.yml can end the wait before
# this deadline or GIVE_UP_SECONDS expires when split builds or runner waits take too long.
START_SECONDS = 180 * 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',)
@@ -97,16 +100,25 @@ def started_at(job):
return parse_time(started) if started else None
def start_wait_began(jobs, began):
"""The last split warm completion, the script's start without splits, or None while waiting."""
splits = [j for j in jobs if SPLIT_WARM_JOB.match(j['name'])]
if not splits:
return began
if any(j['status'] != 'completed' or not j.get('completed_at') for j in splits):
return None
return max(parse_time(j['completed_at']) for j in splits)
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
"""True once START_SECONDS have passed since the start wait began and the leg has not started."""
return began is not None and 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)."""
"""True when the warm leg started more than START_SECONDS after the start wait began."""
started = started_at(job)
return started is not None and (started - began).total_seconds() > START_SECONDS
return began is not None and started is not None and (started - began).total_seconds() > START_SECONDS
def gave_up(job, now):
@@ -173,7 +185,8 @@ def main():
while True:
jobs = gh(jobs_url) or {}
job = warm_job(jobs.get('jobs', []))
if started_late(job, began):
ready = start_wait_began(jobs.get('jobs', []), began)
if started_late(job, ready):
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
return 1
if job and saving(job):
@@ -192,13 +205,14 @@ def main():
print('::error::the gate stopped before its cache warm leg started; nothing deleted')
return 1
if job and job['status'] == 'completed':
if job.get('conclusion') in STOPPED:
# A saving leg skipped because a leg it needs failed (a `cache warm <k>/<N>` leg).
if job.get('conclusion') in STOPPED or job.get('conclusion') == 'skipped' and legs_stopped(jobs.get('jobs', [])):
print(f'::error::{NO_SAVE}')
return 1
print('the cache warm leg finished without a save step; nothing deleted')
return
now = datetime.now(timezone.utc)
if start_overdue(job, now, began):
if start_overdue(job, now, ready):
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
return 1
if gave_up(job, now):