diff --git a/cascade/validator/lane_d.py b/cascade/validator/lane_d.py index b28e417e..c1ec1d24 100644 --- a/cascade/validator/lane_d.py +++ b/cascade/validator/lane_d.py @@ -86,7 +86,12 @@ clear is not swept (``bench_hold`` in ``gate.results``) and re-queued unjudged and uncharged (``pending``/``pending_floor``, as a hold whose KING_D changed), judged afresh against the new king. Only when no held - candidate passes are the new clears gated and ranked; + candidate passes are the new clears gated and ranked. Held defers duels + (owner 2026-12-01, "we don't need that"): a settlement with a held + candidate duels no new entry at all; the queue's selection is skipped + ``pending_floor`` (unjudged, uncharged, no forecast asked) and duelled at + the next settlement against whoever is king then, so a held-only + settlement is the gate alone (no cohort, row or verdict); 6. writes the signed ``lane-d-report/1`` (W7a: the schema file ``schemas/lane_d_report_1.json``; every entry considered and not judged is a typed skip, court slots that burn name a ``burn_reason``; ``pool.snapshots`` @@ -603,6 +608,13 @@ def _king_reveal_ts(state: dict, digest: str) -> int | None: # ── the §1.3b gate (W5e) ──────────────────────────────────────────────────── +# Owner 2026-12-01 ("we don't need that"): the typed skip of a new entry a +# settlement with a held gate candidate does not duel (deferred to the next +# settlement, unjudged and uncharged). An existing reason: the released +# satellite checkers accept it. +HELD_DEFER_REASON = "pending_floor" + + def _held_candidates(state: dict) -> list[str]: """The open entries holding a first clear the gate could not decide (``gate_hold``, a ``bench_hold``). They are re-gated without a new duel. @@ -1510,7 +1522,10 @@ def _choose(state: dict, cfg, boundary: int, boundary_ts, entries: list[dict], u member's forecasts are malformed on a pool window or its public half is not finite), the armed context and the judging start. Mutates ``state`` and returns ``skipped``, ``held``, ``house_held``, ``chosen`` (the miner - members duelled), ``house_open``, ``house_rec`` and ``hd``. + members duelled), ``house_open``, ``house_rec`` and ``hd``. With a held + gate candidate ``chosen`` is empty and the house challenger closed for + the settlement: the queue's selection waits ``pending_floor`` (held + defers duels, owner 2026-12-01). :func:`judged_digests` runs it on a copy of the state, before any forecast exists, to know which digests the settlement duels (owner 2026-12-01).""" @@ -1558,11 +1573,17 @@ def skip(dg: str, reason: str, rec: dict | None = None) -> None: chosen, queued = select_queue(state, cfg, boundary, entries, frozenset(held)) skipped += queued house_held = house_open and _keeps_hold(house_rec, state) + # Owner 2026-12-01 ("we don't need that"): with a held gate candidate + # this settlement duels NO new entry (held first: none could crown). The + # queue's selection is deferred, unjudged and uncharged, to the next + # settlement (``pending`` / ``pending_floor``, a reason the released + # checkers accept): no forecast check, no frozen set, no cohort. + defer = bool(held) or house_held # A member whose forecasts are malformed on any pool window is the miner's fault # (the house's own: its entry closes, fail closed). for dg in list(chosen): - if faulty(dg): + if not defer and faulty(dg): state["entries"][dg]["status"] = "closed" skip(dg, "checkpoint_fault") chosen.remove(dg) @@ -1592,6 +1613,13 @@ def skip(dg: str, reason: str, rec: dict | None = None) -> None: if why is not None: skip(hd, why, house_rec) house_open = False + if defer: + for dg in chosen: + skip(dg, HELD_DEFER_REASON) + chosen = [] + if house_open and not house_held: + skip(hd, HELD_DEFER_REASON, house_rec) + house_open = False if house_open and not house_held and faulty(hd): house_rec["status"] = "closed" skip(hd, "checkpoint_fault", house_rec) @@ -2525,5 +2553,5 @@ def absent_settlement(*, cfg, boundary: int, state_path, house: dict, reason: st receipt=receipt) -__all__ = ["LaneDSettlement", "absent_settlement", "held_gate_digests", "judge_cohort", - "load_pool", "settle_lane_d", "window_id"] +__all__ = ["HELD_DEFER_REASON", "LaneDSettlement", "absent_settlement", "held_gate_digests", + "judge_cohort", "load_pool", "settle_lane_d", "window_id"] diff --git a/docs/MINER_LANE_D.md b/docs/MINER_LANE_D.md index a017170d..d805994f 100644 --- a/docs/MINER_LANE_D.md +++ b/docs/MINER_LANE_D.md @@ -252,11 +252,10 @@ blocks, about 24 h) of `submit`, or the entry expires (`ready_expired`). holds the verdict (`bench_hold`); after `max_bench_holds` (4) holds the entry goes back to the queue unjudged, never charged. - **Crown order: held first.** A held entry was scored on an earlier - settlement's windows, so it is gated before any entry that first clears now. - If a held entry passes, it is crowned. The new clears are not gated or - charged: they go back to `pending` (`pending_floor`) and are duelled at the - next settlement against the new king. Only if no held entry passes are the - new clears gated, and the highest LCB crowns. + settlement's windows, so a settlement with a held entry only re-gates it: + no new entry is duelled there. New entries wait in `pending` + (`pending_floor`), unjudged and never charged, and are duelled at the next + settlement against whoever is king then (the held entry if it passed). ## How you are paid diff --git a/tests/accept/w5g/test_w5g_held_defers.py b/tests/accept/w5g/test_w5g_held_defers.py new file mode 100644 index 00000000..bb06e672 --- /dev/null +++ b/tests/accept/w5g/test_w5g_held_defers.py @@ -0,0 +1,210 @@ +"""Held defers duels (owner 2026-12-01, "we don't need that"). A settlement +with a HELD gate candidate (a ``bench_hold``, re-gated without a duel) duels +NO new entry: held first means none could crown there. Every entry the queue +would have selected is skipped ``pending`` / ``pending_floor`` (an existing +reason), unjudged and uncharged: no forecast check, frozen set, cohort, row +or verdict. The next settlement duels it against whoever is king then (the +held candidate if it passed, else the old KING_D). + +X clears at boundary 2 and is held (bench host down). Y readies after it and +is eligible at boundary 3. With no held candidate nothing changes (the report +bytes on main before held first, ``NO_HELD_REPORT_SHA256``). + +Satellites never update: every report of the new rule is run through the +released validator lines' satellite checker (``git archive`` of +validator-release-laned-live 890fe6d1 and validator-release-laned-1201 +15ae7e96) and must give zero problems and no burn. + +On main (before this rule) Y is duelled at boundary 3, so every test here +fails on an AssertionError. +""" + +from __future__ import annotations + +import io +import json +import subprocess +import sys +import tarfile +from pathlib import Path + +import pytest + +from .helpers import ( + ARM_BLOCK, + ERA, + HORIZON, + MARGIN_H, + entry_of, + fixture_key, + read_state, + rows_of, + skips_of, + verdict_of, +) +from .test_w5g_held_first import _flow, _settle + +REPO = Path(__file__).resolve().parents[3] +# The released validator lines (satellites never update), their satellite +# checker blob (cascade/audit/lane_d.py, the same file on both). +RELEASES = {"laned-live": ("890fe6d1c530eedccd4ee764547041e5c607c1ed", + "3a342edfaff625b53beb45f98ebbcd54773b841d"), + "laned-1201": ("15ae7e961bd4973c00551b526614937a0becd18d", + "3a342edfaff625b53beb45f98ebbcd54773b841d")} + + +def _need_rule() -> None: + """The rule's typed reason exists (so every test fails on the code + before it by assertion, not an import error).""" + import cascade.validator.lane_d as lane_d + + assert getattr(lane_d, "HELD_DEFER_REASON", None) == "pending_floor", \ + "lane_d.HELD_DEFER_REASON missing (held defers duels not built)" + + +def _deferred(f, report: dict, yd: str) -> None: + """Y was not duelled: a typed ``pending_floor`` skip, its record untouched.""" + assert verdict_of(report, yd) is None, "a held settlement duels no new entry" + assert rows_of(report, yd) == set(), "no live row for a deferred entry" + assert report["judged"] == [] and report["cohorts"] == [] and report["rows"] == [], \ + "a held-only settlement is the gate alone (no cohort, row or verdict)" + assert skips_of(report, yd) == ["pending_floor"], report["skipped"] + e = entry_of(report, yd) + assert (e["status"], e["reason"]) == ("pending", "pending_floor"), e + rec = read_state(f.path)["entries"][yd] + assert (rec["status"], rec["reason"]) == ("pending", "pending_floor"), rec + assert rec["used_windows"] == [], "uncharged: no window is spent" + assert rec.get("frozen_set") is None and not rec.get("gate_hold") + assert all(s["digest"] != yd for s in report["pay"]["court"]) + assert all(r["digest"] != yd for r in report["gate"]["results"]), \ + "a deferred entry is never gated" + + +def test_held_settlement_duels_no_new_entry(tmp_path): + _need_rule() + f, y = _flow(tmp_path) + x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] + report, host = _settle(f, 3, 3, [f.x, y], {x: 0.9, yd: 0.85, h: 1.0}) + _deferred(f, report, yd) + assert report["crowned"] == x and read_state(f.path)["king"]["digest"] == x + assert [r["digest"] for r in report["gate"]["results"]] == [x] + assert yd not in host.swept_digests() + + +def test_deferred_entry_is_duelled_next_against_the_new_king(tmp_path): + _need_rule() + f, y = _flow(tmp_path) + x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] + _settle(f, 3, 3, [f.x, y], {x: 0.9, yd: 0.85, h: 1.0}) + nxt, _ = _settle(f, 4, 4, [f.x, y], {yd: 0.85, x: 1.0, h: 1.0}) + v = verdict_of(nxt, yd) + assert v is not None and v["stage"] == "first" and v["king_digest"] == x, v + assert rows_of(nxt, yd), "duelled on the next settlement's windows" + + +@pytest.mark.parametrize("held_mode", ["regress", "fault"]) +def test_held_fails_then_the_deferred_entry_duels_the_old_king(tmp_path, held_mode): + _need_rule() + f, y = _flow(tmp_path) + x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] + spec = {"regress": {x: 1.10}, "fault": {x: "nan"}}[held_mode] + report, _ = _settle(f, 3, 3, [f.x, y], {**spec, yd: 0.85, h: 1.0}) + outcomes = {r["digest"]: r["outcome"] for r in report["gate"]["results"]} + assert outcomes == {x: {"regress": "gate_regression", "fault": "checkpoint_fault"}[ + held_mode]}, outcomes + assert report["crowned"] is None and read_state(f.path)["king"]["digest"] == h + _deferred(f, report, yd) + nxt, host = _settle(f, 4, 4, [f.x, y], {yd: 0.85, h: 1.0}) + v = verdict_of(nxt, yd) + assert v is not None and v["king_digest"] == h, v + assert nxt["crowned"] == yd and yd in host.swept_digests() + + +def test_held_again_defers_again(tmp_path): + _need_rule() + f, y = _flow(tmp_path) + x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] + report, _ = _settle(f, 3, 3, [f.x, y], {x: 0.9, yd: 0.85, h: 1.0}, down={x}) + assert {r["digest"]: r["outcome"] for r in report["gate"]["results"]} == {x: "bench_hold"} + assert read_state(f.path)["entries"][x]["status"] == "hold" + _deferred(f, report, yd) + + +def test_no_held_candidate_is_unchanged(tmp_path): + """No held candidate: the new entries are duelled as before; the report + bytes are main's before held first (test_w5g_held_first's fixture).""" + _need_rule() + from .test_w5g_held_first import test_no_held_candidate_keeps_max_t_order + + test_no_held_candidate_keeps_max_t_order(tmp_path) + + +# ── the released satellite checker (never updated) ────────────────────────── + + +_OLD_CHECK = r""" +import json, sys +sys.path.insert(0, sys.argv[1]) +import cascade +assert cascade.__file__.startswith(sys.argv[1]), cascade.__file__ +from cascade.shared.config.lane_d import parse_lane_d +from cascade.audit.lane_d import lane_d_findings +raw = json.loads(sys.argv[3]) +cfg = parse_lane_d(raw, era_blocks_at=lambda _b: int(sys.argv[5])) +report = json.loads(open(sys.argv[2]).read()) +f = lane_d_findings(report, cfg, signer_hotkey=sys.argv[4]) +print(json.dumps({"burn": f.burn, "alerts": f.alerts, "transient": f.transient, + "findings": f.findings})) +""" + + +def _old_tree(tmp: Path, which: str) -> Path: + rel, blob = RELEASES[which] + dest = tmp / f"old-{which}" + if dest.exists(): + return dest + got = subprocess.run(["git", "-C", str(REPO), "rev-parse", f"{rel}:cascade/audit/lane_d.py"], + capture_output=True, text=True) + assert got.returncode == 0 and got.stdout.strip() == blob, \ + (f"the released checker {which} ({rel}) is not readable here", got.stdout, got.stderr) + raw = subprocess.run(["git", "-C", str(REPO), "archive", "--format=tar", rel, "cascade"], + check=True, capture_output=True).stdout + with tarfile.open(fileobj=io.BytesIO(raw)) as tf: + tf.extractall(dest, filter="data") + return dest + + +def _old_findings(tmp: Path, which: str, report: dict, tag: str) -> dict: + tree = _old_tree(tmp, which) + raw = {"from_block": ARM_BLOCK, "share": 0.25, "takes_from": "lane_a", "remainder": "burn", + "contexts": [4096, 8192, 16384], "horizon": HORIZON, + "forward_margin_hours": MARGIN_H, "max_mirror_lag_hours": 6.0, "min_windows": 24, + "min_clusters": 4, "bootstrap_B": 200, "public_weight": 0.0, + "window_ratio_floor": 1e-9, "horizon_bands": []} + path = tmp / f"report-{which}-{tag}.json" + path.write_text(json.dumps(report)) + out = subprocess.run([sys.executable, "-I", "-c", _OLD_CHECK, str(tree), str(path), + json.dumps(raw), fixture_key("signer").ss58_address, str(ERA)], + capture_output=True, text=True, cwd=str(tmp)) + assert out.returncode == 0, f"the old checker crashed: {out.stderr[-2000:]}" + return json.loads(out.stdout.strip().splitlines()[-1]) + + +@pytest.mark.parametrize("which", sorted(RELEASES)) +@pytest.mark.parametrize("case", ["held_crowns", "held_fails", "held_again"]) +def test_the_released_satellite_checker_accepts_held_defers(tmp_path, which, case): + _need_rule() + f, y = _flow(tmp_path / "flow") + x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] + spec = {x: 1.10 if case == "held_fails" else 0.9, yd: 0.85, h: 1.0} + report, _ = _settle(f, 3, 3, [f.x, y], spec, down={x} if case == "held_again" else ()) + _deferred(f, report, yd) + # the next settlement duels the deferred entry (against X, or the house) + nxt, _ = _settle(f, 4, 4, [f.x, y], {yd: 0.85, x: 1.0, h: 1.0}) + if case != "held_again": + assert verdict_of(nxt, yd) is not None, "the deferred entry is duelled next" + for n in (2, 3, 4): + got = _old_findings(tmp_path, which, f.reports[n], f"{case}-{n}") + assert got["transient"] == "", (n, got) + assert got["burn"] is None, (n, got) + assert got["findings"] == [], (n, got) diff --git a/tests/accept/w5g/test_w5g_held_first.py b/tests/accept/w5g/test_w5g_held_first.py index e65820fb..c3c1e6aa 100644 --- a/tests/accept/w5g/test_w5g_held_first.py +++ b/tests/accept/w5g/test_w5g_held_first.py @@ -1,41 +1,21 @@ """Held first (owner 2026-12-01: "they need to be scored first"; lane D order = reveal order). A candidate HELD from an earlier settlement (a ``bench_hold``: status ``hold``, its clear in ``gate_hold``) was scored on -that settlement's eval set; a clear first made at this settlement was scored -on this settlement's set, so their LCBs are never ranked against each other. - -The held candidates are gated first. When one passes it crowns, and every -new clear is neither crowned nor charged: it is not swept (``bench_hold`` in -``gate.results``), its verdict stays ``cleared``, and the entry is re-queued -unjudged (``pending`` / ``pending_floor``, as a hold whose KING_D changed), -duelled afresh at the next settlement against the new king. Only when no held -candidate passes do the new clears go through the gate and ranking as before. - -X clears at boundary 2 and is held (bench host down). At boundary 3 Y enters -and clears on a fresh snapshot with an LCB above X's held one. Every report -is also run through the satellite checker of the deployed releases (they -never update): a new rule must give zero problems there. - -On main the boundary-3 crown is Y (the highest LCB across both eval sets), -so the held-first tests fail on an AssertionError. +that settlement's eval set, so its LCB is never ranked against a new clear. + +Superseded the same day by held defers duels (owner 2026-12-01, "we don't +need that"; ``test_w5g_held_defers``): a settlement with a held candidate +duels no new entry at all, so a held candidate and a new clear never meet in +one gate. This file keeps the fixtures those tests share and the no-held +case: every clear is swept and the highest LCB crowns, report bytes +unchanged. """ from __future__ import annotations -import io -import json -import subprocess -import sys -import tarfile from pathlib import Path -import pytest - from .helpers import ( - ARM_BLOCK, - ERA, - HORIZON, - MARGIN_H, T_X, BenchHost, Flow, @@ -45,14 +25,11 @@ boundary, entry, entry_of, - fixture_key, forecasts, read_state, report_digest, - rows_of, settle, uids, - verdict_of, ) REPO = Path(__file__).resolve().parents[3] @@ -109,68 +86,6 @@ def _settle(f: Flow, n: int, snap: int, entries, spec: dict, down=()): return out.report, host -def _new_clear_outranks_held(f: Flow, y: dict, report: dict) -> None: - held = read_state(f.path)["entries"][f.x["digest"]].get("gate_hold") or {} - xl = next(r["held_from"]["lcb"] for r in report["gate"]["results"] - if r["digest"] == f.x["digest"]) - v = verdict_of(report, y["digest"]) - assert v is not None and v["cleared"] is True, f"fixture: Y did not clear: {v}" - assert v["lcb"] > xl, f"fixture: Y's LCB {v['lcb']} must outrank X's held {xl} ({held})" - - -def test_held_candidate_crowns_before_a_higher_lcb_new_clear(tmp_path): - _need_held_first() - f, y = _flow(tmp_path) - x, h = f.x["digest"], f.h0["digest"] - report, host = _settle(f, 3, 3, [f.x, y], {x: 0.9, y["digest"]: 0.85, h: 1.0}) - _new_clear_outranks_held(f, y, report) - assert report["crowned"] == x, \ - "a held candidate is decided before any new clear: X crowns, not the higher-LCB Y" - assert read_state(f.path)["king"]["digest"] == x - assert rows_of(report, x) == set(), "a held candidate is re-gated, never re-duelled" - assert verdict_of(report, y["digest"])["outcome"] == "cleared" - - -def test_the_new_clear_is_requeued_unjudged_and_uncharged(tmp_path): - _need_held_first() - f, y = _flow(tmp_path) - x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] - report, host = _settle(f, 3, 3, [f.x, y], {x: 0.9, yd: 0.85, h: 1.0}) - rec = read_state(f.path)["entries"][yd] - assert (rec["status"], rec["reason"]) == ("pending", "pending_floor"), rec - assert not rec.get("gate_hold") and rec.get("confirm") is None - assert rec.get("frozen_set") is None - e = entry_of(report, yd) - assert (e["status"], e["reason"]) == ("pending", "pending_floor") - assert yd not in host.swept_digests(), "the new clear is not gated once a held one crowns" - (res,) = [r for r in report["gate"]["results"] if r["digest"] == yd] - assert res["outcome"] == "bench_hold" and "rows" not in res and "held_from" not in res - assert all(s["digest"] != yd for s in report["pay"]["court"]) - assert all(s["digest"] != yd for s in report["skipped"]), "judged, so never a skip" - # Next settlement (fresh snapshot): Y is duelled afresh against the new king. - nxt, _ = _settle(f, 4, 4, [f.x, y], {yd: 0.85, x: 1.0, h: 1.0}) - v = verdict_of(nxt, yd) - assert v is not None and v["stage"] == "first" and v["king_digest"] == x, v - assert rows_of(nxt, yd) and not rows_of(nxt, yd) & rows_of(report, yd) - - -@pytest.mark.parametrize("held_mode", ["regress", "fault", "hold_again"]) -def test_held_fails_then_new_clears_rank_as_today(tmp_path, held_mode): - _need_held_first() - f, y = _flow(tmp_path) - x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] - spec = {"regress": {x: 1.10}, "fault": {x: "nan"}, "hold_again": {x: 0.9}}[held_mode] - report, host = _settle(f, 3, 3, [f.x, y], {**spec, yd: 0.85, h: 1.0}, - down={x} if held_mode == "hold_again" else ()) - outcomes = {r["digest"]: r["outcome"] for r in report["gate"]["results"]} - want_x = {"regress": "gate_regression", "fault": "checkpoint_fault", - "hold_again": "bench_hold"}[held_mode] - assert outcomes == {x: want_x, yd: "pass"}, outcomes - assert report["crowned"] == yd and read_state(f.path)["king"]["digest"] == yd - assert yd in host.swept_digests() - assert verdict_of(report, yd)["outcome"] == "crowned" - - def test_no_held_candidate_keeps_max_t_order(tmp_path): """No held candidate: every clear is swept and the highest LCB crowns (the order before this rule; its report bytes are unchanged).""" @@ -197,68 +112,3 @@ def test_no_held_candidate_keeps_max_t_order(tmp_path): assert host.swept_digests() >= set(order) # The report bytes of this settlement on main 49ea024c (before held first). assert report_digest(report) == NO_HELD_REPORT_SHA256 - - -# ── the released satellite checker (never updated) ────────────────────────── - - -_OLD_CHECK = r""" -import json, sys -sys.path.insert(0, sys.argv[1]) -import cascade -assert cascade.__file__.startswith(sys.argv[1]), cascade.__file__ -from cascade.shared.config.lane_d import parse_lane_d -from cascade.audit.lane_d import lane_d_findings -raw = json.loads(sys.argv[3]) -cfg = parse_lane_d(raw, era_blocks_at=lambda _b: int(sys.argv[5])) -report = json.loads(open(sys.argv[2]).read()) -f = lane_d_findings(report, cfg, signer_hotkey=sys.argv[4]) -print(json.dumps({"burn": f.burn, "alerts": f.alerts, "transient": f.transient, - "findings": f.findings})) -""" - - -def _old_tree(tmp: Path, rel: str, blob: str) -> Path: - got = subprocess.run(["git", "-C", str(REPO), "rev-parse", f"{rel}:cascade/audit/lane_d.py"], - capture_output=True, text=True) - assert got.returncode == 0 and got.stdout.strip() == blob, (rel, got.stdout, got.stderr) - raw = subprocess.run(["git", "-C", str(REPO), "archive", "--format=tar", rel, "cascade"], - check=True, capture_output=True).stdout - dest = tmp / f"old-{rel}" - with tarfile.open(fileobj=io.BytesIO(raw)) as tf: - tf.extractall(dest, filter="data") - return dest - - -def _old_findings(tmp: Path, which: str, report: dict) -> dict: - tree = _old_tree(tmp, *CHECKERS[which]) - raw = {"from_block": ARM_BLOCK, "share": 0.25, "takes_from": "lane_a", "remainder": "burn", - "contexts": [4096, 8192, 16384], "horizon": HORIZON, - "forward_margin_hours": MARGIN_H, "max_mirror_lag_hours": 6.0, "min_windows": 24, - "min_clusters": 4, "bootstrap_B": 200, "public_weight": 0.0, - "window_ratio_floor": 1e-9} - if which == "deployed": - raw["horizon_bands"] = [] - path = tmp / f"report-{which}.json" - path.write_text(json.dumps(report)) - out = subprocess.run([sys.executable, "-I", "-c", _OLD_CHECK, str(tree), str(path), - json.dumps(raw), fixture_key("signer").ss58_address, str(ERA)], - capture_output=True, text=True, cwd=str(tmp)) - assert out.returncode == 0, f"the old checker crashed: {out.stderr[-2000:]}" - return json.loads(out.stdout.strip().splitlines()[-1]) - - -@pytest.mark.parametrize("which", sorted(CHECKERS)) -@pytest.mark.parametrize("case", ["held_crowns", "held_fails_new_crowns"]) -def test_the_released_satellite_checker_accepts_held_first(tmp_path, which, case): - _need_held_first() - f, y = _flow(tmp_path / "flow") - x, h, yd = f.x["digest"], f.h0["digest"], y["digest"] - spec = {x: 0.9 if case == "held_crowns" else 1.10, yd: 0.85, h: 1.0} - report, _ = _settle(f, 3, 3, [f.x, y], spec) - assert report["crowned"] == (x if case == "held_crowns" else yd) - for n in (2, 3): - got = _old_findings(tmp_path, which, f.reports[n]) - assert got["transient"] == "", got - assert got["burn"] is None, (n, got) - assert got["findings"] == [], (n, got) diff --git a/tests/accept/w_offbox/test_w_offbox_held_defers.py b/tests/accept/w_offbox/test_w_offbox_held_defers.py new file mode 100644 index 00000000..fa2ea8d9 --- /dev/null +++ b/tests/accept/w_offbox/test_w_offbox_held_defers.py @@ -0,0 +1,124 @@ +"""Held defers duels (owner 2026-12-01, "we don't need that"): a settlement +with a held gate candidate duels no new entry, so the eval host does no live +or public scoring of new entries there. Only the gate (bench) runs for the +held candidate. + +The eval host's ``settle`` pool phase is still called once (the signed +report's ``pool`` record, the newest snapshot's name and first-seen roots, +comes from the host's copy of the pins; the box loads no ``pool_d``), but +with an EMPTY need: no forecast, no cohort. The public half asks KING_D +alone (its reply carries the read-time drops the signed public record names). + +The chain is test_w_offbox_judged_only's, with Y past its judging start at +B2 (not at B1): +- B1: X (clears) and L (loses) are duelled; Y before its judging start; the + bench is down, so X is held. +- B2: X is re-gated from its hold (crowned). Y is eligible but deferred + (``pending_floor``): not forecast, not in the settle request. +- B3: Y is selected and forecast against KING_D X. + +On main (before this rule) Y is forecast and duelled at B2, so every test +fails on an AssertionError. +""" + +from __future__ import annotations + +from . import helpers as h +from .test_w_offbox_judged_only import ( + B1, + B2, + B3, + Y_REVEAL_BLOCK, + _fixture, + _report, + _rig, + _run, + w8c, +) + +# Y's T: past its judging start (T + 6 h) at B2, before it at B1. +Y_T_EARLY = w8c.fixture_boundary_ts(B2) - 6 * 3600 - 60 + + +def _need_rule() -> None: + import cascade.validator.lane_d as lane_d + + assert getattr(lane_d, "HELD_DEFER_REASON", None) == "pending_floor", \ + "lane_d.HELD_DEFER_REASON missing (held defers duels not built)" + + +def _early(rig): + rig.reader.timestamps[Y_REVEAL_BLOCK] = Y_T_EARLY + return rig + + +def _check_story(rig, fx) -> None: + x, lo, y = fx["x"], fx["loser"]["digest"], fx["late"]["digest"] + r1, r2, r3 = (_report(rig, b) for b in (B1, B2, B3)) + assert sorted(r1["judged"]) == sorted([x, lo]), r1["judged"] + assert {"digest": y, "reason": "before_eval_delay"} in r1["skipped"] + assert r2["crowned"] == x and [c["digest"] for c in r2["gate"]["results"]] == [x] + assert r2["judged"] == [] and r2["cohorts"] == [] and r2["rows"] == [], \ + "B2 (a held candidate): no new entry is duelled" + assert {"digest": y, "reason": "pending_floor"} in r2["skipped"], r2["skipped"] + (ey,) = [e for e in r2["entries"] if e["digest"] == y] + assert (ey["status"], ey["reason"]) == ("pending", "pending_floor") + # B3: Y is selected and forecast against KING_D X (the forecast / need + # assertions); on this fixture's windows its cohort may fall short of the + # floors (pending_floor), as in test_w_offbox_judged_only. + assert y in r3["judged"] or {"digest": y, "reason": "pending_floor"} in r3["skipped"] + assert {v["king_digest"] for v in r3["verdicts"]} <= {x} + + +def test_held_settlement_forecasts_nothing_in_process(tmp_path): + _need_rule() + fx = _fixture(tmp_path / "fx") + rig, _ = _rig(tmp_path / "v", fx) + per = _run(_early(rig), (B1, B2, B3)) + _check_story(rig, fx) + x, y = fx["x"], fx["late"]["digest"] + assert per[B2] == [], f"B2 forecast {per[B2]}: a held settlement scores no new entry" + assert per[B3] == sorted([y, x]), per[B3] + + +def test_held_settlement_settle_request_has_no_members(tmp_path): + """The eval host's settle pool phase: one call per settlement; at B2 its + need is empty (no live forecast, no duel) and the host forecasts + nothing.""" + _need_rule() + fx = _fixture(tmp_path / "fx") + rig, host = _rig(tmp_path / "v", fx, offload=True) + _early(rig) + calls = {} + for b in (B1, B2, B3): + n_req, n_fc = len(host.requests), len(rig.eval_host.calls) + _run(rig, (b,)) + calls[b] = (len(host.requests) - n_req, len(rig.eval_host.calls) - n_fc) + _check_story(rig, fx) + need = {r["judge"]["boundary"]: sorted(r["need"]) for r in host.requests} + assert calls[B2] == (1, 0), f"B2 settle/forecast calls {calls[B2]}: expected (1, 0)" + assert need[B2] == [], f"B2 settle request needs {need[B2]}; expected nothing" + assert need[B3] == sorted([fx["late"]["digest"], fx["x"]]), need[B3] + + +def test_held_settlement_public_half_asks_king_d_alone(tmp_path): + from tests.accept.w7a import pub + from tests.accept.w8c.test_w8c_public import PublicHost + + _need_rule() + root = tmp_path / "public" + indexes = pub.index_only(root) + fx = _fixture(tmp_path / "fx") + rig, _ = _rig(tmp_path / "v", fx, public=lambda f: PublicHost(f, indexes)) + _early(rig) + step = h.step(rig) + asked = {} + for b in (B1, B2, B3): + rig.bench_host.down = (b == B1) + before = len(rig.eval_host.public_calls) + assert step(b) is not None, f"boundary {b} did not settle" + asked[b] = sorted(c["digest"] for c in rig.eval_host.public_calls[before:]) + assert asked[B2] == [fx["house"]["digest"]], \ + f"B2 public half asked {asked[B2]}: KING_D alone (no new entry is scored)" + assert "public" in _report(rig, B2) + assert fx["late"]["digest"] in asked[B3]