import tempfile
from pathlib import Path
import jammi
from jammi.errors import ModelNotFound, ModelReferenced
from jammi.testing import LiveServer
from jammi_cookbook import fixtures
from jammi_cookbook.claims import claim
BASE = fixtures.model("tiny_bert")
PAIRS = str(fixtures.path("tiny_pairs.csv"))15 The model catalog — referential integrity on either transport
Verbs: fine_tune · list_models · describe_model · delete_model · prune_jobs · [jobs] retention_days · Background: the model catalog as a referenced store — a model is a row other rows point at (Kleppmann 2017), so a hard delete is refused while a reference holds, and absence is a typed condition, not an ambiguous failure · Checked: parity (the same lifecycle, the same outcomes, in process and against a server).
The engine’s model catalog lets you see the models it serves and has trained — list_models, describe_model — and clean them up — delete_model. A model enters the catalog by being used: loading one records it, and training records both its base and the model it produced. And a model is a row other rows point at: the job that trained it names it, so deleting it while that job is on record would leave a dangling reference. The engine refuses that delete, typed, until the reference is gone.
This chapter runs the whole lifecycle as one function, against an in-process engine and against a live server, and checks that every outcome — including every refusal’s class — is the same on both.
15.1 The lifecycle, written once
Train registers two rows: the base model, recorded when the job loads it, and the fine-tuned model, written when the job finishes. The finished job is on record for [jobs] retention_days (30 by default), and until it is pruned it references both. So the lifecycle has four outcomes to observe: the listing, the refused delete, the absent delete, and — once the job is gone — the delete that succeeds.
def outcome(delete) -> str:
"""What a delete did: the refusal's class, or that it succeeded."""
try:
delete()
return "deleted"
except (ModelReferenced, ModelNotFound) as refused:
return type(refused).__name__
def train_and_refuse(db) -> tuple[str, dict]:
db.add_source("pairs", url=PAIRS, format="csv")
job = db.fine_tune(
source="pairs", base_model=BASE, columns=["text_a", "text_b", "score"],
method="lora", task="text_embedding", lora_rank=4, epochs=1,
)
job.wait()
tuned = job.output_model_id
return tuned, {
"listed": sorted((m["task"], m["status"]) for m in db.list_models()),
"described": {k: db.describe_model(tuned)[k] for k in ("task", "status")},
"delete_referenced": outcome(lambda: db.delete_model(tuned)),
"delete_absent": outcome(lambda: db.delete_model("jammi:fine-tuned:absent")),
"delete_absent_if_exists": outcome(
lambda: db.delete_model("jammi:fine-tuned:absent", if_exists=True)
),
}
def prune_and_delete(db, tuned: str) -> dict:
db.prune_jobs()
return {
"jobs_left": len(db.list_jobs()),
"delete_unreferenced": outcome(lambda: db.delete_model(tuned)),
"described_after": db.describe_model(tuned),
}15.2 In process, then against a server
Retention is a deployment setting: each engine is reopened over the same catalog with retention_days = 0 — a configuration file for the in-process engine, the matching environment variable for the server — so the finished job is past it and prune_jobs removes it.
home = Path(tempfile.mkdtemp())
config = home / "retention.toml"
config.write_text("[jobs]\nretention_days = 0\n")
with jammi.connect(f"file://{home / 'embedded'}") as db:
tuned, local = train_and_refuse(db)
with jammi.connect(f"file://{home / 'embedded'}", config=str(config)) as db:
local.update(prune_and_delete(db, tuned))
served_dir = home / "served"
with LiveServer(served_dir) as server, jammi.connect(server.endpoint) as db:
tuned, served = train_and_refuse(db)
with LiveServer(served_dir, env={"JAMMI_JOBS__RETENTION_DAYS": "0"}) as server, \
jammi.connect(server.endpoint) as db:
served.update(prune_and_delete(db, tuned))
for key in local:
print(f"{key:<26} {local[key]!s:<48} same on the server: {local[key] == served[key]}")2026-10-03T07:42:35.733512Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
listed [('text_embedding', 'registered'), ('text_embedding', 'registered')] same on the server: True
described {'task': 'text_embedding', 'status': 'registered'} same on the server: True
delete_referenced ModelReferenced same on the server: True
delete_absent ModelNotFound same on the server: True
delete_absent_if_exists deleted same on the server: True
jobs_left 0 same on the server: True
delete_unreferenced deleted same on the server: True
described_after None same on the server: True
claim("the catalog verbs answer identically in process and over the wire", local == served)
claim("deleting a model a job still references is refused",
local["delete_referenced"] == "ModelReferenced")
claim("deleting an absent model is a typed not-found, and if_exists makes it a no-op",
local["delete_absent"] == "ModelNotFound" and local["delete_absent_if_exists"] == "deleted")
claim("once its jobs are pruned the model deletes, and the catalog no longer describes it",
local["jobs_left"] == 0 and local["delete_unreferenced"] == "deleted"
and local["described_after"] is None)✓ the catalog verbs answer identically in process and over the wire
✓ deleting a model a job still references is refused
✓ deleting an absent model is a typed not-found, and if_exists makes it a no-op
✓ once its jobs are pruned the model deletes, and the catalog no longer describes it
15.3 Reading the outcomes
- Two rows, both
registered. Loading the base model recorded it; the finished job wrote the fine-tuned model.describe_modelreads one back by id, andNoneonce it is gone. - A referenced delete is refused with
ModelReferenced. The job that trained the model names it, so the delete would leave that reference dangling. The refusal is a class, not a message to parse — the same class in process and from a server. - An absent delete is
ModelNotFound, a condition distinct from a referenced one, andif_exists=Truemakes it a no-op for cleanup code that does not care. - Pruning ends the reference. With the job past its retention and pruned, nothing points at the model, and the same delete succeeds.
15.4 Bridge note
A catalog is a set of rows that point at each other. Deleting a model while a job still names it would break the pointer, so the engine refuses it with a typed error (Kleppmann 2017); retention bounds how long a finished job holds its references, and pruning releases them. The outcomes are typed classes, identical on both transports — the property that lets one program manage a catalog in process or on a server without branching on either.