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
29 changes: 29 additions & 0 deletions cascade/shared/config/lane_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
# a suite slot clears.
"tau_anchor_public": 0.0,
"tau_anchor_domain": 0.0,
# owner 2026-12-01 (TRAINER-ONLY, release-only): lane B funded legs' OWN
# worker image, decoupled from lane A's seed-epoch pins. Both or neither;
# "" = the epoch image (today's behaviour, byte for byte).
"pod_image": "",
"worker_code_fingerprint": "",
}

# Lane B EMA, no cooldown (plan rev6.20, owner 2026-11-24: "let's just do EMA,
Expand Down Expand Up @@ -223,6 +228,29 @@ def _skus(v: object) -> tuple[str, ...]:
return tuple(v)


def _pod_pins(lb: dict) -> dict[str, str]:
"""``[lane_b] pod_image`` / ``worker_code_fingerprint`` (owner 2026-12-01,
trainer-only): a digest-pinned ``<repo>:<tag>@sha256:<64 hex>`` ref and its
64-hex worker code fingerprint (``scripts/worker_code_fingerprint.py``),
both or neither. No validator reads them (lane B entries record the image a
leg ran; they never enforce it)."""
image = lb.get("pod_image", LANE_B_TRACK_DEFAULTS["pod_image"])
fp = lb.get("worker_code_fingerprint", LANE_B_TRACK_DEFAULTS["worker_code_fingerprint"])
for key, v in (("pod_image", image), ("worker_code_fingerprint", fp)):
if not isinstance(v, str):
raise ValueError(f"[lane_b] {key} must be a string; got {v!r}")
image, fp = image.strip(), fp.strip().lower()
if bool(image) != bool(fp):
raise ValueError("[lane_b] pod_image and worker_code_fingerprint are set together "
"(both or neither)")
if image and not re.fullmatch(r"[^\s@]+:[^\s@/]+@sha256:[0-9a-f]{64}", image):
raise ValueError(f"[lane_b] pod_image must be pinned by digest "
f"('<repo>:<tag>@sha256:<64 hex>'); got {image!r}")
if fp and not re.fullmatch(r"[0-9a-f]{64}", fp):
raise ValueError(f"[lane_b] worker_code_fingerprint must be 64 hex; got {fp!r}")
return {"pod_image": image, "worker_code_fingerprint": fp}


def parse_lane_b_track(lb: dict, *,
round_funded_pod_skus: tuple[str, ...] | None = None,
generator_max_repo_mb: int | None = None) -> dict[str, object]:
Expand Down Expand Up @@ -277,6 +305,7 @@ def parse_lane_b_track(lb: dict, *,
"tau_anchor_domain": _float("tau_anchor_domain",
lb.get("tau_anchor_domain", d["tau_anchor_domain"])),
"contamination_hashset_key": _hashset_key(lb.get("contamination_hashset_key", "")),
**_pod_pins(lb),
}
from ..rules_menu import parse_lane_menu

Expand Down
8 changes: 8 additions & 0 deletions cascade/shared/config/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,14 @@ def leg_caps_at(self, block: int | None) -> tuple[float, int]:
# clears): the anchor-king guard tolerances
tau_anchor_public: float = 0.0
tau_anchor_domain: float = 0.0
# owner 2026-12-01 (TRAINER-ONLY, release-only; no validator reads them):
# lane B funded legs' own worker image, a "<repo>:<tag>@sha256:<64 hex>"
# ref with its worker code fingerprint, both or neither. Set, every lane
# B funded leg rents, code-checks and declares this image (its leg
# contract's runtime pin) while lane A / king / lane C / MarketCast legs
# keep their pins (cascade.trainer.leg_pins); "" = the epoch image.
pod_image: str = ""
worker_code_fingerprint: str = ""

def active(self, block: int | None) -> bool:
return (self.from_block > 0 and block is not None and int(block) >= self.from_block
Expand Down
3 changes: 3 additions & 0 deletions cascade/shared/netconfig_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ def _hours(hi: float) -> Bound:
("lane_d", "max_horizon"): "the per-window horizon rule is release-only",
("lane_d", "band_slots"): "the per-window horizon rule is release-only",
("lane_d", "min_cell_windows"): "the per-window horizon rule is release-only",
# owner 2026-12-01: lane B's own worker image is a trainer-local pin
("lane_b", "pod_image"): "a worker image pin is release-only",
("lane_b", "worker_code_fingerprint"): "a worker image pin is release-only",
}

# Eval DATA keys (owner 2026-11-24: what data a lane is judged on is
Expand Down
14 changes: 14 additions & 0 deletions cascade/trainer/lane_b_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,15 @@ def done(leg, ptr, *a, failure=None, **kw): # noqa: F811 — the re-attach v
outer(leg, ptr, *a, failure=failure, **kw)

def _run():
# owner 2026-12-01: this thread's leg is a lane B funded leg — with
# [lane_b] pod_image set it rents / code-checks / declares that
# image (leg_pins.leg_round, the dispatch hook); unset = no-op
from .leg_pins import lane_b_leg_scope

with lane_b_leg_scope(self.r):
return _run_leg()

def _run_leg():
if reattach is None:
return _body()
if not self.leg_pod_ledgered(leg):
Expand Down Expand Up @@ -2508,6 +2517,11 @@ def _body():

contract = lane_b_leg_contract(contract)
contract = apply_spec_levers(self.r.cfg.lane_b, contract, spec, int(block))
# owner 2026-12-01: [lane_b] pod_image set ⇒ the leg declares
# (and its pod runs) lane B's own image; unset ⇒ same object
from .leg_pins import lane_b_leg_contract_image

contract = lane_b_leg_contract_image(self.r.cfg, contract)
# 2026-11-30: a leg contract the pinned model cannot build fails
# on the pod every time; refuse it here, before generation and
# any rent (operator side: never charged, never burned)
Expand Down
152 changes: 150 additions & 2 deletions cascade/trainer/leg_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

A MarketCast leg (:func:`mkt_leg_scope`) with ``[marketcast] pod_image`` set
rents and code-checks on that image instead — lane A never sees it.

A lane B funded leg (:func:`lane_b_leg_scope`) with ``[lane_b] pod_image`` set
(owner 2026-12-01) rents, code-checks and DECLARES that image: its leg contract
carries the image as its runtime pin (:func:`lane_b_leg_contract_image`) and
the pod gets a deployed chain.toml whose every image pin is it
(:func:`render_lane_b_toml`), so the worker's FINAL image check and the receipt
digest agree. Lane A's seed-epoch image, contract and W-IMG pins never move.
"""

from __future__ import annotations
Expand Down Expand Up @@ -83,6 +90,11 @@ def leg_round(runner):
is ever rented on an unqualified image (and never on the old one for a
post-switch leg)."""
cfg = runner.cfg
if lane_b_own_image_leg(runner):
# owner 2026-12-01: a lane B leg on its own release ([lane_b]
# pod_image) — checked by its own pin (digest ref + code fingerprint),
# never refused for differing from the [v2] *_after release
return _lane_b_round(cfg)
mc = getattr(cfg, "marketcast", None)
if getattr(_local(runner), "mkt_leg", False) and getattr(mc, "pod_image", ""):
# a MarketCast leg on its own release ([marketcast] pod_image): the SKU
Expand All @@ -109,6 +121,8 @@ def leg_round_view(runner):
pins, without the qualification refusal (no log, never raises for it —
the rent itself still goes through :func:`leg_round`)."""
cfg = runner.cfg
if lane_b_own_image_leg(runner):
return _lane_b_round(cfg)
mc = getattr(cfg, "marketcast", None)
if getattr(_local(runner), "mkt_leg", False) and getattr(mc, "pod_image", ""):
return _mkt_round(cfg, mc)
Expand Down Expand Up @@ -214,6 +228,72 @@ def mkt_leg_scope(runner):
loc.mkt_leg = saved


# ── lane B's own worker image (owner 2026-12-01) ────────────────────────────


def lane_b_image(cfg) -> str:
"""The bare ``sha256:<64 hex>`` of ``[lane_b] pod_image``, or "" (unset:
lane B legs run the epoch image, exactly as before)."""
lb = getattr(cfg, "lane_b", None)
ref = str(getattr(lb, "pod_image", "") or "")
fp = str(getattr(lb, "worker_code_fingerprint", "") or "")
return image_digest(ref) if ref and fp else ""


def lane_b_own_image_leg(runner) -> bool:
"""Whether the leg on this thread is a lane B funded leg
(:func:`lane_b_leg_scope`) AND ``[lane_b] pod_image`` is set."""
return bool(getattr(_local(runner), "lane_b_leg", False) and lane_b_image(runner.cfg))


def contract_runs_lane_b_image(cfg, contract) -> bool:
"""Whether ``contract`` (a leg's contract) declares ``[lane_b] pod_image``
— only a lane B leg's contract does (:func:`lane_b_leg_contract_image`)."""
img = lane_b_image(cfg)
return bool(img and contract is not None
and image_digest(str(getattr(contract, "train_image_digest", "") or "")) == img)


def lane_b_leg_contract_image(cfg, contract):
"""A lane B leg's contract with ``[lane_b] pod_image`` as its runtime pin
(``train_image_digest``, a DEC-CA-0067 runtime-only field: the numerics
digest is unchanged), or ``contract`` itself (same object) when unset.
The pod's worker refuses FINAL unless the contract's image IS the image it
runs (``contract.assert_train_image``), so the leg must declare it; no
validator checks a lane B leg's contract or image (expert entries record
``train_image_digest`` and never enforce it)."""
img = lane_b_image(cfg)
if not img:
return contract
from dataclasses import replace

return replace(contract, train_image_digest=img)


def _lane_b_round(cfg):
from dataclasses import replace

lb = cfg.lane_b
# the [round] SKU-wall gate is unchanged: it still names the image the
# walls were measured on (an unmeasured image rents under the cap)
return replace(cfg.round, funded_pod_image=str(lb.pod_image),
worker_code_fingerprint=str(lb.worker_code_fingerprint).lower())


@contextlib.contextmanager
def lane_b_leg_scope(runner):
"""Mark the leg on this thread as a lane B funded leg for
:func:`leg_round` and the dispatch hook (its ``[lane_b] pod_image`` pins,
when set)."""
loc = runner.__dict__.setdefault("_leg_local_obj", threading.local())
saved = getattr(loc, "lane_b_leg", False)
loc.lane_b_leg = True
try:
yield
finally:
loc.lane_b_leg = saved


@contextlib.contextmanager
def leg_contract_scope(runner, contract):
"""Name the leg's contract for :func:`leg_round` on this thread (paths that
Expand Down Expand Up @@ -335,6 +415,67 @@ def render_after_toml(text: str, cfg) -> str:
return out


LANE_B_TOML_NAME = "chain.deployed.laneb.toml"


def render_lane_b_toml(text: str, cfg) -> str:
"""The deployed chain.toml a lane B own-image leg's worker loads: every
image pin it resolves IS ``[lane_b] pod_image`` — ``[v2.training]
train_image_digest``, ``[round] funded_pod_image`` /
``worker_code_fingerprint`` (+ ``ops_continuation_image_digest`` when
continuation is armed: the worker refuses a continuation root on any
other image) and, while a ``[v2] *_after`` release is configured, the
three ``*_after`` pins — so ``training.at_block(b).train_image_digest`` is
the lane B image at every block (the contract the trainer expects,
:func:`lane_b_leg_contract_image`). Nothing else changes. Verified by
re-parsing."""
lb = cfg.lane_b
img = lane_b_image(cfg)
if not img:
raise ValueError("[lane_b] pod_image is not set")
raw = tomllib.loads(text)
fp = str(lb.worker_code_fingerprint).lower()
want: dict[tuple, object] = {("v2", "training", "train_image_digest"): img}
out = _set_keys(text, "v2.training", {"train_image_digest": img})
round_vals = {"funded_pod_image": str(lb.pod_image), "worker_code_fingerprint": fp}
if str(raw.get("round", {}).get("ops_continuation_image_digest", "") or ""):
round_vals["ops_continuation_image_digest"] = img
out = _set_keys(out, "round", round_vals)
want.update({("round", k): v for k, v in round_vals.items()})
if str(raw.get("v2", {}).get("train_image_digest_after", "") or "").strip():
v2_vals = {"train_image_digest_after": img,
"funded_pod_image_after": str(lb.pod_image),
"worker_code_fingerprint_after": fp}
out = _set_keys(out, "v2", v2_vals)
want.update({("v2", k): v for k, v in v2_vals.items()})
parsed = tomllib.loads(out)
for path, value in want.items():
node = parsed
for part in path:
node = node.get(part, {}) if isinstance(node, dict) else {}
if node != value:
raise ValueError(f"rendered lane B chain.toml: {'.'.join(path)} = {node!r}, "
f"expected {value!r}")
return out


def _push_lane_b_toml(runner, host):
from dataclasses import replace as dc_replace

from ..shared.atomic import write_text_atomic

src = getattr(runner, "deployed_chain_toml", None)
if not src:
raise LegImageMismatch("lane B own-image leg needs the trainer's deployed_chain_toml "
"(--chain-toml) to render its lane B config")
text = render_lane_b_toml(Path(src).read_text(encoding="utf-8"), runner.cfg)
local = Path(getattr(runner, "work_root", ".")) / "_deployed" / LANE_B_TOML_NAME
local.parent.mkdir(parents=True, exist_ok=True)
write_text_atomic(local, text)
pushed = runner._push_deployed_chain_toml(host, src=local, dest_name=LANE_B_TOML_NAME)
return dc_replace(pushed, chain_toml=f"{host.workdir}/{LANE_B_TOML_NAME}")


def _push_after_toml(runner, host):
from dataclasses import replace as dc_replace

Expand Down Expand Up @@ -484,11 +625,15 @@ def __init__(self, runner, fingerprint_fn, image_fn=None, clock=None):

def filters(self, block) -> bool:
cfg = self.runner.cfg
if lane_b_own_image_leg(self.runner):
return True # owner 2026-12-01: lane B's own image, any era
return bool(image_after_armed(cfg) and block is not None
and image_decoupled_era(cfg, int(block)))

def _want(self, block) -> tuple[str, str]:
cfg = self.runner.cfg
if lane_b_own_image_leg(self.runner):
return str(cfg.lane_b.worker_code_fingerprint).lower(), lane_b_image(cfg)
fp = str(round_pins_at(cfg, int(block)).worker_code_fingerprint or "").lower()
img = image_digest(str(cfg.training.at_block(int(block)).train_image_digest or ""))
return fp, img
Expand All @@ -504,8 +649,9 @@ def _observe(self, host, *, fresh: bool) -> tuple[str, str]:

def require_qualified(self, block) -> None:
"""Raise :class:`ImageAfterUnqualified` for a post-switch leg whose
after release is not qualified (before any lane is taken)."""
if self.filters(block):
after release is not qualified (before any lane is taken). A lane B
own-image leg is checked by its own pin only."""
if self.filters(block) and not lane_b_own_image_leg(self.runner):
require_after_qualified(self.runner.cfg, f"dispatch (contract block {int(block)})")

def match_state(self, host, block):
Expand Down Expand Up @@ -555,6 +701,8 @@ def __call__(self, host, block):
f"{getattr(host, 'name', host)} reports runtime image "
f"{got[1][:19] or '<unset>'} but this leg's era (start {block}) pins "
f"{want_img[:19]} — its worker would refuse FINAL; not dispatched here")
if lane_b_own_image_leg(self.runner):
return _push_lane_b_toml(self.runner, host)
return _push_after_toml(self.runner, host)


Expand Down
11 changes: 9 additions & 2 deletions cascade/trainer/runner_funded_legs.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,17 @@ def _run_funded_leg_scoped(self, disp, gen, seeds, block, contract, suffix, *,
ImageRetryCapped,
after_image_refusal,
contract_runs_after,
contract_runs_lane_b_image,
image_retry_exhausted,
leg_key,
)

key = leg_key(gen.hotkey, role, getattr(seeds, "base_seed", ""))
if contract_runs_after(self.cfg, contract) and image_retry_exhausted(self, key):
# owner 2026-12-01: a lane B own-image leg gets the same never-the-
# wrong-image protections (never the after-release qualification)
pinned_release = (contract_runs_after(self.cfg, contract)
or contract_runs_lane_b_image(self.cfg, contract))
if pinned_release and image_retry_exhausted(self, key):
# owner rule: never the wrong image — and a miner is never billed
# over and over for OUR image skew: the leg WAITS (unburned,
# no_capacity, requeued), it is not dropped
Expand Down Expand Up @@ -637,9 +642,11 @@ def release_pod() -> None:
rc = getattr(e, "returncode", None)
text = str(e)
from .leg_pins import contract_runs_after as _runs_after
from .leg_pins import contract_runs_lane_b_image as _runs_lane_b
from .leg_pins import worker_refused_image

if worker_refused_image(e) and _runs_after(self.cfg, contract):
if worker_refused_image(e) and (_runs_after(self.cfg, contract)
or _runs_lane_b(self.cfg, contract)):
# A post-switch leg's worker refused FINAL (exit 2 + its own
# stdout sentinel, before any corpus streaming or training).
# Released (finally below), unburned, billing unchanged,
Expand Down
5 changes: 4 additions & 1 deletion cascade/trainer/runner_funded_pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,12 +1909,15 @@ def on_allocated(machine_id, pod_id, *, allocated=allocated,
from .leg_pins import (
WRONG_IMAGE_BAD_SECONDS,
contract_runs_after,
contract_runs_lane_b_image,
leg_contract,
)

if (why and not blocked and result.machine_id
and why.startswith(STALE_CODE_PREFIX)
and contract_runs_after(self.cfg, leg_contract(self))):
and (contract_runs_after(self.cfg, leg_contract(self))
or contract_runs_lane_b_image(self.cfg,
leg_contract(self)))):
# owner rule 2026-11-02 (never the wrong image), post-
# switch legs only: the pod's code was MEASURED as
# another release — the executor and its learned
Expand Down
8 changes: 5 additions & 3 deletions cascade/trainer/runner_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ def _dispatcher(self):
)

def _leg_pins_hook(self) -> dict:
"""DEC-CA-0067: the per-leg image hook, only while a repin is armed."""
"""DEC-CA-0067: the per-leg image hook, only while a repin is armed
(or, owner 2026-12-01, ``[lane_b] pod_image`` is set: lane B's own
image needs its own code check + rendered config at dispatch)."""
from ..shared.era import image_after_armed
from .leg_pins import dispatch_host_hook, lane_b_image

if not image_after_armed(self.cfg):
if not image_after_armed(self.cfg) and not lane_b_image(self.cfg):
return {}
from .leg_pins import dispatch_host_hook

return {"host_hook": dispatch_host_hook(self)}

Expand Down
5 changes: 5 additions & 0 deletions chain.testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,11 @@ max_leg_seconds = 4500 # TESTNET-FAST (2026-11-24): 54000 (1 h x 1.2
guard_factor = 1.25
tau_anchor_public = 0.0
tau_anchor_domain = 0.0
# Owner 2026-12-01 (trainer-only, release-only): lane B funded legs' own
# worker image + its code fingerprint, both or neither; absent = the epoch
# image. See chain.toml [lane_b] pod_image for the full rule.
# pod_image = ""
# worker_code_fingerprint = ""


[lane_c]
Expand Down
Loading
Loading