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
92 changes: 83 additions & 9 deletions cascade/eval/lane_d_bench_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

1. the W15 :class:`~cascade.eval.lane_d_cache.PrefetchCache` (the eval host's
rule, :func:`cascade.eval.lane_d_forecasts._checkpoint`): a verified hit is
used as is, a miss with a grant fills through W4 ingest;
used as is, a miss with a grant fills through W4 ingest; a miss of the
house (``house_sources``: the lane A king pointer the box read from the
house pointer's ``.source.json``) is built here exactly as the eval host's
house is (``python -P -m cascade.lane_d.house_source build --cache-dir``:
the king fetched from the Hub, the D47 BF16 cast,
:func:`~cascade.lane_d.house_source.build_house_entry`) and admitted only
when it hashes to the requested digest (live bug 2026-12-01: the house was
never on the bench host, so every gate sweep held);
2. the entry (already lane A's sidecar layout: W4 admits exactly
``config.json``, ``forecast_wrapper.py``, ``model.py``,
``weights.safetensors`` with the release's own code) is materialised into
Expand All @@ -19,8 +26,9 @@
:func:`~cascade.eval.benchmarks.item_rows_from_report`.

**Faults.** Infrastructure fails the whole sweep (:class:`LaneDBenchSweepError`,
nothing swept; the box raises, the gate holds): a miss without a grant, a
failed fetch, a vault / disk / budget fault (``checkpoint_unavailable``), a
nothing swept; the box raises, the gate holds): a miss without a grant or a
house source, a failed fetch or house build (or one that does not hash to its
digest), a vault / disk / budget fault (``checkpoint_unavailable``), a
pass with no report at all (``sweep_failed``). The miner's bytes (a W4
refusal) and a digest the sidecar gave no report for get ``{"status":
"error", "rows": []}`` on every suite: the gate's ``checkpoint_fault`` on a
Expand Down Expand Up @@ -96,6 +104,64 @@ def _checked(request) -> tuple[list[str], list[str], dict[str, int], dict]:
_checked_settings(request.get("settings")))


def _checked_house_sources(request: Mapping, digests: list[str]) -> dict[str, str]:
"""``{digest: lane A king pointer}`` from the optional ``house_sources``
(absent: none). Every key is a requested digest whose value names it."""
raw = request.get("house_sources")
if raw is None:
return {}
if not isinstance(raw, Mapping) or not set(raw) <= set(digests) or not all(
isinstance(v, Mapping) and v.get("digest") == d
and isinstance(v.get("king_pointer"), str) and v["king_pointer"]
for d, v in raw.items()):
raise ValueError("request house_sources must map requested digests to "
'{"digest", "king_pointer"}')
return {str(d): str(v["king_pointer"]) for d, v in raw.items()}


def build_house(king_pointer: str, out_dir) -> dict:
"""The eval host's house build (``cascade.lane_d.house_source build``
without the documents): fetch ``king_pointer``'s checkpoint from the Hub
into ``out_dir/king`` and cast it to the house entry ``out_dir/entry``.
Returns :func:`~cascade.lane_d.house_source.build_house_entry`'s
``{"digest", "manifest", "cast"}`` plus ``"dir"``."""
from ..lane_d.house_source import build_house_entry, king_ref
from ..shared.hippius import fetch_from_hub

out = Path(out_dir)
king_dir = out / "king"
fetch_from_hub(king_ref(king_pointer), king_dir)
entry_dir = out / "entry"
shutil.rmtree(entry_dir, ignore_errors=True)
return {**build_house_entry(king_dir, entry_dir), "dir": entry_dir}


def _house_entry(cache, digest: str, king_pointer: str, work_dir, *,
build: Callable) -> Path:
"""Admit the house ``digest`` to ``cache`` from ``build(king_pointer,
dir)``; raises :class:`LaneDBenchSweepError` (``checkpoint_unavailable``)
on any fault, including a build that does not hash to ``digest``."""
tmp = Path(work_dir) / f".house-{digest}"
try:
built = build(king_pointer, tmp)
if built.get("digest") != digest:
raise ValueError(f"the house built from {king_pointer!r} is "
f"{str(built.get('digest'))[:16]}, not {digest[:16]}")
src = Path(built["dir"])

def fill(staging: Path) -> None:
for name in sorted(p.name for p in src.iterdir() if p.is_file()):
shutil.copyfile(src / name, Path(staging) / name)

return Path(cache.put(digest, fill))
except Exception as e: # noqa: BLE001 — the house is ours: never the miner's fault
raise LaneDBenchSweepError("checkpoint_unavailable",
f"{digest[:16]}: house build failed "
f"({type(e).__name__}: {e})") from e
finally:
shutil.rmtree(tmp, ignore_errors=True)


def _pos_int(v, floor: int) -> bool:
return type(v) is int and v >= floor

Expand Down Expand Up @@ -212,13 +278,16 @@ def suite_aggregates(report: Mapping | None) -> dict:


def serve_sweep(request, *, cache, work_dir, contract=None, expect=None,
sidecar: Callable | None = None, fingerprint: Mapping | None = None) -> dict:
sidecar: Callable | None = None, fingerprint: Mapping | None = None,
house_build: Callable | None = None) -> dict:
"""Answer one :data:`REQUEST_SCHEMA` request (see the module docstring).
``ValueError`` on a malformed request; :class:`LaneDBenchSweepError` when
the sweep cannot run here."""
the sweep cannot run here. ``house_build(king_pointer, dir)`` defaults to
:func:`build_house`."""
from .lane_d_forecasts import LaneDForecastError, _checkpoint, _scoring_lease

digests, suites, contexts, grants, settings = _checked(request)
houses = _checked_house_sources(request, digests)
names = _gate_keys()
rows: dict[str, dict] = {}
aggregates: dict[str, dict] = {}
Expand All @@ -231,12 +300,17 @@ def serve_sweep(request, *, cache, work_dir, contract=None, expect=None,
try:
entry = _checkpoint(cache, dg, grants[dg], contract=contract, expect=expect)
except LaneDForecastError as e:
if e.code != "checkpoint_refused":
if e.code == "checkpoint_unavailable" and grants[dg] is None and dg in houses:
entry = _house_entry(cache, dg, houses[dg], work_dir,
build=build_house if house_build is None
else house_build)
elif e.code != "checkpoint_refused":
raise LaneDBenchSweepError("checkpoint_unavailable",
f"{dg[:16]}: {e}") from e
log.warning("lane_d_bench_refused digest=%s detail=%s", dg[:16], e)
rows[dg] = _error_rows(suites)
continue
else:
log.warning("lane_d_bench_refused digest=%s detail=%s", dg[:16], e)
rows[dg] = _error_rows(suites)
continue
try:
dirs.append((dg, materialise(entry, work_dir, digest=dg, context=contexts[dg])))
except (OSError, ValueError) as e:
Expand Down
63 changes: 57 additions & 6 deletions cascade/validator/lane_d_bench_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
GET grant (never weights, histories or targets: D12, §10.2), and runs
``python -m cascade.eval.lane_d_bench_sweep sweep`` there over SSH.

The house (KING_D at genesis) is not in the vault, so it has no grant: the
eval host holds it because the owner's ``house_source build --cache-dir``
step cast it there. The bench host gets the same build instead: for a digest
without a grant that the house pointer's ``.source.json`` sidecar names
(:class:`HouseSidecarSource`), the request carries ``house_sources[digest] =
{"digest", "king_pointer"}`` and the bench host fetches lane A's king from
the Hub, casts it (D47) and admits it only if it hashes to the digest (live
bug 2026-12-01: without it every gate sweep held on
``checkpoint_unavailable``). A digest with neither still holds.

Every failure raises (no host, a digest without a context, a non-zero exit,
a malformed or unexpected reply): ``lane_d._run_gate`` turns it into
``bench_hold``. A row is never guessed.
Expand Down Expand Up @@ -51,13 +61,43 @@ class LaneDBenchHostError(RuntimeError):
"""The bench host cannot answer this sweep (the gate holds)."""


class HouseSidecarSource:
"""``source(digest)``: ``{"digest", "king_pointer"}`` when the house
pointer's ``laned_house_source/1`` sidecar (``<pointer>.source.json``,
written by ``ops_jobs house-pointer`` beside the signed pointer) names
``digest``, else ``None``. Unsigned, and need not be: the bench host
admits the build only when it hashes to ``digest``."""

def __init__(self, house_pointer):
from ..lane_d.ops_jobs import SIDECAR_SUFFIX

p = Path(house_pointer)
self.path = p.with_name(p.name + SIDECAR_SUFFIX)

def __call__(self, digest: str) -> dict | None:
from ..lane_d.ops_jobs import HOUSE_SOURCE_SCHEMA

try:
doc = json.loads(self.path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError, ValueError):
return None
if not isinstance(doc, dict) or doc.get("schema") != HOUSE_SOURCE_SCHEMA \
or doc.get("digest") != digest:
return None
kp = doc.get("king_pointer")
return {"digest": digest, "king_pointer": kp} if isinstance(kp, str) and kp else None


class SSHBenchHost:
"""``host(digests, suites)``: one sweep on the bench host (module
docstring). ``grants(digest)`` gives a presigned GET grant or ``None``;
``run`` is the ``subprocess.run``-shaped runner."""
``house_sources(digest)`` gives ``{"digest", "king_pointer"}`` for a
digest without a grant that the bench host builds as the house (or
``None``); ``run`` is the ``subprocess.run``-shaped runner."""

def __init__(self, hosts_path, *, cache_dir: str, budget_bytes: int, settings: Mapping,
grants: Callable[[str], Mapping | None] | None = None,
house_sources: Callable[[str], Mapping | None] | None = None,
run: Callable | None = None):
self.hosts_path = Path(hosts_path)
self.cache_dir = str(cache_dir)
Expand All @@ -69,6 +109,7 @@ def __init__(self, hosts_path, *, cache_dir: str, budget_bytes: int, settings: M
self.timeout_per_checkpoint_s = float(
self.settings.get("timeout_s_per_checkpoint", DEFAULT_TIMEOUT_S))
self._grants = grants
self._house_sources = house_sources
self._run = run or subprocess.run
self._contexts: dict[str, int] = {}

Expand Down Expand Up @@ -103,9 +144,19 @@ def _request(self, digests: list[str], suites: list[str],
for d in digests:
g = None if self._grants is None else self._grants(d)
grants[d] = None if g is None else dict(g)
return {"schema": REQUEST_SCHEMA, "digests": digests, "suites": suites,
"contexts": {d: ctx[d] for d in digests}, "grants": grants,
"settings": {k: self.settings[k] for k in SETTINGS_KEYS}}
houses = {}
for d in digests:
src = None if grants[d] is not None or self._house_sources is None \
else self._house_sources(d)
if src is not None and src.get("digest") == d and src.get("king_pointer"):
houses[d] = {"digest": d, "king_pointer": str(src["king_pointer"])}
request = {"schema": REQUEST_SCHEMA, "digests": digests, "suites": suites,
"contexts": {d: ctx[d] for d in digests}, "grants": grants,
"settings": {k: self.settings[k] for k in SETTINGS_KEYS}}
if houses:
# optional key: a request without a house is byte-identical to before
request["house_sources"] = houses
return request

@staticmethod
def _checked(reply, digests: list[str]) -> dict:
Expand Down Expand Up @@ -197,5 +248,5 @@ def _sweep(self, ds: list[str], ss: list[str], *,
return reply


__all__ = ["REPLY_SCHEMA", "REQUEST_SCHEMA", "SETTINGS_KEYS", "LaneDBenchHostError", "SSHBenchHost",
"bench_settings"]
__all__ = ["REPLY_SCHEMA", "REQUEST_SCHEMA", "SETTINGS_KEYS", "HouseSidecarSource",
"LaneDBenchHostError", "SSHBenchHost", "bench_settings"]
5 changes: 4 additions & 1 deletion cascade/validator/lane_d_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,10 +1611,13 @@ def load_inputs_services(cfg: Any, path) -> dict:
score_cache = ScoreCache(raw["score_cache_dir"])
bench = None
if raw.get("bench_hosts"):
from .lane_d_bench_host import SSHBenchHost, bench_settings
from .lane_d_bench_host import HouseSidecarSource, SSHBenchHost, bench_settings

# the house has no vault grant: the bench host builds it from the
# house pointer's sidecar (the eval host's house_source build step)
bench = SSHBenchHost(raw["bench_hosts"], cache_dir=raw["eval_cache_dir"],
budget_bytes=raw["eval_cache_budget_bytes"], grants=grants,
house_sources=HouseSidecarSource(raw["house_pointer"]),
settings=bench_settings(cfg))
return {"intake_state_dir": intake, "pool": PinFilePool(raw["pool_pins"]),
"eval_host": host, "house_pointer": Path(raw["house_pointer"]),
Expand Down
5 changes: 5 additions & 0 deletions tests/accept/w3b6a/PATHS
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ cascade/validator/eval_offload.py
# (suite_aggregates: lane A's extract_bench_scores convention) beside the
# unchanged gate rows; SSHBenchHost.sweep_full returns them merged into the
# rows, with a context override and a capped allowance.
# Live bug 2026-12-01 (every gate sweep held: the house has no vault grant):
# SSHBenchHost sends house_sources for a grantless digest the house pointer's
# .source.json names (HouseSidecarSource, wired in lane_d_inputs.py); the
# bench host builds it as the eval host's house_source build step does (Hub
# fetch + D47 cast) and admits it only when it hashes to the digest.
Loading
Loading