Review engine and dropped files: fixes after the independent check
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

- The probe turns down an engine not called «Stockfish 19» right after `uci`, without
  a search; a search has a 10 s guard, the probe 30 s; probes stop and their engines
  quit (or are killed) when the program quits. Play engines (Rodent, Maia) are never
  candidates.
- «Did not start» is its own outcome, said once and tried again next time; verdicts
  are kept for the real file with the reference's key; the engine's name is checked
  again when a job starts (a wrapper may run another program).
- The wait for a probe belongs to its game or preparation; the game analysis and the
  opening errors wait apart; «analyse anew» keeps its `full`.
- The offer says why: another engine (settings / system), a Stockfish 19 that
  calculates otherwise, one that did not start; the size line is back.
- Dropped files: missing ones told, known ChessBase parts only, duplicates by the real
  file, each folder listed once; drops never replace a database being chosen again,
  a cancelled «Choose again» ends it; «Added to the shelf» over a game; a framed
  highlight with a card; long names shortened.
- decisions.md: where dropping works (not in a Wayland session: winit 0.30).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-31 13:42:19 +03:00
parent 4fc1d5b67d
commit 829bde9fdb
14 changed files with 1164 additions and 334 deletions

View file

@ -105,7 +105,15 @@ fn worker(
let mut search = |pos: &EnginePosition, among: Vec<String>, nodes: u64| {
next_id += 1;
let _ = handle.new_game();
search_once(&handle, pos, SearchId(next_id), among, nodes, halted)
search_once(
&handle,
pos,
SearchId(next_id),
among,
nodes,
SEARCH_GUARD,
halted,
)
};
'targets: while let Some(t) = targets.get(next.fetch_add(1, Ordering::Relaxed)) {
if halted() {
@ -135,13 +143,15 @@ fn worker(
}
/// One node-limited search: its last full line and the best move. `None` when it gave
/// no line or the job was halted.
/// no line or the job was halted. After `guard` the search is stopped (an engine that
/// ignores `stop` is killed by the `uci` crate's stop timeout: `Terminated`).
pub(super) fn search_once(
handle: &uci::EngineHandle,
pos: &EnginePosition,
id: SearchId,
among: Vec<String>,
nodes: u64,
guard: Duration,
halted: &dyn Fn() -> bool,
) -> Result<Answer, JobFailure> {
handle
@ -154,7 +164,7 @@ pub(super) fn search_once(
if halted() {
return Ok(None);
}
if !stopping && started.elapsed() > SEARCH_GUARD {
if !stopping && started.elapsed() > guard {
let _ = handle.stop();
stopping = true;
}

View file

@ -11,7 +11,7 @@
//! set: its own check of the universal build (`scripts/check_universal.sh` of the
//! release) requires the same `bench` node count from every per-CPU build.
use std::sync::atomic::AtomicBool;
use std::time::{Duration, Instant};
use uci::{EnginePosition, Score};
@ -55,8 +55,11 @@ pub const REFERENCE: [(&str, Score, u64); 3] = [
pub struct Probe {
/// The engine's name (`id name`).
pub name: Option<String>,
/// The answers, one per position of [`PROBE_POSITIONS`] (fewer when one gave none).
/// The answers, one per position of [`PROBE_POSITIONS`] (fewer when one gave none,
/// took too long, or the engine is not called Stockfish 19: then none is searched).
pub answers: Vec<ProbeAnswer>,
/// A search took longer than allowed (an engine that ignores `go nodes`).
pub timed_out: bool,
}
impl Probe {
@ -74,23 +77,75 @@ impl Probe {
}
}
/// Runs the probe searches in a process of the engine. Takes about a second (the
/// engine's start included); the engine is quit at the end.
pub fn probe(config: uci::EngineConfig) -> Result<Probe, JobFailure> {
/// How long the probe may take: a search (Stockfish needs about 0.1 s) and all of it.
#[derive(Clone, Copy, Debug)]
pub struct ProbeLimits {
pub search: Duration,
pub total: Duration,
}
impl Default for ProbeLimits {
fn default() -> Self {
ProbeLimits {
search: Duration::from_secs(10),
total: Duration::from_secs(30),
}
}
}
/// What [`REFERENCE`] is a reference of — the positions, the nodes, the hash, the
/// answers — as a short text kept with the verdicts: a verdict of another probe is
/// not trusted. (FNV-1a of their text: the same in every build.)
pub fn reference_key() -> String {
let text = format!("{PROBE_POSITIONS:?}|{PROBE_NODES}|{SEARCH_HASH_MB}|{REFERENCE:?}");
let hash = text.bytes().fold(0xcbf2_9ce4_8422_2325_u64, |h, b| {
(h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3)
});
format!("{hash:016x}")
}
/// Runs the probe in a process of the engine; `halted` gives it up (the program
/// quits). An engine not called Stockfish 19 is not searched at all. The engine is
/// quit at the end (killed if it does not go).
pub fn probe(
config: uci::EngineConfig,
limits: ProbeLimits,
halted: &dyn Fn() -> bool,
) -> Result<Probe, JobFailure> {
let started = Instant::now();
let handle = uci::Engine::spawn_with(config, Box::new(|| {}))
.map_err(|e| JobFailure::Start(e.to_string()))?;
let name = handle.info().name.clone();
let mut probe = Probe {
name: handle.info().name.clone(),
answers: Vec::new(),
timed_out: false,
};
if probe.name.as_deref() != Some(STOCKFISH_19) {
handle.quit();
return Ok(probe);
}
let _ = handle.set_threads(1);
let _ = handle.set_hash_mb(SEARCH_HASH_MB);
let _ = handle.set_multipv(1);
let never = AtomicBool::new(false);
let halted = || never.load(std::sync::atomic::Ordering::Relaxed);
let mut answers = Vec::new();
let over = || halted() || started.elapsed() > limits.total;
for (i, fen) in PROBE_POSITIONS.iter().enumerate() {
let _ = handle.new_game();
let pos = EnginePosition::fen(*fen, Vec::<String>::new());
let id = uci::SearchId(i as u64 + 1);
let answer = search_once(&handle, &pos, id, Vec::new(), PROBE_NODES, &halted)?;
let search_started = Instant::now();
let answer = search_once(
&handle,
&pos,
id,
Vec::new(),
PROBE_NODES,
limits.search,
&over,
)?;
if search_started.elapsed() > limits.search || started.elapsed() > limits.total {
probe.timed_out = true;
break;
}
let Some((info, best)) = answer else { break };
let (Some(best), Some(score), Some(nodes)) = (
best.or_else(|| info.pv.first().cloned()),
@ -99,20 +154,24 @@ pub fn probe(config: uci::EngineConfig) -> Result<Probe, JobFailure> {
) else {
break;
};
answers.push(ProbeAnswer {
probe.answers.push(ProbeAnswer {
best,
score: score.score,
nodes,
});
}
handle.quit();
Ok(Probe { name, answers })
Ok(probe)
}
#[cfg(test)]
mod tests {
use super::*;
fn run(config: uci::EngineConfig) -> Result<Probe, JobFailure> {
probe(config, ProbeLimits::default(), &|| false)
}
fn fake() -> &'static str {
let fake = concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/debug/fake_uci");
assert!(
@ -143,7 +202,7 @@ mod tests {
#[test]
fn the_reference_answers_pass() {
let p = probe(engine(STOCKFISH_19, &REFERENCE)).expect("the probe runs");
let p = run(engine(STOCKFISH_19, &REFERENCE)).expect("the probe runs");
assert_eq!(p.name.as_deref(), Some(STOCKFISH_19));
assert_eq!(p.answers.len(), 3);
assert!(p.same(), "{p:?}");
@ -154,24 +213,24 @@ mod tests {
// Another network or version: one score differs.
let mut other = REFERENCE;
other[1].1 = Score::Cp(-117);
let p = probe(engine(STOCKFISH_19, &other)).expect("the probe runs");
let p = run(engine(STOCKFISH_19, &other)).expect("the probe runs");
assert!(!p.same());
// The nodes differ (another search), the move and score the same.
let mut other = REFERENCE;
other[2].2 += 1;
assert!(!probe(engine(STOCKFISH_19, &other)).unwrap().same());
assert!(!run(engine(STOCKFISH_19, &other)).unwrap().same());
// Another best move.
let mut other = REFERENCE;
other[0].0 = "g8f6";
assert!(!probe(engine(STOCKFISH_19, &other)).unwrap().same());
assert!(!run(engine(STOCKFISH_19, &other)).unwrap().same());
// The same answers under another name.
let p = probe(engine("Stockfish 18", &REFERENCE)).unwrap();
let p = run(engine("Stockfish 18", &REFERENCE)).unwrap();
assert_eq!(p.name.as_deref(), Some("Stockfish 18"));
assert!(!p.same());
// An engine that answers nothing of the kind (the fake's own lines).
let mut plain = uci::EngineConfig::new(fake());
plain.args = vec!["--name".into(), STOCKFISH_19.into()];
assert!(!probe(plain).unwrap().same());
assert!(!run(plain).unwrap().same());
}
/// A real Stockfish 19 gives [`REFERENCE`] (run when the reference is taken again
@ -181,15 +240,72 @@ mod tests {
#[ignore = "needs a Stockfish 19 in CP_PROBE_ENGINE"]
fn a_real_stockfish_19_gives_the_reference() {
let path = std::env::var("CP_PROBE_ENGINE").expect("CP_PROBE_ENGINE");
let p = probe(uci::EngineConfig::new(path)).expect("the probe runs");
let p = run(uci::EngineConfig::new(path)).expect("the probe runs");
println!("{p:?}");
assert!(p.same(), "{p:?}");
}
/// An engine not called Stockfish 19 is not searched (Rodent searches on past
/// `go nodes`): its name is the verdict, at once.
#[test]
fn another_engine_is_not_searched() {
let mut config = uci::EngineConfig::new(fake());
config.args = vec![
"--name".into(),
"Rodent V 1.2".into(),
"--ignore-nodes".into(),
];
let started = Instant::now();
let p = run(config).expect("the probe runs");
assert_eq!(p.name.as_deref(), Some("Rodent V 1.2"));
assert!(p.answers.is_empty() && !p.timed_out && !p.same());
assert!(started.elapsed() < Duration::from_secs(5));
}
/// A «Stockfish 19» that ignores `go nodes`: stopped by the guard, not the same.
#[test]
fn an_endless_search_is_cut_short() {
let mut config = uci::EngineConfig::new(fake());
config.args = vec![
"--name".into(),
STOCKFISH_19.into(),
"--ignore-nodes".into(),
];
let limits = ProbeLimits {
search: Duration::from_millis(300),
total: Duration::from_secs(2),
};
let started = Instant::now();
let p = probe(config, limits, &|| false).expect("the probe runs");
assert!(p.timed_out && !p.same(), "{p:?}");
assert!(
started.elapsed() < Duration::from_secs(5),
"{:?}",
started.elapsed()
);
// Halted from outside (the program quits): at once.
let mut config = uci::EngineConfig::new(fake());
config.args = vec![
"--name".into(),
STOCKFISH_19.into(),
"--ignore-nodes".into(),
];
let started = Instant::now();
let p = probe(config, ProbeLimits::default(), &|| true).expect("the probe runs");
assert!(!p.same());
assert!(started.elapsed() < Duration::from_secs(5));
}
#[test]
fn the_reference_key_is_stable() {
assert_eq!(reference_key(), reference_key());
assert_eq!(reference_key().len(), 16);
}
#[test]
fn an_engine_that_does_not_start_fails() {
assert!(matches!(
probe(uci::EngineConfig::new("/nonexistent/engine")),
run(uci::EngineConfig::new("/nonexistent/engine")),
Err(JobFailure::Start(_))
));
}

View file

@ -30,6 +30,7 @@
//! best move, scored 30 cp lower (a worse move)
//! --shallow N MOVE `go nodes n` with n < N (no `searchmoves`): MOVE is the
//! best move (a shallow search choosing another move)
//! --ignore-nodes `go nodes N` searches until `stop` (as Rodent does)
//! --answer MARKER TAIL `go` in the position of MARKER answers at once with
//! `info depth 10 multipv 1 score TAIL` and the bestmove of
//! the first move after `pv` in TAIL (repeatable)
@ -64,6 +65,7 @@ struct Cfg {
searchmoves: bool,
shallow: Option<(u64, String)>,
answers: Vec<(String, String)>,
ignore_nodes: bool,
}
fn parse_args() -> Cfg {
@ -98,6 +100,7 @@ fn parse_args() -> Cfg {
let n = num(args.next());
c.shallow = args.next().map(|m| (n, m));
}
"--ignore-nodes" => c.ignore_nodes = true,
"--answer" => {
if let (Some(m), Some(t)) = (args.next(), args.next()) {
c.answers.push((m, t));
@ -309,7 +312,7 @@ fn main() {
.and_then(|p| toks.get(p + 1))
.and_then(|v| v.parse().ok())
// `go nodes N`: a short search that ends by itself, like a real one.
.or_else(|| toks.contains(&"nodes").then_some(3));
.or_else(|| (toks.contains(&"nodes") && !cfg.ignore_nodes).then_some(3));
since_new_game += 1;
let mut bias = if cfg.hash_memory {
let of_position = marker.bytes().map(i32::from).sum::<i32>() % 97;