$ fssg build --deterministic --validate |

How FACET Makes Dependency Evaluation Deterministic

FACET

A dependency graph does not become deterministic merely because it has no cycles.

That sentence matters for AI contract compilers. Two implementations can accept the same variables, build the same directed acyclic graph, and still evaluate independent nodes in different orders. If evaluation includes bounded transforms, caching, diagnostics, or policy checks, “any valid topological order” is not a portable execution contract. It is hidden implementation freedom.

FACET closes that freedom in its Reactive Dependency Graph, or R-DAG. The interesting mechanism is not the graph alone. It is the stable schedule around the graph.

The missing rule in ordinary DAG execution

Consider a small variable set:

@vars
  region: "eu"
  retry_limit: 3
  endpoint: $region |> prepend("https://")
  request_key: $region |> append("-primary")

endpoint and request_key both depend on region, but neither depends on the other. A normal topological sorter may legally emit either order:

region → endpoint → request_key → retry_limit

or:

region → retry_limit → request_key → endpoint

Both schedules satisfy the graph. They are not the same observable execution history.

For a general-purpose batch job, that may be acceptable. For a portable contract language, it creates questions that should not be delegated to a hash map, runtime version, or compiler author:

  • Which transform is evaluated first?
  • Which diagnostic appears first if two independent nodes fail?
  • What order does an execution artifact record?
  • Can two conforming compilers produce byte-identical evidence for the same source?

Determinism requires one answer, not a set of valid answers.

FACET’s stable scheduling rule

The FACET v2.1.3 specification defines the R-DAG phase precisely:

  1. build dependencies from $var references;
  2. reject unknown references with F401;
  3. reject cycles with F505;
  4. evaluate in topological order;
  5. break ties between ready, independent nodes by the merged @vars ordered-map insertion order;
  6. freeze the computed variable map before context layout begins.

The tie-break is the small rule with large consequences. Source order becomes a semantic input only where the dependency relation leaves a choice. Dependencies still dominate. Among equally ready nodes, first insertion wins.

The reference compiler implements this boundary explicitly. Its dependency graph stores both the nodes and a separate insertion_order vector with an index map. The scheduler can therefore choose a stable ready node rather than inheriting iteration order from an unordered container.

This is a useful compiler pattern: keep semantic order as data. Never assume the collection carrying values will also preserve the order needed by the language.

Overrides replace values, not identity

Imports and merged declarations make the rule more subtle. Suppose a base contract introduces variables in this order:

@vars
  model_class: "balanced"
  locale: "en"

A later source overrides model_class. FACET requires the new value to occupy the original variable’s first-insertion position. The override changes the definition, not the variable’s scheduling identity.

Without this rule, a merge implementation might remove and reinsert the key. That would move it to the end of the ordered map and silently alter tie-breaking. A configuration override would then change evaluation order even when the dependency graph had not changed.

The stable model is:

first declaration → scheduling identity
later override    → effective value

Those are separate concerns. This distinction resembles the separation between semantic normalization and canonical serialization: one process determines the effective meaning; another preserves a stable representation of that meaning. In the R-DAG, merge resolution chooses the value, while first-insertion identity stabilizes the schedule.

Forward references are not cycles

FACET permits forward references. Declaration order is a deterministic tie-break, not an instruction to evaluate text from top to bottom.

@vars
  url: $host |> append("/v1")
  host: "https://example.test"

This is valid because the graph has a clear order: host before url. By contrast:

@vars
  left: $right
  right: $left

has no valid schedule and must fail with F505.

That distinction is important for authoring. A contract may be organized for readability without sacrificing executable semantics. The compiler derives order from dependencies, then uses source identity only to resolve genuine ties.

Unknown references are a different failure class again. $missing is not a cycle; it is an absent node and raises F401. Keeping these diagnostics distinct gives tooling a precise recovery action: define or correct a name for F401; break a dependency loop for F505. This follows the broader FACET principle that diagnostics are part of the control plane, not decorative error strings.

The freeze boundary

The R-DAG phase ends by freezing the computed variable map. Context packing happens afterward through the Token Box Model, and rendering follows that.

This phase boundary prevents later layers from becoming hidden evaluators. Layout may allocate, compress, truncate, or drop flexible context sections according to its own deterministic algebra. It must not reinterpret variable dependencies. A provider adapter may render the result, but—as I argued in Provider Adapters Must Not Think—it must not repair or invent semantics.

The pipeline therefore has a clean shape:

resolved typed AST
        ↓
R-DAG: one computed variable state
        ↓ freeze
Token Box: one bounded context layout
        ↓
renderer: provider payload preserving canonical semantics

Each arrow narrows freedom. That is what a contract compiler should do.

What a conformance test should prove

A useful R-DAG test suite should not stop at “the values are correct.” It should include at least four fixture classes:

Fixture Required result
Independent ready nodes Stable first-insertion order
Override after import/merge New value, original scheduling position
Forward reference Successful dependency-derived order
Cycle and unknown reference Distinct F505 and F401 failures

A stronger fixture also records the evaluation sequence or execution artifact and compares it across repeated runs and implementations. Equal final values can hide a different schedule; a conformance test should inspect the mechanism it claims to verify.

This does not prove empirical performance, production adoption, or equivalence among all FACET implementations. It defines the normative behavior and shows how the current reference compiler represents it. Broader claims require independent conformance results.

Determinism lives in the tie-breaks

Large architectural claims often depend on small ordering rules.

“Use a DAG” is an architecture sketch. “Reject unknown nodes, reject cycles, permit forward references, preserve first insertion through overrides, select ready nodes by that order, then freeze the result” is an execution contract.

I care about that difference because nondeterminism rarely announces itself in the main algorithm. It survives in the places where the algorithm says either is valid. FACET’s R-DAG turns that remaining choice into language semantics.

The graph proves what must precede what. The stable schedule proves what happens when the graph is silent.

That is how dependency evaluation becomes reproducible engineering.

Sources

FACET AI CLI Terminal
facet@ai:~$