From 3173f209bc5d8538a2ee2a6a21806b4402e6f856 Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Thu, 3 Dec 2026 01:04:33 +0000 Subject: [PATCH] fix(lane C): keep a carry round's MarketCast entry count when 0 (no false '? entries defer as infra' ERROR) A settlement with no MarketCast entry of its own is awaited while an earlier round is (the carry), but _mkt_arbiters stored its entry count only when > 0, so at timeout it was treated as having candidates and logged an ERROR 'its ? MarketCast entr(ies) defer as infra' at nearly every settlement since 2026-11-27, burying the real alert. The count is now always kept; a candidate-less round's timeout is a WARNING. The signed manifest is unchanged (mkt_reports still records 'absent'); mkt_await is trainer-internal state. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe --- cascade/trainer/lane_c_driver.py | 7 ++- tests/unit/test_marketcast_trainer.py | 63 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/cascade/trainer/lane_c_driver.py b/cascade/trainer/lane_c_driver.py index bcb99de3f..724b539c2 100644 --- a/cascade/trainer/lane_c_driver.py +++ b/cascade/trainer/lane_c_driver.py @@ -756,8 +756,11 @@ def _mkt_arbiters(self, rid: str, block: int, *, entries: int = 1) -> tuple[dict else: keep.append({**a, "rid": r, "age": age}) if (entries > 0 or out or keep) and not any(a["rid"] == str(rid) for a in keep): - keep.append({"rid": str(rid), "age": 0, **({"entries": int(entries)} - if entries > 0 else {})}) + # the count is recorded even when 0: a round awaited only as a carry + # behind an earlier one has no MarketCast entry of its own, and its + # absence must not read as "?" entries deferred (live 11-27 → 12-02: + # an ERROR at nearly every settlement for candidate-less rounds) + keep.append({"rid": str(rid), "age": 0, "entries": int(entries)}) return out, keep def _arbiters(self, rid: str, block: int) -> tuple[dict, dict]: diff --git a/tests/unit/test_marketcast_trainer.py b/tests/unit/test_marketcast_trainer.py index 56909e526..64885936e 100644 --- a/tests/unit/test_marketcast_trainer.py +++ b/tests/unit/test_marketcast_trainer.py @@ -741,6 +741,69 @@ def _finish(hk, n): assert not published +def test_candidate_less_carry_round_times_out_as_warning_not_error(tmp_path, caplog): + """Live 11-27 → 12-02: a settlement with no MarketCast entry of its own is + still awaited while an earlier round is (the carry), but its entry count + was dropped when 0, so its timeout logged an ERROR "? MarketCast entr(ies) + defer as infra" at nearly every settlement. The count is now kept (0): + the timeout is a WARNING and the manifest still records "absent".""" + import logging + from dataclasses import replace + + from cascade.funding.queue import LaneCQueue + from cascade.shared.config.lane_c import LaneCConfig + from cascade.shared.lane_c_manifest import load_lane_c_manifest + from cascade.shared.manifest import format_trained_pointer + from cascade.trainer.lane_c_driver import LaneCDriver + + FROM = 9000 + king = format_trained_pointer("cascade/ckpt@sha256:" + "a" * 64) + ref = "alfa/recipe@sha256:" + "1" * 64 + mc = replace(MC, from_block=FROM, report_timeout_settlements=2) + cfg = SimpleNamespace(lane_c=LaneCConfig(from_block=FROM, targets=("mkt:returns",), + legs_per_target=1), marketcast=mc) + published = [] + + class Ops: + q = LaneCQueue(tmp_path / "q.json", clock=lambda: 1_000_000.0) + + def queue(self): + return self.q + + def sign(self, m): + return replace(m, signature="ab" * 32) + + def publish(self, key, text): + published.append((key, text)) + + def read_mkt_report(self, rid): + return None # the validator never publishes one + + drv = LaneCDriver(cfg, Ops(), tmp_path / "drv.json") + drv.st.finished.append({ + "leg": {"hotkey": "BRAVO", "uid": 1, "target": "mkt:returns", "ref": ref, + "entry_ref": "", "started_block": FROM + 1}, + "trained_pointer": format_trained_pointer("cascade/ckpt@sha256:" + "1" * 64), + "train_block": FROM + 1}) + assert drv.settle(round_id="r1", block=FROM + 7200, era_index=1, base_pointer=king) + # r2 has no entry of its own: awaited only as a carry behind r1, count kept as 0 + drv.settle(round_id="r2", block=FROM + 2 * 7200, era_index=1, base_pointer=king) + assert {"rid": "r2", "age": 0, "entries": 0} in drv.st.mkt_await + with caplog.at_level(logging.WARNING, logger="cascade.trainer.lane_c"): + for i, rid in enumerate(("r3", "r4", "r5"), start=3): + drv.settle(round_id=rid, block=FROM + i * 7200, era_index=1, base_pointer=king) + absent = [r for r in caplog.records if "absent after" in r.getMessage()] + r2 = [r for r in absent if " r2 " in r.getMessage()] + assert r2 and all(r.levelno == logging.WARNING for r in r2) + assert not any(r.levelno >= logging.ERROR and " r2 " in r.getMessage() for r in absent) + # r1 HAD an entry: its timeout is still the ERROR alert + assert any(r.levelno == logging.ERROR and " r1 " in r.getMessage() for r in absent) + recorded = {} + for _, text in published: + recorded.update(load_lane_c_manifest(text).mkt_reports or {}) + assert recorded.get("r2") == "absent" and recorded.get("r1") == "absent" + + def test_marketcast_continuation_preserves_optimizer_sampler_and_ema(tmp_path): from cascade.trainer.continuation import Continuation, SnapshotStore snap = _train_snap(tmp_path)