r/javascript • • 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?

0 Upvotes

11 comments sorted by

2

u/ZnV1 10d ago

How many users do you have?

1

u/Fair-Process-7291 10d ago

dont have any yet lol.... still working on making it better haha

1

u/ZnV1 10d ago

You have your answer. If the user doesn't see it, you're wasting your time.

→ More replies (2)

1

u/OneVictory874 10d ago

overkill today probably saves you a headache tomorrow when someone in the lab insists two runs were identical and you can just show them the raw logs side by side

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.