Repository navigation
178 deterministic sim 23 determinism in ci
Question: after stage S6.4d no simulation file holds a float, and the determinism check agrees with itself on one Windows machine: a match recorded, then replayed in the same process and in a second Godot process, gives the same state hash on every tick. Netplay needs more than that. Two peers on different operating systems, or one in a browser, must turn the same input words into the same state. Does the simulation give the same hashes on Linux, on Windows and in a web build, and how does every change to the engine keep proving it (document 155, issue #133)?
The deterministic simulation series: document 155 is the plan. Documents 156 to 160 are stages S0 to S4, documents 161 to 170 are S5, and documents 171 to 177 took the last floats out of the simulation files (S6.1 to S6.4d). This document is S6.5, the last part of S6: the check in CI.
There is nothing to trace in this stage: it adds no simulation code. It runs the S0 check (document 156) on more machines.
| Term | Meaning |
|---|---|
| input log |
InputLog (document 156): the match's setup (level, seed, tick count) and every player's input word for every tick. It is all a netplay peer would receive. |
state hash, SimHash
|
A 64-bit digest of every simulated value after a tick (document 156). Two runs agree when every tick's hash is equal. |
| recording | A computer-vs-computer match played once: its input log and its per-tick hashes. |
| replay | A fresh match fed the recording's input log: no computer player runs, only the words. |
| web export | The engine's test harness built for the browser (WebAssembly), single-threaded. |
| runner | A GitHub Actions machine: ubuntu-latest (Linux x86-64) or windows-latest. |
- One recording, replayed everywhere. The Linux job records the harness's match (1500 ticks, both computer players driving and shooting, a squad of soldiers throwing grenades). It then replays the log in a fresh Linux process. The Windows job replays the same log, and so does a web export in headless Chromium. A last job compares every replay's 1500 hashes with the recording's and names the first tick that differs.
- The whole check runs on both desktop systems. Linux and Windows each run the full S0 check (record, replay twice in one process with noise on the global generator, replay in a second process), and Linux runs the float lint, whose allow-list is empty.
-
The browser shares the desktop's match. The match's setup moved out of
determinism_check.gdintotests/determinism/determinism_match.gd, so the web replay builds exactly the same match. Vehicles and soldiers are now placed with integer positions. - The result: all 1500 hashes agree on Linux, on Windows and in the browser. The recording made on the Linux runner is also hash for hash the recording made on a Windows desktop, computer players included.
That meets document 155's condition for S6: the check runs in CI on Linux and Windows runners and in a web export in a headless browser, comparing every platform's per-tick hashes for the same recording, and the float lint's allow-list is empty. S6 is done.
Mermaid source
flowchart TB
R["record (Linux)<br/>float lint<br/>determinism check<br/>record 1500 ticks<br/>replay in a new process"] --> W["windows<br/>determinism check<br/>replay the Linux log"]
R --> B["web<br/>export the harness<br/>replay the Linux log<br/>in headless Chromium"]
R --> C["compare<br/>linux, windows, web<br/>against recorded.txt"]
W --> C
B --> C
The engine's .github/workflows/determinism.yml runs on every push to main, on pull requests and by hand. It holds four jobs:
| Job | Runner | What it does | What it passes on |
|---|---|---|---|
record |
ubuntu-latest | Installs Godot, runs float_lint_check and determinism_check through tools/run_tests.sh, then determinism_check.gd -- --record and -- --child on the recorded log |
recording: determinism_log.json, recorded.txt, linux.txt
|
windows |
windows-latest | Runs determinism_check and -- --child on the Linux log |
windows: windows.txt
|
web |
ubuntu-latest | Installs Godot and its export templates, tools/ci/web_export.sh, then tools/ci/web_replay.mjs in Playwright's Chromium |
web: web.txt
|
compare |
ubuntu-latest | Compares each of the three hash files with recorded.txt, line by line |
fails on the first difference |
Godot is the official build of the version the games use (GODOT_VERSION: 4.7.2-stable), downloaded from godotengine/godot-builds by tools/ci/install_godot.sh. On Windows it is the console build, so its output reaches the log.
The check's match used to live inside determinism_check.gd, an extends SceneTree script that the web build cannot run as its main loop. The match now lives in a RefCounted script with static functions that both sides call:
# Engine tests/determinism/determinism_match.gd
static func new_match(pack: Pack, parent: Node, replay: InputLog, ticks: int) -> Array:
seed(SEED)
var level := LevelData.new()
level.load_from(pack.level_dir("LEVEL01"))
...
var tsz := pack.tile_size_px
mc.slots[0].vehicle.pos_fx = Vector2i(5 * tsz + tsz / 2, 8 * tsz + tsz / 2) * 65536
mc.slots[0].vehicle.heading_fx = 0x100000 # east
mc.slots[1].vehicle.pos_fx = Vector2i(10 * tsz + tsz / 2, 8 * tsz + tsz / 2) * 65536
mc.slots[1].vehicle.heading_fx = 0x300000 # west
for k in SOLDIERS: # a squad of each side's soldiers between the two vehicles, each nearer the other side's
var c := Vector2i(8 - k % 2, 6 + k)
mc._new_soldier((c * tsz + Vector2i(tsz / 2, tsz / 2)) * 65536, k % 2)
var ilog := InputLog.attach(mc, replay)
...The old code placed the vehicles through the float views (position = (Vector2(5, 8) + Vector2(0.5, 0.5)) * tsz, heading_deg = 0.0). The views round to the same integers, so the hashes did not change. The new placement just doesn't depend on the views.
determinism_check.gd keeps its checks and calls DM.new_match, DM.load_pack and DM.dispose. It gains one mode for CI:
# Engine tests/determinism_check.gd
## One recorded match (the computer players play), for the CI workflow: its input log saved to `log_path`, its per-tick hashes to `out_path`.
func _record(log_path: String, out_path: String) -> int:
var m := _new_match()
var hashes := _run(m[0])
var ilog: InputLog = m[1]
_dispose(m)
print("recorded %d ticks: %s" % [hashes.size(), _action])
ilog.save(log_path)
...-- --child <log> <out> was already there (the second-process replay of document 156); the Windows job and the Linux job's own replay use it unchanged.
tools/ci/web_export.sh builds a bare project next to the checkout, .webharness/, like tools/run_tests.sh's .harness/: a project.godot whose main scene is tests/determinism/determinism_web.tscn, a link back to the engine as addons/openfire_engine, the recording's input log copied in as res://determinism_log.json (exported by an include filter), and a Web export preset without thread support. A single-threaded build needs no cross-origin isolation headers, so any static file server can serve it.
The main scene replays the log and hands the hashes to the page:
# Engine tests/determinism/determinism_web.gd
func _ready() -> void:
await get_tree().process_frame
var pack := DM.load_pack()
var ilog := InputLog.load_from(LOG)
...
var m := DM.new_match(pack, self, ilog, ticks)
var out := DM.hashes(m[0], ticks)
DM.dispose(m)
_finish("\n".join(out), "")
func _finish(hashes: String, error: String) -> void:
...
if OS.has_feature("web"):
JavaScriptBridge.eval("window.ofError = %s; window.ofHashes = %s;" % [JSON.stringify(error), JSON.stringify(hashes)], true)tools/ci/web_replay.mjs opens the page in Playwright's headless Chromium. Godot's web build draws with WebGL 2 and a runner has no GPU, so Chromium renders in software (SwiftShader). The script waits for window.ofHashes and writes it to a file, one hash a line. The fixture pack is built into user:// at start-up, which the web build keeps in the browser's storage, so the replay reads no files from the server except the log.
The compare job downloads the three jobs' artifacts and checks linux.txt, windows.txt and web.txt against recorded.txt. Any difference fails the run with the first differing line and the file's tick count:
if cmp -s <(grep . "$ref") <(grep . "$f"); then
echo "ok $f: all $n ticks agree"
else
first=$(diff <(grep . "$ref") <(grep . "$f") | head -1)
echo "::error::$f differs from the recording (first difference: $first; it has $(grep -c . "$f") ticks)"
fail=1
fiThe comparison says which tick and which platform. To see which part of the state differs, run the replay of that log locally: determinism_check.gd's _explain dumps the hashed lines at a tick (document 156).
- The new placement: the match recorded with
-- --recordon Windows gives the same 1500 hashes as the S6.4d golden (document 177), so moving the setup changed nothing. -
-- --childon that log, in a new process: all 1500 hashes agree. - The web export, built on Windows with
tools/ci/web_export.shand opened in a Chromium-based browser from a local file server, replayed the log in the page:window.ofHashesheld 1500 hashes, all equal to the recording's. - Engine suite: all 61 checks pass, no script errors. (The new scripts sit in
tests/determinism/, so the suite, which runstests/*.gd, does not run them as checks.)
The run on engine 77d3dba (run 44876386394) passed every job:
the recording: 1500 ticks
ok all/recording/linux.txt: all 1500 ticks agree
ok all/windows/windows.txt: all 1500 ticks agree
ok all/web/web.txt: all 1500 ticks agree
The recording job's own check printed the same action as on the desktop: shot_ticks 681, both vehicles hit, 2 deaths, the vehicles moved 236.76 tiles, 6 soldiers moved, 3 grenades thrown. The recording's hashes, downloaded from the run, are identical to the ones recorded on Windows. The computer players are float code (they are not part of the simulation), yet they chose the same words on both systems. That is a bonus, not a requirement: in netplay only one peer runs each of them.
The jobs take about a minute and a half each; the whole run takes about 3 minutes, the Windows and web jobs in parallel. (The run before it, at a76b5f9, passed too; the only change since moved the workflow to the Node 24 versions of GitHub's checkout and artifact actions.)
-
One recording. CI replays one match on the synthetic fixture: everything that match exercises (driving, turning, shells, hits, deaths, soldiers, grenades). The Heli, the Drones, mines and the original pack's maps are covered by the desktop checks of S5 and S6, not across platforms. More recordings can join the
recordjob later. S7's test game brings its own (document 155's S7: a game with no copyrighted assets, so CI can play its real levels). - x86-64 only. The runners are x86-64; an ARM machine (a Mac, a phone browser) is not in the run. The simulation uses only integer arithmetic, so the architecture should not matter, but it is not tested.
- The computer players run only in the recording. A replay takes their words, as a netplay peer would (document 155's "The computer players are not on this list").
- Engine
.github/workflows/determinism.yml: the four jobs. - Engine
tools/ci/install_godot.sh,tools/ci/web_export.sh,tools/ci/web_replay.mjs. - Engine
tests/determinism/determinism_match.gd(load_pack,new_match,hashes,dispose,soldier_table),tests/determinism/determinism_web.gd+.tscn. - Engine
tests/determinism_check.gd:-- --record, and the match taken fromdeterminism_match.gd.
Commits: engine a76b5f9, 77d3dba; openfire 4e675f3.
S6.5 is done, and with it S6: the simulation gives the same hashes on Linux, Windows and in the browser, and CI checks it on every push. Next: S7, a test game with no copyrighted assets made with the modding tools, before netplay (Phase 5); its audit is document 179.
Return Fire, rebuilt
Elsewhere