$ fssg build --deterministic --validate |

FACET Can Authorize a Side Effect. Your Runtime Must Compensate It

FACET

FACET can decide whether an operation is allowed before it starts. It cannot make an external side effect disappear after the operation succeeds.

That boundary matters whenever an agent performs more than one mutation. A run may reserve inventory, create an invoice, send a message, and then fail before the final step. The policy decision was correct. The execution was still incomplete.

I treat authorization and recovery as two separate contracts:

  1. FACET decides whether the operation may begin.
  2. The host runtime decides how the operation can be retried, observed, or compensated.

Trying to hide both responsibilities inside one “retry the agent” button creates duplicate effects and ambiguous state.

Start with the FACET boundary

FACET v2.1.3 requires tools to declare an effect class. The runtime guard evaluates policy before a guarded operation begins, and the execution artifact records the decision in a provenance chain. This gives the host a stable answer to a precise question: was this operation authorized under this contract and policy?

It does not answer a different question: did the remote system commit the mutation, and what should happen if the workflow later fails?

That is not a weakness in the contract layer. It is a separation of concerns. The FACET execution-layer thesis explains why model intent needs an external control boundary. Compensation belongs immediately outside that boundary, in the runtime that owns side effects.

Give every mutation an operation identity

Before calling a mutating tool, the host should derive an operation identifier from stable inputs rather than from a transient retry attempt:

operation_id = hash(
  run_id,
  step_id,
  tool_name,
  canonical_arguments,
  contract_hash,
  policy_hash
)

The exact fields can vary, but the identity must remain stable when the runtime retries the same intended mutation. A new intent must produce a new identity.

Pass that value to the downstream API as an idempotency key when the API supports one. If it does not, store the identity in a host-side operation ledger before dispatch.

This is the first hard rule:

A retry is safe only when the runtime can distinguish “repeat the same operation” from “start a new operation.”

AWS makes the same distinction in its guidance for idempotent APIs: callers need an explicit request identity because identical parameters do not always mean identical intent.

Record an operation receipt

After every tool call, persist a small receipt before advancing the agent loop:

{
  "operation_id": "sha256:…",
  "effect": "payment",
  "tool": "Payments.charge",
  "status": "committed",
  "external_ref": "pay_…",
  "contract_hash": "sha256:…",
  "policy_hash": "sha256:…",
  "provenance_head": "sha256:…",
  "compensation": {
    "tool": "Payments.refund",
    "status": "available"
  }
}

The receipt is not a second authorization system. FACET already records the guard decision. The receipt joins that decision to the external system’s result.

This gives the runtime three identities that must not be collapsed:

  • contract identity — what was compiled;
  • authorization identity — what policy allowed;
  • effect identity — what the external system actually committed.

The split mirrors FACET’s distinction between request and execution artifacts, but extends it across the network boundary.

Retry, resume, or compensate

When a run fails, I would not immediately rerun the model. I would inspect the ledger and choose one of three paths.

Retry

Use retry when the operation has no committed receipt and the same operation_id can be submitted safely. Timeouts are not proof of failure: the remote service may have committed the mutation before the response was lost.

Resume

Use resume when earlier operations are committed and the next step can continue from their receipts. The model does not need to rediscover what happened. The runtime already has the durable state.

Compensate

Use compensation when the workflow cannot continue and a previous committed effect has a defined semantic inverse: refund a payment, release a reservation, revoke a grant, or delete a draft resource.

Compensation is not rollback in the database sense. It is another side effect. It can fail, require authorization, or be only partially equivalent to the original state. The Saga pattern makes this explicit: a distributed workflow restores an acceptable business state through compensating actions rather than pretending that multiple services share one atomic transaction.

Compensations need FACET policy too

A compensation tool must not inherit permission from the original operation. Payments.charge and Payments.refund are different capabilities with different risks.

Declare the compensation as its own interface operation and evaluate it through the runtime guard:

@interface Payments {
  fn charge(input: ChargeInput) -> ChargeResult (effect="payment")
  fn refund(input: RefundInput) -> RefundResult (effect="payment")
}

The host can build the refund input from the committed receipt, but FACET should still decide whether the refund is allowed under the current effective policy. The compensation then receives its own operation_id, receipt, and provenance event.

This avoids a dangerous shortcut: treating recovery mode as a policy bypass.

A minimal failure algorithm

The host-side algorithm can remain small:

for step in plan:
  decision = guard(step)
  if decision != ALLOW:
    stop

  receipt = ledger.lookup(step.operation_id)
  if receipt.status == committed:
    continue

  result = dispatch(step, idempotency_key=step.operation_id)
  ledger.commit(result)

on terminal failure:
  for receipt in committed_receipts.reverse():
    if receipt.compensation.status == available:
      authorize_and_execute_compensation(receipt)

Real systems need timeouts, leases, reconciliation, and manual escalation. The invariant is simpler: never infer external state from the model transcript when a durable receipt can state it directly.

This pattern also complements replay-before-retry testing and the FACET CI gate. CI proves that contracts and deterministic tests are valid. Replay proves how a recorded run behaves. The operation ledger proves which real-world effects crossed the boundary.

Where the guarantee stops

This design does not make arbitrary side effects reversible. An email cannot be unsent. A published message may already have been copied. A physical action may have no meaningful inverse.

For those operations, the contract should expose the irreversibility instead of inventing a fake compensation. The runtime may require human approval, delay execution, use a draft/commit protocol, or accept that recovery means escalation rather than rollback.

That is the useful limit: FACET can make authority explicit and auditable. The runtime can make effects identifiable and recoverable where the domain permits it. Neither layer should promise that the world is transactional when it is not.

Sources

FACET AI CLI Terminal
facet@ai:~$