Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cascade/shared/config/lane_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ class LaneDConfig:
# A weight-side knob only: not a signed report parameter, not part of the
# eval host's judge request (lane_d_config_record leaves it out).
court_carry_max_settlements: int = 2
# Owner 2026-12-01 (display only): the main validator's full public bench
# of a lane D king sweeps one suite per settlement; with less allowance
# left before the pre-settlement guard than this estimate of one suite's
# sweep (seconds), it is not started (retried next settlement). Never a
# signed report parameter; left out of the judge request.
king_bench_suite_estimate_s: float = 1800.0
# Rate limits, queue and TTLs (D3, D8, A1, A8, A9, B10).
max_entries_per_settlement: int = 8
max_open_per_coldkey: int = 2
Expand Down Expand Up @@ -214,6 +220,15 @@ def _float(raw: object, name: str) -> float:
return float(raw)


def _king_bench_estimate(raw: object) -> float:
"""``[lane_d] king_bench_suite_estimate_s``: seconds in [60, 86400]."""
v = _float(raw, "king_bench_suite_estimate_s")
if not (math.isfinite(v) and 60.0 <= v <= 86400.0):
raise ValueError(f"[lane_d] king_bench_suite_estimate_s must be in [60, 86400]; "
f"got {raw!r}")
return v


def _open_unit(raw: object, name: str) -> float:
"""A float in (0, 1)."""
v = _float(raw, name)
Expand Down Expand Up @@ -439,6 +454,8 @@ def on_era(name: str, block: int) -> None:
reward_prior_kings=rpk, court_weights=court_w,
court_carry_max_settlements=_int(ld.get("court_carry_max_settlements", 2),
"court_carry_max_settlements", lo=0, hi=64),
king_bench_suite_estimate_s=_king_bench_estimate(
ld.get("king_bench_suite_estimate_s", 1800.0)),
max_entries_per_settlement=_int(ld.get("max_entries_per_settlement", 8),
"max_entries_per_settlement", lo=1),
max_open_per_coldkey=_int(ld.get("max_open_per_coldkey", 2),
Expand Down
2 changes: 1 addition & 1 deletion cascade/validator/lane_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ def plain_json(obj, where: str = "$"):

# Weight-side ``[lane_d]`` knobs the judge never reads: left out of the judge
# request, so an eval host on a release without them still parses it.
_JUDGE_SKIP_FIELDS = frozenset({"court_carry_max_settlements"})
_JUDGE_SKIP_FIELDS = frozenset({"court_carry_max_settlements", "king_bench_suite_estimate_s"})


def lane_d_config_record(cfg) -> dict:
Expand Down
246 changes: 162 additions & 84 deletions cascade/validator/lane_d_king_bench.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cascade/validator/lane_d_wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
11. with a ``king_bench`` wired (the main validator), a miner KING_D without
a stored full bench is handed to
:meth:`~cascade.validator.lane_d_king_bench.KingBench.schedule`: one
display-only sweep on all four public suites on its own thread, ending
display-only sweep of its next missing public suite (gift, boom, time,
fev; one per settlement, each stored at once) on its own thread, ending
an hour before the next boundary; never gating, never pay, never in the
signed report, retried at the next settlement after a failure.

Expand Down
4 changes: 3 additions & 1 deletion cascade/validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,9 @@ def main(argv: list[str] | None = None) -> int:
if lane_d_services is not None and lane_d_services.get("bench_host") is not None:
from .lane_d_king_bench import KingBench

lane_d_king_bench = KingBench(lane_d_services["bench_host"], state_dir=lane_d_dir)
lane_d_king_bench = KingBench(
lane_d_services["bench_host"], state_dir=lane_d_dir,
suite_estimate_s=getattr(runner.cfg.lane_d, "king_bench_suite_estimate_s", 1800.0))
runner.lane_d_step = build_lane_d_step(
runner.cfg, state_dir=lane_d_dir,
signer=runner.bench_signer,
Expand Down
8 changes: 8 additions & 0 deletions tests/accept/w8b/PATHS
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ docs/VALIDATOR.md
# (lane A's BenchScores keys, the ones cascade/website reads). Never gate,
# crown, pay, signed report or any consensus value; main validator only.
cascade/validator/lane_d_king_bench.py
# Live 2026-12-01 (all four suites in one call outran the 2484 s allowance,
# TimeoutExpired every settlement): one missing suite per attempt (gift, boom,
# time, fev), each merged into the stored record at once (complete: false
# until all four, published partial), resumed at the next missing suite, a
# complete record never re-swept; skipped when less than one suite's estimate
# ([lane_d] king_bench_suite_estimate_s, default 1800, parsed in
# cascade/shared/config/lane_d.py above, left out of the judge request in
# cascade/validator/lane_d.py) is left. Display only.
# Owner 2026-12-01 ("miners only stop getting paid when someone beats them"):
# while a settlement's lane D report is not yet known, the weight fold
# (weights.py, above) pays the newest published court at most [lane_d]
Expand Down
196 changes: 196 additions & 0 deletions tests/accept/w8b/test_w8b_king_bench_per_suite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
"""W8b x live 2026-12-01: the lane D king's display-only full public bench
swept all four suites in one call, outran its allowance (2484 s) and failed
``TimeoutExpired`` at every settlement. Now each attempt sweeps ONE missing
suite (gift, boom, time, fev: GIFT-Eval first, the dashboard reads it),
merges it into the stored record at once (``complete: false`` until all
four), publishes the partial record, resumes at the next missing suite at a
later attempt, never re-sweeps a complete record, and skips (retried next
settlement) when the allowance left is shorter than one suite's estimate
(``[lane_d] king_bench_suite_estimate_s``, default 1800 s). A failed suite
never loses the earlier ones. Display only.

:class:`KingBench` runs inline over a fake host; nothing in PATHS is
imported at module import time; a missing feature on the base fails by
assertion.
"""

from __future__ import annotations

import importlib
import inspect
import json
import tomllib

import pytest

from . import helpers as h

KING_BENCH = "cascade.validator.lane_d_king_bench"
X = "ab" * 32
ORDER = ("gift", "boom", "time", "fev")
DEADLINE = 1_000_000.0


class Host:
"""A lane D bench host: each suite ``ok`` with an aggregate pair; a suite
in ``fail`` raises (a timeout), one in ``bad`` answers without one."""

def __init__(self):
self.calls: list[dict] = []
self.fail: set[str] = set()
self.bad: set[str] = set()

def context_of(self, digest):
return 4096

def sweep_full(self, digests, suites, *, contexts=None, timeout_s=None):
self.calls.append({"suites": tuple(suites), "timeout_s": timeout_s})
if self.fail & set(suites):
raise TimeoutError("w8b: the bench host ran out of allowance")
out = {}
for d in digests:
out[d] = {}
for s in suites:
k = ORDER.index(s)
agg = ({"status": "error", "crps": None, "mase": None, "partial": False}
if s in self.bad else
{"status": "ok", "crps": 0.40 + 0.01 * k, "mase": 0.80 + 0.01 * k,
"partial": False, "bench_method": "observed_mask/3",
"data_revision": f"rev-{s}"})
out[d][s] = {"status": "ok", "rows": [{"item": f"{s}/i0", "crps": 0.5,
"mase": 1.1}], "aggregate": agg}
return out


class Clock:
def __init__(self, t: float = DEADLINE - 7000.0):
self.t = t

def __call__(self):
return self.t


def _kb(tmp_path, host, clock=None, **kw):
mod = importlib.import_module(KING_BENCH)
params = inspect.signature(mod.KingBench).parameters
assert "suite_estimate_s" in params, "KingBench takes no per-suite estimate"
return mod.KingBench(host, state_dir=tmp_path, spawn=lambda fn: fn(),
now=clock or Clock(), **kw)


def _attempt(kb, done):
return kb.schedule(digest=X, boundary=100, deadline_ts=DEADLINE, on_done=done.append)


def _stored(tmp_path):
p = tmp_path / "lane_d_king_bench" / f"{X}.json"
return json.loads(p.read_text()) if p.is_file() else None


def test_one_suite_per_attempt_gift_first_partial_stored_and_published(tmp_path):
host = Host()
kb = _kb(tmp_path, host)
done: list[dict] = []
assert _attempt(kb, done) is True
assert [c["suites"] for c in host.calls] == [("gift",)], host.calls
rec = _stored(tmp_path)
assert rec is not None, "the gift suite was not stored"
assert rec["complete"] is False
assert (rec["gifteval_crps"], rec["gifteval_mase"]) == (0.40, 0.80)
assert "boom_crps" not in rec and "fev_mase" not in rec
assert done == [rec], "the partial record was not handed to the status republish"


def test_resumes_at_the_next_missing_suite_and_completes(tmp_path):
host = Host()
done: list[dict] = []
for _ in range(4):
# a fresh KingBench each time: the progress lives in the store
assert _attempt(_kb(tmp_path, host), done) is True
assert [c["suites"] for c in host.calls] == [(s,) for s in ORDER]
rec = _stored(tmp_path)
assert rec["complete"] is True
assert rec["boom_crps"] == pytest.approx(0.41) and rec["fev_mase"] == pytest.approx(0.83)
assert (rec["gifteval_crps"], rec["gifteval_mase"]) == (0.40, 0.80)
assert rec["data_revisions"] == {s: f"rev-{s}" for s in ORDER}
assert [d["complete"] for d in done] == [False, False, False, True]


def test_a_complete_record_is_never_swept_again(tmp_path):
host = Host()
kb = _kb(tmp_path, host)
for _ in range(4):
_attempt(kb, [])
assert _stored(tmp_path)["complete"] is True
assert kb.due(X) is False
assert _attempt(kb, []) is False
assert _attempt(_kb(tmp_path, host), []) is False
assert len(host.calls) == 4, host.calls


def test_too_short_an_allowance_for_one_suite_skips(tmp_path):
host = Host()
est = 1800.0
kb = _kb(tmp_path, host, Clock(DEADLINE - (est - 60.0)), suite_estimate_s=est)
assert _attempt(kb, []) is False
assert host.calls == [], "a suite started with less allowance than one suite needs"
assert kb.due(X) is True, "a skipped king is no longer due"
kb2 = _kb(tmp_path, host, Clock(DEADLINE - (est + 60.0)), suite_estimate_s=est)
assert _attempt(kb2, []) is True
call = host.calls[0]
assert call["suites"] == ("gift",)
# the allowance handed to the host (its on-host timeout -k) is the time left
assert call["timeout_s"] == pytest.approx(est + 60.0)


def test_a_failed_suite_keeps_the_earlier_ones_and_is_retried(tmp_path):
host = Host()
kb = _kb(tmp_path, host)
done: list[dict] = []
_attempt(kb, done)
host.fail = {"boom"}
assert _attempt(kb, done) is True # started; the sweep then fails
rec = _stored(tmp_path)
assert rec is not None and (rec["gifteval_crps"], rec["gifteval_mase"]) == (0.40, 0.80), \
"the boom failure lost the stored gift suite"
assert rec["complete"] is False and len(done) == 1
host.fail = set()
_attempt(kb, done)
assert [c["suites"] for c in host.calls] == [("gift",), ("boom",), ("boom",)]
assert _stored(tmp_path)["boom_crps"] == pytest.approx(0.41)


def test_a_suite_answering_without_aggregates_is_left_out_after_its_attempts(tmp_path):
host = Host()
host.bad = {"boom"}
kb = _kb(tmp_path, host, max_attempts=2)
for _ in range(5):
_attempt(kb, [])
assert [c["suites"] for c in host.calls] == [("gift",), ("boom",), ("boom",), ("time",),
("fev",)], host.calls
rec = _stored(tmp_path)
assert rec["complete"] is False and "boom_crps" not in rec
assert rec["fev_crps"] == pytest.approx(0.43)
assert kb.due(X) is False


def test_the_suite_estimate_knob_parses_and_round_trips():
from cascade.shared.config import parse_chain_config
from cascade.validator.lane_d import lane_d_config_from_record, lane_d_config_record

raw = tomllib.loads(h._shipped_raw())
cfg = parse_chain_config(raw)
assert getattr(cfg.lane_d, "king_bench_suite_estimate_s", None) == 1800.0, \
"no [lane_d] king_bench_suite_estimate_s (default 1800)"
raw.setdefault("lane_d", {})["king_bench_suite_estimate_s"] = 2400
cfg = parse_chain_config(raw)
assert cfg.lane_d.king_bench_suite_estimate_s == 2400.0, \
"load_chain_config does not parse [lane_d] king_bench_suite_estimate_s"
for bad in (-1, 0, True, "1800", 10 ** 6):
raw["lane_d"]["king_bench_suite_estimate_s"] = bad
with pytest.raises(ValueError):
parse_chain_config(raw)
# display only: never in the eval host's judge request
rec = lane_d_config_record(cfg.lane_d)
assert "king_bench_suite_estimate_s" not in rec
assert lane_d_config_from_record(rec).king_bench_suite_estimate_s == 1800.0
19 changes: 14 additions & 5 deletions tests/accept/w8b/test_w8b_king_full_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _website_king_bench(king):
return None


def test_a_crowning_schedules_exactly_one_full_sweep_of_the_new_king(tmp_path):
def test_a_crowning_schedules_one_suite_per_settlement_until_complete(tmp_path):
cfg = h.chain_cfg(tmp_path / "v", sentinel=False)
rig = KBRig(tmp_path / "rig", cfg, h.fixture(tmp_path))
rig.run(h.B1)
Expand All @@ -138,15 +138,19 @@ def test_a_crowning_schedules_exactly_one_full_sweep_of_the_new_king(tmp_path):
assert len(rig.full.calls) == 1, rig.full.calls
call = rig.full.calls[0]
assert call["digests"] == (rig.fx["x"],)
assert set(call["suites"]) == {"gift", "boom", "time", "fev"}
# live 2026-12-01: one suite per attempt, GIFT-Eval first
assert call["suites"] == ("gift",), call["suites"]
assert call["contexts"] == {rig.fx["x"]: 4096}
# the allowance ends an hour before the next boundary (chain time)
grid_s = 12 * h.SETTLEMENT
assert call["timeout_s"] is not None and 0 < call["timeout_s"] <= grid_s - 3600 - 60 + 1
rig.run(h.B3)
rig.restart()
rig.run(h.B3 + h.SETTLEMENT)
assert len(rig.full.calls) == 1, "the king was swept again after a stored full bench"
for k in (1, 2, 3):
rig.run(h.B3 + k * h.SETTLEMENT)
assert [c["suites"] for c in rig.full.calls] == [("gift",), ("boom",), ("time",),
("fev",)], rig.full.calls
assert rig.status()["king"]["bench"]["complete"] is True
# the gate's bench host never saw the full sweep
assert all(set(s) != {"gift", "boom", "time", "fev"} for _, s in rig.host.calls)

Expand All @@ -160,7 +164,12 @@ def test_the_result_lands_in_status_king_bench_in_the_website_shape(tmp_path):
assert king["digest"] == rig.fx["x"] and king["house"] is False
bench = king.get("bench")
assert isinstance(bench, dict), f"status king carries no bench: {king}"
# GIFT-Eval alone already feeds the website's best-model panel
assert _website_king_bench(king) == (0.40, 0.80)
assert bench["complete"] is False
for b in (h.B3, h.B3 + h.SETTLEMENT, h.B3 + 2 * h.SETTLEMENT):
rig.run(b)
bench = rig.status()["king"]["bench"]
for k in SIX + ("fev_crps", "fev_mase"):
assert isinstance(bench.get(k), float) and bench[k] > 0, k
assert bench["digest"] == rig.fx["x"]
Expand All @@ -172,7 +181,7 @@ def test_the_result_lands_in_status_king_bench_in_the_website_shape(tmp_path):
.read_text())
assert stored == bench
# the next settlement's status still carries it (read from the store)
rig.run(h.B3)
rig.run(h.B3 + 3 * h.SETTLEMENT)
assert rig.status()["king"]["bench"] == bench


Expand Down
Loading