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
1 change: 1 addition & 0 deletions .github/workflows/provider-release-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on:
- 'scripts/verify-nemotron-prompt-parity.sh'
- 'scripts/prepare-prompt-fixtures.py'
- 'scripts/verified_download_cache.py'
- 'scripts/fixture_redirects.py'
- 'scripts/test-prepare-prompt-fixtures.py'
- 'scripts/run-provider-tests.sh'
- 'provider-swift/Tests/ProviderCoreTests/Qwen4StandaloneAdmissionTests.swift'
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/mimo-prompt-fixture-redirects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### MiMo prompt fixture downloads follow only allowed redirects

`scripts/prepare-mimo-prompt-fixtures.py` now follows a redirect only when the
target keeps the scheme, host and port of the URL that redirected, or when
`https://huggingface.co` redirects over HTTPS to a Hugging Face CDN host
(`hf.co` or a name that ends in `.hf.co`), where the Hub serves
`tokenizer.json`. Any other redirect (another host, another port or plain HTTP)
fails at once, is not retried, and its target is never requested. Before, the
script followed any redirect and refused only a final plain-HTTP URL. The
prompt fixture downloaders now share this rule in `scripts/fixture_redirects.py`.
7 changes: 6 additions & 1 deletion docs/developer/mimo-prompt-fixtures.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MiMo prompt fixture reproduction

> Last updated: 2026-10-18
> Last updated: 2026-11-08

Public MiMo golden-vector checks require pinned metadata and an independent
20-case corpus. Missing inputs are failures, not silently skipped checks. No
Expand All @@ -22,6 +22,11 @@ weights or executable model code. The unchanged synthetic corpus is checked in
at `fixtures/prompt-contract/mimo-v26-additional20.json`; its attribution is in
`fixtures/prompt-contract/README-mimo-v26.md`. An existing output directory,
changed input, oversized file or checksum mismatch is a failure, not a skip.
The script follows a same-origin redirect and, from `https://huggingface.co`
only, an HTTPS redirect to a Hugging Face CDN host (`hf.co` or a name that ends
in `.hf.co`), where the Hub serves `tokenizer.json`. Any other redirect fails at
once and its target is never requested; the
[test guide](test.md#public-fixtures-and-private-qualification) states the rule.

Alternatively, set `MIMO_PROMPT_ARTIFACT_DIRECTORY` to a metadata-only directory and
`MIMO_PROMPT_REFERENCE_VECTORS` to the unchanged20-case JSON file. Both must
Expand Down
28 changes: 18 additions & 10 deletions docs/developer/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1285,16 +1285,24 @@ many it downloaded, their bytes and the seconds it took.

`scripts/prepare-mimo-prompt-fixtures.py` and
`scripts/prepare-mimo-image-http-fixtures.py` apply the same retry rule to each
metadata file, with these differences. The MiMo prompt script refuses a
redirect to plain HTTP but follows a redirect to a different HTTPS host: Hugging
Face serves `tokenizer.json` from its CDN host. It has no total deadline: each
connect and read has a 60 s socket timeout. The image script has a 120 s
deadline for each file, and it classifies curl's exit code: a cut transfer (for
example exit 18 or 56) retries, and an oversize body (63) or a certificate
failure does not. curl does not follow redirects for the image script. The
script follows a redirect only when its scheme, host and port are those of the
requested URL, for at most 10 redirects. A redirect to another origin, plain
HTTP included, fails at once and is not requested. Provisioning failures fail
metadata file, with these differences. The MiMo prompt script has no total
deadline: each connect and read has a 60 s socket timeout. The image script has
a 120 s deadline for each file, and it classifies curl's exit code: a cut
transfer (for example exit 18 or 56) retries, and an oversize body (63) or a
certificate failure does not. curl does not follow redirects for the image
script.

The three downloaders share one redirect rule (`scripts/fixture_redirects.py`),
for at most 10 redirects. A download follows a redirect only when the target
has the scheme, host and port of the URL that answered with it, and the target
has no credentials. The MiMo prompt script also follows an HTTPS redirect from
`https://huggingface.co` to a Hugging Face CDN host on port 443: `hf.co` or a
name that ends in `.hf.co`. Hugging Face answers `tokenizer.json` at the pinned
revision with a 302 to `us.aws.cdn.hf.co`; the other three metadata files take a
same-origin 307. The pinned SHA-256 values still protect the bytes. Any other
redirect (another host, another port or plain HTTP) fails at once, is not
retried, and its target is never requested. The prompt-asset downloader also
refuses a redirect target with a query or fragment. Provisioning failures fail
qualification; they must not silently skip vectors.

Public validation means **this implementation matches those fixed expectations**.
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci-component-paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"scripts/provider-test-shard-weights.json",
"scripts/cluster-test-plan.py", "scripts/cluster-stage-content-inventory.py",
"scripts/swift_test_lock_retry.py",
"scripts/prepare-mimo-*-fixtures.py", "scripts/verified_download_cache.py",
"scripts/prepare-mimo-*-fixtures.py", "scripts/verified_download_cache.py", "scripts/fixture_redirects.py",
"scripts/verify-*-prompt-parity.sh",
"scripts/prepare-prompt-fixtures.py", "scripts/test-prepare-prompt-fixtures.py",
"scripts/verify-prompt-parity.sh", "scripts/test-qwen4-packaged-resources.py",
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs-impact-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
{
"name": "public fixtures and qualification",
"source_patterns": ["fixtures/**", "provider-swift/Tests/ProviderCoreTests/Fixtures/**", "scripts/verify*prompt*", "scripts/prepare-prompt-fixtures.py", "scripts/prepare-mimo*", "scripts/generate*prompt*", "scripts/qualify*", "provider-swift/Tests/test_protocol_fixture_resources.py"],
"source_patterns": ["fixtures/**", "provider-swift/Tests/ProviderCoreTests/Fixtures/**", "scripts/verify*prompt*", "scripts/prepare-prompt-fixtures.py", "scripts/prepare-mimo*", "scripts/fixture_redirects.py", "scripts/generate*prompt*", "scripts/qualify*", "provider-swift/Tests/test_protocol_fixture_resources.py"],
"docs_any_of": ["docs/developer/test.md", "docs/developer/mimo-prompt-fixtures.md", "docs/developer/serving-performance-qualification.md"]
},
{
Expand Down
49 changes: 49 additions & 0 deletions scripts/fixture_redirects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""The redirect rule of the fixture download scripts.

A download follows a redirect only when the target has the origin (scheme, host
and port) of the URL that answered with it, and the target has no credentials.
A caller can allow one more redirect: from https://huggingface.co to an HTTPS
Hugging Face CDN host on port 443, that is `hf.co` or a name that ends in
`.hf.co`. The Hub answers a file stored with Xet or LFS with a 302 to such a
host (for example `us.aws.cdn.hf.co`, `cas-bridge.xethub.hf.co` or
`cdn-lfs-us-1.hf.co`). The pinned SHA-256 of each fixture still protects its
bytes. Every other redirect raises ValueError before its target is requested.
"""

import urllib.parse
import urllib.request

DEFAULT_PORTS = {"http": 80, "https": 443}
HUGGING_FACE_HUB_ORIGIN = ("https", "huggingface.co", 443)
HUGGING_FACE_CDN_DOMAIN = "hf.co"


def origin(url):
parts = urllib.parse.urlsplit(url)
return parts.scheme, parts.hostname, parts.port or DEFAULT_PORTS.get(parts.scheme)


def redirect_allowed(source, target, hugging_face_cdn=False):
parts = urllib.parse.urlsplit(target)
if parts.username is not None or parts.password is not None:
return False
if origin(target) == origin(source):
return True
if not hugging_face_cdn or origin(source) != HUGGING_FACE_HUB_ORIGIN:
return False
host = parts.hostname or ""
# An exact name or a dot-separated suffix: hf.co.evil.example and evilhf.co do not match.
return (origin(target) == ("https", host, 443)
and (host == HUGGING_FACE_CDN_DOMAIN or host.endswith("." + HUGGING_FACE_CDN_DOMAIN)))


class OriginRedirect(urllib.request.HTTPRedirectHandler):
"""A urllib redirect handler that applies redirect_allowed to each hop."""

def __init__(self, hugging_face_cdn=False):
self.hugging_face_cdn = hugging_face_cdn

def redirect_request(self, req, fp, code, msg, headers, newurl):
if not redirect_allowed(req.full_url, newurl, self.hugging_face_cdn):
raise ValueError("fixture download redirected to another origin")
return super().redirect_request(req, fp, code, msg, headers, newurl)
18 changes: 6 additions & 12 deletions scripts/prepare-mimo-image-http-fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import subprocess
import tempfile
import time
import urllib.parse
import zlib

from fixture_redirects import redirect_allowed
from verified_download_cache import cached

SPEC = importlib.util.spec_from_file_location(
Expand All @@ -27,12 +27,11 @@
# (35), empty reply (52), send (55) and receive (56). Plain `--retry` skips 18
# and 56; `--retry-all-errors` would also retry 4xx and an oversize body (63).
TRANSIENT_CURL_EXITS = {6, 7, 16, 18, 28, 35, 52, 55, 56, 92}
# curl itself never follows a redirect: each hop is checked against the
# requested origin before it is requested, so a fixture download never leaves
# its host. The cap is urllib's, as in prepare-prompt-fixtures.py.
# curl itself never follows a redirect: each hop is checked with
# fixture_redirects.py before it is requested, so a fixture download never
# leaves its host. The cap is urllib's, as in prepare-prompt-fixtures.py.
REDIRECT_STATUSES = {"301", "302", "303", "307", "308"}
MAX_REDIRECTS = 10
DEFAULT_PORTS = {"http": 80, "https": 443}


class TransientTransfer(ValueError):
Expand All @@ -51,14 +50,9 @@ def chunk(kind, data):
+ chunk(b"IDAT", compressed) + chunk(b"IEND", b""))


def origin(url):
parts = urllib.parse.urlsplit(url)
return parts.scheme, parts.hostname, parts.port or DEFAULT_PORTS.get(parts.scheme)


def fetch_once(name, size, seconds):
url = PINS.BASE_URL + "/" + name
requested, stop = origin(url), time.monotonic() + seconds
stop = time.monotonic() + seconds
with tempfile.TemporaryDirectory() as directory:
body = Path(directory) / "body"
for _ in range(MAX_REDIRECTS + 1):
Expand All @@ -78,7 +72,7 @@ def fetch_once(name, size, seconds):
if status not in REDIRECT_STATUSES or not location:
break
# A plain-HTTP downgrade is a different origin too.
if origin(location) != requested:
if not redirect_allowed(url, location):
raise ValueError("MiMo HTTP fixture redirected to another origin: " + name)
url = location
else:
Expand Down
11 changes: 6 additions & 5 deletions scripts/prepare-mimo-prompt-fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import stat
import time
import urllib.error
import urllib.parse
import urllib.request

from fixture_redirects import OriginRedirect
from verified_download_cache import cached

REPOSITORY = "XiaomiMiMo/MiMo-V2.6-Flash-RL"
Expand All @@ -25,6 +25,9 @@
MAXIMUM = 128 * 1024 * 1024
DOWNLOAD_ATTEMPTS = 3
RETRY_BACKOFF_SECONDS = (1, 3)
# The Hub answers tokenizer.json at REVISION with a 302 to its CDN
# (us.aws.cdn.hf.co); the others take a same-origin 307. See fixture_redirects.py.
OPENER = urllib.request.build_opener(OriginRedirect(hugging_face_cdn=True))


class TransientTransfer(ValueError):
Expand All @@ -40,7 +43,7 @@ def checked_bytes(data, expected, maximum):
def retryable(error):
# Retry only a failed or cut transfer: a TLS, socket or connection error,
# a timeout, an incomplete body, a short body or an HTTP 5xx. A wrong
# digest, an oversize body, an insecure redirect or a 4xx stays final.
# digest, an oversize body, a refused redirect or a 4xx stays final.
# HTTPError is an OSError subclass: test it first.
if isinstance(error, urllib.error.HTTPError):
return error.code >= 500
Expand All @@ -49,9 +52,7 @@ def retryable(error):

def fetch_once(url):
request = urllib.request.Request(url, headers={"User-Agent": "darkbloom-fixture-check/1"})
with urllib.request.urlopen(request, timeout=60) as response:
if urllib.parse.urlsplit(response.geturl()).scheme != "https":
raise ValueError("insecure fixture redirect")
with OPENER.open(request, timeout=60) as response:
declared = response.headers.get("Content-Length")
data = response.read(MAXIMUM + 1)
# http.client returns a short body without error when the connection ends
Expand Down
11 changes: 5 additions & 6 deletions scripts/prepare-prompt-fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import urllib.parse
import urllib.request

from fixture_redirects import OriginRedirect, origin
from verified_download_cache import restore_file, store_file

MAX_MANIFEST_BYTES = 1 << 20
Expand Down Expand Up @@ -153,11 +154,9 @@ def https_url(value):
return parsed


class SameOriginRedirect(urllib.request.HTTPRedirectHandler):
class SameOriginRedirect(OriginRedirect):
def redirect_request(self, req, fp, code, msg, headers, newurl):
old, new = urllib.parse.urlsplit(req.full_url), https_url(newurl)
if (old.scheme, old.netloc) != (new.scheme, new.netloc):
raise ValueError("cross-origin artifact redirect")
https_url(newurl)
return super().redirect_request(req, fp, code, msg, headers, newurl)


Expand All @@ -182,8 +181,8 @@ def download_once(opener, url, output, artifact, deadline):
raise TransientTransfer("artifact request returned an HTTP server error")
if response.status != 200:
raise ValueError("artifact request did not return HTTP 200")
original, final = https_url(url), https_url(response.url)
if (original.scheme, original.netloc) != (final.scheme, final.netloc):
https_url(response.url)
if origin(url) != origin(response.url):
raise ValueError("cross-origin artifact response")
length = response.headers.get("Content-Length")
if length is not None and int(length) != artifact["size_bytes"]:
Expand Down
1 change: 1 addition & 0 deletions scripts/test-ci-component-paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_component_and_shared_dependency_matrix(self):
"scripts/run-provider-tests.sh": {"provider"},
"scripts/provider-ci-cold-retry.sh": {"provider", "cluster"},
"scripts/verified_download_cache.py": {"provider"},
"scripts/fixture_redirects.py": {"provider"},
"scripts/provider-test-shards.py": {"provider"},
"scripts/cluster-test-plan.py": {"provider", "cluster"},
"scripts/swift_test_lock_retry.py": {"provider", "cluster"},
Expand Down
Loading
Loading