Skip to content

Commit 2431dba

Browse files
justinchubyCopilot
andcommitted
Harden tokenizer package identity checks
Bind runtime packaging to the captured materialized tokenizer digest in addition to its route, evidence, and metadata identities. Clarify the artifact resolver contract and cover fail-closed digest drift. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 8bebbaa commit 2431dba

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎src/mobius/integrations/gguf/_component_export.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def resolve_tokenizer_export_verdict(
5959
verdict: GGUFTokenizerVerdict | None = None,
6060
artifact_identity: Any | None = None,
6161
) -> GGUFTokenizerVerdict:
62-
"""Add an exact artifact blocker to an otherwise validated tokenizer verdict."""
62+
"""Apply exact artifact evidence to promote or block a tokenizer verdict."""
6363
if verdict is None:
6464
verdict = inspect_gguf_tokenizer(gguf_model.metadata, source=str(source_path))
6565
if verdict.materialized or verdict.metadata_sha256 is None:

‎src/mobius/integrations/gguf/_runtime_package.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ def write_gguf_runtime_package(
427427
or built_verdict.metadata_sha256 != verdict.metadata_sha256
428428
or built_verdict.route != verdict.route
429429
or built_verdict.evidence_id != verdict.evidence_id
430+
or built_verdict.tokenizer_sha256 != verdict.tokenizer_sha256
430431
):
431432
raise ValueError(
432433
"The GGUF tokenizer metadata no longer matches the identity captured during "

‎src/mobius/integrations/gguf/_runtime_package_test.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import dataclasses
89
import json
910
from contextlib import contextmanager
1011
from pathlib import Path
@@ -57,6 +58,7 @@ def _materialized():
5758
route="copy",
5859
route_identifier="embedded",
5960
reason="exact embedded tokenizer",
61+
tokenizer_sha256="e" * 64,
6062
metadata_sha256="f" * 64,
6163
evidence_id=None,
6264
)
@@ -224,6 +226,35 @@ def test_exact_tokenizer_evidence_exports_without_runtime_evidence(self, tmp_pat
224226
)
225227
assert materialize.call_args.kwargs["source"] is tokenizer_source
226228

229+
def test_changed_pinned_tokenizer_digest_rejects_before_package_save(self, tmp_path):
230+
pkg = _FakePackage()
231+
built = GGUFTokenizerVerdict(
232+
route="pinned-source",
233+
model="gpt2",
234+
pre="qwen2",
235+
canonical_pre="qwen2",
236+
reason="exact tokenizer evidence",
237+
token_count=2,
238+
tokenizer_sha256="a" * 64,
239+
metadata_sha256="f" * 64,
240+
audit_status="validated-pinned-source",
241+
evidence_id="tokenizer-only-evidence",
242+
)
243+
current = dataclasses.replace(built, tokenizer_sha256="b" * 64)
244+
pkg.gguf_tokenizer_verdict = built
245+
with (
246+
_successful_runtime_dependencies(),
247+
mock.patch(
248+
"mobius.integrations.gguf._component_export.resolve_tokenizer_export_verdict",
249+
return_value=current,
250+
),
251+
pytest.raises(ValueError, match="replaced tokenizer source"),
252+
):
253+
_write_runtime(pkg, tmp_path / "m.gguf", tmp_path / "out")
254+
255+
assert pkg.saved_to is None
256+
assert not (tmp_path / "out").exists()
257+
227258
def test_runtime_disposition_is_replaced_when_runtime_changes(self):
228259
from mobius.integrations.gguf._component_export import (
229260
attach_runtime_unvalidated_report,

0 commit comments

Comments
 (0)