State export and replay contracts
Choose the artifact according to the evidence it actually contains. A state export describes a session and its recorded path. A complete debug trace supplies the per-step evidence needed for reconstruction. Reevaluation compares selected historical choices with a target graph under controlled time.
This reference covers ExecKernel\Application\StateExport\StateExporter and the types in ExecKernel\Replay. For the diagnostic workflow, see Deterministic, comparative and partial replay.
Artifact and supported operation
Section titled “Artifact and supported operation”| Artifact | Evidence | Supported operation |
|---|---|---|
StateExport, export_version: "1.0.0" |
Current node/context, visited node IDs and used edge IDs; optional supplied timeline and time configuration. | Inspection. With an explicit fixed clock and a complete path, construction of a reevaluation scenario. It does not recover earlier context values. |
Debug trace, version: "1.0", export_scope: "full_trace" |
Initial state, consecutive steps with availability, condition results, context changes and timestamps; optional final boundary. | Strict reconstruction and selection of a comparison interval with its real prefix. |
Debug export with export_scope: "inspection_window" |
Selected original steps plus window metadata. Its initial and final boundaries still belong to the full source trace. | Inspection of that slice. It is rejected as a new complete trace. |
ReplayRequest |
Typed input, selected mode, graph references, initial evidence and ReplayStep objects. |
ReplayEngine::replay(): ReplayResult. |
ReplayResult |
Reconstructed or reevaluated state, evidence label, history and divergence report. | Interpretation of what was checked, attempted and compared. It is a PHP result object, not an HTTP response schema. |
Download a StateExport, the complete debug trace, its inspection window, and the result-property examples. The trace is an explicit two-step fixture: 10 → 20 → 30 through edges 101 and 102. Its timestamps and context changes are declared evidence, not history inferred from the final export.
StateExporter
Section titled “StateExporter”The constructor accepts five optional values, all defaulting to null:
new StateExporter( ?array $timeline = null, ?array $contextPolicy = null, ?array $timeSnapshot = null, ?string $engineVersion = null, ?string $sessionId = null,);export(Graph $graph, SessionState $sessionState, string $lang): array returns the structure below. exportAsJson(...): string serializes that same structure. Export checks the state’s graph code and the existence of its current node in the graph; callers must supply the intended revision.
| Field | Type and origin |
|---|---|
export_version |
Literal "1.0.0". |
graph_code |
Canonical graph code. |
flow_id |
Numeric identity from the state, or null. |
current.node_id |
Integer current node ID. |
current.is_terminal |
Boolean from the graph node. |
current.available_edges |
Integer IDs of structural outgoing edges. This exporter does not evaluate conditions to filter them. |
current.metadata |
Optional title, subtitle and description. Language lookup uses the requested language, then the graph default, then the first metadata entry. |
history.visited_nodes |
Ordered integer node IDs. |
history.used_edges |
Ordered integer edge IDs. |
history.timeline |
Optional array whose entries must be arrays. Preserves keys and normalizes each entry’s ts when present. The exporter does not synthesize per-step history. |
context.values |
The state’s current context map. |
session_id |
Included when supplied to the exporter. |
versions |
Optional nonempty map of engine_version, graph_version, dsl_version and schema_version. Engine version comes from the exporter; graph/DSL versions prefer state values over graph values. |
time_snapshot |
Optional supplied map; its timestamp is normalized to an integer instant. |
context_policy |
Optional supplied map; its expires_at is normalized when present. |
The fixed-clock export used in the example contains:
{ "export_version": "1.0.0", "graph_code": "replay-contract", "flow_id": 7, "current": { "node_id": 30, "is_terminal": true, "available_edges": [] }, "history": { "visited_nodes": [10, 20, 30], "used_edges": [101, 102] }, "context": {"values": {"reviewed": true}}, "session_id": "replay-session", "versions": { "engine_version": "1.0.0", "graph_version": "1.0.0", "dsl_version": "1.0", "schema_version": "1.0" }, "time_snapshot": {"mode": "fixed", "timestamp": 1767225600}}This document says that the final context has reviewed: true. The two history lists do not say when that value changed.
Complete debug trace
Section titled “Complete debug trace”DebugReplayExporter exposes:
export( array $payload, ?int $step = null, ?int $rangeStart = null, ?int $rangeEnd = null,): array
exportAsJson( array $payload, ?int $step = null, ?int $rangeStart = null, ?int $rangeEnd = null,): stringIt validates and normalizes a complete source before selecting any window. A supplied version must be "1.0". Input export_scope must be absent or full_trace, and a source with window is rejected.
| Location | Required evidence or restriction |
|---|---|
| Root/session identity | graph_code, flow_id, graph_version, dsl_version, engine_version and session identity are resolved across the root and session representations. Conflicting declarations are rejected. Session identity must resolve to a nonempty ID. |
session.initial_min_state |
Array containing integer node_id, context map context and an explicit timestamp. |
session.steps |
A list of consecutive step objects with the fields below. |
session.final |
Optional recorded boundary. When provided, its node and any supplied context, timestamp or terminal evidence must agree with reconstruction. |
| Normalized output | version: "1.0" and export_scope: "full_trace", unless a window was requested. |
The JSON step field names correspond to the PHP ReplayStep properties as follows:
| Trace field | PHP property | Strict evidence |
|---|---|---|
step_number |
stepNumber: int |
Consecutive number, beginning at the request’s firstStepNumber. |
node_before |
nodeBefore: int |
Must equal the preceding reconstructed node. |
node_after |
nodeAfter: int |
Recorded destination. |
selected_edge |
selectedEdge: ?int |
Strict reconstruction requires a selected edge and a successful transition. |
available_edges |
availableEdges: ?array |
List of distinct integer IDs containing the selected edge. |
context_diff |
contextDiff: array |
Declarative context changes applied by shallow replacement. |
timestamp |
timestamp: ?int |
Explicit nondecreasing instant. |
evaluated_conditions |
evaluatedConditions: ?array |
List of recorded outcomes; an empty list is valid for an edge with no conditions. |
edge_block_reason |
edgeBlockReason: ?string |
Optional token. A blocked step cannot serve as a successful strict transition. |
A condition outcome has integer edge_id, a rule name rule using lowercase letters, digits or underscores, boolean result, and optional array details. An available edge cannot carry a recorded rejecting outcome. A historical graph enables verification of edge endpoints and the recorded condition sequence as well.
The PHP constructor permits null defaults for availableEdges, timestamp and evaluatedConditions, with contextDiff = [] and edgeBlockReason = null. Those defaults support different request modes; they do not supply missing strict evidence.
Trace timestamp normalization accepts an integer, a canonical decimal string, or an explicit ISO 8601 instant with timezone and whole seconds. Relative time and ambiguous local timestamps do not establish replay evidence.
Inspection windows
Section titled “Inspection windows”Selectors are zero-based and inclusive. step selects one step and cannot be combined with either range argument. A missing range start defaults to 0; a missing end selects the last step. Negative, reversed and out-of-range selectors are rejected.
A selection of step 1 from the example adds:
{ "export_scope": "inspection_window", "window": { "start_step": 1, "end_step": 1, "source_step_count": 2 }}The fragment above describes the changed envelope fields. The complete window document retains the source’s initial and final state and only slices session.steps. Its lone step begins at node 20, while its source initial state is node 10. Replay from a selected interval therefore starts with the complete trace and reconstructs the prefix through ReplayScenario.
Modes and request fields
Section titled “Modes and request fields”ReplayMode::STRICT has value strict. ReplayMode::REEVALUATION has value reeval.
| Property | Strict | Reevaluation |
|---|---|---|
| Meaning | Reconstruct the recorded transitions and validate their consistency. | Apply selected choices against a target graph and compare recorded evidence where available. |
| Graph | Optional historical graph for structural checks. | Required target graph. |
| Rule execution | No live condition evaluation. | Target conditions on selected edges are evaluated. |
| Evidence level | trace_consistency without a historical graph; graph_consistency with one. |
counterfactual. Source evidence remains identified separately in sourceMetadata. |
| Missing or inconsistent input | Rejected as invalid replay evidence. | Invalid input is rejected; a valid attempted comparison can report divergences. |
| External effects | Reconstruction does not invoke navigation effects. | An isolated replay navigator is used; enabling effects or webhooks is rejected. |
ReplayRequest requires mode: ReplayMode, initialNodeId: int, initialContext: array, initialTimestamp: int and steps: ReplayStep[]. Its remaining constructor fields are:
| Field | Type | Default and use |
|---|---|---|
graph |
?Graph |
null; historical graph in strict mode, target in reevaluation. |
graphCode, graphVersion, dslVersion |
?string |
null; explicit identity assertions. |
flowId |
?int |
null; numeric identity. Graph code takes precedence for target identity. |
engineVersion |
?string |
null; reevaluation asserts equality with the replay engine’s configured version when provided. |
allowSideEffects, allowWebhooks |
?bool |
null; reevaluation rejects either value being true. |
recordedFinal |
?array |
null; recorded boundary evidence for validation or comparison. |
expectedTerminal |
?bool |
true in direct construction. The scenario factories use null, allowing a valid interval to end before a terminal node. |
firstStepNumber |
int |
0; first step number of the selected interval. |
initialHistory |
?array |
null; prefix nodes and edges when starting after the source beginning. |
createdAt, lastTransitionAt |
?int |
null; session temporal origin and last transition at the selected boundary. |
fixedEvaluationTimestamp |
?int |
null; fixed clock for a state-export scenario. |
sourceMetadata |
array |
[]; provenance, source evidence and comparison scope. |
The request copies declarative arrays and requires a list of ReplayStep objects. Identity strings must be valid tokens. The replay engine constructor is new ReplayEngine(Navigator $navigator, string $engineVersion = '1.0.0'); that default is a constructor value and is not inferred from a package release.
Prefix and time requirements
Section titled “Prefix and time requirements”A prefix contains integer node and edge lists, with one more node than edges. Its edge count must match firstStepNumber, and its last node must match initialNodeId. A historical graph can check those connections during reconstruction.
Reevaluation with a prefix additionally requires a valid target path from the root, without a repeated edge or an earlier terminal node, and consistent temporal boundaries: createdAt ≤ lastTransitionAt ≤ initialTimestamp. Without a prefix, a reevaluation request must begin at the target root with step number 0.
Each reevaluated step uses its explicit timestamp or the request’s fixed clock. Time cannot move backwards. Under a fixed clock, supplied step timestamps must agree with it. These rules prevent the current wall clock from silently replacing recorded time.
Constructing a scenario from evidence
Section titled “Constructing a scenario from evidence”ReplayScenario::fromTrace has this signature:
fromTrace( array $source, ReplayMode $mode, ?Graph $target = null, ?Graph $historicalGraph = null, ?int $start = null, ?int $end = null, array $overrides = [], ?string $engineVersion = null, ?bool $allowSideEffects = null, ?bool $allowWebhooks = null,): ReplayRequestIt normalizes and checks the full trace first. The selected interval uses inclusive zero-based bounds, but the factory reconstructs every earlier step needed to establish its initial state, history and times. The request keeps the original step numbers and the prefix history.
In strict mode, context overrides are rejected. A supplied target must be the same object as historicalGraph. In reevaluation, target is required; historicalGraph remains the optional graph used to verify source evidence. Supplying a target does not establish historical consistency.
Reevaluation overrides replace keys in the reconstructed context at the selected boundary. Later recorded context_diff values can replace those same keys again. The factory records the override keys and source hash in sourceMetadata.
fromStateExport instead accepts:
fromStateExport( array $source, Graph $target, ?int $start = null, ?int $end = null, array $overrides = [], ?string $engineVersion = null, ?bool $allowSideEffects = null, ?bool $allowWebhooks = null,): ReplayRequestThis factory requires history.visited_nodes, history.used_edges, context values and time_snapshot.mode: fixed with an explicit timestamp. It uses the exported context as scenario input at the beginning of the path. Since earlier context is unavailable, the start must be 0; a later start is rejected with reason state_scenario_prefix_unavailable. An end bound can limit the path attempted.
The source is marked source_kind: state_export_scenario, source_evidence_level: scenario_only and comparison_scope: scenario_path_only. It has no recorded final historical boundary. The export’s nested versions map is descriptive metadata; this factory reads optional source-version assertions from top-level keys rather than unpacking that map. The target graph and explicit engine-version argument supply the target assertions.
Reevaluation limits and divergences
Section titled “Reevaluation limits and divergences”Reevaluation supports deterministic built-in conditions on the selected edges. A custom_rule or an unsupported rule family on those edges raises a non-deterministic-rule error. The replay navigator isolates runtime callbacks; allowSideEffects: true or allowWebhooks: true is rejected with reason replay_effects_forbidden.
The comparison covers selected edges, their recorded condition outcomes and the selected boundary. It does not claim that every alternative edge or every possible route has the same behavior.
| Divergence type | Meaning |
|---|---|
edge_missing |
A selected edge is absent from the target. |
edge_source_mismatch |
The edge no longer starts at the current target node. |
terminal_before_step |
The target is already terminal before the next selected transition. |
edge_blocked |
Target evaluation rejects the selected edge. |
node_after_mismatch |
A completed target transition reaches a different node. |
rule_order_mismatch |
Recorded and actual selected-edge condition order differ. |
rule_missing |
A recorded condition occurrence has no target counterpart. |
rule_outcome_mismatch |
The condition result or compared details differ. |
rule_unexpected |
The target produced an additional condition occurrence. |
final_context_mismatch |
A complete comparison reaches a different final context. |
terminal_mismatch |
Terminal evidence differs at the compared boundary. |
Rule occurrences are matched in order, including repeated rule families. Timing detail duration_ms is excluded from outcome comparison; value types and other compared details retain their meaning. Structural stops and blocked edges can end the attempted path. A destination mismatch retains the target state reached by that completed transition.
Reading ReplayResult
Section titled “Reading ReplayResult”| Property | Type and interpretation |
|---|---|
mode |
ReplayMode; its string value is strict or reeval. |
finalNodeId, finalContext |
Reconstructed or actually reached target node/context. |
steps |
The request’s selected steps. This is not a log claiming that every selected step executed. |
divergenceReport.divergences |
List of ReplayDivergence objects. Each has stepNumber, type, expected, actual and details. |
evidenceLevel |
Nullable string: trace_consistency, graph_consistency or counterfactual for these engine paths. |
terminalVerified |
Nullable boolean describing the checked terminal status; without a historical graph strict reconstruction cannot establish it. |
finalTimestamp |
Nullable integer instant at the result boundary. |
recordedFinal |
Nullable recorded boundary; strict results retain it. |
reconstructedHistory |
Nullable nodes/edges history, including a reconstructed prefix. Reevaluation reports the target path reached. |
sourceMetadata |
Source kind/hash, source identities, window, source evidence level, override keys and comparison scope when built through a scenario factory. |
targetGraphCode, targetGraphVersion, targetDslVersion, targetEngineVersion |
Nullable target identities, populated by reevaluation. |
attemptedStepCount, completedStepCount |
Nullable integer counts. An edge blocked during navigation is attempted but not completed. Pre-navigation structural stops do not count as attempts. |
timeBasis |
Nullable; reevaluation uses explicit_steps or fixed_scenario. |
historicalComparisonComplete |
Nullable boolean. A false value can reflect missing comparison evidence or an early stop; a state-export scenario cannot establish a full historical comparison. Strict results leave this reevaluation field null. |
stopReason |
Nullable divergence reason that stopped the selected path. |
In the checked example, strict replay of interval [1, 1] with the historical graph reconstructs node 30, retains history [10, 20, 30] and reports graph_consistency with no divergence. Reevaluation of the same selected edge against graph revision 1.1.0 reaches node 40:
{ "stepNumber": 1, "type": "node_after_mismatch", "expected": 30, "actual": 40, "details": {"edge_id": 102}}That result has finalNodeId: 40, attemptedStepCount: 1, completedStepCount: 1, evidenceLevel: counterfactual, stopReason: node_after_mismatch and historicalComparisonComplete: false. The full result-property example also contains the source hash, target identity, temporal basis and reconstructed histories, so the divergence can be read with its evidence.