# CAIN-42 E23 — Forensic Baseline (recorded before any behavior change)

**Method:** traced from source (call graphs, imports, routes, tests, evidence) — not from filenames.
Scope: E20, E21, E22, E8, RIG, OpenShell, MemVault, VIGIL, SCITT, MCPGate, the gateway, Frontier-20.

## 1. What E22 actually implements
`cain/e22/`: single-use `GovernedExecutionPermit`; `AuthorizationStateBinding`; governed
prepare/commit `GovernedExecutionTransaction` (staleness abort); execution + composition
certificates; composition engine; real RIG/OpenShell executors; replica quarantine; checkpoint
recovery + Byzantine recovery lab; multi-process transport harness; forensics; feature-flagged gate
(OFF|SHADOW|ENFORCING|EMERGENCY_DISABLED); invariants I51–I72; zero-CAIN-import clean-room verifier.

## 2. What E22 actually executes
In-process: RIG agent registration → single-use proof-of-possession token → consumption; E22 permit
consume; OpenShell `register_policy` → `execute_sandboxed_command(["echo", …])` (real kernel sandbox,
exit 0). Replay: deterministic on synthetic compositions only.

## 3. What E22 does **not** execute
- Not on the live gateway authorization path (module built, flag not enabled).
- No real multi-host transport (multi-process, same host).
- No five-product composition (only RIG→OpenShell).
- No distributed soak; no consensus/data-plane benchmarks.

## 4. Where E8 currently authorizes execution
`platform-gateway/main.py` `frontier20_gate` middleware (auth + tenant binding) and the E8
authorize/commit boundary. The live, unauthenticated enforcement decision point is
`POST /frontier/authorize` (`cain/substrate/cain_frontier_api.py`), which calls
`cain/frontier/gate.py::FrontierGate.evaluate` and returns `{allow, would_block, reasons, evidence_hash}`.

## 5. Where E22 can safely intercept authorization
At the `/frontier/authorize` handler: evaluate E22 in SHADOW against a binding derived from the same
request, record the comparison, and **never** change the E8 response. This is the E23 SHADOW layer.

## 6. Existing feature flags
`CAIN_E22_MODE` (cain/e22/gate.py, default SHADOW), `CAIN_FRONTIER_MODE` (shadow|enforce, gate.py),
`CAIN_FRONTIER_DATA`, plus gateway service-level flags. None currently enforce E22.

## 7. Existing distributed transport mechanisms
None wired to E20–E22. The repository has PBFT containers and `cain/substrate/cain_bft_consensus.py`,
and multi-region deploy records; E22's transport is `multiprocessing` fork (same host).

## 8. Existing state replication mechanisms
PBFT cluster containers on the host; `cain/substrate/cain_bft_consensus.py`. Not connected to E21/E22
state roots.

## 9. Replay limitations
E21 replay is byte-deterministic for governed transitions. E22's real composition is **not**
byte-reproducible: RIG mints random token ids, OpenShell produces random execution ids/attestation
digests and wall-clock timestamps. Recorded as `NONDETERMINISTIC_EXTERNAL`.

## 10. Determinism limitations
E21: deterministic. E22 synthetic composition: deterministic. E22 real composition: external
nondeterminism (above). No replay envelope exists yet.

## 11. Known fail-open paths
None identified in E22 in-process code: missing/unknown values fail closed. The gateway is unaffected
because E22 is not enabled. (E22 = NOT_DEPLOYED.)

## 12. Known fail-closed paths
Binding mismatch, permit replay/expiry, stale state at commit, quarantine, recovery rejection.

## 13. Security boundaries
E8 authorization boundary; tenant boundary (binding tenant checks); RIG capability scope;
OpenShell kernel sandbox; evidence (SCITT) append-only.

## 14. Cross-tenant boundaries
E22 binding rejects wrong-tenant; RIG scopes are per agent; MemVault namespaces per agent. Not yet
stress-tested under concurrency across the E23 path.

## 15. Remaining E22 gaps
G1 live enforcement not enabled. G2 no multi-host. G3 no 5-product composition. G4 real-composition
non-reproducibility. G5 no consensus/data-plane perf. G6 no soak.

## 16. Exact E23 implementation plan
1. **SHADOW activation** on `/frontier/authorize` (observe only) + divergence engine + report.
2. **Authority conservation** model + per-transition delta records.
3. **Real 5-product composition** RIG→OpenShell→MemVault→VIGIL→SCITT (all real APIs).
4. **Governance lineage graph** + machine validation.
5. **Five-phase transaction lifecycle** (REQUESTED…RECORDED + failure states).
6. **Replay envelope** separating logical / cryptographic / external determinism.
7. **Real TCP multi-process Byzantine transport** (N=4, quorum 3, signed messages, fault injection),
   labelled same-host (NOT independent failure domains).
8. **Chaos + recovery** campaign; **short soak** with exact measured duration.
9. **Invariants I73–I96**; clean-room verifier; CLI; tests; artifacts; publish; commit.
10. Honest classification of multi-host / soak / independent verification as NOT_MEASURED unless run.

**No production behavior changes until this baseline is committed.**
