From 24d1f86e60ea8538b4f9a34698fb9f84e2047ba9 Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Tue, 1 Dec 2026 20:12:01 +0000 Subject: [PATCH] fix(lane D): king Hub repo name is lowercase (live 2026-12-01 first publish 401) The first live king publish failed with 401 Unauthorized on cascade/laned-king-c4096-5HpKLEju/manifests/main. The Hippius registry (Harbor) answers 401 "un-recognized request" for any call on a repository name with an uppercase letter (anonymous probe: the existing cascade/ckpt-...-king-toto2-4m answers 200, the same name with KING answers 401; a missing lowercase laned-king repo answers 404). hub_repo used the raw mixed-case ss58 prefix. It now lowercases hotkey8 and refuses any result that is not a valid OCI repository name. The publisher and pull-king share hub_repo, so both sides move together; no king was ever published, so no existing repo is renamed. Not upload_file vs upload_folder: both GET manifests/main through the same fetch_manifest(missing_ok=True) (404 tolerated, 401 raised), and the 401 hit the read-back pre-check (hf_hub_download) before any upload. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe --- cascade/lane_d/mirrors.py | 5 +- cascade/lane_d/publish.py | 20 ++- cascade/miner/lane_d_pull_king.py | 2 +- docs/LANE_D.md | 2 +- docs/MINER_LANE_D.md | 2 +- docs/OPERATOR.md | 2 +- tests/accept/w13/PATHS | 3 + tests/accept/w13/README.md | 2 +- tests/accept/w13/test_w13_mirrors.py | 4 +- tests/unit/test_lane_d_hub_repo_lowercase.py | 123 +++++++++++++++++++ 10 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 tests/unit/test_lane_d_hub_repo_lowercase.py diff --git a/cascade/lane_d/mirrors.py b/cascade/lane_d/mirrors.py index dc72e6316..479a5a46c 100644 --- a/cascade/lane_d/mirrors.py +++ b/cascade/lane_d/mirrors.py @@ -11,8 +11,9 @@ :data:`~cascade.lane_d.storage.STREAM_CHUNK_BYTES`, never held in memory: * **hub**: the public Hippius Hub repo ``{[storage] hub_namespace}/laned-king- - c{context}-{hotkey8}`` (:func:`cascade.lane_d.publish.hub_repo`; one repo per - king), through ``hippius_hub.HippiusApi``; the token is the existing + c{context}-{hotkey8}`` (``hotkey8`` lowercased: an OCI repo name is + lowercase; :func:`cascade.lane_d.publish.hub_repo`; one repo per king), + through ``hippius_hub.HippiusApi``; the token is the existing ``HIPPIUS_HUB_TOKEN`` / ``HIPPIUS_TOKEN`` (or the username/password pair), resolved by :mod:`cascade.shared.hippius`. A file is ```` in the repo. * **hf**: the HF dataset :data:`cascade.lane_d.publish.HF_MIRROR_REPO` through diff --git a/cascade/lane_d/publish.py b/cascade/lane_d/publish.py index c140e367e..3742ff4f7 100644 --- a/cascade/lane_d/publish.py +++ b/cascade/lane_d/publish.py @@ -119,9 +119,25 @@ def __init__(self, code: str, detail: str = ""): self.detail = detail +# An OCI distribution repository name: lowercase path components only. The +# Hippius registry (Harbor) answers 401 "un-recognized request" for ANY call on +# a name with an uppercase letter (live 2026-12-01: the first king publish +# failed on ``cascade/laned-king-c4096-5HpKLEju/manifests/main``), so a king's +# repo carries the lowercased hotkey prefix. +OCI_REPO_RE = re.compile(r"^[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*" + r"(?:/[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*)+$") + + def hub_repo(ns: str, context: int, hotkey: str) -> str: - """§11.1: the public Hub repository of a king.""" - return f"{ns}/laned-king-c{int(context)}-{str(hotkey)[:8]}" + """§11.1: the public Hub repository of a king, + ``{ns}/laned-king-c{context}-{hotkey8}`` with ``hotkey8`` the LOWERCASED + first 8 characters of the ss58 hotkey (an OCI repository name is lowercase). + ``ValueError`` when the result is still not a valid OCI repository name.""" + repo = f"{ns}/laned-king-c{int(context)}-{str(hotkey)[:8].lower()}" + if not OCI_REPO_RE.match(repo): + raise ValueError(f"{repo!r} is not a valid OCI repository name (lowercase " + f"[a-z0-9] components separated by '.', '_', '__' or '-')") + return repo def king_mirror_names(names=None) -> tuple[str, ...]: diff --git a/cascade/miner/lane_d_pull_king.py b/cascade/miner/lane_d_pull_king.py index ce99ee61c..6e85c2fe8 100644 --- a/cascade/miner/lane_d_pull_king.py +++ b/cascade/miner/lane_d_pull_king.py @@ -3,7 +3,7 @@ A crowned lane D king is published to the Hippius Hub only (``[lane_d_ops] king_mirrors``, default ``["hub"]``): one public model repo per king, -``{[storage] hub_namespace}/laned-king-c{context}-{hotkey8}`` +``{[storage] hub_namespace}/laned-king-c{context}-{hotkey8}`` (``hotkey8`` lowercased) (:func:`cascade.lane_d.publish.hub_repo`), holding the entry's four files and its ``manifest.json``. The signed index ``champions/lane_d/index.json`` on the public manifest store lists every king (context, digest, crown block, diff --git a/docs/LANE_D.md b/docs/LANE_D.md index 15a4c1c85..207b15ec3 100644 --- a/docs/LANE_D.md +++ b/docs/LANE_D.md @@ -203,7 +203,7 @@ licence permits it. Kings are published to the Hippius Hub only (owner 2026-12-01; the mirrors are `[lane_d_ops] king_mirrors`), one public repo per king, -`cascade/laned-king-c-`. `cascade lane-d pull-king [--digest D] +`cascade/laned-king-c-` (`hotkey8`: the first 8 characters of the hotkey, lowercased — OCI repo names are lowercase). `cascade lane-d pull-king [--digest D] --out DIR` downloads the current king (or a prior one) anonymously, after it has checked the signed index against `[manifest] validator_hotkey` and every file against the signed digest. Pass `DIR` to `cascade lane-d test --king DIR diff --git a/docs/MINER_LANE_D.md b/docs/MINER_LANE_D.md index a017170da..30c8e6c2a 100644 --- a/docs/MINER_LANE_D.md +++ b/docs/MINER_LANE_D.md @@ -86,7 +86,7 @@ It reads the signed index `champions/lane_d/index.json` from the public manifest store (, `--index-url` to override) and checks its signature against the main validator hotkey pinned in `chain.toml` (`[manifest] validator_hotkey`). It -then pulls the king's Hippius Hub repo `cascade/laned-king-c-` +then pulls the king's Hippius Hub repo `cascade/laned-king-c-` (`hotkey8`: the first 8 characters of the hotkey, lowercased — OCI repo names are lowercase) anonymously and checks `manifest.json` against the signed digest and every file against its sha256. Nothing is written unless every check passes. `--out` then holds `config.json`, `weights.safetensors`, `model.py`, diff --git a/docs/OPERATOR.md b/docs/OPERATOR.md index 9fc2a5abe..777797c9d 100644 --- a/docs/OPERATOR.md +++ b/docs/OPERATOR.md @@ -4405,7 +4405,7 @@ is blocked on an owner step. | `cascade-laned-evidence` | 3 h | `ops_jobs evidence` | `LANED_CHAIN_TOML`, `LANED_EVIDENCE_STAGE`, `LANED_PINNED_READINESS` / `LANED_PINNED_T7` (the inputs TOML `readiness` / `t7`) | **T7 is an owner step.** On the eval host pod run `python -P -m cascade.eval.lane_d_t7_pod --checkpoint-dir --histories (or --synthetic-seed N) --host --gpu --mem-gb --out t7.json` (CUDA, `source = "pod"`; every variant at 1000 and 5000 windows, the 5000 row gates, both under `window_sweep`), stage `t7.json`, then add `--t7`. A non-pod T7, an unparseable document, or one that disarms an armed context is refused (`--allow-disarm` overrides the last). | | `cascade-laned-vault-sweep` | daily 04:30 UTC | `ops_jobs vault-ledger`, then `python -P -m cascade.laned.vault_sweeper --dry-run` | `LANED_STATE`, `LANED_LEDGER`, `LANED_VAULT_DIR` / `LANED_ARCHIVE_DIR` (fs mode, testnet), `LANED_SWEEP_LOG_DIR` | A `--live` sweep needs the standing approval **D16** and a drop-in. S3 mode (`--s3 --archive-bucket`) takes its credentials from the owner's own mode-600 env file, never this one. | | `cascade-laned-king-check` | hourly | `ops_jobs king-check` | `LANED_STATE` (its persisted reports), `LANED_INDEX`, `LANED_SIGNER_SS58`, `LANED_PUBLISH_PATH_UNIT` (`--path-unit`: the installed `cascade-laned-king-publish.path`); optional `--vault-dir` and `--mirror hub=… r2=… hf=…` local copies for the full re-hash (files are hashed as they stream) | A red check after `cascade-laned-king-publish` ran is an owner look. `path_unit_mismatch` / `path_unit_unreadable` under `problems.path_unit`: the installed path unit does not watch the validator's request folder (below); fix its `PathChanged=`. | -| `cascade-laned-king-publish` (+ `.path`) | on each publish request, hourly backstop; **runs on the validator host, the 7 GB box included** (bounded memory, `MemoryMax=1G`) | `ops_jobs king-publish` | `LANED_STATE` (its reports and `lane_d_publish_requests/`), `LANED_INTAKE_STATE` (ready licences), `LANED_INDEX`, `LANED_SIGNER_SS58`, `LANED_CHAIN_TOML` (`[storage]` names), `LANED_WALLET_NAME` / `LANED_WALLET_HOTKEY`; env credentials by name only: `HIPPIUS_S3_*`, `HIPPIUS_HUB_TOKEN`, `HF_TOKEN`, `BACKUP_S3_*` | The validator's settlement step writes `lane_d_publish_requests/.json` for each crowning (with the era's sentinel record). The job copies the king vault → the king mirrors of `[lane_d_ops] king_mirrors` (default the Hub only: `{hub_namespace}/laned-king-c{context}-{hotkey8}`; opt-in R2 `[storage] backup_bucket`, else `manifest_bucket`, under `lane-d-kings/`, and HF `tensorlink-dev/cascade-lane-d-kings`), re-signs the index, puts it on the manifest store and writes `LANED_INDEX`. Exit 3 without a ready licence record or a missing armed sentinel record. Live drop-in. Memory, spool and trigger folder: below. **Takedown** (B13) is a one-shot: `ops_jobs takedown --digest D --reason licence\|rights --block B --index … --signer-ss58 … --chain-toml …` (`--dry-run` first). | +| `cascade-laned-king-publish` (+ `.path`) | on each publish request, hourly backstop; **runs on the validator host, the 7 GB box included** (bounded memory, `MemoryMax=1G`) | `ops_jobs king-publish` | `LANED_STATE` (its reports and `lane_d_publish_requests/`), `LANED_INTAKE_STATE` (ready licences), `LANED_INDEX`, `LANED_SIGNER_SS58`, `LANED_CHAIN_TOML` (`[storage]` names), `LANED_WALLET_NAME` / `LANED_WALLET_HOTKEY`; env credentials by name only: `HIPPIUS_S3_*`, `HIPPIUS_HUB_TOKEN`, `HF_TOKEN`, `BACKUP_S3_*` | The validator's settlement step writes `lane_d_publish_requests/.json` for each crowning (with the era's sentinel record). The job copies the king vault → the king mirrors of `[lane_d_ops] king_mirrors` (default the Hub only: `{hub_namespace}/laned-king-c{context}-{hotkey8}` (hotkey8 lowercased); opt-in R2 `[storage] backup_bucket`, else `manifest_bucket`, under `lane-d-kings/`, and HF `tensorlink-dev/cascade-lane-d-kings`), re-signs the index, puts it on the manifest store and writes `LANED_INDEX`. Exit 3 without a ready licence record or a missing armed sentinel record. Live drop-in. Memory, spool and trigger folder: below. **Takedown** (B13) is a one-shot: `ops_jobs takedown --digest D --reason licence\|rights --block B --index … --signer-ss58 … --chain-toml …` (`--dry-run` first). | **`king-publish` on the box.** The job signs the index with the validator hotkey, so it runs on the validator host. It holds no checkpoint in memory: diff --git a/tests/accept/w13/PATHS b/tests/accept/w13/PATHS index acb8a9486..7a53c48b4 100644 --- a/tests/accept/w13/PATHS +++ b/tests/accept/w13/PATHS @@ -29,3 +29,6 @@ docs/LANE_D.md docs/MINER_LANE_D.md docs/OPERATOR.md docs/ARCHITECTURE.md +# Live 2026-12-01 (first king publish 401): hub_repo lowercases hotkey8 (the +# Hippius registry 401s any uppercase repository name); the regression test. +tests/unit/test_lane_d_hub_repo_lowercase.py diff --git a/tests/accept/w13/README.md b/tests/accept/w13/README.md index 5aa102412..0248f4f83 100644 --- a/tests/accept/w13/README.md +++ b/tests/accept/w13/README.md @@ -28,7 +28,7 @@ Torch-free. It may use the existing lane D intake and storage modules MIRRORS = ("hub", "r2", "hf") HF_MIRROR_REPO = "tensorlink-dev/cascade-lane-d-kings" class PublishError(ValueError): # .code: a string from the codes below -def hub_repo(ns, context, hotkey) -> str # f"{ns}/laned-king-c{context}-{hotkey[:8]}" +def hub_repo(ns, context, hotkey) -> str # f"{ns}/laned-king-c{context}-{hotkey[:8].lower()}" def publish_king(*, hotkey, digest, vault, mirrors, alert) -> dict def verify_mirrors(digest, mirrors) -> dict[str, str] def build_index(kings, signer) -> dict diff --git a/tests/accept/w13/test_w13_mirrors.py b/tests/accept/w13/test_w13_mirrors.py index 3dc27061e..9a02085ef 100644 --- a/tests/accept/w13/test_w13_mirrors.py +++ b/tests/accept/w13/test_w13_mirrors.py @@ -181,7 +181,7 @@ def test_hub_repo_and_hf_mirror_names(): """§11.1: ``{ns}/laned-king-c{context}-{hotkey8}`` and the HF dataset.""" pub = h.publish() hotkey = h.fixture_key("king").ss58_address - assert pub.hub_repo("tensorlink", 8192, hotkey) == f"tensorlink/laned-king-c8192-{hotkey[:8]}" - assert pub.hub_repo("ns", 4096, hotkey) == f"ns/laned-king-c4096-{hotkey[:8]}" + assert pub.hub_repo("tensorlink", 8192, hotkey) == f"tensorlink/laned-king-c8192-{hotkey[:8].lower()}" + assert pub.hub_repo("ns", 4096, hotkey) == f"ns/laned-king-c4096-{hotkey[:8].lower()}" assert pub.HF_MIRROR_REPO == h.HF_REPO assert tuple(pub.MIRRORS) == h.MIRRORS diff --git a/tests/unit/test_lane_d_hub_repo_lowercase.py b/tests/unit/test_lane_d_hub_repo_lowercase.py new file mode 100644 index 000000000..40619e936 --- /dev/null +++ b/tests/unit/test_lane_d_hub_repo_lowercase.py @@ -0,0 +1,123 @@ +"""A lane D king's Hub repo is a valid (lowercase) OCI repository name. + +Live 2026-12-01: the first king publish failed with ``401 Unauthorized`` on +``cascade/laned-king-c4096-5HpKLEju/manifests/main``. The Hippius registry +(Harbor) answers 401 "un-recognized request" for ANY call on a repository name +with an uppercase letter (an existing repo with its name case-changed answers +401 too; a missing lowercase repo answers 404), and ``hub_repo`` put the raw +mixed-case ss58 prefix into the name. The fake API below rejects such names the +same way. Torch-free. +""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +from cascade.lane_d import mirrors as mirrors_mod +from cascade.lane_d import publish +from tests.accept.w13.helpers import fixture_key, vault_with_king + +HOTKEY = fixture_key("king").ss58_address + + +class _Resp: + def __init__(self, status_code: int): + self.status_code = status_code + + +class HTTPStatusError(Exception): + """httpx-shaped: ``response.status_code``.""" + + def __init__(self, msg: str, status_code: int): + super().__init__(msg) + self.response = _Resp(status_code) + + +class RevisionNotFoundError(Exception): + pass + + +class HarborLikeApi: + """``hippius_hub.HippiusApi``-shaped: every call on a repo name that is not + a lowercase OCI name answers 401, like registry.hippius.com; a missing repo + or file answers a not-found error.""" + + def __init__(self): + self.repos: dict[str, dict[str, bytes]] = {} + self.calls: list[tuple[str, str]] = [] + + def _gate(self, op: str, repo_id: str) -> None: + self.calls.append((op, repo_id)) + if repo_id != repo_id.lower(): + raise HTTPStatusError( + f"Client error '401 Unauthorized' for url " + f"'https://registry.hippius.com/v2/{repo_id}/manifests/main'", 401) + + def create_repo(self, repo_id, *, repo_type, private, exist_ok): + self._gate("create_repo", repo_id) + assert private is False and exist_ok is True + self.repos.setdefault(repo_id, {}) + + def upload_file(self, *, path_or_fileobj, path_in_repo, repo_id, repo_type, commit_message): + self._gate("upload_file", repo_id) + data = (path_or_fileobj if isinstance(path_or_fileobj, bytes) + else Path(path_or_fileobj).read_bytes()) + self.repos.setdefault(repo_id, {})[path_in_repo] = data + + def hf_hub_download(self, *, repo_id, filename, repo_type, local_dir): + self._gate("hf_hub_download", repo_id) + files = self.repos.get(repo_id) + if files is None or filename not in files: + raise RevisionNotFoundError(f"{repo_id}:{filename}") + p = Path(local_dir) / filename + p.parent.mkdir(parents=True, exist_ok=True) + p.write_bytes(files[filename]) + return str(p) + + +def test_the_fixture_hotkey_is_mixed_case(): + assert HOTKEY.lower() != HOTKEY, "the regression needs an ss58 with uppercase letters" + + +def test_hub_repo_is_a_lowercase_oci_name(): + repo = publish.hub_repo("cascade", 4096, HOTKEY) + assert repo == f"cascade/laned-king-c4096-{HOTKEY[:8].lower()}" + assert repo == repo.lower() and publish.OCI_REPO_RE.match(repo) + # the live king's name + assert (publish.hub_repo("cascade", 4096, "5HpKLEjuXXXXXXXX") + == "cascade/laned-king-c4096-5hpkleju") + + +def test_hub_repo_refuses_a_name_that_is_still_invalid(): + with pytest.raises(ValueError, match="OCI repository name"): + publish.hub_repo("Cascade", 4096, HOTKEY) + with pytest.raises(ValueError, match="OCI repository name"): + publish.hub_repo("", 4096, HOTKEY) + + +def test_a_king_publishes_to_a_registry_that_401s_uppercase_names(tmp_path): + vault, digest, files = vault_with_king(tmp_path, HOTKEY) + api = HarborLikeApi() + hub = mirrors_mod.hub_mirror(api, namespace="cascade", context=4096, hotkey=HOTKEY, + digest=digest, tmp_dir=tmp_path) + spool = tmp_path / "spool" + spool.mkdir() + alerts: list[dict] = [] + out = publish.publish_king(hotkey=HOTKEY, digest=digest, vault=vault, + mirrors={"hub": hub}, alert=alerts.append, spool_dir=spool) + assert out["mirrors"] == {"hub": "ok"} and alerts == [] + repo = f"cascade/laned-king-c4096-{HOTKEY[:8].lower()}" + assert {r for _, r in api.calls} == {repo} + assert {n: api.repos[repo][n] for n in files} == files + assert publish.MANIFEST_OBJECT in api.repos[repo] + # the read-back re-hash ran after the upload + ops = [op for op, _ in api.calls] + assert "hf_hub_download" in ops[ops.index("upload_file"):] + + +def test_pull_king_reads_the_same_repo_the_publisher_writes(): + from cascade.miner import lane_d_pull_king + + assert lane_d_pull_king._publish().hub_repo is publish.hub_repo