$ fssg build --deterministic --validate |

How to Upgrade the FACET Compiler Without Silent Contract Drift

FACET

A compiler upgrade is a contract migration, even when every .facet file still compiles.

The dangerous upgrade is not the one that fails loudly. It is the one that stays green while canonical messages, policy decisions, dependency order, or context layout change underneath the same source. If the compiler defines the boundary between intent and execution, its revision is part of that boundary.

I therefore upgrade FACET with two compilers in the same pull request: the current pinned revision and the candidate revision. Both run against the same representative contracts and runtime inputs. The upgrade is accepted only after every semantic delta is explained.

This is narrower than a benchmark and stricter than “run the test suite.” It is a migration procedure for preserving contract meaning.

Start with two immutable identities

Do not compare an installed binary with a moving branch. Record both revisions and build both binaries explicitly:

OLD_REV=<current-pinned-commit>
NEW_REV=9b61d0659e18cc2b9df3fb8e08d069a81a7cb6c3

cargo install \
  --git https://github.com/rokoss21/facet-compiler \
  --rev "$OLD_REV" \
  --bin facet-fct \
  --root .tools/facet-old

cargo install \
  --git https://github.com/rokoss21/facet-compiler \
  --rev "$NEW_REV" \
  --bin facet-fct \
  --root .tools/facet-new

.tools/facet-old/bin/facet-fct --version
.tools/facet-new/bin/facet-fct --version

The current public repository revision is useful as a concrete example, not as a promise that it will remain the newest revision. A production repository should update NEW_REV deliberately and preserve the selected commit in its lock file, CI workflow, or build manifest.

The version string alone is not enough. The commit identifies the source actually built; the binary digest identifies the artifact actually executed. Record both when the build pipeline can do so.

Build a migration corpus, not a demo file

One minimal contract proves that the executable starts. It does not prove compatibility with the contracts your system depends on.

I use a small migration corpus that covers semantic surfaces rather than every production request:

Fixture Boundary under review
imports and overrides resolution and merge order
typed runtime inputs FTS validation and materialization
dependent variables R-DAG order and computed values
tight context budget Token Box keep, compress, and drop behavior
allowed and denied tools effective policy and guard decisions
negative @test cases stable refusal behavior and failure codes
generated interface host boundary and schema mapping

Each fixture includes sanitized runtime input and a short statement of the invariant it protects. The corpus should contain failures as well as successes. An upgrade that unexpectedly accepts a previously rejected contract is a semantic change, not automatically an improvement.

This is different from the broad CI gate in How to Add a FACET Contract Gate to CI. That gate checks every change with one compiler. The migration corpus compares two compiler identities before the repository switches from one to the other.

Export comparable artifacts

For each fixture, run deterministic preparation through both binaries:

for side in old new; do
  fct=".tools/facet-$side/bin/facet-fct"
  out="artifacts/facet-upgrade/$side/support"
  mkdir -p "$out"

  "$fct" build --input contracts/support.facet
  "$fct" test \
    --input contracts/support.facet \
    --output json \
    --pure > "$out/tests.json"
  "$fct" inspect \
    --input contracts/support.facet \
    --ast "$out/ast.json" \
    --dag "$out/dag.json" \
    --layout "$out/layout.json" \
    --policy "$out/policy.json"
  "$fct" run \
    --input contracts/support.facet \
    --runtime-input fixtures/support.input.json \
    --pure > "$out/canonical.json"
done

Use --pure for the comparison unless the fixture explicitly tests a bounded or volatile boundary. A compiler migration should not need live provider calls, mutable clocks, or network state to explain deterministic preparation.

Normalize only fields the artifact contract declares non-semantic. Never delete a changed field merely to make the diff quiet. If a timestamp, path, or build identifier is expected to vary, document that projection in the comparison script. Everything else remains evidence.

The four inspect views should stay separate. A changed AST means something different from a changed dependency edge, layout allocation, or effective policy. Debug AI Contracts Before They Run explains why collapsing them into one JSON diff makes review weaker.

Classify every delta

I use four buckets:

  1. No semantic change. Formatting or explicitly non-semantic metadata differs; the normalized artifact is equivalent.
  2. Expected correction. The candidate fixes behavior against the specification. The pull request links the relevant specification rule or repository change and updates the fixture expectation.
  3. Intentional migration. Contract behavior changes by design. Source, runtime input, adapter, or policy must change with it.
  4. Unexplained drift. The upgrade stops until the delta has an owner and a reason.

This classification prevents a common review failure: accepting a large golden-file rewrite because “the new compiler generated it.” Generated output is evidence, not authority. The candidate compiler is precisely what the migration is evaluating.

Some deltas deserve automatic escalation. I treat these as security- or behavior-sensitive even when the textual diff is small:

  • a tool becomes newly exposed;
  • a deny becomes allow or undecidable;
  • a critical context section moves, compresses, or drops;
  • message role or order changes;
  • a dependency edge changes evaluation order;
  • a formerly invalid input becomes valid;
  • document or policy identity changes without an explained semantic delta.

Canonical JSON gives stable bytes for comparison, but byte stability is not the whole review. A hash tells me that something changed. The artifact views tell me what changed.

Make the upgrade pull request reversible

The pull request should contain the compiler pin, migration corpus result, classified delta report, and any required contract changes. Do not mix it with unrelated prompt rewrites or provider migrations. A narrow change gives rollback a narrow shape.

The merge gate is simple:

both compiler revisions are reproducible
+ representative positive and negative fixtures ran
+ all semantic artifacts were compared
+ every delta was classified
+ sensitive deltas received explicit review
+ the candidate passed the repository's normal FACET gate
= upgrade may merge

Keep the old binary or reproducible build revision until the deployed system has passed its normal acceptance checks. Rollback should mean restoring the prior pin and prior compatible contracts—not editing generated JSON in production.

FACET's canonical output and stable hashes make this process possible, but they do not perform the judgment for us. The repository's v2.1.3 migration history itself shows why: parser, resolver, type system, layout, renderer, guards, and artifacts can evolve independently. “It compiles” observes only part of that surface.

The boundary condition

This workflow does not prove that model answers remain equally useful. It does not measure provider quality, latency, or task success. Those require a separate evaluation or experiment when the upgrade changes model-facing meaning.

It does prove something narrower and valuable: which deterministic contract surfaces changed between two compiler identities, and whether the team accepted each change deliberately.

I want compiler upgrades to be boring dependency changes. That does not mean trusting them. It means reducing them to pinned inputs, replayable fixtures, semantic artifacts, classified deltas, and a one-line rollback.

If an AI contract is compiled software, the compiler upgrade deserves the same migration discipline as the contract itself.

Sources

FACET AI CLI Terminal
facet@ai:~$