Skip to content
7 changes: 6 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3448,7 +3448,12 @@ jobs:
# while `attempt` is the run's own attempt (a re-run of failed jobs that keeps this job takes
# `alternate`). Outside attempt 1 of a push (the rescue's workflow_run watch) it stands only once
# the owned-pool-watch marker is uploaded, as pick-nightly-build-runner's does.
owned: ${{ (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}
# The all-nightly reservation is the first owned choice for the secret-free
# verify and DMG-image jobs. It is deliberately an exact capability check:
# an unset, stale or foreign value falls through to the normal owned picker.
# Release-pool signing jobs consume sign_owned instead and keep their
# existing keychain and claim contract.
owned: ${{ github.repository == 'manaflow-ai/cmux' && github.ref_name == 'nightly-next' && github.run_attempt == 1 && vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro' && vars.CI_NIGHTLY_ONLY_RUNNER || (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Use the full branch ref here so a manually dispatched tag named nightly-next cannot receive the reserved NEXT-only runner. Otherwise this regular nightly run also selects the reserved label and PR Xcode configuration, contrary to the fallback behavior for other tracks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/nightly.yml, line 4065:

<comment>Use the full branch ref here so a manually dispatched tag named `nightly-next` cannot receive the reserved NEXT-only runner. Otherwise this regular nightly run also selects the reserved label and PR Xcode configuration, contrary to the fallback behavior for other tracks.</comment>

<file context>
@@ -4057,7 +4057,12 @@ jobs:
+      # an unset, stale or foreign value falls through to the normal owned picker.
+      # Release-pool signing jobs consume sign_owned instead and keep their
+      # existing keychain and claim contract.
+      owned: ${{ github.repository == 'manaflow-ai/cmux' && github.ref_name == 'nightly-next' && github.run_attempt == 1 && vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro' && vars.CI_NIGHTLY_ONLY_RUNNER || (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}
       # A drained (or draining) owned Mac for the release signing jobs (sign-nightly-identity-legacy), as the JSON runs-on
       # array scripts/ci/signing_runner.py prints, or empty, under the same marker and `attempt` rules as `owned`.
</file context>
Suggested change
owned: ${{ github.repository == 'manaflow-ai/cmux' && github.ref_name == 'nightly-next' && github.run_attempt == 1 && vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro' && vars.CI_NIGHTLY_ONLY_RUNNER || (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}
owned: ${{ github.repository == 'manaflow-ai/cmux' && github.ref == 'refs/heads/nightly-next' && github.run_attempt == 1 && vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro' && vars.CI_NIGHTLY_ONLY_RUNNER || (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}

# A drained (or draining) owned Mac for the release signing jobs (sign-nightly-identity-legacy), as the JSON runs-on
# array scripts/ci/signing_runner.py prints, or empty, under the same marker and `attempt` rules as `owned`.
sign_owned: ${{ (github.event_name == 'push' && github.run_attempt == 1 || steps.upload-marker.outcome == 'success') && steps.sign-owned.outputs.owned || '' }}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_ci_signing_owned_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,12 @@ def test_the_picker_runs_when_only_the_legacy_sign_does(self) -> None:
self.assertTrue(self.value(self.PICK, "if", {"needs.prepare-nightly-variant.result": "success"}))
outputs = self.jobs[self.PICK]["outputs"]
self.assertEqual(str(outputs["attempt"]).strip(), "${{ github.run_attempt }}")
# Any attempt's pick stands (attempt 1 of a push, or once the sweeper's marker is up), as `owned` does.
self.assertEqual(str(outputs["sign_owned"]).replace("sign-owned", "owned"), str(outputs["owned"]))
# The secret-free verify pick may opt into the all-nightly reservation,
# while credentialed legacy signing keeps the separate claim-capable
# `sign_owned` output. Both outputs still stand on their marker rules.
self.assertIn("steps.sign-owned.outputs.owned", str(outputs["sign_owned"]))
self.assertNotIn("CI_NIGHTLY_ONLY_RUNNER", str(outputs["sign_owned"]))
self.assertIn("CI_NIGHTLY_ONLY_RUNNER", str(outputs["owned"]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: These substring checks no longer enforce the marker predicates described by the test. Assert each output against its complete expected expression so retries cannot claim stale picks and the reservation remains restricted to its valid scope.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/test_ci_signing_owned_mac.py, line 482:

<comment>These substring checks no longer enforce the marker predicates described by the test. Assert each output against its complete expected expression so retries cannot claim stale picks and the reservation remains restricted to its valid scope.</comment>

<file context>
@@ -474,8 +474,12 @@ def test_the_picker_runs_when_only_the_legacy_sign_does(self) -> None:
+        # `sign_owned` output. Both outputs still stand on their marker rules.
+        self.assertIn("steps.sign-owned.outputs.owned", str(outputs["sign_owned"]))
+        self.assertNotIn("CI_NIGHTLY_ONLY_RUNNER", str(outputs["sign_owned"]))
+        self.assertIn("CI_NIGHTLY_ONLY_RUNNER", str(outputs["owned"]))
 
 
</file context>

self.assertIn("steps.sign-owned.outputs.owned_pool", str(outputs["sign_owned_pool"]))


Expand Down
28 changes: 28 additions & 0 deletions tests/test_nightly_dedicated_mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
EARLY = ("decide", "resolve-nightly-cmux-tui-client", "resolve-nightly-ghostty-cli-helper",
"build-nightly-inputs", "find-nightly-next-recovery", "pick-nightly-build-runner",
"build-nightly-ghostty-cli-helper")
VERIFY_OWNED = ("verify-signed-nightly", "verify-final-dmg-nightly", "signer-dmg-image")
DOC = yaml.safe_load((ROOT / ".github/workflows/nightly.yml").read_text())


Expand Down Expand Up @@ -164,6 +165,33 @@ def test_builder_variable_is_validated_and_mints_the_read_token_only_when_set(se
def test_linux_elf_signer_does_not_take_the_mac_reservation(self):
self.assertNotIn(VARIABLE, DOC["jobs"]["signer-build"]["runs-on"])

def test_sign_picker_prefers_reservation_for_secret_free_mac_consumers(self):
output = DOC["jobs"]["pick-nightly-sign-runner"]["outputs"]["owned"]
expression = parse_expression(output.removeprefix("${{").removesuffix("}}"))
valid = context(**{"github.ref_name": "nightly-next",
"steps.owned.outputs.owned": "glaeda-side-std-xcode-26.6"})
self.assertEqual(evaluate(expression, valid), LABEL)
self.assertEqual(evaluate(expression, {**valid, "github.event_name": "workflow_dispatch"}), LABEL)
# A bad variable, fork, other track or retry falls through to the normal
# owned picker (or an empty output); it can never widen the reservation.
self.assertEqual(evaluate(expression, {**valid, VARIABLE: "glaeda-unregistered"}),
"glaeda-side-std-xcode-26.6")
for changes in ({VARIABLE: "", "steps.owned.outputs.owned": "glaeda-side-std-xcode-26.6"},
{"github.run_attempt": 2},
{"github.repository": "other/cmux", "github.repository_owner": "other"},
{"github.ref_name": "main"}):
with self.subTest(changes=changes):
self.assertNotEqual(evaluate(expression, {**valid, **changes}), LABEL)

for job in VERIFY_OWNED:
source = DOC["jobs"][job]["runs-on"]
selected_job = evaluate(parse_expression(source.removeprefix("${{").removesuffix("}}")),
{**valid,
"needs.pick-nightly-sign-runner.outputs.attempt": "1",
"needs.pick-nightly-sign-runner.outputs.owned": LABEL,
"vars.CI_PR_POOL_OWNED": "1"})
self.assertEqual(selected_job, LABEL, job)


if __name__ == "__main__":
unittest.main()
8 changes: 5 additions & 3 deletions tests/test_nightly_sign_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,11 @@ def test_no_job_that_holds_a_secret_reads_the_owned_pick(self) -> None:
def test_the_owned_pick_is_bounded_and_never_blocks(self) -> None:
job = WORKFLOW["jobs"]["pick-nightly-sign-runner"]
# Outside attempt 1 of a push the pick stands only with the sweeper's marker uploaded.
self.assertEqual(job["outputs"]["owned"],
"${{ (github.event_name == 'push' && github.run_attempt == 1 || "
"steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}")
owned_output = job["outputs"]["owned"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This weakens the regression test enough to allow retries to route to the reserved or legacy owned runner. Restore an exact assertion, or assert each attempt/event gate and its grouping, so a future routing change cannot bypass the attempt-1 and marker safeguards unnoticed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/test_nightly_sign_runner.py, line 584:

<comment>This weakens the regression test enough to allow retries to route to the reserved or legacy owned runner. Restore an exact assertion, or assert each attempt/event gate and its grouping, so a future routing change cannot bypass the attempt-1 and marker safeguards unnoticed.</comment>

<file context>
@@ -581,9 +581,11 @@ def test_no_job_that_holds_a_secret_reads_the_owned_pick(self) -> None:
-        self.assertEqual(job["outputs"]["owned"],
-                         "${{ (github.event_name == 'push' && github.run_attempt == 1 || "
-                         "steps.upload-marker.outcome == 'success') && steps.owned.outputs.owned || '' }}")
+        owned_output = job["outputs"]["owned"]
+        self.assertIn("vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro'", owned_output)
+        self.assertIn("github.repository == 'manaflow-ai/cmux'", owned_output)
</file context>

self.assertIn("vars.CI_NIGHTLY_ONLY_RUNNER == 'glaeda-nightly-only-m4pro'", owned_output)
self.assertIn("github.repository == 'manaflow-ai/cmux'", owned_output)
self.assertIn("github.ref_name == 'nightly-next'", owned_output)
self.assertIn("steps.owned.outputs.owned", owned_output)
self.assertEqual(job["outputs"]["attempt"], "${{ github.run_attempt }}")
# The routing environment only scopes the routing App key; it has no reviewers, so nothing waits.
self.assertEqual(job.get("environment"), "ci-routing-agent")
Expand Down