Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(ship): canonicalize suite order in provenance bindings (#2038)

Nurkhan Esenbek6ea09a95025e
diff --git a/changelog.d/0.76.0/2038.fixed.md b/changelog.d/0.76.0/2038.fixed.md
new file mode 100644
index 00000000..9dd0670d
--- /dev/null
+++ b/changelog.d/0.76.0/2038.fixed.md
@@ -0,0 +1 @@
+- Canonicalize ship provenance suite order so re-stamped evidence passes strict replay for non-alphabetical and default suite selections (#2035, reported by @abdulwaarith0, fixed by @kok-o in #2038).
diff --git a/docs/evaluation.md b/docs/evaluation.md
index f94c272c..10b8136f 100644
--- a/docs/evaluation.md
+++ b/docs/evaluation.md
@@ -708,9 +708,15 @@ reruns during an offline gate.
Legacy/default replay remains recipe-only. `--require-provenance` keeps all
checks even when `--emit-evidence` is also present. Ordinary external-score
stamping remains available: it binds caller-trusted supplied scores to declared
-inputs, and records their actual task mode/suite axes. It is not a model run,
-attestation, signature or forgery protection. The unkeyed hashes detect drift;
-use the existing signing/attestation tools for a trust boundary.
+inputs, and records their actual task mode/suite axes. Suite names are stored in
+canonical alphabetical order in both the suite descriptor and its policy.
+This allows a restamp to replay against the same configuration with a
+non-alphabetical or default suite selection. Different suite selections and
+config-hash drift still refuse replay. Older bindings that kept a different
+suite order can be re-stamped from their trusted scores before strict replay.
+This is not a model run, attestation, signature or forgery protection.
+The unkeyed hashes detect drift; use the existing signing/attestation tools for a
+trust boundary.
**Baseline provenance (#404).** Produce a stamped baseline with
`soup eval gate --suite <suite.yaml> --model <id> --write-baseline baseline.json`
diff --git a/src/soup_cli/utils/ship_provenance.py b/src/soup_cli/utils/ship_provenance.py
index 0f6ed891..f39b2fda 100644
--- a/src/soup_cli/utils/ship_provenance.py
+++ b/src/soup_cli/utils/ship_provenance.py
@@ -31,6 +31,10 @@ def make_binding(
from soup_cli.utils.adapter_sign import compute_adapter_manifest
validate_data_identity(data_sha256)
+ # Suite order is not part of score identity; verdict deltas sort names too.
+ # Canonicalize both declarations before hashing, without changing callers.
+ suites = sorted(suites)
+ policy = {**policy, "general_suite": sorted(policy["general_suite"])}
root = None
if adapter is not None:
try:
diff --git a/tests/test_ship_provenance.py b/tests/test_ship_provenance.py
index 24c14590..a70e2153 100644
--- a/tests/test_ship_provenance.py
+++ b/tests/test_ship_provenance.py
@@ -41,6 +41,54 @@ def work(tmp_path, monkeypatch):
return tmp_path
+ "selection", ["mini_tool_call,mini_mmlu", None, "mini_mmlu,mini_tool_call"],
+)
+def test_restamped_suite_order_and_default_roundtrip(work, selection):
+ from soup_cli.eval.gate_suites import DEFAULT_GENERAL_SUITE
+
+ cfg = work / "soup.yaml"
+ text = cfg.read_text(encoding="utf-8")
+ suites = list(DEFAULT_GENERAL_SUITE) if selection is None else selection.split(",")
+ text = text.replace(
+ " general_suite: mini_mmlu\n",
+ "" if selection is None else f" general_suite: {selection}\n",
+ )
+ cfg.write_text(text, encoding="utf-8")
+ raw = work / "raw.json"
+ payload = json.loads(raw.read_text(encoding="utf-8"))
+ payload["benchmarks"] = {name: {"base": 0.6, "tuned": 0.6} for name in suites}
+ raw.write_text(json.dumps(payload), encoding="utf-8")
+ bound = _produce()
+ binding = bound["provenance"]["binding"]
+ assert binding["suites"]["names"] == sorted(suites)
+ assert binding["policy"]["general_suite"] == sorted(suites)
+ result = _gate()
+ assert result.exit_code == 0, (result.output, result.exception)
+ assert "SHIP" in strip_ansi(result.output)
+ # A different selection must still be refused after canonicalization.
+ changed = _gate("--general-suite", "mini_arithmetic")
+ assert changed.exit_code == 3
+ assert "provenance" in strip_ansi(changed.output).lower()
+
+
+def test_binding_canonicalizes_both_suite_fields_without_mutating_inputs():
+ from soup_cli.utils.ship_provenance import make_binding
+
+ names = ["mini_tool_call", "mini_mmlu"]
+ policy = {"general_suite": names.copy(), "forgetting_threshold": 0.05}
+ binding = make_binding(
+ adapter=None, task_eval_sha256=None, source_data_sha256=None,
+ data_sha256=None, suites=names, policy=policy,
+ )
+ assert binding["suites"]["names"] == sorted(names)
+ assert binding["policy"]["general_suite"] == sorted(names)
+ assert names == policy["general_suite"] == ["mini_tool_call", "mini_mmlu"]
+ assert binding["policy_sha256"] == hashlib.sha256(json.dumps(
+ binding["policy"], sort_keys=True, separators=(",", ":"),
+ ).encode()).hexdigest()
+
+
def _produce(*extra):
result = runner.invoke(app, [
"ship", "--evidence", "raw.json", "--config", "soup.yaml", "--adapter", "adapter",