# How the audit contract is checked (/docs/ci-enforcement)



The auditability and replayability contract isn't only a promise in
prose. Pleach's CI checks each clause below. This page pairs every
clause with what's checked and what a broken clause looks like.

For the same checks by subsystem, see
[Release checks](/docs/audit-gates).

**Subpath:** `@pleach/core`

## The auditability contract [#the-auditability-contract]

The promise: every model call writes a typed, tenant-scoped,
reconstructable row to the event log (one per request when the
provider [audits every attempt](/docs/providers#one-audit-row-per-provider-attempt)).

| Contract clause                             | What's checked                                                                                                                    |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| The row shape is locked and versioned       | A change to the `AuditableCall` wire format comes with an `AuditRecordVersion` bump.                                              |
| Every row can reconstruct its configuration | Every event-log write stamps a manifest hash, the reference replay uses to recover the configuration active when the event fired. |
| The referenced manifest exists              | `SessionRuntime` wiring reaches the manifest write, so an event row points at a manifest that was written.                        |
| A referenced manifest survives retention    | A retention pass leaves no surviving event pointing at a dropped manifest.                                                        |
| Every event type has a redaction decision   | Each `EventLogInput` member has an entry in the scrubbable-fields allowlist.                                                      |
| Every event type is really produced         | Each `EventLogInput` member has a producer.                                                                                       |
| Event rows stay attributable to a tenant    | Core's event-log write paths carry `tenantId`.                                                                                    |

`AUDIT_RECORD_VERSION_HISTORY` records every additive version bump.
See [the AuditableCall row](/docs/auditable-call-row) for the
field-by-field shape.

## The replayability contract [#the-replayability-contract]

The promise: a recorded session re-executes deterministically against
an untampered log, and the chain makes any later edit detectable.

| Contract clause                     | What's checked                                                                                                   |
| ----------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| The hash-chain wire-in stays intact | `EventLogWriter` keeps stamping the chain that `verifyChainForChat` and `generateProof` read.                    |
| Canonicalization is versioned       | A canonicalization version constant pins the format. The verifier and writer share one canonicalization helper.  |
| The replay surface holds            | The `@pleach/eval` subpaths (`.`, `./scorers`, `./replay`, `./report`) keep their exports and test coverage.     |
| The graph stays a fixed lattice     | Every compiled cross-stage edge is on the allowed list. Replay can only reproduce a graph whose edges are fixed. |

`verifyChain` returns `{ ok: true }` or a row-precise
`{ ok: false, failedIndex, expected, actual, reason }`, so a broken
chain names the row.

See [Tamper-evident hash chain](/docs/hash-chain) for what the chain
proves, and [Eval and replay](/docs/eval-and-replay) for the replay
path that reads it.

## When the checks run [#when-the-checks-run]

CI runs the contract checks on changes to the packages. It also packs
each package on changes, installs it into a scratch directory, and
imports it from there. Nightly and weekly runs repeat that for core and
a subset of the packages, so a packaging break that no change touched
still surfaces between releases.

## Verifying the contract yourself [#verifying-the-contract-yourself]

A host embedding `@pleach/core` inherits the contract but not the CI.
You can verify the parts that matter in your deployment:

* **The chain.** `npx @pleach/core audit verify` checks the permission
  ledger and exits `1` if the chain is broken. `verifyChainForChat`
  checks a chat's event-log rows from your own code.
* **Your plugin.** `npx @pleach/core dev --plugin … --scenarios … --assert …`
  drives a battery and exits non-zero on a failed expectation.
* **Your install.** Run `npm pack` on your package, install the
  tarball in an empty directory, and import each subpath you depend on
  under `strict`.

For your own rules, see
[Add your own checks](/docs/audit-gates#add-your-own-checks).

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="Release checks" href="/docs/audit-gates" description="The same checks, organized by subsystem." />

  <Card title="AuditableCall row" href="/docs/auditable-call-row" description="The typed per-call row shape locked at AuditRecordVersion." />

  <Card title="Tamper-evident hash chain" href="/docs/hash-chain" description="What the chain proves and how to verify it." />

  <Card title="Eval and replay" href="/docs/eval-and-replay" description="The replay surface that reads the chain to assert deterministic re-execution." />

  <Card title="Config manifest" href="/docs/config-manifest" description="The content-addressable configuration snapshot the config-manifest hash points back to." />
</Cards>
