spec: re-probe stale full chains when shorter chains pay

A profitable shorter chained lookup returned before the stale full-size check, so the full chain could stay excluded for good
although the policy re-probes stale sizes in the other selection paths (#1252). Check a confident stale full size before
returning the profitable shorter chain. The 300-round policy, the EMA, the header and plain lookup are unchanged; a regression
test covers the bounded re-probe spacing and the MTP confidence gate.
This commit is contained in:
Hulk authored and Niko1221 committed 2026-10-09 03:18:07 +02:00
1 parent a26fcbcdba
commit 71eaee17b9
2 files changed
+30 -2

No files matched your search

+6 -2
View File
@@ -128,9 +128,13 @@ int DraftPolicy::chain(int t_mtp, double p_mtp, int k_avail, int match) const {
const double r = (e0 + p_mtp * gain) / cost_ms(t_mtp + k);
if (r > best) { best = r; best_k = k; }
}
if (best_k > 0 && best > base * (1.0 + margin_)) return best_k;
// as choose(): a size whose cost is only guessed is tried a few times when the continuation looks likely
const int t_full = t_mtp + kmax;
if (best_k > 0 && best > base * (1.0 + margin_)) {
// As choose(): a profitable shorter chain must not keep a stale full size from being measured again.
if (best_k < kmax && p_mtp * c >= 0.6 && stale(t_full)) return kmax;
return best_k;
}
// as choose(): a size whose cost is only guessed is tried a few times when the continuation looks likely
if ((cost_n_[t_full] < kProbes || stale(t_full)) && p_mtp * c >= 0.6) return kmax;
return 0;
}
+24
View File
@@ -90,6 +90,30 @@ int main() {
check(q.chain(4, 0.9, 3, 4) == 0, "chain: dear rows, never accepted -> none");
check(q.chain(4, 0.9, 0, 4) == 0 && q.chain(8, 1.0, 3, 40) == 0, "chain: nothing proposed / no room -> none");
}
{
// The stale-size check must also run when a shorter chain already pays. Synthetic costs isolate the
// selection policy: even a size that stays expensive is retried, but only once per stale interval.
DraftPolicy p(6);
for (int i = 0; i < 3; ++i) p.observe(false, 4, 3, 0, 40.0);
for (int i = 0; i < 3; ++i) p.observe_chain(4, 1, 4, 40, 42.0);
for (int i = 0; i < 3; ++i) p.observe_chain(4, 2, 5, 40, 1000.0);
check(p.chain(4, 1.0, 2, 40) == 1, "chain: the profitable shorter chain initially wins");
int probes = 0, last_probe = -1;
bool spaced = true, confident = true;
for (int i = 0; i < 1000; ++i) {
const int k = p.chain(4, 1.0, 2, 40);
if (k == 2) {
++probes;
spaced &= last_probe < 0 ? i >= 300 : i - last_probe > 300;
last_probe = i;
confident &= p.chain(4, 0.5, 2, 40) < 2;
}
p.observe_chain(4, k, 3 + k, 40, k == 2 ? 1000.0 : 42.0);
}
check(probes > 0 && probes <= 3 && spaced,
"chain: stale full size is re-probed despite a profitable shorter chain");
check(probes > 0 && confident, "chain: stale re-probes retain the MTP confidence gate");
}
std::printf(g_fail ? "FAIL\n" : "PASS\n");
return g_fail ? 1 : 0;
}