Skip to content

Deterministic execution

A graph decision is deterministic when repeating it with the same relevant inputs produces the same outcome. Given the same graph, session state, requested edge and data, the engine should make the same decision about that edge and its destination.

This is useful when you need to understand a result or repeat a test. You can examine the inputs that led to a decision and reproduce it. Time, configuration and data read by rules are part of those inputs too.

Start with the graph definition and the session state. The definition supplies the possible routes and their conditions; the state supplies the current position, context and recorded history. Repeating a choice from a later position is already a different operation.

The request matters as well: which edge your application selects and which context values it supplies with that selection. If your application proposes different data, it is asking the engine to evaluate a different case.

Finally, keep the relevant configuration and rule behaviour the same. A rule that depends on the current time or an external answer brings that information into the decision. Reusing the graph alone is not enough to reproduce the result.

Consider the workshop graph introduced in Graph-based execution model. At node 200, edge 201 selects the Valencia venue. In this example, the context contains placesAvailable: true, so the availability condition passes.

For this comparison, we also give that edge a deadline: it may be selected up to 12:00 UTC on 10 December 2026. Each row below starts from the same state at node 200 and requests edge 201. Only the evaluation time changes.

Evaluation Time on 10 December, UTC Result
First attempt 10:00 The choice is accepted; the resulting state is at node 300.
Repeat from the same starting state 10:00 The same choice is accepted with the same resulting state.
Evaluate after the deadline 13:00 The choice is rejected; the starting state remains at node 200.

The third result does not contradict determinism. The time used by the condition has changed. Two requests that look identical in your application code can therefore have different outcomes if they read different times.

For a repeatable temporal test, you can give the engine a fixed clock. FixedTimeProvider supplies the chosen instant, and ExecKernelFactory builds an engine that uses it.

This fragment fixes the engine’s time at the 10:00 UTC instant from the table:

use ExecKernel\Domain\Engine\FixedTimeProvider;
use ExecKernel\Infrastructure\Engine\ExecKernelFactory;
$clock = new FixedTimeProvider(
new \DateTimeImmutable('2026-12-10T10:00:00+00:00')
);
$engine = (new ExecKernelFactory())->build(timeProvider: $clock);

The timeProvider argument makes that clock available to the engine’s temporal evaluation. Operations that do not supply an explicit evaluation time use this clock. In this example, running the decision later on your computer still evaluates it at the supplied instant. You can then change the fixed instant to 13:00 UTC to check the other outcome deliberately.

The fragment configures the engine; your test also needs the same graph, starting state and choice used in the comparison. Temporal conditions and TimeDSL explains how to define the time condition itself.

A custom rule might ask a service whether a resource is available. The service’s answer then matters just as much as the context or the clock. If that answer changes between runs, the outcome can change even when your application submits the same request.

To make such a test repeatable, use a controlled response for that dependency or preserve the input you need to reproduce. A fixed engine clock controls the engine’s time source; a rule that obtains time or data elsewhere must also make that dependency controllable.

When comparing payloads, keep the requested language the same as well. Text can legitimately change with the language while the graph decision remains the same.

The useful guarantee concerns the decision made from the relevant inputs. It does not imply that separate sessions share an identity or that complete HTTP responses and external operations are identical. For reproducing recorded executions, see Deterministic, comparative and partial replay.