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(registry): refuse ambiguous name:tag lookups (#1934)

Abdulwaarith Zakariyya222283e8c159
diff --git a/changelog.d/0.76.0/1934.fixed.md b/changelog.d/0.76.0/1934.fixed.md
new file mode 100644
index 00000000..dad0da7d
--- /dev/null
+++ b/changelog.d/0.76.0/1934.fixed.md
@@ -0,0 +1,6 @@
+- **A registry `name:tag` that matches more than one entry is refused instead of resolving to the newest, and `RegistryStore.list()` filters by `run_id` (#1763 by @abdulwaarith0 in #1934).**
+ `push` keeps every entry, so pushing the same name and tag twice left twins, and any
+ command given that `name:tag` silently used the newest. The error now names the
+ candidates and asks for the full id, as an ambiguous id prefix already did.
+ `soup eval quant-check` reports either kind of ambiguity as a usage error instead of a
+ traceback. `RegistryStore.list(run_id=...)` finds the entries registered from one run.
diff --git a/docs/adapters-and-governance.md b/docs/adapters-and-governance.md
index 46eb6508..302d1bdb 100644
--- a/docs/adapters-and-governance.md
+++ b/docs/adapters-and-governance.md
@@ -300,7 +300,7 @@ soup registry delete llama31-chat-v1 --yes
soup history llama31-chat
```
-**Refs resolve flexibly** — you can use a registry ID, a name (latest), or `name:tag`. Ambiguous prefixes raise an error rather than silently picking the wrong entry. Registry files are stored with `600` perms on POSIX; override the path with `SOUP_REGISTRY_DB_PATH`.
+**Refs resolve flexibly** — you can use a registry ID, a unique ID prefix, or `name:tag`. A bare name is not a ref; `soup history <name>` lists every entry with that name. Pushing the same `name:tag` twice keeps both entries. A `name:tag` that matches more than one entry raises an error naming the candidates, and an ambiguous prefix raises one too, rather than silently picking an entry; use the full ID then. Registry files are stored with `600` perms on POSIX; override the path with `SOUP_REGISTRY_DB_PATH`.
## Adapter Management (git for LoRA)
diff --git a/src/soup_cli/commands/eval.py b/src/soup_cli/commands/eval.py
index efcfbb77..d64cd060 100644
--- a/src/soup_cli/commands/eval.py
+++ b/src/soup_cli/commands/eval.py
@@ -1380,8 +1380,14 @@ def quant_check_cmd(
console.print(f"[red]{exc}[/]")
raise typer.Exit(EXIT_USAGE_ERROR) from exc
- resolved_before = resolve_model_ref(before)
- resolved_after = resolve_model_ref(after)
+ resolved: dict[str, Optional[str]] = {}
+ for label, ref in (("--before", before), ("--after", after)):
+ try:
+ resolved[label] = resolve_model_ref(ref)
+ except ValueError as exc: # AmbiguousRefError: a registry prefix or name:tag with twins
+ console.print(f"[red]Cannot resolve {label}:[/] {for_terminal(str(exc))}")
+ raise typer.Exit(EXIT_USAGE_ERROR) from exc
+ resolved_before, resolved_after = resolved["--before"], resolved["--after"]
if resolved_before is None:
console.print(f"[red]Cannot resolve --before: {before}[/]")
raise typer.Exit(EXIT_USAGE_ERROR)
diff --git a/src/soup_cli/registry/store.py b/src/soup_cli/registry/store.py
index 87720043..664f9e76 100644
--- a/src/soup_cli/registry/store.py
+++ b/src/soup_cli/registry/store.py
@@ -34,6 +34,10 @@ if TYPE_CHECKING:
class AmbiguousRefError(ValueError):
"""Raised when a reference matches more than one registry entry."""
+
+# How many candidate ids an ambiguous ``name:tag`` error lists before "and N more".
+_AMBIGUOUS_IDS_SHOWN = 5
+
REGISTRY_DB_FILENAME = "registry.db"
_VALID_KINDS = frozenset(
@@ -340,9 +344,10 @@ class RegistryStore:
tag: Optional[str] = None,
base: Optional[str] = None,
task: Optional[str] = None,
+ run_id: Optional[str] = None,
limit: int = 100,
) -> list[dict]:
- """Return entries filtered by name/tag/base/task."""
+ """Return entries filtered by name/tag/base/task/run_id."""
conn = self._get_conn()
clauses: list[str] = []
params: list[object] = []
@@ -356,6 +361,9 @@ class RegistryStore:
if task:
clauses.append("e.task = ?")
params.append(task)
+ if run_id:
+ clauses.append("e.run_id = ?")
+ params.append(run_id)
if tag:
clauses.append(
"e.id IN (SELECT entry_id FROM registry_tags WHERE tag = ?)"
@@ -408,7 +416,7 @@ class RegistryStore:
"""Resolve a reference (id, prefix, name:tag, or registry://id) to an id.
Returns ``None`` on miss. Raises :class:`AmbiguousRefError` when a
- prefix matches more than one entry.
+ prefix or a ``name:tag`` matches more than one entry.
"""
if not ref:
return None
@@ -424,7 +432,9 @@ class RegistryStore:
if row:
return row["id"]
- # name:tag form — pick most recent
+ # name:tag form: must match exactly one entry. push() never replaces an
+ # entry, so a repeated name and tag leaves twins; picking the newest
+ # silently would hide the others.
if ":" in ref:
name, _, tag = ref.partition(":")
try:
@@ -432,14 +442,23 @@ class RegistryStore:
validate_tag(tag)
except ValueError:
return None
- row = conn.execute(
+ ids = [row["id"] for row in conn.execute(
"""SELECT e.id FROM registry_entries e
JOIN registry_tags t ON t.entry_id = e.id
WHERE e.name = ? AND t.tag = ?
- ORDER BY e.created_at DESC, e.rowid DESC LIMIT 1""",
+ ORDER BY e.created_at DESC, e.rowid DESC""",
(name, tag),
- ).fetchone()
- return row["id"] if row else None
+ ).fetchall()]
+ if len(ids) > 1:
+ shown = ", ".join(ids[:_AMBIGUOUS_IDS_SHOWN])
+ more = len(ids) - _AMBIGUOUS_IDS_SHOWN
+ if more > 0:
+ shown += f" and {more} more"
+ raise AmbiguousRefError(
+ f"reference '{ref}' matches {len(ids)} entries ({shown}) - "
+ "use the full id"
+ )
+ return ids[0] if ids else None
# Prefix — must be unambiguous. Escape LIKE wildcards so a query
# like "%" doesn't match everything.
diff --git a/tests/test_registry.py b/tests/test_registry.py
index a18bd904..addea8b7 100644
--- a/tests/test_registry.py
+++ b/tests/test_registry.py
@@ -210,20 +210,22 @@ class TestRegistryStore:
assert "v1" in entry["tags"]
store.close()
- def test_push_duplicate_tag_under_name_replaces(self, tmp_path):
+ def test_push_duplicate_tag_under_name_keeps_both_and_refuses_to_pick(self, tmp_path):
+ from soup_cli.registry.store import AmbiguousRefError
+
store = self._store(tmp_path)
e1 = store.push(name="model-a", tag="v1", base_model="b", task="sft",
run_id=None, config={"x": 1})
e2 = store.push(name="model-a", tag="v1", base_model="b", task="sft",
run_id=None, config={"x": 2})
- # both entries exist but v1 points to the most recent by default
+ # both entries exist; neither replaces the other
listing = store.list(name="model-a")
ids = [e["id"] for e in listing]
assert e1 in ids
assert e2 in ids
- # Latest tagged v1 should be e2
- latest = store.resolve("model-a:v1")
- assert latest == e2
+ # model-a:v1 now names two entries, so resolve refuses to pick one (#1763)
+ with pytest.raises(AmbiguousRefError, match="matches 2 entries"):
+ store.resolve("model-a:v1")
store.close()
def test_list_all(self, tmp_path):
diff --git a/tests/test_registry_lookup.py b/tests/test_registry_lookup.py
new file mode 100644
index 00000000..a5cd858e
--- /dev/null
+++ b/tests/test_registry_lookup.py
@@ -0,0 +1,217 @@
+"""Registry lookups: list by run_id, and a name:tag that matches more than one entry (#1763).
+
+``push`` always creates a new entry, so two pushes with the same name and tag leave twins.
+``resolve("name:tag")`` used to return the newest twin silently; it now raises
+``AmbiguousRefError`` naming the candidates, as an ambiguous id prefix already did. The CLI
+paths that resolve a ref must report that as an error, not a traceback or a silent pick.
+"""
+
+import pytest
+import yaml
+from typer.testing import CliRunner
+
+from soup_cli.cli import app
+from soup_cli.registry.store import AmbiguousRefError, RegistryStore
+from tests.conftest import strip_ansi
+
+runner = CliRunner()
+
+
+def push(tmp_path, monkeypatch):
+ """Isolated registry and branches dir under cwd; returns a push helper."""
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("SOUP_REGISTRY_DB_PATH", str(tmp_path / "registry.db"))
+ (tmp_path / "branches").mkdir()
+ monkeypatch.setenv("SOUP_BRANCHES_DIR", str(tmp_path / "branches"))
+
+ def _push(name="model", tag="v1", run_id=None):
+ with RegistryStore() as store:
+ return store.push(name=name, tag=tag, base_model="org/base", task="sft",
+ run_id=run_id, config={"lr": 0.0001})
+
+ return _push
+
+
+def _plain(result) -> str:
+ return " ".join(strip_ansi(result.output).split())
+
+
+def _ids(entries) -> list:
+ return [entry["id"] for entry in entries]
+
+
+class TestListByRunId:
+ def test_filters_by_run_id(self, push):
+ first = push(run_id="run-a")
+ other = push(name="other", run_id="run-b")
+ second = push(tag="v2", run_id="run-a")
+ with RegistryStore() as store:
+ assert set(_ids(store.list(run_id="run-a"))) == {first, second}
+ assert _ids(store.list(run_id="run-b")) == [other]
+ assert store.list(run_id="run-missing") == []
+
+ def test_combines_with_the_other_filters(self, push):
+ first = push(run_id="run-a")
+ push(tag="v2", run_id="run-a")
+ push(run_id="run-b")
+ with RegistryStore() as store:
+ assert _ids(store.list(run_id="run-a", tag="v1")) == [first]
+ assert store.list(run_id="run-a", name="other") == []
+
+ def test_without_run_id_nothing_is_filtered(self, push):
+ ids = {push(run_id="run-a"), push(name="other")}
+ with RegistryStore() as store:
+ assert set(_ids(store.list())) == ids
+
+
+class TestResolveNameTag:
+ def test_a_single_match_resolves(self, push):
+ entry = push()
+ push(tag="v2")
+ with RegistryStore() as store:
+ assert store.resolve("model:v1") == entry
+ assert store.resolve("registry://model:v1") == entry
+
+ def test_no_match_is_none(self, push):
+ push()
+ with RegistryStore() as store:
+ assert store.resolve("model:v9") is None
+ assert store.resolve("nobody:v1") is None
+
+ @pytest.mark.parametrize("ref", ["model:v1", "registry://model:v1"])
+ def test_twins_raise_naming_both_ids(self, push, ref):
+ first, second = push(), push()
+ with RegistryStore() as store, pytest.raises(AmbiguousRefError) as excinfo:
+ store.resolve(ref)
+ message = str(excinfo.value)
+ assert "'model:v1' matches 2 entries" in message
+ assert first in message and second in message
+ assert "use the full id" in message
+
+ def test_twins_still_resolve_by_full_id(self, push):
+ first, second = push(), push()
+ with RegistryStore() as store:
+ assert store.resolve(first) == first
+ assert store.resolve(second) == second
+
+ def test_only_the_shared_tag_is_ambiguous(self, push):
+ push()
+ push()
+ other = push(tag="v2")
+ with RegistryStore() as store:
+ assert store.resolve("model:v2") == other
+
+ def test_a_long_candidate_list_is_capped(self, push):
+ ids = [push() for _ in range(7)]
+ with RegistryStore() as store, pytest.raises(AmbiguousRefError) as excinfo:
+ store.resolve("model:v1")
+ message = str(excinfo.value)
+ assert "matches 7 entries" in message
+ assert sum(entry_id in message for entry_id in ids) == 5
+ assert "and 2 more" in message
+
+ def test_an_ambiguous_prefix_is_unchanged(self, push):
+ push()
+ push(name="other")
+ with RegistryStore() as store, pytest.raises(AmbiguousRefError) as excinfo:
+ store.resolve("reg_")
+ assert "supply a longer prefix or the full id" in str(excinfo.value)
+
+
+class TestCallers:
+ """Each path that resolves a user-supplied ref reports the ambiguity and changes nothing."""
+
+ def test_registry_show(self, push):
+ first, second = push(), push()
+ result = runner.invoke(app, ["registry", "show", "model:v1"])
+ assert result.exit_code == 1, (result.output, repr(result.exception))
+ out = _plain(result)
+ assert "matches 2 entries" in out and first in out and second in out
+
+ def test_can_pack(self, push, tmp_path):
+ push()
+ push()
+ result = runner.invoke(app, ["can", "pack", "--entry-id", "model:v1", "--out", "model.can"])
+ assert result.exit_code == 1, (result.output, repr(result.exception))
+ assert "matches 2 entries" in _plain(result)
+ assert not (tmp_path / "model.can").exists()
+
+ def test_eval_gate_baseline(self, push, tmp_path):
+ push()
+ push()
+ (tmp_path / "gate.yaml").write_text(yaml.safe_dump({
+ "suite": "gate",
+ "tasks": [{"type": "custom", "name": "acc", "tasks": "evals/acc.jsonl",
+ "scorer": "exact", "threshold": 0.5}],
+ }), encoding="utf-8")
+ result = runner.invoke(app, ["eval", "gate", "--suite", "gate.yaml",
+ "--baseline", "registry://model:v1"])
+ assert result.exit_code == 3, (result.output, repr(result.exception))
+ assert "matches 2 entries" in _plain(result)
+
+ def test_resolve_baseline_used_by_ship_and_the_training_gate(self, push):
+ from soup_cli.eval.gate import resolve_baseline
+
+ push()
+ push()
+ with pytest.raises(AmbiguousRefError):
+ resolve_baseline("registry://model:v1")
+
+ @pytest.mark.parametrize("ref", ["registry://model:v1", "registry://reg_"])
+ def test_eval_quant_check(self, push, tmp_path, ref):
+ push()
+ push()
+ (tmp_path / "tasks.jsonl").write_text('{"prompt": "1+1", "answer": "2"}\n',
+ encoding="utf-8")
+ result = runner.invoke(app, ["eval", "quant-check", "--before", ref,
+ "--after", "after.gguf", "--tasks", "tasks.jsonl"])
+ assert result.exit_code == 3, (result.output, repr(result.exception))
+ out = _plain(result)
+ assert "--before" in out and "matches 2 entries" in out
+
+ def test_attach_artifact(self, push, tmp_path):
+ from soup_cli.registry.attach import attach_artifact
+
+ first, second = push(), push()
+ (tmp_path / "report.json").write_text("{}", encoding="utf-8")
+ with pytest.raises(AmbiguousRefError):
+ attach_artifact("model:v1", path="report.json", kind="diagnose_report")
+ with RegistryStore() as store:
+ assert store.get_artifacts(first) == [] and store.get_artifacts(second) == []
+
+ def test_adapters_branch_from_registry(self, push, tmp_path):
+ push()
+ push()
+ result = runner.invoke(app, ["adapters", "branch", "fromtag",
+ "--from-registry", "model:v1"])
+ assert result.exit_code == 2, (result.output, repr(result.exception))
+ assert "matches 2 entries" in _plain(result)
+ assert not (tmp_path / "branches" / "fromtag.json").exists()
+ assert not (tmp_path / "fromtag.from-registry.yaml").exists()
+
+ def test_adapters_branch_attach_to_registry(self, push, tmp_path):
+ first, second = push(), push()
+ (tmp_path / "soup.yaml").write_text("base: org/base\ntask: sft\n", encoding="utf-8")
+ result = runner.invoke(app, ["adapters", "branch", "attached", "-c", "soup.yaml",
+ "--base", "org/base", "--attach-to-registry", "model:v1"])
+ assert result.exit_code == 2, (result.output, repr(result.exception))
+ assert "matches 2 entries" in _plain(result)
+ with RegistryStore() as store:
+ assert store.get_artifacts(first) == [] and store.get_artifacts(second) == []
+
+ def test_card(self, push):
+ from soup_cli.commands.card import CardError, build_card_for_ref
+
+ push()
+ push()
+ with pytest.raises(CardError, match="matches 2 entries"):
+ build_card_for_ref("model:v1")
+
+ def test_mcp_registry_show(self, push):
+ from soup_cli.mcp_server import registry as mcp_registry
+
+ push()
+ push()
+ with pytest.raises(mcp_registry.McpToolError, match="ambiguous"):
+ mcp_registry.tool_registry_show({"ref": "model:v1"})