$ fssg build --deterministic --validate |

Debug AI Contracts Before They Run: FACET Inspect Artifacts

FACET

An AI trace starts too late when the defect already exists in the compiled request.

I want to know what the system resolved, which values depend on which inputs, what context survived the budget, and which policy will govern effects before a provider receives anything. That is why I treat compiler inspection as a separate observability plane—not as a prettier debug log.

The current FACET compiler makes this plane concrete. Its inspect command can emit four structured artifacts:

facet-fct inspect --input support.facet \
  --ast ast.json \
  --dag dag.json \
  --layout layout.json \
  --policy policy.json

These files are not four views of the same blob. Each answers a different engineering question at a different compiler phase.

The debugging boundary belongs before inference

Most agent observability begins with spans: model calls, tool calls, latency, tokens, retries. Those signals matter, but they describe an execution that has already crossed the model boundary. A perfect trace can faithfully record a malformed tool contract, a stale dependency, an accidental context drop, or an over-permissive policy.

FACET uses a strict pipeline: resolution, type checking, reactive computation through the R-DAG, Token Box layout, then canonical rendering. Inspection exposes the intermediate state around that pipeline. This changes the first debugging question from “Why did the model do that?” to “What exactly did we authorize the model to see and do?”

That distinction is operational. Model behavior remains probabilistic. The compiled request boundary does not have to be opaque.

Four artifacts, four failure classes

Artifact Question it answers Typical defect it can reveal
Resolved AST What document did imports and normalization produce? unexpected merge, misplaced construct, wrong resolved value
R-DAG In what dependency order will variables compute? hidden coupling, missing reference, cycle, surprising order
Token Box layout What receives context budget, and what is compressed or dropped? critical overflow, low-priority context surviving over essential context
Effective policy What permissions and effect constraints actually apply? inherited access, policy drift, mismatch between prose and enforcement

The important word is effective. Source text expresses intent. A compiler artifact records the machine-resolved object that later phases consume.

1. The AST catches resolution mistakes

The AST is useful when a contract looks correct in one file but behaves differently after imports and deterministic merge. Instead of reviewing fragments independently, I can inspect the resolved structure that passed into type checking.

This is where normalization also matters. FACET defines a stable resolution phase, including UTF-8, NFC, and line-ending normalization. The resulting document hash belongs to that resolved source form. If two environments claim to run the same contract but resolve different structures, inference is not yet the problem.

2. The DAG makes computation order reviewable

Agent configuration often hides computation inside interpolation and helper calls. A flat document does not show the dependency graph clearly.

The FACET DAG artifact lists nodes, their depends_on edges, and a deterministic topological order. Unknown references and cycles have explicit failure surfaces (F401 and F505). More subtly, the artifact lets a reviewer see valid but unwanted coupling before execution.

For me, this is the difference between “the variables eventually evaluate” and “the evaluation topology is an inspectable part of the contract.” That topology should be reviewable in a pull request just like a database migration plan.

3. The layout proves what the model will actually receive

A context declaration is not evidence that content survived packing. The layout artifact reports the budget, total size, overflow, and per-section properties such as base size, final size, priority, minimum allocation, and whether the section was dropped, compressed, or truncated.

This turns context management into a diffable allocation decision. A test can reject a build when a protected instruction becomes shrinkable, when a retrieval section displaces a critical system section, or when a budget change silently alters the final package.

This mechanism complements the FACET lens trust model. Lens gas bounds computation; Token Box layout bounds context; policy bounds authority. Combining them into one generic “budget” would erase the failure domain each control is supposed to isolate.

4. The policy artifact separates written intent from authority

The policy view contains the effective policy and its hash. That makes policy review about the resolved enforcement object, not only about a friendly source declaration.

A useful CI check can compare the policy hash against an approved value, or inspect a structured diff when it changes. The hash alone does not explain whether a change is safe, but it makes silent semantic drift detectable. It also fits the broader requirement to bind execution to a versioned host profile and to preserve guard decisions in a verifiable provenance chain.

A compiler diff is not an execution trace

I would keep both.

A compiler inspection artifact describes the deterministic preparation boundary. An execution artifact records what happened after that boundary: guard decisions, effects, provider interaction, and resulting provenance. Conflating them weakens diagnosis because a preparation defect and an execution defect demand different remedies.

A practical review pipeline can therefore have two gates:

source change
  -> inspect artifacts
  -> semantic diff + policy/layout checks
  -> canonical request
  -> authorized execution
  -> execution artifact + trace

The first gate asks whether the proposed execution package is correct. The second asks whether the authorized run behaved within its boundaries.

What I would check in CI

I would not snapshot every byte blindly. Large golden files become noise. I would select invariants that represent authority and execution shape:

  • no unexpected R-DAG node or dependency edge;
  • stable topological order for critical variables;
  • critical context sections are never dropped or truncated;
  • layout stays within the declared budget;
  • policy hash changes require explicit review;
  • pure and exec modes produce the expected inspection boundary;
  • the document hash and host profile identity travel into downstream evidence.

This is a narrow mechanism, not a claim that inspection proves model correctness. It cannot predict a provider response, validate an external API, or replace runtime guards. The current command also computes its views using the compiler's present host implementation; reproducibility still depends on pinning the compiler revision and relevant host profile.

That limitation is exactly why the artifacts are useful. They state what can be known before inference without pretending to control what cannot.

Compile the question before asking the model

AI debugging becomes expensive when every defect is blamed on generation. Some failures are already visible in the contract's structure, dependency topology, context allocation, or effective authority.

I want those failures to be boring. A reviewer should be able to open dag.json, see an unwanted dependency, and stop the run. A build should fail because a critical section became droppable. A policy change should appear as a deliberate semantic diff rather than as a surprise tool call.

The model is still probabilistic. The package we give it can be inspected like software.

Sources

FACET AI CLI Terminal
facet@ai:~$