flowsemantics.trust package¶
Submodules¶
flowsemantics.trust.replay module¶
flowsemantics.trust.replay - Replay records and four replay operations.
Layer: Trust Module: flowsemantics.trust.replay Since: 0.3.0 Implements: SPEC.md sections 12.6, 12.10, 9.5 Depends on: flowsemantics.configuration.flow, flowsemantics.execution.*,
stdlib (hmac, hashlib, json, datetime)
Used by: audit, regression testing, decision forensics See also: SPEC.md sections 12.6, 9.5, 12.10
Notes
Four distinct operations, never conflated (SPEC 12.6): SIMULATION (re-evaluate, no effects), HISTORICAL (return recorded data), DECISION (re-evaluate + semantic comparison), EFFECTS (apply recorded effects via authorized executor; never default).
Replay guarantee is SEMANTIC equivalence, not bit-for-bit (A5).
Fail closed on spec_version or contract_version mismatch (9.5).
Integrity: HMAC-SHA256 over a canonical JSON payload. An unkeyed hash alone is NOT sufficient (12.6); integrity is optional on the record but verified whenever present.
- exception flowsemantics.trust.replay.ReplayError[source]¶
Bases:
FlowSemanticsErrorRaised when a replay record cannot be safely replayed.
- class flowsemantics.trust.replay.ReplayMode(value)[source]¶
Bases:
StrEnumThe four replay operations (SPEC 12.6).
- SIMULATION = 'simulation'¶
- HISTORICAL = 'historical'¶
- DECISION = 'decision'¶
- EFFECTS = 'effects'¶
- class flowsemantics.trust.replay.ReplayRecord(spec_version: str, contract_version: str, input: Any, clock_wall: datetime, clock_monotonic: float, outcome: FlowOutcome, trace: ExecutionTrace | None = None, effects: tuple[Any, ...] = (), integrity: str | None = None)[source]¶
Bases:
objectA recorded decision tuple (SPEC 12.6, 12.10).
- spec_version¶
SPEC.md version that produced the record.
- Type:
str
- contract_version¶
Structural hash of the FlowContract.
- Type:
str
- input¶
The recorded input (application data; handle per 12.2).
- Type:
Any
- clock_wall¶
Recorded wall-clock value.
- Type:
datetime.datetime
- clock_monotonic¶
Recorded monotonic value.
- Type:
float
- outcome¶
The recorded FlowOutcome.
- trace¶
The recorded trace, if collected.
- Type:
- effects¶
Recorded proposed effects.
- Type:
tuple[Any, …]
- integrity¶
Optional HMAC-SHA256 hex digest (see sign()).
- Type:
str | None
- spec_version: str¶
- contract_version: str¶
- input: Any¶
- clock_wall: datetime¶
- clock_monotonic: float¶
- outcome: FlowOutcome¶
- trace: ExecutionTrace | None = None¶
- effects: tuple[Any, ...] = ()¶
- integrity: str | None = None¶
- __init__(spec_version: str, contract_version: str, input: Any, clock_wall: datetime, clock_monotonic: float, outcome: FlowOutcome, trace: ExecutionTrace | None = None, effects: tuple[Any, ...] = (), integrity: str | None = None) None¶
- class flowsemantics.trust.replay.ReplayResult(mode: ReplayMode, outcome: FlowOutcome | None = None, equivalent: bool | None = None, effects_applied: int = 0)[source]¶
Bases:
objectResult of a replay operation.
- mode: ReplayMode¶
- outcome: FlowOutcome | None = None¶
- equivalent: bool | None = None¶
- effects_applied: int = 0¶
- __init__(mode: ReplayMode, outcome: FlowOutcome | None = None, equivalent: bool | None = None, effects_applied: int = 0) None¶
- flowsemantics.trust.replay.record(contract: FlowContract, input: Any, *, clock: Any | None = None) ReplayRecord[source]¶
Execute with tracing and capture a ReplayRecord (SPEC 12.6).
- flowsemantics.trust.replay.replay(record: ReplayRecord, contract: FlowContract, *, mode: ReplayMode = ReplayMode.SIMULATION, integrity_key: bytes | None = None, effect_executor: Any | None = None, authorize_effects: bool = False) ReplayResult[source]¶
Replay a recorded decision (SPEC 12.6).
- Parameters:
record – The recorded tuple.
contract – The current FlowContract to replay against.
mode – One of the four replay operations.
integrity_key – HMAC key when the record is integrity-tagged.
effect_executor – Callable(Effect) for EFFECTS mode only.
authorize_effects – Must be True for EFFECTS mode; never default.
- flowsemantics.trust.replay.sign(record: ReplayRecord, key: bytes) ReplayRecord[source]¶
Return a copy of the record with an HMAC-SHA256 integrity tag.
flowsemantics.trust.shadow module¶
flowsemantics.trust.shadow - Shadow evaluation (SPEC 12.7).
Layer: Trust Module: flowsemantics.trust.shadow Since: 0.3.0 Implements: SPEC.md section 12.7 Depends on: flowsemantics.configuration.flow, flowsemantics.execution.outcome Used by: pre-deployment candidate comparison See also: SPEC.md section 12.7
Notes
Shadow evaluation NEVER applies effects: both flows run via simulate(), so hooks and finalizers are suppressed (12.5).
Deterministic: same inputs + contracts + clock -> same report.
- class flowsemantics.trust.shadow.ShadowEntry(index: int, input: Any, current: FlowOutcome, candidate: FlowOutcome, differs: bool, differing_fields: tuple[str, ...])[source]¶
Bases:
objectOne input’s current-vs-candidate comparison.
- index: int¶
- input: Any¶
- current: FlowOutcome¶
- candidate: FlowOutcome¶
- differs: bool¶
- differing_fields: tuple[str, ...]¶
- __init__(index: int, input: Any, current: FlowOutcome, candidate: FlowOutcome, differs: bool, differing_fields: tuple[str, ...]) None¶
- class flowsemantics.trust.shadow.ShadowReport(entries: tuple[ShadowEntry, ...], total: int, differences: int)[source]¶
Bases:
objectAggregate shadow comparison report (SPEC 12.7).
- entries: tuple[ShadowEntry, ...]¶
- total: int¶
- differences: int¶
- __init__(entries: tuple[ShadowEntry, ...], total: int, differences: int) None¶
- flowsemantics.trust.shadow.shadow(current: FlowContract, candidate: FlowContract, inputs: Iterable[Any], *, clock: Clock | None = None) ShadowReport[source]¶
Compare a candidate flow against the current flow (SPEC 12.7).
Both flows are simulated (no effects, no hooks, no finalizers).
Module contents¶
flowsemantics.trust - Trust layer: replay, shadow, explain helpers.
Layer: Trust Module: flowsemantics.trust Since: 0.3.0 Implements: SPEC.md section 12 Depends on: flowsemantics.configuration, flowsemantics.execution Used by: consumers needing replay/shadow/audit capabilities See also: SPEC.md sections 12.5-12.7, 9.5
- exception flowsemantics.trust.ReplayError[source]¶
Bases:
FlowSemanticsErrorRaised when a replay record cannot be safely replayed.
- class flowsemantics.trust.ReplayMode(value)[source]¶
Bases:
StrEnumThe four replay operations (SPEC 12.6).
- SIMULATION = 'simulation'¶
- HISTORICAL = 'historical'¶
- DECISION = 'decision'¶
- EFFECTS = 'effects'¶
- class flowsemantics.trust.ReplayRecord(spec_version: str, contract_version: str, input: Any, clock_wall: datetime, clock_monotonic: float, outcome: FlowOutcome, trace: ExecutionTrace | None = None, effects: tuple[Any, ...] = (), integrity: str | None = None)[source]¶
Bases:
objectA recorded decision tuple (SPEC 12.6, 12.10).
- spec_version¶
SPEC.md version that produced the record.
- Type:
str
- contract_version¶
Structural hash of the FlowContract.
- Type:
str
- input¶
The recorded input (application data; handle per 12.2).
- Type:
Any
- clock_wall¶
Recorded wall-clock value.
- Type:
datetime.datetime
- clock_monotonic¶
Recorded monotonic value.
- Type:
float
- outcome¶
The recorded FlowOutcome.
- trace¶
The recorded trace, if collected.
- Type:
- effects¶
Recorded proposed effects.
- Type:
tuple[Any, …]
- integrity¶
Optional HMAC-SHA256 hex digest (see sign()).
- Type:
str | None
- spec_version: str¶
- contract_version: str¶
- input: Any¶
- clock_wall: datetime¶
- clock_monotonic: float¶
- outcome: FlowOutcome¶
- trace: ExecutionTrace | None = None¶
- effects: tuple[Any, ...] = ()¶
- integrity: str | None = None¶
- __init__(spec_version: str, contract_version: str, input: Any, clock_wall: datetime, clock_monotonic: float, outcome: FlowOutcome, trace: ExecutionTrace | None = None, effects: tuple[Any, ...] = (), integrity: str | None = None) None¶
- class flowsemantics.trust.ReplayResult(mode: ReplayMode, outcome: FlowOutcome | None = None, equivalent: bool | None = None, effects_applied: int = 0)[source]¶
Bases:
objectResult of a replay operation.
- mode: ReplayMode¶
- outcome: FlowOutcome | None = None¶
- equivalent: bool | None = None¶
- effects_applied: int = 0¶
- __init__(mode: ReplayMode, outcome: FlowOutcome | None = None, equivalent: bool | None = None, effects_applied: int = 0) None¶
- class flowsemantics.trust.ShadowEntry(index: int, input: Any, current: FlowOutcome, candidate: FlowOutcome, differs: bool, differing_fields: tuple[str, ...])[source]¶
Bases:
objectOne input’s current-vs-candidate comparison.
- index: int¶
- input: Any¶
- current: FlowOutcome¶
- candidate: FlowOutcome¶
- differs: bool¶
- differing_fields: tuple[str, ...]¶
- __init__(index: int, input: Any, current: FlowOutcome, candidate: FlowOutcome, differs: bool, differing_fields: tuple[str, ...]) None¶
- class flowsemantics.trust.ShadowReport(entries: tuple[ShadowEntry, ...], total: int, differences: int)[source]¶
Bases:
objectAggregate shadow comparison report (SPEC 12.7).
- entries: tuple[ShadowEntry, ...]¶
- total: int¶
- differences: int¶
- __init__(entries: tuple[ShadowEntry, ...], total: int, differences: int) None¶
- flowsemantics.trust.record(contract: FlowContract, input: Any, *, clock: Any | None = None) ReplayRecord[source]¶
Execute with tracing and capture a ReplayRecord (SPEC 12.6).
- flowsemantics.trust.replay(record: ReplayRecord, contract: FlowContract, *, mode: ReplayMode = ReplayMode.SIMULATION, integrity_key: bytes | None = None, effect_executor: Any | None = None, authorize_effects: bool = False) ReplayResult[source]¶
Replay a recorded decision (SPEC 12.6).
- Parameters:
record – The recorded tuple.
contract – The current FlowContract to replay against.
mode – One of the four replay operations.
integrity_key – HMAC key when the record is integrity-tagged.
effect_executor – Callable(Effect) for EFFECTS mode only.
authorize_effects – Must be True for EFFECTS mode; never default.
- flowsemantics.trust.shadow(current: FlowContract, candidate: FlowContract, inputs: Iterable[Any], *, clock: Clock | None = None) ShadowReport[source]¶
Compare a candidate flow against the current flow (SPEC 12.7).
Both flows are simulated (no effects, no hooks, no finalizers).
- flowsemantics.trust.sign(record: ReplayRecord, key: bytes) ReplayRecord[source]¶
Return a copy of the record with an HMAC-SHA256 integrity tag.