httk.workflow.protocol¶
The language-neutral filesystem protocol surface of httk₂ workflows.
This module is the one deliberate public home of the on-disk protocol: the shapes, validators, and primitives an implementation in any language reads and writes to interoperate through a workspace. The normative specification is the filesystem protocol reference in the httk-workflow documentation; everything named here is what that document describes, and an independent inspection or verification tool should be able to work from this namespace and that document alone.
Nothing here is manager bookkeeping, a subprocess wrapper, a CLI handler, or a
scheduling pass — those live in their own modules and are not part of the
protocol. The implementations are owned by the modules re-exported below
(models, journal,
transactions, and the runtime builders), which are
internal detail from the protocol’s point of view; import the names from here.
Attributes¶
Exceptions¶
A workspace, job, journal frame, outcome, or request is malformed. |
|
A shared runner cannot be resolved, staged, or verified. |
|
A transactional-data manifest cannot be safely replayed. |
|
Another actor committed a transition from the expected marker. |
|
A workspace requires an extension this implementation does not support. |
|
Base class for workflow protocol failures. |
|
The authoritative filesystem state is internally inconsistent. |
|
The workspace cannot currently provide a coherent protocol view. |
Classes¶
One intact frame found by walking a segment from its header. |
|
The outcome of reading one referenced frame without raising. |
|
One canonical structured failure record. |
|
How long a workspace keeps the history it is allowed to collect. |
|
The attempt budgets of one job and the failures it retries within them. |
|
The members of one state frame, typed for the manager that uses them. |
|
The tunables every implementation attaching to one workspace shares. |
|
The immutable identity and restart evidence for one running attempt. |
|
The stable identity used in a native join. |
|
Values needed to create an immutable native job definition. |
|
One unpublished outcome bundle below an attempt control directory. |
|
A sealed, idempotently replayable set of workdir changes. |
|
Append-only structured application evidence in a workdir. |
|
Build a validated replayable transaction manifest. |
|
One state entry shaped like a marker that cannot be interpreted. |
Functions¶
|
Encode one canonical |
|
Yield every intact frame of every segment of every writer. |
|
Yield every intact frame of one segment. |
|
Parse one canonical |
|
Read and verify a journal record, retrying visibility-short reads. |
|
Return the segment file one record reference names. |
|
Read one referenced frame, reporting damage rather than raising. |
|
|
|
Report whether one payload entry name is runner-private scratch. |
|
Return the normative immutable job digest of stored |
|
|
|
|
|
|
|
|
|
Split the reserved |
|
|
|
Validate one attempt-control directory name read from a state frame. |
|
Validate one declaration name of a job. |
|
Validate the optional |
|
Validate one published failure object. |
|
Validate the optional application-defined |
|
|
|
Validate |
|
Validate one lowercase hexadecimal SHA-256 digest string. |
|
|
|
Return the validated |
|
Create and validate |
|
Idempotently apply one published transaction. |
Module Contents¶
- exception httk.workflow.protocol.FormatError[source]¶
Bases:
WorkflowError,ValueErrorA workspace, job, journal frame, outcome, or request is malformed.
- exception httk.workflow.protocol.RunnerResolutionError(code: str, message: str)[source]¶
Bases:
WorkflowErrorA shared runner cannot be resolved, staged, or verified.
The failure carries the exact protocol failure
codethe manager records, so an unresolvable runner (runner_unavailable) and a runner whose staged bytes disagree with the digest the job pinned (runner_mismatch) stay distinguishable to an operator.- code¶
- exception httk.workflow.protocol.TransactionError[source]¶
Bases:
WorkflowErrorA transactional-data manifest cannot be safely replayed.
- exception httk.workflow.protocol.TransitionLostError[source]¶
Bases:
WorkflowErrorAnother actor committed a transition from the expected marker.
- exception httk.workflow.protocol.UnsupportedExtensionError[source]¶
Bases:
WorkflowErrorA workspace requires an extension this implementation does not support.
- exception httk.workflow.protocol.WorkflowError[source]¶
Bases:
ExceptionBase class for workflow protocol failures.
- exception httk.workflow.protocol.WorkspaceCorruptionError[source]¶
Bases:
WorkflowErrorThe authoritative filesystem state is internally inconsistent.
Bases:
WorkflowErrorThe workspace cannot currently provide a coherent protocol view.
- class httk.workflow.protocol.JournalFrame[source]¶
One intact frame found by walking a segment from its header.
- class httk.workflow.protocol.RecordVerification[source]¶
The outcome of reading one referenced frame without raising.
- httk.workflow.protocol.encode_record_ref(writer_id: str, segment: int, offset: int, length: int, checksum: bytes) str[source]¶
Encode one canonical
hwref-v1reference.
- httk.workflow.protocol.iter_journal_frames(control_dir: pathlib.Path) collections.abc.Iterator[JournalFrame][source]¶
Yield every intact frame of every segment of every writer.
- httk.workflow.protocol.iter_segment_frames(path: pathlib.Path, writer_id: str, segment: int) collections.abc.Iterator[JournalFrame][source]¶
Yield every intact frame of one segment.
The walk is deliberately forgiving. A damaged frame whose framing is still intact is skipped, because the frames behind it remain locatable and are exactly what a repair is looking for; a torn or partially visible tail is the normal state of a segment a live writer is appending to and simply ends the walk.
- httk.workflow.protocol.parse_record_ref(record_ref: str) tuple[str, int, int, int, str][source]¶
Parse one canonical
hwref-v1reference.
- httk.workflow.protocol.read_record(control_dir: pathlib.Path, record_ref: str, *, deadline_seconds: float | None = None) dict[str, Any][source]¶
Read and verify a journal record, retrying visibility-short reads.
A frame that is absent, short, or undecodable may be an extension of a segment that has not reached this client yet, so it is retried with bounded backoff until deadline_seconds — the workspace’s configured visibility deadline — expires. Damage that no amount of waiting can repair is reported at once.
- httk.workflow.protocol.segment_path(control_dir: pathlib.Path, writer_id: str, segment: int) pathlib.Path[source]¶
Return the segment file one record reference names.
- httk.workflow.protocol.verify_record(control_dir: pathlib.Path, record_ref: str, *, deadline_seconds: float | None = None) RecordVerification[source]¶
Read one referenced frame, reporting damage rather than raising.
This is the reading half of a workspace check: it distinguishes a segment that is gone from one that is truncated, corrupt, or simply not holding the frame the reference names, which is what a repair decision needs.
- httk.workflow.protocol.CARRIED_STATE_MEMBERS = ('step', 'activation_id', 'activation_ordinal', 'attempt_id', 'attempt_ordinal',...¶
- httk.workflow.protocol.CORE_PROFILE = 'core-v2'¶
- httk.workflow.protocol.CORE_STATE_KINDS¶
- httk.workflow.protocol.QUIESCENT_KINDS¶
- httk.workflow.protocol.READABLE_CORE_PROFILES¶
- httk.workflow.protocol.RUNNER_SOURCES¶
- httk.workflow.protocol.STATE_KINDS = ('submitted', 'ready', 'claimed', 'running', 'committing', 'cancelling', 'relocating',...¶
- httk.workflow.protocol.SUPPORTED_EXTENSIONS¶
- httk.workflow.protocol.TERMINAL_KINDS¶
- httk.workflow.protocol.WITHDRAWN_EXTENSIONS¶
- class httk.workflow.protocol.Failure[source]¶
One canonical structured failure record.
Every failure published by a runner, a bridge, or the manager itself uses exactly this shape: a stable machine
code, one humanmessage, optional structureddetails, and the advisoryretryableflag. Retry policy is keyed oncodealone;retryableis recorded evidence and never a manager decision.- details: collections.abc.Mapping[str, object] | None = None¶
- class httk.workflow.protocol.JobDefinition[source]¶
-
- runner_path: pathlib.PurePosixPath¶
- workdir_path: pathlib.PurePosixPath¶
- retry_policy: RetryPolicy¶
- resources: collections.abc.Mapping[str, object]¶
- inputs: collections.abc.Mapping[str, object]¶
- declarations: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- parent: collections.abc.Mapping[str, object] | None¶
- raw: collections.abc.Mapping[str, object]¶
- property digest: str¶
Return the immutable job digest.
Normatively the digest is
job_digest()over the storedjob.jsonfile bytes exactly as submitted, which is what every definition read throughfrom_bytes()carries. A definition composed in memory has no stored bytes yet, so its canonical serialization is hashed instead; the two agree as soon as that serialization is what gets written.
- classmethod from_bytes(data: bytes, *, name: str = 'job.json') JobDefinition[source]¶
Parse stored
job.jsonbytes, pinning the normative job digest.
- classmethod from_path(path: pathlib.Path) JobDefinition[source]¶
Read one stored
job.json, pinning the normative job digest.
- classmethod from_mapping(value: collections.abc.Mapping[str, object]) JobDefinition[source]¶
- class httk.workflow.protocol.Marker[source]¶
-
- placement: pathlib.PurePosixPath¶
- path: pathlib.Path¶
- classmethod from_path(state_root: pathlib.Path, path: pathlib.Path) Marker[source]¶
- class httk.workflow.protocol.RetentionPolicy[source]¶
How long a workspace keeps the history it is allowed to collect.
Every member is optional and means “no configured limit” when absent. The collector that acts on these numbers is a separate concern; the workspace only carries them so that every implementation attaching to it agrees on what may be removed and when.
- classmethod from_mapping(value: object, name: str = 'policy.retention') RetentionPolicy[source]¶
- class httk.workflow.protocol.RetryPolicy[source]¶
The attempt budgets of one job and the failures it retries within them.
Two independent rules make a failure retry-eligible, and both are bounded by exactly the same budgets:
retry_onlists failure codes. A manager-detected failure — a lost lease, a process failure, an unusable outcome — is retried when its code appears in this set.A runner-declared failure published with
retryable: trueis retried whether or not its code appears inretry_on, because the runner that produced the failure is the authority on whether repeating the attempt can help.
Neither rule can exceed
maximum_attempts_per_activationormaximum_total_attempts: an exhausted budget always ends the job.- classmethod from_mapping(value: object) RetryPolicy[source]¶
- class httk.workflow.protocol.StateFrame[source]¶
The members of one state frame, typed for the manager that uses them.
The frame is held exactly as it is on disk, so every member round-trips verbatim — including one written by a newer implementation, by an enabled extension, or by a workspace older than this code. What this implementation reads and writes goes through the typed accessors and through
of(), so a mistyped member name is a type error at the call site rather than a silently defaulted value at runtime.The envelope members
format,workspace_id,job_id,kind,state_generation, and their siblings belong to the transition that publishes a frame and are supplied by the workspace, never here.- members: collections.abc.Mapping[str, Any]¶
- classmethod from_mapping(value: object, name: str = 'state frame') StateFrame[source]¶
Read one stored state frame, keeping every member verbatim.
- classmethod of(base: StateFrame | None = None, *, step: str = _UNSET, activation_id: str = _UNSET, activation_ordinal: int = _UNSET, attempt_id: str = _UNSET, attempt_ordinal: int = _UNSET, total_attempts: int = _UNSET, data_generation: int | None = _UNSET, join_summary: collections.abc.Sequence[object] | None = _UNSET, runner_steps: collections.abc.Sequence[str] = _UNSET, manager_id: str = _UNSET, writer_id: str = _UNSET, claim_id: str = _UNSET, attempt_control: str = _UNSET, lease_seconds: float = _UNSET, matched_pool: str = _UNSET, matched_capabilities: collections.abc.Sequence[str] = _UNSET, started_at: str = _UNSET, workdir: str = _UNSET, outcome_action: str = _UNSET, child_digests: collections.abc.Mapping[str, str] = _UNSET, child_labels: collections.abc.Mapping[str, str] = _UNSET, next_step: str = _UNSET, join: collections.abc.Mapping[str, object] = _UNSET, pause: object = _UNSET, failure: collections.abc.Mapping[str, object] = _UNSET, job_digest: str = _UNSET, unclean_restart: bool = _UNSET, unsafe_persistent_takeover: bool = _UNSET, takeover_evidence: collections.abc.Mapping[str, object] = _UNSET, cancellation: collections.abc.Mapping[str, object] = _UNSET, previous_attempt_id: str | None = _UNSET, operator: object = _UNSET, operator_key: object = _UNSET, operator_reason: object = _UNSET, request_id: object = _UNSET, revival_hazard: collections.abc.Mapping[str, object] = _UNSET, reason: str = _UNSET) StateFrame[source]¶
Return base with the named members set, absent ones untouched.
Every member a manager writes is one declared keyword, so the complete vocabulary of a state frame is visible in one signature and no call site can invent a member by misspelling one. Passing
Nonewrites the JSON null the protocol distinguishes from an absent member.
- carried() StateFrame[source]¶
Return only the members every transition of this activation repeats.
- select(names: collections.abc.Sequence[str]) StateFrame[source]¶
Return only the named members this frame actually carries.
- property manager_id: str | None¶
Return the owning manager, refusing anything that is not one.
The value is joined below
managers/to reach a heartbeat, so a frame that does not name a canonical manager UUID is a protocol violation rather than a path to try.
- property join: collections.abc.Mapping[str, object] | None¶
- property failure: collections.abc.Mapping[str, object] | None¶
- property cancellation: collections.abc.Mapping[str, object] | None¶
- property child_digests: collections.abc.Mapping[str, object] | None¶
- class httk.workflow.protocol.WorkspacePolicy[source]¶
The tunables every implementation attaching to one workspace shares.
These are workspace properties rather than per-process options: two managers on different hosts must agree on how long a marker may take to become visible and on how long an unheartbeaten lease means anything. They live in
format.jsonbeside the format and profile declarations, and a workspace written before this section existed simply reads as the defaults.- retention: RetentionPolicy¶
- classmethod from_mapping(value: object, name: str = 'policy') WorkspacePolicy[source]¶
Validate one complete policy object, filling in absent members.
- as_mapping() dict[str, object][source]¶
Return the complete JSON representation stored in
format.json.
- updated(changes: collections.abc.Mapping[str, object], name: str = 'policy') WorkspacePolicy[source]¶
Return this policy with changes applied and revalidated.
- httk.workflow.protocol.is_payload_private(name: str) bool[source]¶
Report whether one payload entry name is runner-private scratch.
A runner-private entry is excluded from every payload digest, so publishing an outcome or writing job state can never change the digest of a payload that a manager, a transfer, or a registration check must still recognize.
- httk.workflow.protocol.job_digest(data: bytes) str[source]¶
Return the normative immutable job digest of stored
job.jsonbytes.The digest of a job is the SHA-256 over the
job.jsonfile bytes exactly as submitted. Nothing rewrites or renormalizes those bytes, so the digest is reproducible by any implementation with only a hash utility.
- httk.workflow.protocol.marker_basename(job_key: str, priority: int, generation: int, record_ref: str) str[source]¶
- httk.workflow.protocol.normalize_placement(value: str | pathlib.PurePosixPath) pathlib.PurePosixPath[source]¶
- httk.workflow.protocol.parse_package_runner(value: str) tuple[str, pathlib.PurePosixPath] | None[source]¶
Split the reserved
pkg:<module>/<resource>installed runner form.Return
Nonewhen value is an ordinary relative runner path, so callers can treat the reserved form as one alternative spelling ofrunner.pathrather than as a separate protocol member.
- httk.workflow.protocol.validate_attempt_control(value: object, name: str = 'attempt_control') str[source]¶
Validate one attempt-control directory name read from a state frame.
The name is joined below a job payload to reach the control directory of an attempt, so it is exactly one relative component of the canonical
.httk-attempt.<attempt-id>shape. Validating it before it is joined is what keeps a hostile or damaged frame from naming a path outside the job.
- httk.workflow.protocol.validate_declaration_name(value: object, name: str = 'declaration name') str[source]¶
Validate one declaration name of a job.
The name keys the
declarationsobject ofjob.jsonand is also the basename of the runtime-refined document below.httk-job/declarations/, so it must be a safe single path component and nothing else.
- httk.workflow.protocol.validate_declarations(value: object, name: str = 'declarations') dict[str, dict[str, object]][source]¶
Validate the optional
declarationsobject of a job.Each member is one workflow-declaration document carried verbatim: the protocol checks that a declaration is a JSON object and never looks inside it, because what the members mean is owned by the vocabulary the document names itself — the OPTIMADE workflow-declaration work is standardizing exactly that, and an engine that reinterpreted it would only be able to disagree with it. The bytes live in
job.jsonand are therefore covered by the immutable job digest like every other member.
- httk.workflow.protocol.validate_failure(value: object, name: str = 'failure') Failure[source]¶
Validate one published failure object.
- httk.workflow.protocol.validate_inputs(value: object, name: str = 'inputs') dict[str, object][source]¶
Validate the optional application-defined
inputsobject of a job.The member is opaque to the protocol: only its shape, its key syntax, and its serialized size are checked. Its bytes are part of
job.jsonand are therefore covered by the immutable job digest like every other member.
- httk.workflow.protocol.validate_runner_path(value: object, source: str) pathlib.PurePosixPath[source]¶
Validate
runner.pathagainst the root implied byrunner.source.Every source resolves the same relative path below a different root: the job payload, the workspace runner store, or one configured installed-runner search path. The path must therefore stay below its root under every source, and only an installed runner may use the reserved
pkg:form.
- httk.workflow.protocol.validate_sha256(value: object, name: str) str[source]¶
Validate one lowercase hexadecimal SHA-256 digest string.
- class httk.workflow.protocol.AttemptContext[source]¶
The immutable identity and restart evidence for one running attempt.
- settings: collections.abc.Mapping[str, object]¶
- resources: collections.abc.Mapping[str, object]¶
- raw: collections.abc.Mapping[str, Any]¶
- classmethod read(path: str | os.PathLike[str]) Self[source]¶
Read and validate a manager-written attempt context.
- class httk.workflow.protocol.JobSpec[source]¶
Values needed to create an immutable native job definition.
A
payloadrunner is a file inside the job payload. Aworkspaceorinstalledrunner lives outside the payload and must therefore pin its ownrunner_sha256, which is how one published runner serves a whole campaign of jobs without being copied per job.- runner_source: Literal['payload', 'workspace', 'installed'] = 'payload'¶
- workdir_mode: Literal['persistent', 'isolated'] = 'persistent'¶
- data_mode: Literal['none', 'transactional'] = 'none'¶
- resources: collections.abc.Mapping[str, object]¶
- inputs: collections.abc.Mapping[str, object]¶
- declarations: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- type httk.workflow.protocol.JoinCondition = Literal['all_succeeded', 'all_terminal', 'any_succeeded', 'at_least']¶
- type httk.workflow.protocol.OutcomeAction = Literal['advance', 'retry', 'wait', 'succeed', 'fail', 'pause']¶
- class httk.workflow.protocol.OutcomeDraft(context: httk.workflow.runtime.AttemptContext, control: pathlib.Path, root: pathlib.Path | None = None, *, durable: bool = False)[source]¶
One unpublished outcome bundle below an attempt control directory.
The draft is the single place that writes the protocol shapes of an outcome: its transaction, its spawn set, and the atomic rename that publishes it. It is bound to nothing but the attempt identity and the control directory, so the authoring SDK and the Bash bridge publish through exactly one implementation.
- context¶
- control¶
- durable = False¶
- root¶
- transaction() TransactionBuilder[source]¶
- add_child(payload: str | os.PathLike[str], placement: str | pathlib.PurePosixPath, *, label: str | None = None) ChildReference[source]¶
Register one prepared payload directory as a child of this outcome.
- add_child_job(job: collections.abc.Mapping[str, object], placement: str | pathlib.PurePosixPath, *, label: str) ChildReference[source]¶
Register one synthesized child that needs no prepared payload.
A child whose runner lives outside the payload — a workspace or installed runner — is completely described by its
job.json, so a partitioned campaign can spawn children without copying a payload tree per child.
- property children: tuple[ChildReference, Ellipsis]¶
- publish(action: OutcomeAction, *, next_step: str | None = None, priority: int | None = None, failure: collections.abc.Mapping[str, object] | None = None, retry: collections.abc.Mapping[str, object] | None = None, join: collections.abc.Mapping[str, object] | None = None, pause: collections.abc.Mapping[str, object] | None = None, message: str | None = None, expected_data_generation: int | None = None, runner_steps: collections.abc.Sequence[str] | None = None) pathlib.Path[source]¶
- class httk.workflow.protocol.ReplayableWorkdirBatch(workdir: pathlib.Path, root: pathlib.Path, *, durable: bool = False)[source]¶
A sealed, idempotently replayable set of workdir changes.
- workdir¶
- root¶
- durable = False¶
- transaction¶
- classmethod create(workdir: str | os.PathLike[str], *, durable: bool = False) ReplayableWorkdirBatch[source]¶
- seal() pathlib.Path[source]¶
- commit() pathlib.Path[source]¶
- static recover(workdir: str | os.PathLike[str], *, durable: bool = False) tuple[pathlib.Path, Ellipsis][source]¶
- class httk.workflow.protocol.RunLog(workdir: str | os.PathLike[str])[source]¶
Append-only structured application evidence in a workdir.
- path¶
- append(kind: str, message: str, *, files: collections.abc.Sequence[str | os.PathLike[str]] = ()) None[source]¶
- class httk.workflow.protocol.TransactionBuilder(root: pathlib.Path, *, expected_generation: int, durable: bool = False)[source]¶
Build a validated replayable transaction manifest.
- root¶
- expected_generation¶
- durable = False¶
- classmethod resume(root: str | os.PathLike[str], *, expected_generation: int, durable: bool = False) Self[source]¶
Reattach to a transaction an earlier process of this attempt sealed.
A Bash runner publishes one outcome through many short-lived processes, so the staged manifest on disk — not any in-memory counter — is what carries the operations of a draft from one call to the next. Resuming reads it back, so appending an operation continues the same sequence and the same overlap checks as the process that staged the first one.
- put_file(operation_id: str, source: str | os.PathLike[str], path: str | os.PathLike[str]) None[source]¶
- put_tree(operation_id: str, source: str | os.PathLike[str], path: str | os.PathLike[str], *, replace: bool = False) None[source]¶
- seal() pathlib.Path[source]¶
- httk.workflow.protocol.join_mapping(children: collections.abc.Sequence[ChildReference], condition: JoinCondition = 'all_succeeded', count: int | None = None, on_impossible_step: str | None = None) dict[str, object][source]¶
Return the validated
joinmember of one waiting outcome.
- httk.workflow.protocol.prepare_job_payload(destination: str | os.PathLike[str], spec: JobSpec, *, parent: collections.abc.Mapping[str, object] | None = None, durable: bool = False) httk.workflow.models.JobDefinition[source]¶
Create and validate
job.jsonin an existing prepared payload.durable synchronizes the written
job.jsonfor a caller preparing a payload directly on durable storage; it defaults toFalsebecause a payload prepared here is not yet a workspace artifact, and its submission is what makes it authoritative and durable.
- httk.workflow.protocol.replay_transaction(transaction_dir: pathlib.Path, data_dir: pathlib.Path, *, expected_generation: int, durable: bool = False) bool[source]¶
Idempotently apply one published transaction.
Returns whether the manifest contains operations and therefore advances the data generation.
When durable is set, every destination this replay installs and every directory whose entries it changes — including the parents that gained or lost a name, and the trash a removal moved into — is synchronized before this call returns. The manager relies on that ordering: it appends the destination state frame and renames the marker out of
committingonly after replay returns, so a committed transaction is on storage before the marker that claims it is.