H13: Say which part of the world differs when a soak hash does

When a client's world hash differs from the server's, the soak report
now names the part that differs (tide, props, pieces or loot), the
client's ClientWorld tick, and each piece whose entry differs on the
two sides, so the next transient mismatch can be traced.

- NetWorld.world_detail(): part hashes and a piece list. world_hash()
  is unchanged: the same bytes, hashed in four parts.
- The server's world_hash log lines and the soak clients' hash lines
  carry the detail.

A full soak with this (24 clients, 2 matches) compared 3,743 hashes
with 0 differing, so the mismatch didn't come back to trace yet.

Refs #80

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:46:35 -05:00
co-authored by Claude Opus 5.5
parent 8505216568
commit 0ddcb48ea0
5 changed files with 127 additions and 29 deletions
+3 -2
View File
@@ -11,7 +11,8 @@
## client whose world has drifted is caught.
##
## Prints JSON lines:
## {"event":"hash", "client", "match", "sim_tick", "hash"}: the client's world hash on
## {"event":"hash", "client", "match", "sim_tick", "hash", "detail", "replica_tick"}: the
## client's world hash (with NetWorld.world_detail() and its ClientWorld's tick) on
## the snapshots where the server logs its own (--world-hash-every on the server, the
## same N as --hash-every here), when the client's world has caught up exactly.
## {"event":"client_match", "client", "match", ...}: a client's prediction statistics
@@ -206,7 +207,7 @@ func _sample(client: Dictionary) -> void:
if int(client["number"]) == _tamper and game.playing() and game.world.props.count() > 0:
_tamper = -1
game.world.props.health[0] -= 1
print(JSON.stringify({"event": "hash", "client": client["number"], "match": game.match_index, "sim_tick": tick, "hash": NetWorld.world_hash(game.world)}))
print(JSON.stringify({"event": "hash", "client": client["number"], "match": game.match_index, "sim_tick": tick, "hash": NetWorld.world_hash(game.world), "detail": NetWorld.world_detail(game.world), "replica_tick": game.replica.tick}))
func _finish() -> void:
+40 -1
View File
@@ -118,8 +118,10 @@ func check(server: Array[Dictionary], clients: Array[Dictionary], client_count:
result["client_mem_growth_bytes"] = _client_growth(clients)
# The world, compared hash by hash.
var server_hashes: Dictionary = {}
var server_detail: Dictionary = {}
for record: Dictionary in _all(server, "world_hash"):
server_hashes[Vector2i(int(record["match"]), int(record["sim_tick"]))] = String(record["hash"])
server_detail[Vector2i(int(record["match"]), int(record["sim_tick"]))] = record.get("detail", {})
var compared: int = 0
var differ: int = 0
var per_client: Dictionary = {}
@@ -132,7 +134,7 @@ func check(server: Array[Dictionary], clients: Array[Dictionary], client_count:
if server_hashes[key] != String(record["hash"]):
differ += 1
if differ <= 5:
_fail("client %d's world differs from the server's in match %d at tick %d" % [record["client"], key.x, key.y])
_fail("client %d's world differs from the server's in match %d at tick %d (replica tick %s): %s" % [record["client"], key.x, key.y, record.get("replica_tick", "?"), describe_difference(server_detail.get(key, {}), record.get("detail", {}))])
result["hashes_compared"] = compared
result["hashes_differing"] = differ
if differ > 5:
@@ -233,3 +235,40 @@ func _all(lines: Array[Dictionary], event: String) -> Array[Dictionary]:
func _count(lines: Array[Dictionary], event: String) -> int:
return _all(lines, event).size()
## Which parts of two NetWorld.world_detail() records differ, and for the pieces, each
## piece whose entry differs, as "id: server [...] client [...]" (at most eight).
static func describe_difference(server: Dictionary, client: Dictionary) -> String:
if server.is_empty() or client.is_empty():
return "no detail logged"
var parts: Array[String] = []
for name: String in ["tide", "props", "pieces", "loot"]:
if String(server.get(name, "")) != String(client.get(name, "")):
parts.append(name)
var notes: Array[String] = ["parts differing: %s" % (", ".join(parts) if not parts.is_empty() else "none")]
var theirs: Dictionary = {}
for entry: Array in client.get("piece_list", []):
theirs[int(entry[0])] = entry
var ours: Dictionary = {}
for entry: Array in server.get("piece_list", []):
ours[int(entry[0])] = entry
var ids: Dictionary = {}
for piece_id: int in ours:
ids[piece_id] = true
for piece_id: int in theirs:
ids[piece_id] = true
var sorted: Array = ids.keys()
sorted.sort()
var shown: int = 0
for piece_id: int in sorted:
var server_entry: Variant = ours.get(piece_id)
var client_entry: Variant = theirs.get(piece_id)
if server_entry != null and client_entry != null and str(server_entry) == str(client_entry):
continue
shown += 1
if shown <= 8:
notes.append("piece %d: server %s client %s" % [piece_id, str(server_entry), str(client_entry)])
if shown > 8:
notes.append("and %d more pieces" % (shown - 8))
return "; ".join(notes)