registry
registry
¶
Persistent job registry for the Marianne daemon.
SQLite-backed registry that tracks all jobs submitted to the daemon.
Survives daemon restarts so mzt list always shows job history.
Separate from the learning store (which tracks patterns across jobs). This DB tracks operational state: which jobs exist, their workspaces, PIDs, and statuses.
All database methods are async (via aiosqlite) so they never block
the daemon's asyncio event loop — even under heavy concurrent load.
Attributes¶
TERMINAL_DAEMON_JOB_STATUSES
module-attribute
¶
TERMINAL_DAEMON_JOB_STATUSES = frozenset({DaemonJobStatus.COMPLETED, DaemonJobStatus.FAILED, DaemonJobStatus.CANCELLED})
The daemon job-level terminal set — the single definition (GH #225).
Classes¶
DaemonJobStatus
¶
Bases: str, Enum
Status values for daemon-managed jobs.
Inherits from str so meta.status serializes directly as
a plain string in JSON/dict output — no .value calls needed.
FailureHooksInProgressError
¶
Bases: RuntimeError
Raised when a stable job ID still owns an unsettled hook claim.
JobRecord
dataclass
¶
JobRecord(job_id, config_path, workspace, status=QUEUED, pid=None, submitted_at=time(), running_seconds=0.0, started_at=None, completed_at=None, error_message=None, current_sheet=None, total_sheets=None, last_event_at=None, log_path=None, snapshot_path=None, checkpoint_json=None, max_wall_seconds=None, wall_deadline_at=None, terminal_reason=None, deadline_diagnostic=None, failure_hooks_started_at=None, failure_hooks_completed_at=None, chain_depth=None)
A single job's registry entry.
Methods:¶
to_dict
¶
Serialize for JSON-RPC responses.
Source code in src/marianne/daemon/registry.py
JobRegistry
¶
Async SQLite-backed persistent job registry.
Uses aiosqlite so all I/O happens off the event loop thread.
The daemon is single-threaded (asyncio) so contention is minimal,
but the DB is safe for external readers (e.g. a monitoring tool
reading the same file).
Usage::
registry = JobRegistry(db_path)
await registry.open() # creates tables, sets WAL mode
...
await registry.close()
Or as an async context manager::
async with JobRegistry(db_path) as registry:
await registry.register_job(...)
Source code in src/marianne/daemon/registry.py
Methods:¶
open
async
¶
Open the database connection and create tables.
Source code in src/marianne/daemon/registry.py
register_job
async
¶
register_job(job_id, config_path, workspace, log_path=None, *, submitted_at=None, max_wall_seconds=None, wall_deadline_at=None, concert_config_json=None, chain_depth=None)
Commit and return one newly submitted execution authority.
Source code in src/marianne/daemon/registry.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
update_status
async
¶
update_status(job_id, status, *, pid=None, error_message=None, snapshot_path=None, terminal_reason=None, running_seconds=None)
Update a job's status and optional fields in the registry only.
Breadcrumb (#263): this writes ONLY the registry row. It does NOT touch
the daemon's in-memory _job_meta / _live_states, so calling it
directly for a live job diverges mzt list from mzt status.
Status changes for live jobs MUST go through
JobManager._set_job_status (the three-store update). Direct use is
reserved for paths with no in-memory state (startup orphan recovery,
task-creation-failure cleanup) or registry/live reconciliation
(shutdown flush) — see test_set_job_status_guard_263 for the
enforced allow-list.
Source code in src/marianne/daemon/registry.py
update_config_metadata
async
¶
Update config-derived metadata for a job.
Called during config reconciliation to keep registry in sync with the reloaded config.
Source code in src/marianne/daemon/registry.py
update_progress
async
¶
Update per-sheet progress counters for a running job.
Source code in src/marianne/daemon/registry.py
save_checkpoint
async
¶
Persist a serialized CheckpointState for a job.
Called on every state publish so the registry always has the latest checkpoint. This is the daemon's single source of truth for historical job status — no disk fallback needed.
Source code in src/marianne/daemon/registry.py
load_checkpoint
async
¶
Load the stored checkpoint JSON for a job.
Returns the raw JSON string, or None if no checkpoint was saved.
Source code in src/marianne/daemon/registry.py
store_hook_config
async
¶
Store hook configuration for a job at submission time.
Source code in src/marianne/daemon/registry.py
get_hook_config
async
¶
Load stored hook config JSON for a job.
Source code in src/marianne/daemon/registry.py
store_hook_results
async
¶
Store hook execution results for a job.
Source code in src/marianne/daemon/registry.py
get_hook_results
async
¶
Load stored hook execution results JSON for a job.
Source code in src/marianne/daemon/registry.py
store_failure_hook_config
async
¶
Store terminal-failure hook configuration for restart recovery.
Source code in src/marianne/daemon/registry.py
get_failure_hook_config
async
¶
Load terminal-failure hook configuration for a job.
Source code in src/marianne/daemon/registry.py
store_concert_config
async
¶
Store concert context used by durable run_job hooks.
Source code in src/marianne/daemon/registry.py
store_concert_context
async
¶
Persist the concert policy and current depth in one update.
Source code in src/marianne/daemon/registry.py
get_concert_config
async
¶
Load concert context used by durable run_job hooks.
Source code in src/marianne/daemon/registry.py
store_failure_hook_results
async
¶
Store terminal-failure hook results without replacing job failure data.
Source code in src/marianne/daemon/registry.py
get_failure_hook_results
async
¶
Load terminal-failure hook results for diagnostics.
Source code in src/marianne/daemon/registry.py
claim_failure_hooks
async
¶
Atomically claim a failed job's hook execution exactly once.
Source code in src/marianne/daemon/registry.py
complete_failure_hooks
async
¶
Persist completion of a previously claimed failure-hook sequence.
Source code in src/marianne/daemon/registry.py
settle_failure_hooks
async
¶
Atomically record hook results and settle their durable claim.
Source code in src/marianne/daemon/registry.py
get_job
async
¶
Get a single job by ID.
Source code in src/marianne/daemon/registry.py
list_jobs
async
¶
List jobs, most recent first.
Source code in src/marianne/daemon/registry.py
has_active_job
async
¶
Check if a job ID exists and is in an active state.
Source code in src/marianne/daemon/registry.py
get_orphaned_jobs
async
¶
Find jobs that were running when the daemon last stopped.
These are jobs with status 'queued' or 'running' — after a daemon restart they're orphans since their asyncio tasks no longer exist.
Source code in src/marianne/daemon/registry.py
mark_orphans_failed
async
¶
Mark all orphaned jobs as failed on daemon startup.
Returns the number of jobs marked.
Source code in src/marianne/daemon/registry.py
delete_jobs
async
¶
Delete terminal jobs from the registry.
Never deletes active jobs (queued/running) regardless of filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_ids
|
list[str] | None
|
Only delete these specific job IDs. |
None
|
statuses
|
list[str] | None
|
Only delete jobs with these statuses. Defaults to all terminal statuses. |
None
|
older_than_seconds
|
float | None
|
Only delete jobs older than this many seconds. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of deleted rows. |