Compaction
Documentation

Apply

Apply is live: the gateway can optimize a real request before it reaches the provider. It is also deliberately hard to trigger by accident — record mode is the default, apply is explicit opt-in, and every change is recoverable byte-exact. There are two apply surfaces.

1 · Gateway apply (live requests)

compaction gateway --mode apply --policy deterministic-dedupe

Starting apply mode is the approval. On each eligible request the gateway applies deterministic optimization and forwards the result; the receipt records what changed.

Every live change passes a fail-closed gate chain:

  • an active, explicitly created authorization scoped to the tool
  • a narrow, non-global optimization scope
  • a source-validated candidate (never a guess)
  • content-free evidence recorded on the receipt
  • the original request body retained locally — recover the exact bytes at any time:
compaction gateway recover <id>

If any gate fails, the original bytes are forwarded unchanged — fail-closed.

2 · Trace apply (offline)

compaction apply trace.json --policy .compaction/runs/first-run/policy.json

Runs a reviewed policy file against a local trace and records the result. Part of the offline trace workflow — see Trace tools (advanced). Trace apply never touches live requests.

Boundaries

  • record mode is always the default — apply requires an explicit flag
  • every mutation is gated, content-free receipted, and byte-exact recoverable
  • Hybrid optimization requires more than apply mode — a Community account, the engine on this device, and compaction mode full
  • compaction mode observe returns to no model-visible mutation at any time