From e22aaf3704c2683e66045bddd005f67819153a1d Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Tue, 1 Dec 2026 09:34:04 +0000 Subject: [PATCH 1/2] fix(lane D): king full bench sweeps one suite per settlement (live 2026-12-01) The first lane D king's display-only full bench swept gift/boom/time/fev in one call, outran its 2484 s allowance and failed TimeoutExpired at 09:27; it would fail every settlement the same way. Each attempt now sweeps ONE missing suite (gift first: the dashboard reads GIFT-Eval), merges it into the stored record at once (complete: false until all four, published as the partial king.bench), and the next settlement resumes at the next missing suite. A complete record is never re-swept; a failed suite never loses the earlier ones; a suite answering without a usable aggregate is left out after max_attempts answers. With less allowance left than one suite's estimate ([lane_d] king_bench_suite_estimate_s, default 1800 s, parsed + range-checked, left out of the judge request) the sweep is skipped and retried next settlement. The bench host's on-host timeout -k (IR008) stays sized to the allowance handed in. Display only: never the signed report, gate, crown or pay. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe --- cascade/shared/config/lane_d.py | 17 ++ cascade/validator/lane_d.py | 2 +- cascade/validator/lane_d_king_bench.py | 246 ++++++++++++------ cascade/validator/lane_d_wiring.py | 3 +- cascade/validator/main.py | 4 +- tests/accept/w8b/PATHS | 8 + .../w8b/test_w8b_king_bench_per_suite.py | 196 ++++++++++++++ tests/accept/w8b/test_w8b_king_full_bench.py | 19 +- 8 files changed, 403 insertions(+), 92 deletions(-) create mode 100644 tests/accept/w8b/test_w8b_king_bench_per_suite.py diff --git a/cascade/shared/config/lane_d.py b/cascade/shared/config/lane_d.py index 073910d0..06b05f71 100644 --- a/cascade/shared/config/lane_d.py +++ b/cascade/shared/config/lane_d.py @@ -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 @@ -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) @@ -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), diff --git a/cascade/validator/lane_d.py b/cascade/validator/lane_d.py index 22035611..4f584dd1 100644 --- a/cascade/validator/lane_d.py +++ b/cascade/validator/lane_d.py @@ -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: diff --git a/cascade/validator/lane_d_king_bench.py b/cascade/validator/lane_d_king_bench.py index 33c3e6d1..6fb1cc80 100644 --- a/cascade/validator/lane_d_king_bench.py +++ b/cascade/validator/lane_d_king_bench.py @@ -1,11 +1,11 @@ """The lane D king's full public bench (owner 2026-12-01: "if someone is crowned we score them"). Main validator only, DISPLAY ONLY. -When a settlement leaves a miner KING_D without a stored bench, the -production step (:class:`cascade.validator.lane_d_wiring.LaneDStep`) hands -the king to :meth:`KingBench.schedule` AFTER the settlement is published. -One full sweep of that king on all four public suites -(:data:`FULL_SUITES`: GIFT-Eval, BOOM, TIME, FEV) then runs on a daemon +When a settlement leaves a miner KING_D without a complete stored bench, +the production step (:class:`cascade.validator.lane_d_wiring.LaneDStep`) +hands the king to :meth:`KingBench.schedule` AFTER the settlement is +published. A sweep of that king's next missing public suite (of +:data:`FULL_SUITES`: GIFT-Eval, BOOM, TIME, FEV) then runs on a daemon thread on the lane D bench host, through a :class:`~cascade.validator.lane_d_bench.SweepSession` over :meth:`~cascade.validator.lane_d_bench_host.SSHBenchHost.sweep_full` (lane @@ -21,15 +21,27 @@ Never part of the gate, the crown, pay, the signed report or any consensus value; external validators never run it (no bench host is wired there). +Per suite (live 2026-12-01: one call for all four suites outran its 2484 s +allowance and failed ``TimeoutExpired`` at every settlement): each attempt +sweeps ONE missing suite, in :data:`FULL_SUITES` order (GIFT-Eval first: the +dashboard's best-model panel reads it), and merges it into the stored record +at once, so a later failure never loses an earlier suite. A record lacking a +suite is stored and published with ``complete: false``; the next settlement +sweeps the next missing suite, and a complete record is never swept again. + Timing: the sweep never blocks the step (its own thread, one at a time) and -its SSH allowance ends :data:`GUARD_S` before the next settlement boundary -(chain time: the boundary's on-chain timestamp plus the grid's blocks), so -it never overlaps the next settlement's gate sweep on the bench host. With -less than :data:`MIN_RUN_S` left it is not started. A failure (host down, -timeout, a reply without aggregates) is logged and the king is retried at -the next settlement; a sweep that completed without all four suites is kept -(published, ``complete: false``) and retried up to :data:`MAX_ATTEMPTS` -completed sweeps. The house is never benched here. +its SSH allowance (the bench host's on-host ``timeout -k`` too, IR008) ends +:data:`GUARD_S` before the next settlement boundary (chain time: the +boundary's on-chain timestamp plus the grid's blocks), so it never overlaps +the next settlement's gate sweep on the bench host. With less than one +suite's estimate (``[lane_d] king_bench_suite_estimate_s``, default +:data:`SUITE_ESTIMATE_S`; never below :data:`MIN_RUN_S`) left it is not +started (retried next settlement). A failure (host down, timeout, a reply +without aggregates) is logged and that suite is retried at the next +settlement; a suite that answered without a usable aggregate counts one +attempt, and after :data:`MAX_ATTEMPTS` such answers it is left out (the +record stays ``complete: false``) and the next suite is swept. The house is +never benched here. """ from __future__ import annotations @@ -56,7 +68,8 @@ FLAT_PREFIX = {"gift": "gifteval", "boom": "boom", "time": "time", "fev": "fev"} GUARD_S = 3600.0 # the sweep's allowance ends this long before the next boundary MIN_RUN_S = 900.0 # less time left than this: not started (retried next settlement) -MAX_ATTEMPTS = 4 # completed-but-incomplete sweeps before the partial result stands +SUITE_ESTIMATE_S = 1800.0 # one suite's sweep: less allowance than this, not started +MAX_ATTEMPTS = 4 # answers without a usable aggregate before a suite is left out _HEX64 = re.compile(r"[0-9a-f]{64}") @@ -142,39 +155,49 @@ def _positive(v) -> float | None: return f if math.isfinite(f) and f > 0 else None -def summarise(suites: Mapping[str, Mapping], *, digest: str, boundary: int, +def _suite_record(e) -> dict: + """One suite's stored entry from a sweep record's suite entry.""" + e = e if isinstance(e, Mapping) else {} + agg = e.get("aggregate") if isinstance(e.get("aggregate"), Mapping) else {} + status = agg.get("status", e.get("status")) + rows = e.get("rows") + rec = {"status": status if isinstance(status, str) else None, + "crps": _positive(agg.get("crps")), "mase": _positive(agg.get("mase")), + "partial": bool(agg.get("partial") or e.get("partial")), + "n_items": len(rows) if isinstance(rows, list) else 0} + method = agg.get("bench_method") or e.get("bench_method") + if isinstance(method, str) and method: + rec["bench_method"] = method + rev = agg.get("data_revision") or e.get("data_revision") + if isinstance(rev, str) and rev: + rec["data_revision"] = rev + return rec + + +def _usable(rec) -> bool: + """A stored suite entry with a publishable CRPS / MASE pair.""" + return (isinstance(rec, Mapping) and rec.get("status") == "ok" + and not rec.get("partial") and _positive(rec.get("crps")) is not None + and _positive(rec.get("mase")) is not None) + + +def _assemble(per: Mapping[str, Mapping], *, digest: str, boundary: int, as_of: str) -> dict: - """The stored / published bench of one sweep record's ``suites`` - (``{suite: {"status", "rows", "aggregate"?, …}}``). Raises - :class:`KingBenchError` when no suite has an aggregate pair (e.g. a bench - host that predates aggregates).""" - per: dict[str, dict] = {} + """The stored / published record of per-suite entries ``per``. Raises + :class:`KingBenchError` when no suite has an aggregate pair.""" + per = {s: dict(per[s]) if isinstance(per.get(s), Mapping) else _suite_record(None) + for s in FULL_SUITES} flat: dict[str, float] = {} methods: set[str] = set() revisions: dict[str, str] = {} - for s in FULL_SUITES: - e = suites.get(s) if isinstance(suites, Mapping) else None - e = e if isinstance(e, Mapping) else {} - agg = e.get("aggregate") if isinstance(e.get("aggregate"), Mapping) else {} - status = agg.get("status", e.get("status")) - crps, mase = _positive(agg.get("crps")), _positive(agg.get("mase")) - partial = bool(agg.get("partial") or e.get("partial")) - rows = e.get("rows") - rec = {"status": status if isinstance(status, str) else None, "crps": crps, - "mase": mase, "partial": partial, - "n_items": len(rows) if isinstance(rows, list) else 0} - method = agg.get("bench_method") or e.get("bench_method") - if isinstance(method, str) and method: - methods.add(method) - rec["bench_method"] = method - rev = agg.get("data_revision") or e.get("data_revision") - if isinstance(rev, str) and rev: - revisions[s] = rev - rec["data_revision"] = rev - per[s] = rec - if status == "ok" and not partial and crps is not None and mase is not None: - flat[f"{FLAT_PREFIX[s]}_crps"] = crps - flat[f"{FLAT_PREFIX[s]}_mase"] = mase + for s, rec in per.items(): + if isinstance(rec.get("bench_method"), str) and rec["bench_method"]: + methods.add(rec["bench_method"]) + if isinstance(rec.get("data_revision"), str) and rec["data_revision"]: + revisions[s] = rec["data_revision"] + if _usable(rec): + flat[f"{FLAT_PREFIX[s]}_crps"] = float(rec["crps"]) + flat[f"{FLAT_PREFIX[s]}_mase"] = float(rec["mase"]) if not flat: raise KingBenchError("the sweep returned no suite aggregate (a bench host that " f"predates them?): {json.dumps(per, sort_keys=True)[:300]}") @@ -184,6 +207,32 @@ def summarise(suites: Mapping[str, Mapping], *, digest: str, boundary: int, "complete": len(flat) == 2 * len(FULL_SUITES), **flat} +def summarise(suites: Mapping[str, Mapping], *, digest: str, boundary: int, + as_of: str) -> dict: + """The stored / published bench of one sweep record's ``suites`` + (``{suite: {"status", "rows", "aggregate"?, …}}``). Raises + :class:`KingBenchError` when no suite has an aggregate pair (e.g. a bench + host that predates aggregates).""" + src = suites if isinstance(suites, Mapping) else {} + return _assemble({s: _suite_record(src.get(s)) for s in FULL_SUITES}, digest=digest, + boundary=boundary, as_of=as_of) + + +def merge(stored: Mapping | None, suites: Mapping[str, Mapping], *, digest: str, + boundary: int, as_of: str) -> dict: + """``stored`` (a record of ``digest``, or ``None``) with the suites swept + now (``suites``, a sweep record's ``suites``) merged in: a suite already + usable in ``stored`` is kept as it was. Raises :class:`KingBenchError` + when the result has no suite aggregate.""" + old = stored.get("suites") if isinstance(stored, Mapping) else None + per = {s: dict(old[s]) for s in FULL_SUITES + if isinstance(old, Mapping) and isinstance(old.get(s), Mapping)} + for s, e in (suites if isinstance(suites, Mapping) else {}).items(): + if s in FULL_SUITES and not _usable(per.get(s)): + per[s] = _suite_record(e) + return _assemble(per, digest=digest, boundary=boundary, as_of=as_of) + + # ── the runner ────────────────────────────────────────────────────────────── @@ -196,22 +245,26 @@ def _iso(ts: float) -> str: class KingBench: - """Schedules and runs the lane D king's full bench (module docstring). - ``host`` is the lane D bench host (``sweep_full`` and ``context_of``: + """Schedules and runs the lane D king's full bench, one suite per + attempt (module docstring). ``host`` is the lane D bench host + (``sweep_full`` and ``context_of``: :class:`~cascade.validator.lane_d_bench_host.SSHBenchHost`); ``spawn`` runs the sweep (default: a daemon thread); ``now`` is wall-clock - seconds.""" + seconds; ``suite_estimate_s`` is one suite's expected sweep time (``[lane_d] + king_bench_suite_estimate_s``).""" def __init__(self, host: Any, *, state_dir, suites: Iterable[str] = FULL_SUITES, guard_s: float = GUARD_S, min_run_s: float = MIN_RUN_S, + suite_estimate_s: float = SUITE_ESTIMATE_S, max_attempts: int = MAX_ATTEMPTS, spawn: Callable[[Callable[[], None]], None] | None = None, now: Callable[[], float] = time.time): self.host = host self.state_dir = Path(state_dir) - self.suites = tuple(suites) + self.suites = tuple(s for s in suites if s in FULL_SUITES) self.guard_s = float(guard_s) self.min_run_s = float(min_run_s) + self.suite_estimate_s = float(suite_estimate_s) self.max_attempts = int(max_attempts) self._spawn = spawn or _thread self._now = now @@ -224,34 +277,53 @@ def running(self) -> str | None: with self._lock: return self._running - def _attempts(self, digest: str) -> int: + def _attempts(self, digest: str) -> dict[str, int]: + """``{suite: answers without a usable aggregate}`` of ``digest``.""" doc = _read(_attempts_path(self.state_dir, digest)) or {} - n = doc.get("attempts", 0) - return int(n) if isinstance(n, int) and not isinstance(n, bool) else 0 - - def due(self, digest: str) -> bool: - """``digest`` still needs a sweep: none stored, or an incomplete one - with completed attempts left.""" + per = doc.get("suites") + if not isinstance(per, Mapping): + return {} + return {s: int(n) for s, n in per.items() + if s in FULL_SUITES and isinstance(n, int) and not isinstance(n, bool)} + + def next_suite(self, digest: str) -> str | None: + """The suite the next attempt sweeps: the first of ``suites`` without + a usable stored entry and with attempts left (``None``: nothing + left).""" stored = load_bench(self.state_dir, digest) if stored is not None and stored.get("complete") is True: - return False - return self._attempts(digest) < self.max_attempts + return None + per = stored.get("suites") if stored is not None else None + per = per if isinstance(per, Mapping) else {} + tries = self._attempts(digest) + for s in self.suites: + if not _usable(per.get(s)) and tries.get(s, 0) < self.max_attempts: + return s + return None + + def due(self, digest: str) -> bool: + """``digest`` still needs a sweep: a suite missing from its stored + record with attempts left.""" + return self.next_suite(digest) is not None def schedule(self, *, digest: str, boundary: int, deadline_ts: float, on_done: Callable[[dict], None] | None = None) -> bool: - """Start one full sweep of ``digest`` (crowned / held at ``boundary``) - when it is due, none is running and at least ``min_run_s`` remain - before ``deadline_ts`` (wall-clock seconds; the allowance ends - there). ``on_done(bench)`` gets the stored record. True when - started. Never raises.""" + """Start one sweep of the next missing suite of ``digest`` (crowned / + held at ``boundary``) when one is due, none is running and at least + one suite's estimate remains before ``deadline_ts`` (wall-clock + seconds; the allowance ends there). ``on_done(bench)`` gets the stored + record. True when started. Never raises.""" try: - if not self.due(digest): + suite = self.next_suite(digest) + if suite is None: return False budget = float(deadline_ts) - float(self._now()) - if budget < self.min_run_s: - log.info("lane_d_king_bench_deferred settlement %d king %s: %.0f s left before " - "the pre-settlement guard; retried next settlement", int(boundary), - digest[:16], budget) + need = max(self.min_run_s, self.suite_estimate_s) + if budget < need: + log.info("lane_d_king_bench_deferred settlement %d king %s suite %s: %.0f s " + "left before the pre-settlement guard (one suite needs ~%.0f s); " + "retried next settlement", int(boundary), digest[:16], suite, + budget, need) return False context_of = getattr(self.host, "context_of", None) context = context_of(digest) if callable(context_of) else None @@ -269,7 +341,7 @@ def schedule(self, *, digest: str, boundary: int, deadline_ts: float, return False def run() -> None: - self._run(digest, int(boundary), int(context), budget, on_done) + self._run(digest, int(boundary), int(context), suite, budget, on_done) try: self._spawn(run) @@ -279,34 +351,40 @@ def run() -> None: log.warning("lane_d_king_bench_failed settlement %d: could not start (%s)", int(boundary), e) return False - log.info("lane_d_king_bench_started settlement %d king %s (allowance %.0f s)", - int(boundary), digest[:16], budget) + log.info("lane_d_king_bench_started settlement %d king %s suite %s (allowance %.0f s)", + int(boundary), digest[:16], suite, budget) return True - def _run(self, digest: str, boundary: int, context: int, timeout_s: float, + def _run(self, digest: str, boundary: int, context: int, suite: str, timeout_s: float, on_done: Callable[[dict], None] | None) -> None: from .lane_d_bench import SweepSession + doc = None try: def sweep(digests, suites): return self.host.sweep_full(digests, suites, contexts={digest: context}, timeout_s=timeout_s) - session = SweepSession(f"{SESSION_PREFIX}/{boundary}/{digest}", sweep) - rec, _, _ = session.paired(digest, digest, digest, suites=self.suites) - doc = summarise(rec["suites"], digest=digest, boundary=boundary, - as_of=_iso(self._now())) - _write(bench_path(self.state_dir, digest), doc) - if not doc["complete"]: + session = SweepSession(f"{SESSION_PREFIX}/{boundary}/{digest}/{suite}", sweep) + rec, _, _ = session.paired(digest, digest, digest, suites=(suite,)) + got = rec["suites"] if isinstance(rec.get("suites"), Mapping) else {} + if not _usable(_suite_record(got.get(suite))): + tries = self._attempts(digest) + tries[suite] = tries.get(suite, 0) + 1 _write(_attempts_path(self.state_dir, digest), - {"attempts": self._attempts(digest) + 1, "boundary": boundary}) - log.info("lane_d_king_bench_done settlement %d king %s complete=%s gift " - "crps=%s mase=%s", boundary, digest[:16], doc["complete"], + {"suites": tries, "boundary": boundary}) + stored = load_bench(self.state_dir, digest) + doc = merge(stored, {suite: got.get(suite)}, digest=digest, boundary=boundary, + as_of=_iso(self._now())) + _write(bench_path(self.state_dir, digest), doc) + log.info("lane_d_king_bench_done settlement %d king %s suite %s usable=%s " + "complete=%s gift crps=%s mase=%s", boundary, digest[:16], suite, + _usable(doc["suites"].get(suite)), doc["complete"], doc.get("gifteval_crps"), doc.get("gifteval_mase")) except Exception as e: # noqa: BLE001 — retried next settlement - log.warning("lane_d_king_bench_failed settlement %d king %s: %s: %s; retried next " - "settlement (display only: the crown and pay stand)", boundary, - digest[:16], type(e).__name__, e) + log.warning("lane_d_king_bench_failed settlement %d king %s suite %s: %s: %s; " + "retried next settlement (display only: the crown and pay stand)", + boundary, digest[:16], suite, type(e).__name__, e) return finally: with self._lock: @@ -319,5 +397,5 @@ def sweep(digests, suites): __all__ = ["FLAT_PREFIX", "FULL_SUITES", "GUARD_S", "MAX_ATTEMPTS", "MIN_RUN_S", "SCHEMA", - "STORE_DIR", "KingBench", "KingBenchError", "attach_benches", "bench_path", - "load_bench", "load_benches", "summarise"] + "STORE_DIR", "SUITE_ESTIMATE_S", "KingBench", "KingBenchError", "attach_benches", + "bench_path", "load_bench", "load_benches", "merge", "summarise"] diff --git a/cascade/validator/lane_d_wiring.py b/cascade/validator/lane_d_wiring.py index 2e091e1d..56d13f8b 100644 --- a/cascade/validator/lane_d_wiring.py +++ b/cascade/validator/lane_d_wiring.py @@ -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. diff --git a/cascade/validator/main.py b/cascade/validator/main.py index 2591ca23..4f2ec299 100644 --- a/cascade/validator/main.py +++ b/cascade/validator/main.py @@ -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, diff --git a/tests/accept/w8b/PATHS b/tests/accept/w8b/PATHS index aaf770af..e4ce1f22 100644 --- a/tests/accept/w8b/PATHS +++ b/tests/accept/w8b/PATHS @@ -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] diff --git a/tests/accept/w8b/test_w8b_king_bench_per_suite.py b/tests/accept/w8b/test_w8b_king_bench_per_suite.py new file mode 100644 index 00000000..b97b20bf --- /dev/null +++ b/tests/accept/w8b/test_w8b_king_bench_per_suite.py @@ -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 diff --git a/tests/accept/w8b/test_w8b_king_full_bench.py b/tests/accept/w8b/test_w8b_king_full_bench.py index a4541455..8321afab 100644 --- a/tests/accept/w8b/test_w8b_king_full_bench.py +++ b/tests/accept/w8b/test_w8b_king_full_bench.py @@ -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) @@ -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) @@ -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"] @@ -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 From 046fd78de22b223ae9586db3c9ab66f8d7a0e51d Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Tue, 1 Dec 2026 09:52:06 +0000 Subject: [PATCH 2/2] ci: re-run the PR gate with the laned:tests-correction label Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe