import tempfile
from pathlib import Path
import jammi
from jammi.errors import JobCancelled
from jammi_cookbook import fixtures
BASE_MODEL = fixtures.model("tiny_bert")
home = Path(tempfile.mkdtemp())
engine = f"file://{home}/engine"
no_worker = home / "submit-only.toml"
no_worker.write_text("[worker]\nenabled = false\n")
with_worker = home / "worker.toml"
with_worker.write_text("[jobs]\nretention_days = 0\n")
def submit(db):
return db.fine_tune(
source="training",
base_model=BASE_MODEL,
columns=["text_a", "text_b", "score"],
method="lora",
task="text_embedding",
lora_rank=4,
epochs=1,
)49 Jobs
Submit long-running work, watch it, cancel it, and pick it up from another process.
When to use this pattern. Training and compute verbs run as rows of the engine’s durable job queue. You need to see a job’s state, stop one, run submission and execution in different processes, or clean up finished jobs.
The program is cookbook/recipes/jobs/example.py; its steps run here in order.
Every long-running verb (a fine-tune, a context-predictor training, a compute verb run as a job) is a row in the engine’s durable job queue. A job outlives the connection that submitted it, and any process with a worker enabled claims it. Two configurations show both sides: one process submits with no worker, another runs the worker.
49.1 Submit work no one claims
With [worker] enabled = false, this process only submits: its jobs stay queued. A handle reads a job’s kind, status() and progress().
db = jammi.connect(engine, config=str(no_worker))
db.add_source("training", url=str(fixtures.path("tiny_pairs.csv")), format="csv")
by_handle, by_id, kept = submit(db), submit(db), submit(db)
print(f"{by_handle.job_id}: kind={by_handle.kind} status={by_handle.status()}")
print(f"progress: {by_handle.progress()}")
assert by_handle.status() == "queued"3c661298-031b-4590-b95c-91197947eeb8: kind=fine_tune status=queued
progress: {'rows_done': None, 'rows_total': None, 'phase': ''}
49.2 Cancel
A job cancels through its handle or by id. Cancelling a finished job does nothing, and wait() on a cancelled job raises JobCancelled.
assert by_handle.cancel()
assert db.cancel_job(by_id.job_id)
assert not db.cancel_job(by_id.job_id), "a terminal job cancels no further"
try:
by_handle.wait()
raise AssertionError("a cancelled job must not complete")
except JobCancelled:
print(f"{by_handle.job_id}: cancelled")3c661298-031b-4590-b95c-91197947eeb8: cancelled
49.3 The queue and who claims from it
list_jobs is the queue; list_workers lists the processes running the claim loop, and here there are none.
for row in db.list_jobs():
print(f" {row['job_id']} {row['kind']:<10} {row['status']}")
assert db.list_workers() == [], "no process runs the claim loop"
db.close() 012dd51e-f859-4914-8ac1-b9ca17d56e0d fine_tune queued
3ea11436-6546-4e26-b998-9c989da4e969 fine_tune cancelled
3c661298-031b-4590-b95c-91197947eeb8 fine_tune cancelled
49.4 Pick the job up from another process
Opened with a worker, the engine claims the job left queued. job(id) attaches to it by id, and wait() returns once the worker has run it; the finished job reports its metrics, the acceleration it ran with, and the model it produced.
db = jammi.connect(engine, config=str(with_worker))
for worker in db.list_workers():
print(f"worker {worker['label'] or worker['instance_id']}: {worker['state']}")
job = db.job(kept.job_id)
job.wait()
print(f"{job.job_id}: {job.status()} → {job.output_model_id}")
print(f"metrics: {job.metrics()}")
print(f"acceleration: {job.acceleration_report()}")
assert job.status() == "completed"worker 9002f90f-726d-4576-93d3-949ff8bb192c: claiming
012dd51e-f859-4914-8ac1-b9ca17d56e0d: completed → jammi:fine-tuned:012dd51e-f859-4914-8ac1-b9ca17d56e0d
metrics: {'final_loss': 2.108142852783203, 'early_stopping_metric': 'val_loss', 'total_steps': 4, 'started_at': '2026-10-03T07:43:30.825505724+00:00', 'completed_at': '2026-10-03T07:43:30.835350717+00:00', 'train_loss_curve': [{'epoch': 0, 'loss': 3.668308436870575}], 'epoch_walls': [{'epoch': 0, 'run_s': 0.00961097, 'steps_s': 0.006520373, 'step_walls': [0.004997369, 0.000639914, 0.000563239, 0.000311199], 'validation_s': 0.0011416, 'checkpoint_s': 0.001945461}], 'media_front_end_wall_s': None, 'kernel_dispatches': {'adamw_step_fused': {'fused': 8, 'eager': 0, 'declined': 0}, 'attention_block_flash': {'fused': 0, 'eager': 0, 'declined': 5}, 'attention_block_fused': {'fused': 0, 'eager': 5, 'declined': 0}, 'gelu_erf_fused': {'fused': 5, 'eager': 0, 'declined': 0}, 'layer_norm_fused': {'fused': 15, 'eager': 0, 'declined': 0}, 'lora_linear_fused': {'fused': 5, 'eager': 0, 'declined': 0}, 'mem_efficient_attention': {'fused': 0, 'eager': 0, 'declined': 5}, 'softmax_last_dim_fused': {'fused': 5, 'eager': 0, 'declined': 0}}, 'kernels_disabled': {'requested': [], 'fired': []}, 'val_loss_curve': [{'epoch': 0, 'loss': 2.108142852783203}], 'timeline': {'claimed_at': '2026-10-03T07:43:30.818461721Z', 'source_bound_at': '2026-10-03T07:43:30.822804935Z', 'published_at': '2026-10-03T07:43:30.836756905Z'}}
acceleration: {'state': 'determined', 'attempt': 1, 'device': 'cpu', 'dtype': 'f32', 'cuda_compiled': False, 'flash_compiled': False, 'ops': {}, 'flash': {'holds': False, 'reason': 'cuda_not_compiled'}}
2026-10-03T07:43:30.830010Z 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"
49.5 Clean up finished jobs
prune_jobs deletes finished jobs older than [jobs] retention_days, zero here. The two cancelled jobs were already swept when this process opened the catalog; prune_jobs sweeps the one that finished since.
pruned = db.prune_jobs()
print(f"pruned {pruned} finished job(s); {len(db.list_jobs())} left")
assert pruned == 1 and db.list_jobs() == []pruned 1 finished job(s); 0 left
db.close()