r/javascript • u/Fair-Process-7291 • 10d ago
AskJS [AskJS] I compare full move logs instead of a hash to prove two bots played the same games. Overkill?
Bots in my game sim (TypeScript, built with Cline) kept printing identical rows. Equal averages can be a coincidence, so I didn't want the lab saying "these bots played the same" unless they actually did. So every move gets logged as a short string: `B:ticker:cents` for a buy, `S:holdingId` for a sell, `K` for a skip. Moves are joined with commas, all 1,000 games with newlines, and two bots only match if the whole strings are equal.
I skipped hashing mostly because the result ends up in posts and I didn't want a collision to be possible at all. Yeah, SHA-256 collisions aren't a real risk. The better reason is probably debugging. Factorio's old desync post does a CRC every tick so they know the first tick where two runs split. A hash just tells you "different."
Would you have hashed it? And if you keep logs, do you store the whole thing or just enough to find the first diff?
1
u/sereikis 9d ago
i'd keep the logs, but test what equality actually proves: replay the same moves from two different starting portfolios and check whether your report still calls them identical games. if you mean identical state transitions rather than identical choices, include the initial state, simulator version, and any random or external inputs in the comparison too.
1
u/DullCollege6507 7d ago
Comparing the logs directly seems reasonable if they're already small enough to keep. You also retain the useful part: the first move where the runs diverge. A hash doesn't replace that debugging record.
One thing I'd check before worrying about SHA-256 collisions is the encoding. Can a ticker or holding ID contain a comma, colon or newline? If so, concatenating fields can make different records serialize identically. For this narrow schema, fixed-position arrays such as ["B", ticker, cents], ["S", holdingId] and ["K"], serialized as a JSON array of moves, avoid delimiter ambiguity. Validate the field types and integer cents too.
If the logs eventually become expensive to compare or transfer, per-game hashes would let you locate a differing game, then inspect its original moves. Until then, I'd keep the exact comparison and logs.
2
u/ZnV1 10d ago
How many users do you have?