Skip to content

Implement deterministic ID hashing for MCTS transposition detection - #19

Merged
REX-codebase merged 1 commit into
mainfrom
jules/deterministic-id-hashing-js1-99a059df-2473-4dc9-80fd-5a23df1b629e
Jun 22, 2026
Merged

REX-codebase merged 1 commit into
mainfrom
jules/deterministic-id-hashing-js1-99a059df-2473-4dc9-80fd-5a23df1b629e

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

Overview

This PR replaces the legacy timestamp and random-based ID generation in the Monte Carlo Tree Search (MCTS) engine with a deterministic, content-based hashing approach. This transition enables the engine to recognize "transpositions"—identical design states reached via different mutation paths.

The "Why" (Rationale)

The previous implementation used Date.now() and Math.random() to generate IDs. This caused a significant efficiency bottleneck:

  • Redundant Computations: Identical designs were treated as unique nodes, triggering expensive re-evaluations by design auditors.
  • Search Depth Limitation: Compute budget was wasted re-auditing known states rather than exploring deeper into the design tree.
  • Cache Inefficiency: The evaluationCache could not be leveraged across different branches of the search tree because IDs never collided, even when the underlying data did.

By implementing deterministic hashing, we ensure that the system recognizes when it has encountered a state before, allowing for instant score retrieval and a higher volume of unique design explorations within the same time budget.

Key Changes

  • Deterministic ID Generation: Replaced random strings in DesignState with SHA-256 hashes using Node's crypto module. The hash is generated from a stable serialization of design properties (colors, typography, layout, etc.).
  • Transposition Recovery: Updated the simulation logic to check the evaluationCache using the new deterministic ID before invoking auditors.
  • Unit Testing: Added a new test suite (skills/utils/test-mcts-hash.js) to verify:
    • Identical states produce identical hashes.
    • Small property changes result in unique, non-colliding hashes.
    • The MCTS engine correctly skips redundant evaluations.

Constraints & Guardrails

  • Performance: SHA-256 was chosen for its collision resistance; the hashing overhead is negligible compared to the seconds saved by skipping a single design audit.
  • State Integrity: The full-state cloning mechanism used for tree nodes remains untouched to maintain memory safety and prevent side effects.

@REX-codebase
REX-codebase merged commit 27561f9 into main Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant