Skip to content

CNP: follow a search's root (engine/root, rootMs, capability root) - #250

Merged
cjus merged 3 commits into
mainfrom
claude/root
Nov 2, 2026
Merged

cjus merged 3 commits into
mainfrom
claude/root

Conversation

@cjus

@cjus cjus commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

cb2026's side of cjus/chess-node-protocol#23 (spec 7.9): a search with rootMs is followed at its root. This is pillar 3, live search, of Solrac's Engine Mind (Solrac Chess AI #357).

The engine: cb2026_engine::root

  • Engine::search_following_root(…, on_root: Option<&mut dyn FnMut(&RootInfo)>). Engine::search calls it with None, so every other caller is unchanged.
  • RootInfo gives the depth being searched, the line (MultiPV), the root move being searched with its place and the line's count, the line's best so far, every root move searched with the main thread's nodes below it (all depths and lines together), the total nodes and the time. RootResearch is Better(mv), FailHigh(score) or FailLow(score).
  • The main thread's Searcher holds a RootFollower. Helper threads don't get one: their roots go in their own orders, a depth apart. The hooks:
    • search_root: the start and end of each root move. A move that raises the score becomes the line's best.
    • search_move: its PVS re-search, when the node is a root move's (path.len() == 1), gives Better, before the full-window re-search.
    • search_depth: an aspiration window's failure gives FailHigh or FailLow with the fail-soft score, before the wider re-search. The report's move is the one the re-search starts with.
    • should_stop's clock check (every CHECK_INTERVAL, 1024 nodes) gives a plain report, so a long first move shows its nodes growing.
    • main_search tells it each line's depth, moves and last best.
  • Nothing is allocated after the root's moves are first seen. A report shares the follower's slice, with the current move's nodes so far added for that report only. Without a follower, the cost is an Option check at those places.
  • The book's search, main_search, pvs, aspiration and cut_node_flags excerpts now show these one-line hooks (chapters 4, 6, 11, 13, 14.1 and 19). No prose changed.

The CNP node

  • It offers capability root and reads rootMs. Reports pass the throttle once rootMs has passed since the last notification, on an interval apart from progressMs's. A research is sent at once, and the interval then counts from it.
  • multipv is present when more than one line was asked for. A level's extra candidate lines are searched and counted but not reported, as their lines aren't.
  • Every report is made inside engine.search_following_root, before the thread sends its answer, so nothing comes after the result. A search that reaches its root sends at least one notification: the first move of depth 1 always passes the throttle.
  • The cnp pin moves to Engine: following the root (engine/root, rootMs, capability root) chess-node-protocol#23's merge, 6274420.

Same search, node for node

cb2026 bench is unchanged at 767812. root::tests::following_the_root_changes_nothing_in_the_search compares the result and every report of a followed search with an unfollowed one, for one line and for three. In the measurements below, the node counts of all four runs of each position are identical.

Cost

These are single-thread fixed-depth searches ("deterministic": true) through cb2026 --cnp, 5 runs each, with the medians shown. main is origin/main's binary (6a0038f); branch is this PR's. The runs were interleaved on the M1 Max with the machine quiet (load about 5–12):

Position Depth Nodes Search Median ms Mnps vs main engine/root sent
start 17 1840216 main 1177 1.56 +0.0% 0
start 17 1840216 branch 1177 1.56 +0.0% 0
start 17 1840216 branch rootMs=250 1172 1.57 -0.4% 15
start 17 1840216 branch rootMs=0 1198 1.54 +1.8% 2168
italian 17 1513981 main 1031 1.47 +0.0% 0
italian 17 1513981 branch 1025 1.48 -0.6% 0
italian 17 1513981 branch rootMs=250 1025 1.48 -0.6% 16
italian 17 1513981 branch rootMs=0 1060 1.43 +2.8% 1951
kiwipete 15 938815 main 711 1.32 +0.0% 0
kiwipete 15 938815 branch 717 1.31 +0.8% 0
kiwipete 15 938815 branch rootMs=250 718 1.31 +1.0% 8
kiwipete 15 938815 branch rootMs=0 756 1.24 +6.3% 1789
qgd 16 1198705 main 891 1.35 +0.0% 0
qgd 16 1198705 branch 888 1.35 -0.3% 0
qgd 16 1198705 branch rootMs=250 884 1.36 -0.8% 10
qgd 16 1198705 branch rootMs=0 918 1.31 +3.0% 1769
endgame 25 5627429 main 2720 2.07 +0.0% 0
endgame 25 5627429 branch 2732 2.06 +0.4% 0
endgame 25 5627429 branch rootMs=250 2722 2.07 +0.1% 20
endgame 25 5627429 branch rootMs=0 2781 2.02 +2.2% 5988

The unused hooks (branch with no rootMs) and rootMs 250 are within ±1% of main, which is run-to-run noise. rootMs 0, the worst case, sends a notification at every clock check, about 1,800 a second, each with all the root moves, and costs 2–6%.

A real search

The position after 1.e4 e5 2.Nf3 Nc6 was searched for 5 s with MultiPV 3 and rootMs 250, reaching depth 19. It sent 57 engine/root, all before the result: 16 plain, 40 better and 1 failLow, with no failHigh. 31 of the betters came in the first 100 ms (depths 1–10). From 200 ms on there were 15 plain, 9 better and 1 failLow. Two of them, abridged here to the three biggest node counts:

{"jsonrpc":"2.0","method":"engine/root","params":{"best":"f1b5","depth":15,"id":2,"move":"f1c4","moves":[{"move":"f1b5","nodes":429815},{"move":"d2d4","nodes":264566},{"move":"f1c4","nodes":258791}],"multipv":1,"nodes":1175905,"number":2,"of":27,"research":{"kind":"better","move":"f1c4"},"timeMs":797}}
{"jsonrpc":"2.0","method":"engine/root","params":{"best":"f1c4","depth":12,"id":2,"move":"f1c4","moves":[{"move":"f1b5","nodes":188643},{"move":"f1c4","nodes":116375},{"move":"d2d4","nodes":102915}],"multipv":2,"nodes":529304,"number":1,"of":26,"research":{"kind":"failLow","score":{"bound":"upper","cp":9}},"timeMs":347}}

Tests

  • Engine (root::tests): the search is unchanged when followed; every root move is followed, with its nodes (their sum never more than the total), its place, the count and a best from depth 1 on; a better (always a later move, about itself) and an aspiration failure (the depth restarting at its first move, which is the fail-high move after a fail high) are heard at depth 8 from the start; with three lines, each line is followed over its own moves (20, 19, 18).
  • CNP node: following_the_root_is_throttled_and_never_comes_after_the_answer covers the ids, line numbers, places, node sums, the throttle (each plain notification at least rootMs after the one before), the bounds on failHigh and failLow, and nothing after the answer. a_search_that_doesn_t_ask_isn_t_followed: no engine/root, and progress still comes.
  • Conformance (crates/cli/tests/cnp.rs): CNP's root (including its new forbid step: no engine/root after the result) and root-multipv pass against the real binary. root-unsupported is skipped, since cb2026 offers root.

Checks

scripts/check.sh passed locally on 2ba3f58, the latest commit: fmt, clippy (with the trainer's gpu feature too), tests (GPU included), the perft suite, docs, cargo deny and the book.

Docs

docs/PRD.md (Chess Node Protocol) and docs/status.md are updated.

No functional change. Bench: 767812

🤖 Generated with Claude Code

Engine::search_following_root tells a caller where the main thread's root loop
is (cb2026_engine::root): the move it is on, its place and the line's count,
the line's best so far and the nodes below each root move, at every root move
and whenever the search looks at the clock, and at once when a later move
beats the best on its null-window search (better) or a depth's score falls
outside its aspiration window (failHigh, failLow). The CNP node passes it on as
engine/root at most every rootMs, research at once, on an interval of its own.
Helpers don't follow. The search is the same node for node, followed or not.

The cnp pin moves to cjus/chess-node-protocol#23's merge, 6274420. For Solrac's
Engine Mind (Solrac Chess AI #357).

No functional change.

Bench: 767812

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cjus added a commit that referenced this pull request Nov 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No functional change.

Bench: 767812

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rustdoc refuses a link from the public root module to the crate-private
RootFollower.

No functional change.

Bench: 767812

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cjus
cjus marked this pull request as ready for review November 2, 2026 02:36
@cjus
cjus merged commit 47a5f5f into main Nov 2, 2026
1 check passed
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