Public API¶
The supported import surface is re-exported from threvo_actions. Optional
adapter types live in their own modules so importing the core never imports a
database or agent framework.
Versioned support
Version 0.1.3 freezes the documented Python imports and CLI for the
0.1.x line. Serialized interoperability forms remain experimental. See
Versioning.
threvo_actions ¶
Experimental confirm-first financial action contracts.
Participant
module-attribute
¶
Participant = Annotated[RequestingPrincipal | ProposingAgent | ConfirmingAuthority | GovernedExecutor | AuthoritativeTarget | EvidenceConsumer, Field(discriminator='kind')]
Receipt
module-attribute
¶
Receipt = Annotated[ProposalReceipt | AuthorityReceipt | ExecutionReceipt | VerificationReceipt, Field(discriminator='receipt_type')]
__all__
module-attribute
¶
__all__ = ['Action', 'ActionConfigurationError', 'ActionDefinition', 'ActionNotRegisteredError', 'ActionOperationResult', 'ActionRegistry', 'ActionRuntime', 'ActionStore', 'ActionType', 'AnyApproval', 'ApprovalReasonCode', 'AuthoritativeTarget', 'AuthorityBinding', 'AuthorityDecision', 'AuthorityEvaluation', 'AuthorityEvaluatorPort', 'AuthorityEvidence', 'AuthorityReceipt', 'AuthorityReceiptStatus', 'AuthorityValidationFailure', 'AuthorityValidationResult', 'AuthorizationDeniedError', 'AuthorizationPort', 'AuthorizationResult', 'CanonicalizationError', 'Clock', 'CommitmentProvider', 'ConfirmingAuthority', 'DecisionContext', 'DefinitionConformanceError', 'DefinitionTypeMismatchError', 'DuplicateActionError', 'EffectClaimResult', 'EffectKind', 'EventSink', 'EvidenceConsumer', 'ExecutionContext', 'ExecutionReceipt', 'ExecutionReceiptStatus', 'ExecutionResult', 'ExecutionStatus', 'ExternalReference', 'GovernedExecutor', 'GovernedExecutorPort', 'IdentifierProvider', 'InvalidActionResultError', 'InvalidAuthorityEvidenceError', 'ItemOutcome', 'ItemOutcomeStatus', 'KeyedCommitment', 'LifecycleStatus', 'MOfNApprovals', 'MemoryActionStore', 'Money', 'NoopEventSink', 'OperationOutcome', 'Participant', 'PreparationContext', 'PreparationPort', 'PreparedAction', 'ProposalAlreadyExistsError', 'ProposalNotFoundError', 'ProposalReceipt', 'ProposalReceiptStatus', 'ProposalView', 'ProposingAgent', 'ProtectedPayload', 'ProtectionCodec', 'ReadContext', 'Receipt', 'RequestingPrincipal', 'ResolvedState', 'RetentionPort', 'RetentionStore', 'RetentionStoreUnavailableError', 'RuntimeAttributionError', 'RuntimeEvent', 'RuntimeEventType', 'RuntimeReasonCode', 'SingleApproval', 'StateResolverPort', 'StoreInvariantError', 'StoredProposal', 'SystemClock', 'UuidIdentifiers', 'VerificationReceipt', 'VerificationReceiptStatus', 'VerificationResult', 'VerificationStatus', 'VerifierPort', 'assert_definition_conforms', 'authority_evidence_matches_binding', 'canonicalize_v1', 'commitment_payload_v1', 'resolve_runtime_revision', 'validate_authority_evidence', 'validate_proposal_create', 'validate_proposal_update']
Action ¶
Action(*, authority_evaluator: AuthorityEvaluatorPort, commitment_provider: CommitmentProvider, protection_codec: ProtectionCodec)
Bases: ABC, Generic[CommandT, PrivateSnapshotT, PreviewT, ResultT]
Author an action as one typed object without creating a second runtime path.
Deployment services remain constructor-injected. Immutable action metadata
stays visible on the subclass. to_definition is the only bridge to the
runtime.
verification_lease_duration
class-attribute
¶
semantic_idempotency_strategy
class-attribute
¶
to_definition ¶
to_definition() -> ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]
Compile this authoring facade to the runtime's public plumbing.
prepare
abstractmethod
async
¶
prepare(command: CommandT, *, context: PreparationContext) -> PreparedAction[PrivateSnapshotT, PreviewT]
can_prepare
abstractmethod
async
¶
can_prepare(command: CommandT, *, context: PreparationContext) -> AuthorizationResult
can_decide
abstractmethod
async
¶
can_decide(evidence: AuthorityEvidence, *, context: DecisionContext) -> AuthorizationResult
can_execute
abstractmethod
async
¶
can_execute(snapshot: PrivateSnapshotT, *, context: ExecutionContext) -> AuthorizationResult
resolve
abstractmethod
async
¶
resolve(snapshot: PrivateSnapshotT, *, context: ExecutionContext) -> ResolvedState[PrivateSnapshotT, PreviewT]
execute
abstractmethod
async
¶
execute(snapshot: PrivateSnapshotT, *, context: ExecutionContext, execution_precondition: str) -> ExecutionResult[ResultT]
authorize_erasure
async
¶
authorize_erasure(proposal_reference: str, *, context: ReadContext) -> bool
ActionConfigurationError ¶
Bases: TypeError
Raised when an Action subclass cannot compile to ActionDefinition.
AnyApproval
dataclass
¶
AnyApproval(authorities: tuple[ConfirmingAuthority, ...])
Require one distinct authority from a declared set.
evaluate
async
¶
evaluate(*, binding: AuthorityBinding, evidence: tuple[AuthorityEvidence, ...]) -> AuthorityEvaluation
ApprovalReasonCode ¶
Bases: StrEnum
Reason codes generated by the evidence-only approval requirements.
MORE_AUTHORITY_REQUIRED
class-attribute
instance-attribute
¶
MOfNApprovals
dataclass
¶
MOfNApprovals(required: int, authorities: tuple[ConfirmingAuthority, ...])
Require approvals from a distinct M-of-N set of authorities.
evaluate
async
¶
evaluate(*, binding: AuthorityBinding, evidence: tuple[AuthorityEvidence, ...]) -> AuthorityEvaluation
SingleApproval
dataclass
¶
SingleApproval(authority: ConfirmingAuthority)
Require one specific authority after the host authorizes the decision.
evaluate
async
¶
evaluate(*, binding: AuthorityBinding, evidence: tuple[AuthorityEvidence, ...]) -> AuthorityEvaluation
RuntimeAttributionError ¶
Bases: RuntimeError
The runtime cannot identify the exact library code producing receipts.
AuthorityBinding ¶
AuthorityDecision ¶
AuthorityEvidence ¶
Bases: ExperimentalModel
A bound authority decision; it is not authorization by itself.
domain
class-attribute
instance-attribute
¶
schema_version
class-attribute
instance-attribute
¶
audience
class-attribute
instance-attribute
¶
audience: tuple[SafeReference, ...] = Field(min_length=1)
AuthorityValidationFailure ¶
AuthorityValidationResult ¶
Bases: ExperimentalModel
CanonicalizationError ¶
Bases: ValueError
Raised when a value cannot enter the canonical finance boundary.
CommitmentProvider ¶
Bases: Protocol
Host-owned proposal-scoped keyed commitment boundary.
Destruction must be idempotent so an interrupted erasure can resume safely.
verify
async
¶
verify(*, proposal_reference: str, canonical_payload: bytes, commitment: KeyedCommitment) -> bool
KeyedCommitment ¶
ProtectedPayload ¶
ProtectionCodec ¶
Bases: Protocol
Host-owned protection boundary for canonical private snapshots.
Destruction must be idempotent so an interrupted erasure can resume safely.
ActionType ¶
AuthoritativeTarget ¶
Bases: ExperimentalModel
kind
class-attribute
instance-attribute
¶
ConfirmingAuthority ¶
Bases: ExperimentalModel
kind
class-attribute
instance-attribute
¶
EvidenceConsumer ¶
Bases: ExperimentalModel
GovernedExecutor ¶
Bases: ExperimentalModel
LifecycleStatus ¶
Money ¶
Bases: ExperimentalModel
A monetary amount whose currency is explicit and precision is host-validated.
ProposingAgent ¶
Bases: ExperimentalModel
RequestingPrincipal ¶
Bases: ExperimentalModel
kind
class-attribute
instance-attribute
¶
AuthorityReceipt ¶
Bases: _ReceiptBase
AuthorityReceiptStatus ¶
EventSink ¶
Bases: Protocol
Best-effort, at-most-once projection called after durable state changes.
ExecutionReceipt ¶
Bases: _ReceiptBase
ExternalReference ¶
ItemOutcome ¶
ItemOutcomeStatus ¶
NoopEventSink ¶
ProposalReceipt ¶
Bases: _ReceiptBase
ProposalReceiptStatus ¶
RuntimeEvent ¶
VerificationReceipt ¶
Bases: _ReceiptBase
receipt_type
class-attribute
instance-attribute
¶
VerificationReceiptStatus ¶
Bases: StrEnum
VERIFIED_COMPLETION
class-attribute
instance-attribute
¶
VERIFIED_TERMINAL_FAILURE
class-attribute
instance-attribute
¶
PROVISIONAL_ABSENCE
class-attribute
instance-attribute
¶
AUTHORITATIVE_FINAL_ABSENCE
class-attribute
instance-attribute
¶
VERIFICATION_UNRESOLVED
class-attribute
instance-attribute
¶
ActionDefinition
dataclass
¶
ActionDefinition(action_type: ActionType, command_model: type[CommandT], private_snapshot_model: type[PrivateSnapshotT], display_preview_model: type[PreviewT], result_model: type[ResultT], preparation: PreparationPort[CommandT, PrivateSnapshotT, PreviewT], authorization: AuthorizationPort[CommandT, PrivateSnapshotT], authority_evaluator: AuthorityEvaluatorPort, state_resolver: StateResolverPort[PrivateSnapshotT, PreviewT], executor: GovernedExecutorPort[PrivateSnapshotT, ResultT], verifier: VerifierPort[ResultT], commitment_provider: CommitmentProvider, protection_codec: ProtectionCodec, retention: RetentionPort, proposal_ttl: timedelta, executor_identity: GovernedExecutor, target_identity: AuthoritativeTarget, authority_audience: str, authority_channel_assurance: str, verification_delay: timedelta = timedelta(0), max_verification_attempts: int = 3, effect_kind: EffectKind = 'single', allow_resend_after_final_absence: bool = False, verification_lease_duration: timedelta = timedelta(minutes=1), semantic_idempotency_strategy: Literal['host_defined'] = 'host_defined')
Bases: Generic[CommandT, PrivateSnapshotT, PreviewT, ResultT]
ActionNotRegisteredError ¶
Bases: LookupError
ActionRegistry ¶
A heterogeneous registry with checked type recovery at its boundary.
register ¶
register(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]) -> None
get_typed ¶
get_typed(action_type: ActionType, *, command_model: type[CommandT], private_snapshot_model: type[PrivateSnapshotT], display_preview_model: type[PreviewT], result_model: type[ResultT]) -> ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]
AuthorityEvaluation ¶
Bases: ExperimentalModel
AuthorityEvaluatorPort ¶
Bases: Protocol
evaluate
async
¶
evaluate(*, binding: AuthorityBinding, evidence: tuple[AuthorityEvidence, ...]) -> AuthorityEvaluation
AuthorizationPort ¶
Bases: Protocol[CommandContraT, PrivateContraT]
can_prepare
async
¶
can_prepare(command: CommandContraT, *, context: PreparationContext) -> AuthorizationResult
can_decide
async
¶
can_decide(evidence: AuthorityEvidence, *, context: DecisionContext) -> AuthorizationResult
can_execute
async
¶
can_execute(snapshot: PrivateContraT, *, context: ExecutionContext) -> AuthorizationResult
AuthorizationResult ¶
Bases: ExperimentalModel
DecisionContext ¶
Bases: ExperimentalModel
DefinitionConformanceError ¶
Bases: ValueError
Raised when declared boundary models cannot satisfy the runtime contract.
DefinitionTypeMismatchError ¶
Bases: TypeError
DuplicateActionError ¶
Bases: RuntimeError
ExecutionContext ¶
Bases: ExperimentalModel
ExecutionResult ¶
Bases: ExperimentalModel, Generic[ResultT]
external_reference
class-attribute
instance-attribute
¶
external_reference: ExternalReference | None = None
GovernedExecutorPort ¶
Bases: Protocol[PrivateContraT, ResultT]
execute
async
¶
execute(snapshot: PrivateContraT, *, context: ExecutionContext, execution_precondition: str) -> ExecutionResult[ResultT]
PreparationContext ¶
Bases: ExperimentalModel
PreparationPort ¶
Bases: Protocol[CommandContraT, PrivateSnapshotT, PreviewT]
prepare
async
¶
prepare(command: CommandContraT, *, context: PreparationContext) -> PreparedAction[PrivateSnapshotT, PreviewT]
PreparedAction
dataclass
¶
PreparedAction(private_snapshot: PrivateSnapshotT, display_preview: PreviewT, semantic_effect_reference: str)
Bases: Generic[PrivateSnapshotT, PreviewT]
ReadContext ¶
Bases: ExperimentalModel
ResolvedState
dataclass
¶
ResolvedState(current_snapshot: PrivateSnapshotT, execution_precondition: str, materially_drifted: bool, replacement: PreparedAction[PrivateSnapshotT, PreviewT] | None = None)
Bases: Generic[PrivateSnapshotT, PreviewT]
replacement
class-attribute
instance-attribute
¶
replacement: PreparedAction[PrivateSnapshotT, PreviewT] | None = None
RetentionPort ¶
Bases: Protocol
authorize_erasure
async
¶
authorize_erasure(proposal_reference: str, *, context: ReadContext) -> bool
StateResolverPort ¶
Bases: Protocol[PrivateSnapshotT, PreviewT]
resolve
async
¶
resolve(snapshot: PrivateSnapshotT, *, context: ExecutionContext) -> ResolvedState[PrivateSnapshotT, PreviewT]
VerificationResult ¶
Bases: ExperimentalModel, Generic[ResultT]
external_reference
class-attribute
instance-attribute
¶
external_reference: ExternalReference | None = None
settling_boundary_passed
class-attribute
instance-attribute
¶
target_idempotency_guaranteed
class-attribute
instance-attribute
¶
absence_requires_consistent_evidence ¶
absence_requires_consistent_evidence() -> VerificationResult[ResultT]
VerificationStatus ¶
ActionOperationResult ¶
Bases: ExperimentalModel
display_preview
class-attribute
instance-attribute
¶
fresh_proposal_reference
class-attribute
instance-attribute
¶
fresh_proposal_reference: SafeReference | None = None
is_terminal
property
¶
Whether the proposal lifecycle has no valid transition left.
needs_reconciliation
property
¶
Whether authoritative reconciliation may advance this proposal.
ActionRuntime ¶
ActionRuntime(*, store: ActionStore, retention_store: RetentionStore | None = None, clock: Clock | None = None, identifiers: IdentifierProvider | None = None, event_sink: EventSink | None = None, runtime_revision: str | None = None)
Coordinates host-owned controls without owning host business truth.
prepare
async
¶
prepare(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, command: CommandT, requesting_principal: RequestingPrincipal, proposing_agent: ProposingAgent | None = None) -> ActionOperationResult
record_authority
async
¶
record_authority(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, evidence: AuthorityEvidence, authenticated_authority: ConfirmingAuthority, proposal_reference: str | None = None) -> ActionOperationResult
expire_due
async
¶
expire_due(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
Expire an unexecuted proposal once its prepared lifetime has elapsed.
execute
async
¶
execute(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
reconcile
async
¶
reconcile(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
read
async
¶
read(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ProposalView
erase
async
¶
erase(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ActionOperationResult
AuthorizationDeniedError ¶
Bases: PermissionError
InvalidActionResultError ¶
Bases: RuntimeError
InvalidAuthorityEvidenceError ¶
Bases: ValueError
OperationOutcome ¶
ProposalView ¶
Bases: ExperimentalModel
RetentionStoreUnavailableError ¶
Bases: RuntimeError
RuntimeReasonCode ¶
Bases: StrEnum
Reason codes generated by the runtime; hosts may still return their own.
PRIVATE_SNAPSHOT_UNAVAILABLE
class-attribute
instance-attribute
¶
PROPOSAL_COMMITMENT_UNAVAILABLE
class-attribute
instance-attribute
¶
AUTHORITY_NO_LONGER_SATISFIED
class-attribute
instance-attribute
¶
REAUTHORIZATION_FAILED
class-attribute
instance-attribute
¶
VERIFICATION_RETRIES_EXHAUSTED
class-attribute
instance-attribute
¶
PARTIAL_NOT_DECLARED
class-attribute
instance-attribute
¶
VERIFIED_TERMINAL_FAILURE
class-attribute
instance-attribute
¶
AUTHORITATIVE_FINAL_ABSENCE
class-attribute
instance-attribute
¶
SystemClock ¶
Production default that returns the current timezone-aware UTC time.
UuidIdentifiers ¶
Production default that creates opaque, cryptographically random references.
ActionStore ¶
Bases: Protocol
compare_and_set
async
¶
compare_and_set(*, tenant_reference: str, proposal_reference: str, expected_revision: int, expected_statuses: tuple[LifecycleStatus, ...], updated: StoredProposal) -> bool
admit_execution
async
¶
admit_execution(*, tenant_reference: str, proposal_reference: str, expected_revision: int, admitted_at: datetime, updated: StoredProposal) -> EffectClaimResult
get_effect_claim_owner
async
¶
get_effect_claim_owner(*, tenant_reference: str, action_type: ActionType, semantic_effect_reference: str) -> str | None
MemoryActionStore ¶
Bases: ActionStore, RetentionStore
An in-process conformance store with tenant-scoped guarded writes.
compare_and_set
async
¶
compare_and_set(*, tenant_reference: str, proposal_reference: str, expected_revision: int, expected_statuses: tuple[LifecycleStatus, ...], updated: StoredProposal) -> bool
admit_execution
async
¶
admit_execution(*, tenant_reference: str, proposal_reference: str, expected_revision: int, admitted_at: datetime, updated: StoredProposal) -> EffectClaimResult
get_effect_claim_owner
async
¶
get_effect_claim_owner(*, tenant_reference: str, action_type: ActionType, semantic_effect_reference: str) -> str | None
mark_erasure_pending
async
¶
mark_erasure_pending(*, tenant_reference: str, proposal_reference: str, expected_revision: int, pending_at: datetime) -> bool
complete_erasure
async
¶
complete_erasure(*, tenant_reference: str, proposal_reference: str, expected_revision: int, erased_at: datetime) -> bool
ProposalAlreadyExistsError ¶
Bases: RuntimeError
RetentionStore ¶
Bases: Protocol
Privileged persistence operations kept outside the runtime DB role.
mark_erasure_pending
async
¶
mark_erasure_pending(*, tenant_reference: str, proposal_reference: str, expected_revision: int, pending_at: datetime) -> bool
complete_erasure
async
¶
complete_erasure(*, tenant_reference: str, proposal_reference: str, expected_revision: int, erased_at: datetime) -> bool
StoredProposal ¶
Bases: ExperimentalModel
Persistence-neutral lifecycle record; private state is always protected.
display_preview
class-attribute
instance-attribute
¶
display_preview: JsonObject = Field(default_factory=dict)
requesting_principal
class-attribute
instance-attribute
¶
requesting_principal: RequestingPrincipal | None = None
authority_evidence
class-attribute
instance-attribute
¶
authority_evidence: tuple[AuthorityEvidence, ...] = ()
verification_attempts
class-attribute
instance-attribute
¶
max_verification_attempts
class-attribute
instance-attribute
¶
next_verification_at
class-attribute
instance-attribute
¶
execution_precondition
class-attribute
instance-attribute
¶
execution_precondition: SafeReference | None = None
erasure_pending_at
class-attribute
instance-attribute
¶
StoreInvariantError ¶
Bases: RuntimeError
resolve_runtime_revision ¶
Return an exact released version or source commit plus package-tree digest.
authority_evidence_matches_binding ¶
authority_evidence_matches_binding(evidence: AuthorityEvidence, *, binding: AuthorityBinding) -> bool
Check proposal binding dimensions without evaluating time or sufficiency.
validate_authority_evidence ¶
validate_authority_evidence(evidence: AuthorityEvidence, *, binding: AuthorityBinding, now: AwareDatetime) -> AuthorityValidationResult
Validate server-bound evidence without treating it as sufficient policy.
canonicalize_v1 ¶
Produce deterministic UTF-8 JSON for the internal canonical v1 profile.
commitment_payload_v1 ¶
Domain-separate a private snapshot commitment from every other digest.
assert_definition_conforms ¶
assert_definition_conforms(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]) -> None
Reject declared model shapes that cannot satisfy the runtime boundary.
validate_proposal_update ¶
validate_proposal_update(*, current: StoredProposal, updated: StoredProposal) -> None