From 70059192bfa287f3bbb3d6e3d0b8490ca14ded45 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 28 Oct 2026 23:28:08 +0000 Subject: [PATCH] ci(overflow): main's switch never points a signing runner variable at an owned mini The scheduled overflow switch runs from main, so the feat-cmux-next fix (#27094) cannot stop it. Port it: MACOS_RUNNER_26 leaves the owned failover, no override may move it, a stalled probe never re-applies an older record's owned value to LINUX_RUNNER or MACOS_RUNNER_26, and check_repo_variables never excuses one. Restoring still puts back the recorded value. Co-Authored-By: Claude Opus 5.5 Agent-Session: https://cmux.com/deeplink/agent?id=aid-7a592ef92c66f080e3cc --- .github/workflows/ci-repo-variables.yml | 1 + docs/ci-runners.md | 11 ++- scripts/ci/check_repo_variables.py | 8 +- scripts/ci/cloud_overflow_switch.py | 53 +++++++++++-- scripts/ci/signing_runner_variables.py | 44 +++++++++++ tests/test_ci_cloud_overflow_switch.py | 100 +++++++++++++++++++++++- 6 files changed, 206 insertions(+), 11 deletions(-) create mode 100644 scripts/ci/signing_runner_variables.py diff --git a/.github/workflows/ci-repo-variables.yml b/.github/workflows/ci-repo-variables.yml index f05f5cde858c..f65db577508e 100644 --- a/.github/workflows/ci-repo-variables.yml +++ b/.github/workflows/ci-repo-variables.yml @@ -27,6 +27,7 @@ on: - scripts/ci/pr_runner_pool.py - scripts/ci/runner_label_policy.py - scripts/ci/runs_on_values.py + - scripts/ci/signing_runner_variables.py workflow_dispatch: permissions: diff --git a/docs/ci-runners.md b/docs/ci-runners.md index 056d9782bc1c..a841ebe5fb02 100644 --- a/docs/ci-runners.md +++ b/docs/ci-runners.md @@ -998,12 +998,19 @@ evicted with nothing decided. failover, when and which run), then points the variables at their failovers: `LINUX_RUNNER` to `blacksmith-16vcpu-ubuntu-2404` and `CI_TRUSTED_RUNNER` to `blacksmith-2vcpu-ubuntu-2404` (another Blacksmith - size; never GitHub-hosted Ubuntu), `MACOS_RUNNER_15`, `_26`, + size; never GitHub-hosted Ubuntu), `MACOS_RUNNER_15`, `_26_LARGE`, `_PR` and `_DUAL_XCODE` to the std owned pool of the lane's Xcode pin (`glaeda-std-xcode-` from `CMUX_CI_XCODE_APP_PR`), `MACOS_RUNNER_DISPLAY` to its gui label, `MACOS_RUNNER_IOS` to `glaeda-ios-sim`, and `CI_PAID_MACOS_OVERFLOW` to `1` so the gated ones are - read. That is the lever pulled by hand on 2026-09-29. Only a variable that + read. That is the lever pulled by hand on 2026-09-29. `MACOS_RUNNER_26` and + `LINUX_RUNNER` are the variables signing jobs read + (`scripts/ci/signing_runner_variables.py`), so the switch never writes a + label other than `blacksmith-*` or `ubuntu-*` to them: `MACOS_RUNNER_26` + has no owned failover, an override naming a reused machine for either is + refused, and a stalled probe never re-applies an older record's owned value + to one (on 2026-10-28 that turned `signing-runner-variables` red on every + pull request). Only a variable that is unset or names a `blacksmith-*` label changes; one someone pointed elsewhere is left alone. Then up to 25 runs holding a job queued 5 minutes or more on a `blacksmith-*` label are force-cancelled (a plain cancel did diff --git a/scripts/ci/check_repo_variables.py b/scripts/ci/check_repo_variables.py index 8503e9d69ef6..c2424d7dbd9e 100755 --- a/scripts/ci/check_repo_variables.py +++ b/scripts/ci/check_repo_variables.py @@ -37,6 +37,7 @@ from runner_label_policy import HOSTED_MACOS_LABEL, PolicyUnreadable, drifted_runner_variables # noqa: E402 from cloud_overflow_switch import (RECORD_VARIABLE, TRUSTED_BLACKSMITH_LABELS, TRUSTED_VARIABLE, # noqa: E402 parse_record) +from signing_runner_variables import allowed_value # noqa: E402 RUNNER_VARIABLES_ENV = "CMUX_CI_RUNNER_VARIABLES" DAEMON_POOL_VARIABLE = "CI_NEXT_DAEMON_POOL" @@ -127,8 +128,11 @@ def problems(env: dict[str, str]) -> list[str]: "Fix: point it at a pool pull requests do not fill, or clear it for the promote pool") found.extend(pin_pool_findings(env.get(PIN_POOL_VARIABLE, "").strip(), daemon_pool, variables)[0]) for name, value, reason in drifted_runner_variables(variables): - if switched.get(name) == value and not HOSTED_MACOS_LABEL.search(value.strip().lower()): - continue # the overflow switch's failover while Blacksmith is down; never a hosted Mac + if (switched.get(name) == value and not HOSTED_MACOS_LABEL.search(value.strip().lower()) + and allowed_value(name, value)): + # The overflow switch's failover while Blacksmith is down; never a hosted Mac, and a + # variable signing jobs read is never excused for naming a reused machine, record or not. + continue found.append(f"{name}={value!r}: {reason}") trusted = variables.get(TRUSTED_VARIABLE, "").strip() if trusted and trusted != "ubuntu-24.04" and trusted not in TRUSTED_BLACKSMITH_LABELS: diff --git a/scripts/ci/cloud_overflow_switch.py b/scripts/ci/cloud_overflow_switch.py index 092af578efb6..1d5849abe19c 100644 --- a/scripts/ci/cloud_overflow_switch.py +++ b/scripts/ci/cloud_overflow_switch.py @@ -42,6 +42,18 @@ elsewhere is left alone. Nothing here touches the lane switches (CI_PR_POOL_OWNED, CI_E2E_OWNED_UI, CI_IOS_OWNED, ...): minis-first routing never changes, only where overflow goes. + +Signing jobs read their runner from the variables in +signing_runner_variables.EPHEMERAL_RUNNER_VARIABLES (LINUX_RUNNER, +MACOS_RUNNER_26), which must only ever name an ephemeral runner (rule 7 of +tests/test_ci_signing_keychain_is_deleted_before_bundle_code.py on +feat-cmux-next, checked live by cmux-next-guards.yml there; the variables are +repository-wide, and this scheduled switch runs from main). The switch +never writes anything else to one: MACOS_RUNNER_26 has no owned failover (its +jobs wait for Blacksmith), an override that names a reused machine for one is +refused, and an older record that still names one as switched to an owned +pool is not re-applied. Turning overflow back on still puts back the value a +record names. """ from __future__ import annotations @@ -64,6 +76,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent)) import pr_runner_pool # noqa: E402 from runner_label_policy import HOSTED_MACOS_LABEL # noqa: E402 +import signing_runner_variables # noqa: E402 API = "https://api.github.com" UTC = dt.timezone.utc @@ -96,13 +109,21 @@ # lane goes through e2e_runner_pool.py, the iOS lane through # MACOS_RUNNER_IOS) and MACOS_RUNNER_BACKGROUND is GitHub-hosted, so neither # is here; CI_CLOUD_FAILOVER can add one. -STD_VARIABLES = ("MACOS_RUNNER_15", "MACOS_RUNNER_26", "MACOS_RUNNER_26_LARGE", "MACOS_RUNNER_PR", - "MACOS_RUNNER_DUAL_XCODE") +# MACOS_RUNNER_26 is not either: signing jobs run on it, so it never names an owned +# mini (SIGNING_VARIABLES below). On 2026-10-28 the failover pointed it at the std +# pool and turned cmux-next-guards.yml's signing-runner-variables red on every PR. +STD_VARIABLES = ("MACOS_RUNNER_15", "MACOS_RUNNER_26_LARGE", "MACOS_RUNNER_PR", "MACOS_RUNNER_DUAL_XCODE") +# The variables signing jobs take their runner from: the switch writes only an +# ephemeral label (blacksmith-* or ubuntu-*) to these, or puts back a recorded value. +SIGNING_VARIABLES = signing_runner_variables.EPHEMERAL_RUNNER_VARIABLES GUI_VARIABLE = "MACOS_RUNNER_DISPLAY" IOS_VARIABLE = "MACOS_RUNNER_IOS" SWITCHED_VARIABLES = (*LINUX_VARIABLES, *STD_VARIABLES, GUI_VARIABLE, IOS_VARIABLE, PAID_OVERFLOW_VARIABLE) # What CI_CLOUD_FAILOVER may name: the workflow passes each one's live value, -# so a restore never guesses what a variable held. +# so a restore never guesses what a variable held. MACOS_RUNNER_26 is not +# one: every value an override could give it is refused (GitHub-hosted, a +# Blacksmith label for a macOS variable, or a reused machine signing jobs +# would run on). OVERRIDABLE_VARIABLES = (*SWITCHED_VARIABLES, "MACOS_RUNNER_TESTS") # Blacksmith Linux started 35,454 jobs on 2026-09-27 with a queue p90 of 13 s; @@ -175,6 +196,11 @@ def parse_record(raw: str | None) -> dict[str, Any] | None: return record +def signing_safe(name: str, value: str | None) -> bool: + """Whether the switch may write `value` to `name`: anything, unless signing jobs read `name`.""" + return signing_runner_variables.allowed_value(name, value) + + def failover_values(xcode_app_pr: str | None, overrides: str | None) -> tuple[dict[str, str], list[str]]: """What each overflow variable points at while Blacksmith is down, and any problems. @@ -221,8 +247,15 @@ def failover_values(xcode_app_pr: str | None, overrides: str | None) -> tuple[di # No job runs on a GitHub-hosted Mac (tests/test_ci_no_github_hosted_macos.py). problems.append(f"{OVERRIDES_VARIABLE} points {name} at {value.strip()}, a GitHub-hosted Mac; " "ignored") + elif not signing_safe(name, value): + problems.append(f"{OVERRIDES_VARIABLE} points {name} at {value.strip()}; signing jobs run on " + f"{name}, so it may only name blacksmith-* or ubuntu-*; ignored") else: values[name] = value.strip() + for name in [name for name, value in values.items() if not signing_safe(name, value)]: + # Nothing above should produce one; this is the backstop the tests pin. + problems.append(f"the failover for {name} is {values.pop(name)}, not an ephemeral runner; signing jobs " + "run on it, so it is left alone") if any(name not in LINUX_VARIABLES for name in values): # MACOS_RUNNER_15, _26 and friends are read only when this is 1. values[PAID_OVERFLOW_VARIABLE] = "1" @@ -236,12 +269,13 @@ def plan_off(current: Mapping[str, str | None], failover: Mapping[str, str]) -> unset (its readers fall back to Blacksmith) or a blacksmith-* label. CI_PAID_MACOS_OVERFLOW changes when it is not already 1. A variable already at its failover is not recorded, so turning overflow back on - never "restores" a value this switch did not set. + never "restores" a value this switch did not set. A variable signing jobs + read never gets a label other than blacksmith-* or ubuntu-*. """ changed: dict[str, dict[str, str | None]] = {} for name, after in failover.items(): before = (current.get(name) or "").strip() or None - if before == after: + if before == after or not signing_safe(name, after): continue if name != PAID_OVERFLOW_VARIABLE and before is not None and not cloud_label(before): continue @@ -284,7 +318,10 @@ def plan_resume(record: Mapping[str, Any], current: Mapping[str, str | None]) -> A value still at the recorded ``before`` value was never switched, so it is safe to apply its recorded failover. Any other value is either already - at ``after`` or was edited by someone else and is left alone. + at ``after`` or was edited by someone else and is left alone. A record + written before signing variables were kept ephemeral may name one with an + owned ``after``; that is never applied (on 2026-10-28 a retry re-applied + MACOS_RUNNER_26 eight minutes after it was put back by hand). """ resumes: list[Resume] = [] for name, change in sorted((record.get("changed") or {}).items()): @@ -297,6 +334,10 @@ def plan_resume(record: Mapping[str, Any], current: Mapping[str, str | None]) -> now = (current.get(name) or "").strip() or None if now == after: continue + if not signing_safe(name, after): + resumes.append(Resume(name, after, f"signing jobs run on {name}, and {after} is not an ephemeral " + "runner; left alone")) + continue if now == before or (now is not None and now == change.get("was")): resumes.append(Resume(name, after)) else: diff --git a/scripts/ci/signing_runner_variables.py b/scripts/ci/signing_runner_variables.py new file mode 100644 index 000000000000..3550f7638063 --- /dev/null +++ b/scripts/ci/signing_runner_variables.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""The repository variables a signing job may take its runner from, and what they may hold. + +A job that holds a signing secret runs on an ephemeral runner (Blacksmith or +GitHub's hosted Linux), never a reused machine +(tests/test_ci_signing_keychain_is_deleted_before_bundle_code.py rule 7). A +few such jobs read their runner from these variables, so the variables may +hold only an ephemeral label, or be unset (their readers then fall back to a +Blacksmith literal). Owned-Mac signing goes through its own routing, never +through one of these. + +This is the one list. Its readers: +- the rule 7 test, which lets a signing job's runs-on read only these; +- cmux-next-guards.yml's signing-runner-variables job, which turns red when + one holds anything else (the rule 7 test asserts it checks exactly these); +- cloud_overflow_switch.py, which never writes a non-ephemeral label to one; +- check_repo_variables.py, which never excuses one holding such a label. + +The rule 7 test and the guard job live on feat-cmux-next. The variables are +repository-wide and the scheduled overflow switch runs from main, so main +carries this list too; keep the two copies the same. +""" + +from __future__ import annotations + +import re + +EPHEMERAL_RUNNER_VARIABLES = ("LINUX_RUNNER", "MACOS_RUNNER_26") +EPHEMERAL_LABEL = re.compile(r"^(blacksmith-|ubuntu-)[a-z0-9.-]+$") + + +def ephemeral_label(value: str | None) -> bool: + """Whether a runner label names an ephemeral runner (blacksmith-* or ubuntu-*).""" + return bool(EPHEMERAL_LABEL.match((value or "").strip())) + + +def allowed_value(name: str, value: str | None) -> bool: + """Whether `name` may hold `value`: any value for other variables; unset or ephemeral for these. + + GitHub reads variable names without regard to case, so this does too. + """ + if (name or "").strip().upper() not in EPHEMERAL_RUNNER_VARIABLES: + return True + return not (value or "").strip() or ephemeral_label(value) diff --git a/tests/test_ci_cloud_overflow_switch.py b/tests/test_ci_cloud_overflow_switch.py index 4d4b2c24cd90..716f3d7fbc78 100644 --- a/tests/test_ci_cloud_overflow_switch.py +++ b/tests/test_ci_cloud_overflow_switch.py @@ -16,6 +16,7 @@ import check_repo_variables as check # noqa: E402 import cloud_overflow_switch as switch # noqa: E402 +import signing_runner_variables as signing # noqa: E402 WORKFLOW = ROOT / ".github" / "workflows" / "ci-cloud-overflow-probe.yml" PIN = "/Applications/Xcode_26.6.app" @@ -140,7 +141,8 @@ def test_overrides_replace_drop_and_refuse(self) -> None: "CI_PR_POOL_OWNED": "0", "MACOS_RUNNER_PR": "macos-15"})) self.assertEqual(values["MACOS_RUNNER_15"], "glaeda-side-std-xcode-26.6") self.assertNotIn("MACOS_RUNNER_26_LARGE", values) - self.assertEqual(values["MACOS_RUNNER_26"], "glaeda-std-xcode-26.6") + # Signing jobs read MACOS_RUNNER_26: no owned failover, and no override may name it. + self.assertNotIn("MACOS_RUNNER_26", values) # A GitHub-hosted Mac is refused like a Blacksmith label: the pool keeps its owned failover. self.assertEqual(values["MACOS_RUNNER_PR"], "glaeda-std-xcode-26.6") self.assertEqual(len(problems), 4) @@ -170,6 +172,96 @@ def test_no_pin_leaves_macos_alone(self) -> None: self.assertEqual(len(problems), 1) +class SigningVariableTests(unittest.TestCase): + """Signing jobs read their runner from these variables; the switch never points one at a reused machine.""" + + PINS = ("/Applications/Xcode_26.6.app", "/Applications/Xcode_27.0.app", "", None) + + def test_the_switch_reads_the_one_list(self) -> None: + self.assertIs(switch.SIGNING_VARIABLES, signing.EPHEMERAL_RUNNER_VARIABLES) + self.assertIn("MACOS_RUNNER_26", switch.SIGNING_VARIABLES) + self.assertIn("LINUX_RUNNER", switch.SIGNING_VARIABLES) + + def test_no_failover_names_a_reused_machine_for_a_signing_variable(self) -> None: + overrides = ("", json.dumps({"MACOS_RUNNER_26": "glaeda-std-xcode-26.6", + "LINUX_RUNNER": "cmux-linux-owned"})) + for pin in self.PINS: + for override in overrides: + values, problems = switch.failover_values(pin, override) + for name in switch.SIGNING_VARIABLES: + if name in values: + self.assertTrue(signing.ephemeral_label(values[name]), (pin, override, name, values[name])) + if override: + self.assertTrue(any("MACOS_RUNNER_26" in p and "ignored" in p for p in problems)) + self.assertTrue(any("signing jobs run on LINUX_RUNNER" in p for p in problems)) + self.assertNotIn("MACOS_RUNNER_26", switch.failover_values(PIN, "")[0]) + + def test_no_override_moves_macos_runner_26(self) -> None: + # Every value one could give it is refused: GitHub-hosted, a Blacksmith label for a macOS + # variable, or a reused machine signing jobs would run on. + for value in ("ubuntu-24.04", "blacksmith-12vcpu-macos-26", "glaeda-std-xcode-26.6"): + values, problems = switch.failover_values(PIN, json.dumps({"MACOS_RUNNER_26": value})) + self.assertNotIn("MACOS_RUNNER_26", values, value) + self.assertEqual(len(problems), 1, value) + + def test_an_ephemeral_linux_override_is_kept(self) -> None: + values, problems = switch.failover_values(PIN, json.dumps({"LINUX_RUNNER": "blacksmith-32vcpu-ubuntu-2404"})) + self.assertEqual((values["LINUX_RUNNER"], problems), ("blacksmith-32vcpu-ubuntu-2404", [])) + + def test_plan_off_never_writes_a_reused_machine_to_a_signing_variable(self) -> None: + # Even a failover map that carries one (an older caller) is filtered. + changed = switch.plan_off({"MACOS_RUNNER_26": "blacksmith-6vcpu-macos-26", "LINUX_RUNNER": None}, + {"MACOS_RUNNER_26": "glaeda-std-xcode-26.6", "LINUX_RUNNER": "ubuntu-24.04"}) + self.assertEqual(changed, {"LINUX_RUNNER": {"before": None, "after": "ubuntu-24.04"}}) + + def test_resume_skips_an_old_record_naming_a_signing_variable(self) -> None: + # 2026-10-28: MACOS_RUNNER_26 was put back by hand, equal to the record's before, and the + # next stalled probe re-applied the owned failover. + record = {"changed": { + "MACOS_RUNNER_26": {"before": "blacksmith-6vcpu-macos-26", "after": "glaeda-std-xcode-26.6"}, + "MACOS_RUNNER_PR": {"before": "blacksmith-6vcpu-macos-26", "after": "glaeda-std-xcode-26.6"}}} + resumes = {item.name: item for item in switch.plan_resume(record, { + "MACOS_RUNNER_26": "blacksmith-6vcpu-macos-26", "MACOS_RUNNER_PR": "blacksmith-6vcpu-macos-26"})} + self.assertTrue(resumes["MACOS_RUNNER_26"].skipped) + self.assertFalse(resumes["MACOS_RUNNER_PR"].skipped) + + def test_a_record_key_in_another_case_is_still_a_signing_variable(self) -> None: + # GitHub reads variable names without regard to case. + record = {"changed": {"macos_runner_26": {"before": None, "after": "glaeda-std-xcode-26.6"}, + "Linux_Runner": {"before": None, "after": "cmux-linux-owned"}}} + resumes = switch.plan_resume(record, {}) + self.assertEqual(len(resumes), 2) + self.assertTrue(all(item.skipped for item in resumes)) + self.assertFalse(signing.allowed_value("macos_runner_26", "glaeda-std-xcode-26.6")) + + def test_restore_still_puts_back_a_recorded_value(self) -> None: + record = {"changed": {"MACOS_RUNNER_26": {"before": "blacksmith-6vcpu-macos-26", + "after": "glaeda-std-xcode-26.6"}}} + restores = switch.plan_on(record, {"MACOS_RUNNER_26": "glaeda-std-xcode-26.6"}) + self.assertEqual([(r.name, r.value, r.skipped) for r in restores], + [("MACOS_RUNNER_26", "blacksmith-6vcpu-macos-26", "")]) + + def test_a_stall_with_an_old_record_never_writes_a_signing_variable(self) -> None: + record = {"since": ago(60), "probe": "blacksmith-4vcpu-ubuntu-2404", "changed": { + "MACOS_RUNNER_26": {"before": "blacksmith-6vcpu-macos-26", "after": "glaeda-std-xcode-26.6"}}} + env = {"VAR_CI_CLOUD_OVERFLOW_SAVED": json.dumps(record), + "VAR_MACOS_RUNNER_26": "blacksmith-6vcpu-macos-26", "VAR_CMUX_CI_XCODE_APP_PR": PIN} + writer = FakeSwitch() + code, _, summary = run_main(env, FakeActions(probe_job(0)), writer) + self.assertEqual((code, writer.writes), (0, [])) + self.assertIn("not an ephemeral runner", summary) + + def test_a_fresh_stall_never_writes_a_signing_variable(self) -> None: + env = {**BLACKSMITH_STEADY, "VAR_MACOS_RUNNER_26": "blacksmith-6vcpu-macos-26"} + writer = FakeSwitch() + code, _, _ = run_main(env, FakeActions(probe_job(0)), writer) + self.assertEqual(code, 0) + record = json.loads(dict(writer.writes)[switch.RECORD_VARIABLE]) + self.assertNotIn("MACOS_RUNNER_26", record["changed"]) + for name, value in writer.writes: + self.assertTrue(signing.allowed_value(name, value), (name, value)) + + class PlanTests(unittest.TestCase): def test_off_changes_only_what_sends_overflow_to_blacksmith(self) -> None: failover, _ = switch.failover_values(PIN, "") @@ -515,6 +607,12 @@ def test_the_switch_failover_is_expected_while_the_record_exists(self) -> None: self.assertTrue(check.problems(self.env(CI_CLOUD_OVERFLOW_SAVED=json.dumps(other)))) self.assertTrue(check.problems(self.env(CI_CLOUD_OVERFLOW_SAVED="not json"))) + def test_a_record_never_excuses_a_reused_machine_in_a_signing_variable(self) -> None: + record = {"changed": {"MACOS_RUNNER_26": {"before": None, "after": "glaeda-std-xcode-26.6"}}} + env = self.env(CI_CLOUD_OVERFLOW_SAVED=json.dumps(record), + CMUX_CI_RUNNER_VARIABLES="MACOS_RUNNER_26=glaeda-std-xcode-26.6\n") + self.assertTrue(any("MACOS_RUNNER_26" in p for p in check.problems(env))) + if __name__ == "__main__": unittest.main()