Skip to content

ADR-R2-4. Weakness metric rulings (detectors W1-W12)

Source: docs/decisions/ADR-R2-4-weakness-metric-rulings.md. Generated at build time; edit the source file.

Date: 2026-11-22 Status: Accepted (R2 Task 8, profile-core::weakness::{detectors, observe_game, tilt}). Placeholder number; the controller renumbers R2 ADRs before merging.

Improvement-engine §6.2 defines the weaknesses W1-W12 in prose. TS M2 Task 7 (ADR 0037 in the TS plan) turned that prose into a per-move opportunity/event table. R2 ports the table to Rust and adds the R2 honesty rules: nothing is claimed from zero evidence, every denominator counts only computable opportunities, invalid inputs are skipped and counted, and no NaN or infinity reaches the output. It also carries the hand-offs from Tasks 4 and 6: lines (best, refutation, threat) and threat_addressed are None when no line exists, and move difficulty comes only from Maia.

  1. Sub-series. W3 splits into W3.shallow and W3.deep, W4 into W4.missed and W4.allowed, W7 into W7.traps and W7.prep, and W8 into W8.basics and W8.advanced. Each is its own binomial key, posterior and series. §6.2’s ratios and means become binomial counts as follows:

    • W10 counts events (ΔW ≥ 5) over quiet eligible middlegame moves. Each event’s ΔW still becomes EPL.
    • W9b counts decisive errors over eligible moves with the clock under 30 s, in bullet, blitz or rapid. The band comparison replaces §6.2’s ratio of the low-clock rate to the high-clock rate.
    • W9c counts a mistake or blunder played in under half the player’s median time, over eligible critical moves with a time reading.
  2. W9d and W12 are continuous and never ranked.

    • W9d is the per-game Spearman ρ of time spent against the MultiPV gap.
    • W12 is the residual (actual minus expected score) of “tilted” games against the rest. “Tilted” means index_in_session ≥ 4 or right after a loss in the same session (tilt_residual_difference).
  3. Depth 4 counts as deep. §6.2 says shallow is “≤ 3” and deep is “≥ 5”, which leaves depth 4 out. We count depth ≤ 3 as shallow and depth ≥ 4 as deep.

  4. W6 event cost is 0.5, a fixed half point per losing episode that was lost. W5’s EPL is 1 − score.

  5. W1 uses the settled swing as its SEE stand-in. W1 fires when the refutation wins ≥ 2 pawns of material (Task 4’s settled swing) within ≤ 3 plies and is not a mate. It does not compute a static exchange evaluation.

  6. Tablebase-eligible means ≤ 5 men, kings included (the local Syzygy 3-4-5 set). A WDL pair on a larger position is invalid input.

  7. T_win is fixed at 85 (observe_game::T_WIN) until the per-band fit of §4.3 exists. A t_win that is not finite or lies outside (50, 100] finds no winning episode, and the run reports invalid_t_win.

  8. EPL is attributed once per move by EPL_PRECEDENCE (W4 > W2 > W1 > W3 > W8 > W7 > W10). The first key in that list that claims a move takes its ΔW/100, and later keys get 0 for that move. The other keys keep their own costs:

    • W9a, W9b, W9c and W11 keep the ΔW of their own event moves;
    • W5 and W6 keep their game-level costs.

    W7.prep claims the player’s opening-phase moves when its event fires, so its EPL is the opening loss that no higher key claimed. W9a’s EPL is the player’s ΔW from the first low-clock ply on.

    The keys outside the precedence list (W5, W6, W9a, W9b, W9c, W11) are each computed on their own, independently of every other key and of input order. So their EPL has no attribution order: it overlaps the precedence keys’ EPL and each other’s. For example, a decisive move under 30 s that hung a piece counts in W1, W9b and possibly W9a and W11. Consumers (T31, T34) must never sum EPL across keys outside EPL_PRECEDENCE (improvement-engine §5.3 already warns that such a total overstates the loss). Only the precedence keys’ EPLs are disjoint and may be added up.

  1. Opportunities are moves whose event can be decided. A missing input counts as unknown, never as a non-event. When the missing value cannot change the answer, the move stays an opportunity.

    • W1 and motif.allowed:*: an eligible move without a refutation line is an opportunity only if it is not decisive. A non-decisive move is never a W1 event, whatever its line, while a decisive move without a line cannot be judged.
    • W2: opportunities need threat_existed == Some(true). A move whose threat_addressed is None counts only if it is not decisive.
    • W3, W10 and W11: these define their opportunities by the line or the difficulty itself. A move with best or difficulty set to None is never one of their opportunities.
    • W8: both WDL values must be present.
    • W9: W9a and W9b need a valid clock, and W9c needs a valid time spent.
  2. W3 and W10 need complete best-line coverage. Enrichment fills a missing PV only on critical plies (R2 Task 25: ΔW ≥ 5, or after a ΔW ≥ 10 ply). In a game whose evals came from Lichess without PVs, the moves that have a best line were therefore selected on their outcome, and a denominator built from them would push the W3 and W10 rates towards 100%. If any eligible own move lacks its best line, the game reports no W3, no W10 and no motif.missed:*, and counts the missing lines in moves_without_best_line. Games analysed by our own Stockfish have a PV on every ply and are unaffected.

  3. MultiPV-only flags keep TS’s “≠ true”. W3 requires in_top2 != Some(true), and W10 requires is_critical != Some(true). MultiPV runs only on critical plies, so requiring Some(false) would select on the outcome in the same way as ruling 10.

    Caveat: is_critical and multipv_gap exist only on T25’s critical plies (ΔW ≥ 5, or after an opponent ΔW ≥ 10), so these values are conditional on that selection:

    • W9c’s denominator (is_critical == Some(true)) consists mostly of error plies, so its rate is a rate among selected plies.
    • W10’s “≠ true” drops critical events but keeps critical non-events, whose flag is unknown.

    W9c and W10 are therefore comparable only with band references built by the same enrichment (same selection rule and ENRICHMENT_PROTOCOL; ADR-R2-14).

  4. W9d never substitutes a gap. TS used multipvGap ?? 0. R2 uses only own moves that have both a time spent and a MultiPV gap, needs at least 10 of them, and otherwise reports None. W9d uses stats::correlation::spearman from Task 11, which merged before this task. The plan asked for a local helper only to avoid waiting on Lane P3. Because the gap exists only on critical plies (ruling 11), W9d’s ρ is conditional on that selection. It is comparable only with references built by the same enrichment, and it is not a correlation over all moves.

  5. Difficulty is Maia only. W11 passes every value through features::maia_difficulty again. A non-Maia model or an invalid probability is skipped and counted (invalid_difficulty). Plies ≤ 10 have no difficulty. Nothing is ever substituted.

  6. Game-level keys need their evidence. Each of these keys gets its single opportunity only when its condition holds; otherwise the key is absent.

    Key Opportunity requires
    W5 / W6 a known result (1, 0.5 or 0) and the episode
    W7.traps at least one valid own move by ply 20
    W7.prep a valid last opening ply
    W9a a clocked, non-daily game (in_trouble known)

    The endgame:* and opening:* series also need a known result.

  7. Series.

    • Every present binomial key gets a series row with the same counts and EPL.
    • motif.missed:<t> covers the W3 opportunities (both depths) whose best line carries tag t.
    • motif.allowed:<t> has the W1 opportunity count for every tag, with events where a decisive move’s refutation carries t. A tag with zero events still records how many times it could have happened.
    • endgame:<type>: the opportunity is the first endgame ply with the player’s W ≥ 30. The event is “not won” from W ≥ 70, or “lost” from 30 ≤ W < 70. The EPL is the player’s endgame ΔW when the event fires.
    • opening:<line_key>: opportunity 1, event “lost”, and the EPL is the player’s opening ΔW when lost.
  8. Invalid inputs are skipped and counted (ObservationScan):

    • moves (either colour) with a non-finite or out-of-range W, ΔW or score;
    • clocks or times spent that are non-finite or negative;
    • out-of-range or oversize tablebase values;
    • invalid difficulty;
    • an unknown result.

    Moves are read in ply order whatever the input order. A ply that appears more than once is dropped in every copy and counted (duplicate_plies). Keeping “the first” copy would depend on input order, and the copies contradict each other.

    An invalid own move is unknown, never a non-event:

    • it breaks an episode run (it is passed to the episode scan with W = NaN, as T7 requires), so it cannot silently join a run or drop out from between two run moves;
    • a skipped own move by ply 20 makes “no trap” unknown, so W7.traps has no opportunity unless a trap was found on a valid move.

    Every EPL is finite.

  9. Exemplars. The binomial keys give these exemplar plies:

    Key Exemplar plies
    Per-move keys their event plies, by ΔW descending, ties by ply
    W5 the drop ply
    W9a the first low-clock ply
    W7.prep the last opening ply, the position the player came out of the opening with
    W6 none

    W6 has no exemplar because a lost losing episode has no single “mistake” ply to show. The brief asks only for “event plies by ΔW descending”, and W6 is a game-level outcome.

Side effects of Task 4’s whole-PV mate detection

Section titled “Side effects of Task 4’s whole-PV mate detection”

Task 4 detects mates on the whole PV, so mate_in is set even for a mate far down the line.

  • W1 drops a refutation that wins material early and then mates deep. The mate_in == None condition removes it, even though a piece was hung.
  • W10 drops positions whose best line ends in a deep mate, because the swing then has a depth, so such a position is not “quiet”.
  • “Deep mates count as W3.deep” holds only when no settled swing ≥ 2 appears at k ≤ 3. An early material swing sets a shallow depth, and the move counts as W3.shallow.

weakness::game_metrics::compute_game_metrics fills PlayerGameMetrics. It reads the game through the detectors’ GameView, so it sees the same moves as the observation: sorted by ply, duplicate plies dropped, invalid moves skipped and counted. The TS M2 Task 8 definitions are ported as written:

  • one-move blunders;
  • missed punishment, where a miss is ΔW ≥ 10;
  • sharp positions;
  • the eval trend (W after ply 70 − W after ply 30);
  • the critical time ratio;
  • W at the end of the opening;
  • saveable resignations (final W ≥ 25);
  • the expected score.

These definitions are not in TS:

Metric Rule Reason
low_clock / high_clock Eligible own moves with clock < 30 s / > 60 s, in bullet, blitz and rapid only. decisive counts ΔW ≥ 15. improvement-engine §6.2 W9b compares clock < 30 s with clock > 60 s. Using W9b’s own population keeps blunder_rate_low_clock consistent with W9b. Daily and classical clocks say nothing about time pressure in seconds. Moves between 30 and 60 s belong to neither bucket, so the two rates don’t blur.
endgame.outcome Entry W ≥ 70: converted if won, else failed_conversion. Entry W ≤ 30: held if not lost, else failed_hold. In between, or with no valid result: None. The 70 matches the endgame series’ “should be won” entry (§6.2 W8). The 30 is its mirror, so hold is the symmetric test. A balanced entry is neither a conversion nor a hold chance, and calling it one would dilute both rates.
endgame.kind endgame_type of the first endgame ply’s FEN; an invalid FEN gives None. No guessed type (T7).
tactics.missed Option. None when W3 is unknown for the game: the whole-game best-line rule (§10), an observation of another game, or a refused W3 row. Version 2. Under the v1 u32 a dropped W3 read as “0 missed”, which tactics_missed_per_game averaged as evidence. None games are left out of that KPI’s numerator and its n.
tactics.allowed Eligible decisive moves whose refutation is a tactic (gain ≥ 2 or a mate). A missing refutation is unknown and is counted, not claimed. This is W3’s tactic test applied to the opponent’s line, so “allowed” and “missed” use one definition.
one_move_blunders A decisive move with a refutation at depth 1, or a missed mate in 1. “The played move is a mate” is read from the SAN #. When a missing line could change the answer, the move is unknown and counted. The SAN is exact. Inferring the mate from the engine score would depend on how the terminal position is scored (R1 scores a delivered mate as Mate(1)).
quiet Exactly W10’s opportunity set (detectors::is_quiet_move, shared). loss is the sum of ΔW on a 0–100 scale. One rule, so quiet_loss_per_move and W10 can never diverge. The 0–100 scale matches T15’s pct unit.
time_in_opening The total own time in the opening phase. None when any own opening move (valid or skipped) has no valid time. A sum with missing terms would be an undercount that reads like a fast opening.
time_trouble None for daily games and for games without clocks. It matches W9a. 10 % of a daily base is days, not time trouble.
missed_punish Opportunity: a valid own move whose ply − 1 is a valid opponent move judged a mistake or blunder. A missing previous ply gives no opportunity. The opponent’s error must be known to be there.
critical_time_ratio Mean time on is_critical = true moves over the mean on = false moves. None when either group is empty or the denominator is 0. Unknown criticality is in neither group. A zero denominator would give infinity.
expected_score Only with both ratings positive; otherwise None, counted. A rating of 0 or below is a data error, not a rating.
accuracy, accuracy_by_phase Only finite values in [0, 100]; others are skipped and counted. No NaN reaches the means.
Observation An observation whose game_id differs from the game’s is refused. Rows with events > opportunities, 0 opportunities, or a non-finite or negative EPL are dropped and counted, as is a non-finite W9d or one with abs(ρ) > 1. Inconsistent rows can’t be evidence. Move-level metrics stay, because they come from the game itself.
  • Lichess-eval games without PVs contribute no W3 or W10 evidence until they are re-analysed with PVs. This is less data, but no rate is inflated.
  • W1 and W2 rates on such games stay unbiased. Decisive moves always get a PV, because they are critical plies.
  • Task 9 can reuse observe_game::win_at_opening_end and the detector constants.
  • Tests: backend/crates/profile-core/tests/detectors.rs covers every key with a positive case, a negative case and a no-opportunity case, plus the honesty rules.
  • Task 9: PlayerGameMetrics is version 2. Version-1 rows are stale under the version gate (global constraints) and must be recomputed. GameMetricsScan reports every skip and unknown count, for T31 to log.