diff --git a/docs/parity-workflow.md b/docs/parity-workflow.md index 73ac5c47c..5c83c6a33 100644 --- a/docs/parity-workflow.md +++ b/docs/parity-workflow.md @@ -44,6 +44,8 @@ Harnesses can also run on the Mac mini, the desktop and playhorizon (`tools/pari Harnesses a host can't run are listed in the file: `local_only` (`save_roundtrip` runs the game on a virtual screen) and each host's `exclude`. The Mac excludes nothing: vanilla's `Math.sin`, `pow`, `log` and the like don't round the same on an Apple silicon Mac as on Linux (HotSpot uses fdlibm there, Intel's stubs on x86-64), and Rust's float functions round like neither (they call the platform libm), so code that mirrors a vanilla `Math` call uses `horizon_core::jmath`, which computes what HotSpot computes on the host architecture. The ThinkPad no longer runs harnesses (2026-10-26): playhorizon is the Linux host that is always on. +The file's `solo` list names harnesses that drive game windows (`remote_fireworks`, `server_player_sculk`, `world_reopen`, ...). On a machine where `parity.py` has 4 CPUs or fewer, such as playhorizon's CI runner, each of them runs alone, after the others: there frames are drawn on the CPU, and beside other harnesses a screenshot or a control request took more ticks than the check allows. `PARITY_SOLO=1` or `0` forces this on or off. + ### Any command on playhorizon: `tools/remote.sh` For Linux work that doesn't need a whole parity run (a crate's tests, a few harnesses, a server build), `tools/remote.sh ` runs the command on playhorizon at the worktree's commit and streams its output back; its exit status is the command's. Commit and push first: the host fetches the commit from GitHub, and nothing else leaves this machine (no files, no credentials, no environment). Each worktree keeps one checkout there, `~/remote-work/` with its own `target/`, so the next run only rebuilds what changed, and one run per name goes at a time. The command runs niced in the host's CI slice, pinned to CPUs 0-3 (`--cpus`): the CI runner has 4-7, so these runs never slow a pull request's parity job. A benchmark asks for its CPUs with `--cpus 0-3 --exclusive` (and says so in its pull request): it starts only when no other run uses them, and later runs wait for it to end. The command gets scratch game and launcher homes and the vanilla data linked as CI links it; a command naming `parity`, `lan_e2e` or `horizon-prepare` also gets `.local/horizon-client`, prepared as CI prepares it. Whatever the command leaves running (a game, a daemon) is stopped when it ends, and stopping `remote.sh` (or losing the connection) stops the command on the host. Logs stay in `~/remote-work/.logs/`; `--list` shows the checkouts, `--gc [DAYS]` removes old ones. diff --git a/tests/test_parity_runner.py b/tests/test_parity_runner.py index 39d3cc783..fdc636a24 100644 --- a/tests/test_parity_runner.py +++ b/tests/test_parity_runner.py @@ -399,6 +399,38 @@ class KnownFlakyTests(unittest.TestCase): self.assertTrue(set(flaky) <= {parity.base_name(name) for name in parity.harnesses()}) + +class SoloTests(unittest.TestCase): + """Harnesses driving game windows run alone on a small machine (playhorizon's 4-CPU runner).""" + + def executor(self, running): + with tempfile.TemporaryDirectory() as tmp, mock.patch.object(parity, "STATE_DIR", Path(tmp)): + local = parity.LocalExecutor(4, 1 << 40, 60) + local.solo = {"remote_fireworks"} + local.running = {label: {} for label in running} + return local + + def test_a_solo_harness_waits_for_an_empty_machine_and_then_holds_it(self): + busy = self.executor(["food"]) + self.assertFalse(busy.accepts("remote_fireworks")) + self.assertTrue(busy.accepts("light")) + self.assertEqual(busy.free(), 3) + self.assertTrue(self.executor([]).accepts("remote_fireworks")) + alone = self.executor(["remote_fireworks~2"]) + self.assertEqual(alone.free(), 0) + + def test_only_small_machines_and_listed_harnesses(self): + config = {"solo": {"remote_fireworks": "two game windows"}} + with mock.patch.dict(os.environ, {"PARITY_SOLO": "1"}): + self.assertEqual(parity.solo_harnesses(config), {"remote_fireworks"}) + with mock.patch.dict(os.environ, {"PARITY_SOLO": "0"}): + self.assertEqual(parity.solo_harnesses(config), set()) + with mock.patch.dict(os.environ, {"PARITY_SOLO": ""}), mock.patch.object(parity, "SOLO_CPUS", 10 ** 6): + self.assertEqual(parity.solo_harnesses(config), {"remote_fireworks"}) + solo = parity.host_config().get("solo", {}) + self.assertTrue(solo and set(solo) <= {parity.base_name(name) for name in parity.harnesses()}) + + if __name__ == "__main__": unittest.main() diff --git a/tools/parity.py b/tools/parity.py index cd8d1e2f6..38d113cab 100644 --- a/tools/parity.py +++ b/tools/parity.py @@ -800,16 +800,21 @@ class LocalExecutor: self.name, self.jobs, self.memory_budget, self.timeout = HOST, jobs, memory_budget, timeout self.max_peak = max_peak # set while other machines can take heavier harnesses self.running = {} + self.solo = set() # harnesses that run alone here (solo_harnesses) self.dead = False # this machine never drops out, unlike a remote host self.available, self.measured = 0, 0.0 (STATE_DIR / "logs").mkdir(parents=True, exist_ok=True) (STATE_DIR / "traces").mkdir(parents=True, exist_ok=True) def free(self): + if any(harness_of(label) in self.solo for label in self.running): + return 0 return self.jobs - len(self.running) def accepts(self, name): - return True + # A solo harness waits until nothing else runs here; the others fill the slots meanwhile, so solo ones + # run last, alone. + return name not in self.solo or not self.running def fits(self, expected, only_here=True): """Admission by recorded peak, within the budget and leaving MEMORY_RESERVE of what is free now. @@ -1462,6 +1467,21 @@ def known_flaky(config): return dict(config.get("known_flaky", {})) +def solo_harnesses(config): + """Harnesses tools/parity_hosts.json's "solo" lists ({name: reason}: those driving game windows, whose frames + are drawn on the CPU on Linux runners) run alone on a machine with SOLO_CPUS CPUs or fewer for this process + (playhorizon's runner has 4): beside other harnesses there they lose ticks between control requests. The set, + or an empty one on a bigger machine. PARITY_SOLO=1 or 0 forces it on or off.""" + forced = os.environ.get("PARITY_SOLO") + cpus = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else os.cpu_count() or 1 + if forced == "0" or forced != "1" and cpus > SOLO_CPUS: + return set() + return set(config.get("solo", {})) + + +SOLO_CPUS = 4 + + def named_only(config): """Harnesses tools/parity_hosts.json keeps out of every automatic selection (--changed, --failed, the default, --flake-check): they run only when named or with --all, the nightly audit. {name: reason}""" @@ -1640,6 +1660,10 @@ def main(): reuse_oracles = not (args.fresh or args.all) local = LocalExecutor(jobs, int(memory_available() * 0.75), args.timeout, REMOTE_LOCAL_PEAK if remotes and args.jobs is None else None) + local.solo = solo_harnesses(config) + if local.solo & {harness_of(name) for name in selected}: + print(f"Alone on this machine ({SOLO_CPUS} CPUs or fewer), after the others: " + f"{', '.join(sorted(local.solo & {harness_of(name) for name in selected}))}", flush=True) results, elapsed = run(selected, state, hasher, environment_key(hasher), [*remotes, local], reuse_oracles, rounds, known_flaky(config)) finally: diff --git a/tools/parity_hosts.json b/tools/parity_hosts.json index 29815a9f6..cec022194 100644 --- a/tools/parity_hosts.json +++ b/tools/parity_hosts.json @@ -40,6 +40,12 @@ "save_roundtrip": "runs the game on a virtual screen (vscreen) with a null ALSA device, or offscreen in the logged-in macOS session" }, "linux_only": {}, + "solo": { + "remote_fireball": "two game windows (lan_e2e); on 4 CPUs beside other harnesses, screenshots and control requests take ticks the check needs", + "remote_fireworks": "two game windows (lan_e2e); a screenshot took ~1.5 s beside 3 other harnesses on playhorizon's runner, past the sparks' life (2026-10-27)", + "server_player_sculk": "two game windows (lan_e2e); failed on playhorizon's runner beside other harnesses, passes alone (2026-10-27)", + "world_reopen": "a game window reopening a world: failed on playhorizon's runner beside other harnesses (2026-10-27)" + }, "named_only": { "lan_integration": "the whole lan_e2e suite: ~40 min a run on a loaded runner, and single checks flake under load; run it by name, or tools/lan_e2e.py" },