mechaharness.sqlite_checkpoint_store
Durable SQLite reference
CheckpointStore backend.
SQLite reference CheckpointStore (DR-02).
Single-host durable persistence: one database may hold many runs keyed by
run_id. Schema is initialized/migrated deterministically on open. Writes
are transactional; readers use shared locks with serialized writers.
Survive process restart by reopening the same path:
>>> import tempfile
>>> from pathlib import Path
>>> from pyiv.time import PythonDateTimeService
>>> from mechaharness.external_effect import EffectRecord, EffectState
>>> from mechaharness.graph import ExecutionGraph, GraphNode, NodeStatus
>>> from mechaharness.sqlite_checkpoint_store import SqliteCheckpointStore
>>> path = Path(tempfile.mkdtemp()) / "runs.sqlite"
>>> clock = PythonDateTimeService()
>>> store = SqliteCheckpointStore(path, datetime_service=clock)
>>> store.durability
'durable'
>>> g = ExecutionGraph(goal="dispatch coding job")
>>> _ = g.add_node(GraphNode(id="job", kind="coding_job", status=NodeStatus.RUNNING))
>>> _ = store.save(g, run_id="run-1", boundary="dispatch", fingerprint="fp")
>>> _ = store.save_effect(EffectRecord(
... effect_id="run-1:job:1",
... run_id="run-1",
... node_id="job",
... node_attempt=1,
... backend_id="host.cursor",
... state=EffectState.ACCEPTED,
... external_handle="cursor-run-42",
... ))
>>> store.close()
>>> # Fresh process against the same file:
>>> again = SqliteCheckpointStore(path, datetime_service=clock)
>>> again.latest(run_id="run-1").nodes["job"].status.value
'running'
>>> again.get_effect("run-1:job:1").external_handle
'cursor-run-42'
>>> again.latest_boundary(run_id="run-1")
'dispatch'
>>> again.close()
- class mechaharness.sqlite_checkpoint_store.SqliteCheckpointStore(path: str | Path, *, datetime_service: DateTimeService)[source]
Bases:
CheckpointStoreProcess-restart-durable checkpoint + effect store.
- durability: Literal['ephemeral', 'durable'] = 'durable'
- get_effect(effect_id: str) EffectRecord | None[source]
- latest_boundary(*, run_id: str | None = None) Literal['planning', 'dispatch', 'post_effect_pre_record', 'reduce', 'commit'] | None[source]
- list_effects(*, run_id: str, node_id: str | None = None) list[EffectRecord][source]
- save(graph: ExecutionGraph, *, run_id: str | None = None, boundary: Literal['planning', 'dispatch', 'post_effect_pre_record', 'reduce', 'commit'] | None = None, fingerprint: str | None = None) int[source]
Persist a checkpoint; return the new monotonic revision.
- save_effect(effect: EffectRecord) EffectRecord[source]
Upsert an effect record; bumps revision; returns stored copy.