Skip to content

perf(prune-reinsert): exact directional insertion scorer (last Wagner-fix sharer) + regime-soundness tests - #263

Merged
ms609 merged 3 commits into
cpp-searchfrom
claude/scoreapprox-land
Jul 3, 2026
Merged

perf(prune-reinsert): exact directional insertion scorer (last Wagner-fix sharer) + regime-soundness tests#263
ms609 merged 3 commits into
cpp-searchfrom
claude/scoreapprox-land

Conversation

@ms609

@ms609 ms609 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Exact-directional insertion scorer in expand_and_reinsert (last Wagner-fix sharer)

Completes the June Wagner insertion-cost fix (2b299e4b, #26/#27). expand_and_reinsert
(taxon prune-reinsert, T-266) was the one sharer missed by that migration: it still
scored candidate insertion edges with the union-of-finals approximation
(fitch_indirect_length_bounded), which undercounts insertion cost. This routes it through
the exact directional edge-set scorer (compute_insertion_edge_sets +
fitch_indirect_length_cached), mirroring ts_wagner.cpp.

A gated -DTS_SCOREAPPROX_PROBE Δ-oracle (off by default, byte-identical when undefined)
measured the pre-port cost on Zanol: the bounded path chose a strictly-worse edge on ~62% of
placements (mean ~6 steps); after the port Δ=0 at every placement (production == exact argmin).

Prune-reinsert auto-enables at nTip ≥ 120 (large preset, pruneReinsertCycles=5), so this
path runs on the large-dataset tail of the corpus (up to ~4000 tips) — where wall-clock is
largest and least characterised.

Commits

  1. port (42a1f021) — the bounded→exact swap + Δ-probe (original, June worktree).
  2. fix (0307f4e8) — thread_local the probe's static accumulators (parallel-search data race, review-confirmed low, diagnostic-only).
  3. test (6b378f0d) — NA + IW score-soundness regression tests (close the review coverage gap).

Validation

  • Adversarial correctness review (6 lenses × verify: regime-safety, bounds/OOB, prelim-currency,
    cutoff/argmin, probe-gating, coverage): 0 soundness bugs. Regime-safety CONFIRMED safe — the
    port correctly follows the ts_wagner.cpp all-regime convention (ranking-only construction
    heuristic, corrected by a regime-correct score_tree() accept gate), not the ts_tbr.cpp
    ew_directional guard convention; on NA it swaps one NA-blind heuristic for another and cannot
    corrupt the accepted tree. Bounds, prelim-currency, cutoff/argmin equivalence and tw stride all
    verified safe.
  • Clean build against current cpp-search tip; targeted suites green on the freshly built DLL:
    prune-reinsert (incl. new NA/IW), tbr-search, tbr-symmetry, wagner, wagner-quality, drift, ratchet — 0 failures.
  • New regime tests assert result$best_score == ts_fitch_score(returned tree) under NA-EW and IW
    (concavity=3) with forced pruneReinsertCycles — the score-soundness invariant no prior test checked.

Scope / safety

  • EW: strict improvement (exact placement, was approximate). NA/IW: same approximation class as the
    sibling Wagner builder; accepted tree always gated by regime-correct score_tree() → cannot alter
    final reported score. Default (probe-undefined) production path behaviour on EW ≤120t is unchanged
    except that placement edges may now be chosen exactly.
  • A time-matched ≥120t Δ=0 re-confirmation and an NA placement A/B are queued on Hamilton as
    post-merge confirmation (also a BGS-recipe-tuning input); neither is a correctness gate — the code
    path is scale-invariant and statically proven.

🤖 Generated with Claude Code

ms609 and others added 3 commits July 3, 2026 14:02
… + Δ-probe

expand_and_reinsert (T-266, 2026-03-27) used the union-of-finals
fitch_indirect_length_bounded approximation that the June directional fix
(#26/#27) replaced everywhere else — it was MISSED. Port it to the exact
edge_set scorer, mirroring ts_wagner.cpp:487:
  - per-tip compute_insertion_edge_sets (prelim is current via
    wagner_incremental_rescore) + fitch_indirect_length_cached per edge.

Also a gated, non-perturbing -DTS_SCOREAPPROX_PROBE oracle that tallied
Δ = exact_cost(E_bounded) − min_E exact_cost(E) per placement. On Zanol
(forced pruneReinsertCycles): bounded chose strictly-worse edges in ~62%
of placements, mean ~6 steps, ~48% greedy-regret SHARE. After the port the
probe reports Δ=0 at every placement (production == exact argmin).

NOTE: this is greedy-regret SHARE, not realizable wall-clock — prune_reinsert
auto-enables ONLY at nTip>=120 (`large` preset); NO mission dataset reaches
120t (max=88). So this path runs on zero default mission searches. Land +
time-matched A/B (NNI-polish `large` preset, ≥120t) is COMPOSITION-gated (#40).
Worktree-only; NOT for cpp-search until composition.

Tests: prune-reinsert 44/0, drift 22/0, ratchet 17/0, tbr 28/0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-search data race

Post-review hardening of the exact-directional scorer port. The
-DTS_SCOREAPPROX_PROBE diagnostic block's function-local `static` counters
(sa_placements/sa_delta_*/sa_*_exact_sum) are mutated with no synchronization,
but expand_and_reinsert runs concurrently on parallel-search workers — an
unsynchronised data race (adversarial review, CONFIRMED low). thread_local gives
each worker its own tally (per-thread partials under multithreading; exact for
the single-threaded diagnostic runs this probe is intended for). Production
(probe undefined) is byte-identical and unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…w coverage gap)

Adversarial review of the exact-directional scorer port found no prior test
drove expand_and_reinsert on NA (inapplicable) or IW (implied-weights) data, nor
asserted score self-consistency in any regime — yet prune_reinsert_search runs on
both (its guard only early-returns for PROFILE/HSJ/XFORM). The port is a
ranking-only construction heuristic; the accepted tree is gated by a
regime-correct score_tree() (strict-improve + revert), so the REPORTED best_score
must equal an independent length recompute of the RETURNED tree in every regime.

Adds two tests (Vinther2008, 23t, forced pruneReinsertCycles=3): NA-EW and
IW (concavity=3) — each asserts result$best_score == ts_fitch_score(returned tree).
Both green. Empirically confirms the port cannot corrupt the accepted tree on
NA/IW (mirrors the ts_wagner.cpp all-regime convention, not the ts_tbr.cpp guard).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ms609
ms609 force-pushed the claude/scoreapprox-land branch from 6b378f0 to 98122e5 Compare July 3, 2026 13:02
@ms609
ms609 merged commit 74bc802 into cpp-search Jul 3, 2026
7 of 8 checks 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