mechaharness.checkpoint_store
Authoritative graph checkpoint and effect persistence seam
(CheckpointStore).
Checkpoint store protocol: authoritative graph + effect persistence (DR-01..05).
EventLogCheckpointStore is the ephemeral/default adapter
(observability-friendly, not process-restart durable).
SqliteCheckpointStore
is the durable SQLite reference backend.
Hosts bind a store through MechaHarnessConfig.get_checkpoint_store().
Inspect durability so ephemeral EventLog adapters are never mistaken for
process-restart safety:
>>> from pyiv.time import PythonDateTimeService
>>> from mechaharness.checkpoint_store import EventLogCheckpointStore
>>> from mechaharness.core.events import InMemoryEventLog
>>> from mechaharness.graph import ExecutionGraph, GraphNode, GraphStore
>>> log = InMemoryEventLog()
>>> store = EventLogCheckpointStore(
... GraphStore(log), datetime_service=PythonDateTimeService()
... )
>>> store.durability
'ephemeral'
>>> g = ExecutionGraph(goal="plan")
>>> _ = g.add_node(GraphNode(id="a", kind="compute"))
>>> rev = store.save(g, run_id="r1", boundary="dispatch", fingerprint="fp")
>>> rev
1
>>> store.latest_fingerprint(run_id="r1")
'fp'
>>> store.latest_boundary(run_id="r1")
'dispatch'
>>> store.latest(run_id="r1").nodes["a"].kind
'compute'
- class mechaharness.checkpoint_store.CheckpointStore[source]
Bases:
ABCAuthoritative persistence seam for graph checkpoints and effects.
durabilityis inspectable so hosts are not led to believe EventLog-backed stores survive process restart (compatibility note in requirements).- durability: Literal['ephemeral', 'durable'] = 'ephemeral'
- abstractmethod get_effect(effect_id: str) EffectRecord | None[source]
- get_node_effect(*, run_id: str, node_id: str, node_attempt: int | None = None) EffectRecord | None[source]
Return the latest effect for a node (optionally filtered by attempt).
- latest_authorization_epoch(*, run_id: str | None = None) int[source]
Authorization epoch of the latest checkpoint (0 when absent).
Epoch rides on the persisted graph, so every store carries it and pre-epoch checkpoints read as 0 without a schema migration.
- abstractmethod latest_boundary(*, run_id: str | None = None) Literal['planning', 'dispatch', 'post_effect_pre_record', 'reduce', 'commit'] | None[source]
- abstractmethod list_effects(*, run_id: str, node_id: str | None = None) list[EffectRecord][source]
- abstractmethod 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.
- abstractmethod save_effect(effect: EffectRecord) EffectRecord[source]
Upsert an effect record; bumps revision; returns stored copy.
- class mechaharness.checkpoint_store.EventLogCheckpointStore(store: GraphStore, *, datetime_service: DateTimeService, event_log: TypeAliasForwardRef('mechaharness.core.events.EventLog') | None = None, agent_id: str | None = None)[source]
Bases:
CheckpointStoreEphemeral adapter around
GraphStore.Effects are kept in-process (and mirrored as observational events). This store does not provide process-restart durability.
Persist an effect intent before a non-idempotent external call:
>>> from pyiv.time import PythonDateTimeService >>> from mechaharness.checkpoint_store import EventLogCheckpointStore >>> from mechaharness.core.events import InMemoryEventLog >>> from mechaharness.external_effect import EffectRecord, EffectState >>> from mechaharness.graph import GraphStore >>> store = EventLogCheckpointStore( ... GraphStore(InMemoryEventLog()), ... datetime_service=PythonDateTimeService(), ... ) >>> effect = store.save_effect(EffectRecord( ... effect_id="r1:job:1", ... run_id="r1", ... node_id="job", ... node_attempt=1, ... backend_id="host.coding_job", ... state=EffectState.INTENDED, ... )) >>> effect.state.value 'intended' >>> store.get_effect("r1:job:1").revision 1
- __init__(store: GraphStore, *, datetime_service: DateTimeService, event_log: TypeAliasForwardRef('mechaharness.core.events.EventLog') | None = None, agent_id: str | None = None) None[source]
- durability: Literal['ephemeral', 'durable'] = 'ephemeral'
- 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.
- class mechaharness.checkpoint_store.GraphEffectEvent[source]
Bases:
CoreEventObservational effect-transition event (not authoritative for recovery).
- name: ClassVar[str] = 'graph_effect'
- mechaharness.checkpoint_store.effect_from_mapping(payload: dict[str, Any]) EffectRecord[source]
Validate a stored effect mapping into
EffectRecord.