Why FACET Imports Need Deterministic Merge Semantics
An import statement in an AI contract is not a convenience. It is an execution decision.
The moment a contract can import another file, its meaning no longer lives in one document. It lives in a graph: files, resolution roots, encounter order, overrides, repeated blocks, and failure rules. If any edge in that graph is ambiguous, the final prompt may look reasonable while representing a different program.
This is why I do not treat @import in FACET as textual copy-and-paste. The compiler must produce one Resolved Source Form with one reproducible meaning before type checking, dependency evaluation, context layout, or provider rendering begins.
Imports compose contracts
Consider a small system split into three files:
# base.facet
@vars
tone: "precise"
audience: "engineers"
@policy
max_tokens: 1200
# review.facet
@vars
audience: "reviewers"
format: "decision-record"
# main.facet
@import "base.facet"
@import "review.facet"
A naïve loader can read both files. That is not enough. The language must answer four separate questions:
- Where is each path allowed to resolve?
- In which order are declarations encountered?
- Which structures override, deep-merge, or append?
- What happens when the graph is missing, cyclic, or escapes its trust boundary?
Those are language semantics, not loader implementation details.
One merge operator is not enough
FACET v2.1.3 classifies facets by cardinality. Singleton maps such as @meta, @context, @vars, @var_types, and @policy are deep-merged. Repeatable blocks such as @interface, @system, @user, @assistant, and @test are concatenated in resolved encounter order.
That distinction matters because the two classes express different intent:
| Facet shape | Composition rule | Engineering meaning |
|---|---|---|
| Singleton map | recursive merge | produce one effective configuration |
| Repeatable block | ordered append | preserve a sequence of declarations |
| Ordinary list | replace by default | avoid inventing list identity |
Policy allow/deny |
merge by string id when present |
make policy-rule identity explicit |
“Deep-merge everything” is not a neutral default. Applied to messages, it can erase sequence. Applied to arbitrary lists, it can silently invent equality between elements. Applied to policies without stable rule identities, it can make authorization depend on accidental array position.
A compiler should not guess what two declarations mean together. The language must specify it.
Override value without rewriting history
FACET uses a subtle rule for singleton maps: the first appearance of a key establishes its position; a later declaration may replace the value, but it does not move the key.
For the example above, the effective values are:
tone = "precise"
audience = "reviewers"
format = "decision-record"
The effective key order remains tone, audience, format. audience changes value but keeps the position created in base.facet.
This is not cosmetic. FACET’s later R-DAG scheduling rules use stable insertion order to break ties between simultaneously ready nodes. Canonical rendering also depends on specified ordering. If override moved a key to the end, a harmless configuration edit could alter evaluation and serialization order.
The merge phase therefore preserves two different facts:
- effective value — the declaration that currently wins;
- structural position — where the identity first entered the resolved contract.
Conflating them makes override semantics unstable.
Import order is observable
FACET expands imports in source order and in place. Repeatable blocks then append in that resolved encounter order. Swapping two import lines may therefore change the contract, and that is correct: the source expresses a sequence.
What must never happen is for filesystem enumeration, hash-map iteration, parallel loading, or cache arrival order to choose the sequence. Performance optimizations may fetch files concurrently, but they must commit results according to the language-defined order.
This is the same boundary I described for canonical JSON as an AI intermediate representation: determinism is not “the output usually looks the same.” It means every observable ordering decision has an explicit rule.
The import root is a capability boundary
Composition also expands authority. A file that can import arbitrary paths can read host configuration, secrets, or unreviewed contracts and inject them into model context.
FACET therefore constrains imports to allowlisted roots. Absolute paths, .. traversal, URLs, paths outside those roots, and missing files fail with F601; cycles fail with F602. Resolution and merge occur in the hermetic part of the pipeline: no network access and no environment leakage.
This is more than path hygiene. The allowed import roots define the compiler’s read capability. The resolved contract should be explainable entirely from declared source files, compiler semantics, and explicit runtime input—not from whatever happened to exist elsewhere on the host.
Failing closed also keeps errors local. A missing policy module must not degrade into “continue without that policy.” A cycle must not be broken by silently dropping an edge. Both would produce a valid-looking contract with invalid authority.
What a merge receipt should expose
The specification defines deterministic resolution and merge. The next useful implementation artifact is a compact merge receipt emitted by inspection tooling:
{
"root": "main.facet",
"imports": ["base.facet", "review.facet"],
"effective": {
"vars.audience": {
"value_from": "review.facet",
"position_from": "base.facet"
}
},
"failures": []
}
This is an engineering proposal, not a claim that the current compiler already emits this exact schema. Its value is diagnostic: when a reviewer asks why a value won, the answer should not require replaying the compiler mentally.
The receipt would complement, not replace, source and policy hashes. As I argued in FACET policy semantic hashing, identity proves which effective semantics were used. A merge receipt explains how the compiler arrived there.
Its boundary is equally important: provenance does not make an unsafe merge safe. The compiler must reject ambiguous or forbidden composition first. The receipt explains accepted composition and structured failure; it is not permission to continue after an error.
Composition must be a language feature
AI systems often begin with one prompt file and acquire imports later. That transition looks small, but it changes the system from a document into a module graph.
At that point, deterministic merge semantics are load-bearing. Path capability, source order, facet cardinality, rule identity, override position, cycle rejection, and canonical output become one contract.
I want imports to make FACET systems easier to decompose without making them harder to reason about. The standard for success is simple: two conforming compilers given the same import graph must resolve the same contract—or reject it with the same failure class. Anything weaker is file loading, not language design.