# Sovereign Evolution 4 Specification — Worker Process Isolation, Distributed Nonces, and Hosted CI Activation

**Status:** PROPOSED  
**Supersedes:** Evolution 3  
**Target Invariant:**  
`AGENT PROPOSES → CAIN AUTHENTICATES & VERIFIES → POLICY DECIDES → WORKER BOUNDARY ENFORCES → KERNEL LSM CONFINES → EVIDENCE COMMITS`

---

## 1. Objectives

1. **Worker Process Isolation for Hosted Gateway Tools**:
   - Currently, hosted `/mcp` tool bodies run in-process inside the FastAPI gateway process (`platform-gateway/main.py`), leaving them without Landlock or OS-level containment.
   - Evolution 4 will introduce an out-of-process Worker Daemon (`cain_worker_daemon.py`) communicating over restricted Unix Domain Sockets (UDS). Each tool request is dispatched to a disposable worker process initialized with Landlock ABI 8, seccomp-bpf, `PR_SET_NO_NEW_PRIVS`, and RLIMITs before executing user code.

2. **Distributed Nonce & Replay Prevention**:
   - Move beyond in-memory per-process `_CAPABILITY_NONCES` to prevent cross-process / blue-green replay attacks (T-S46-06).
   - Integrate an atomic, WAL-backed persistent nonce store with optimistic locking or lightweight PBFT consensus settlement.

3. **Cryptographic Principal Binding for Hosted Pipelines**:
   - Eliminate self-asserted `_cain_agent` and `_cain_tenant` HTTP parameters (T-S46-05).
   - Require signed `ActionEnvelope` or authenticated DID bearer tokens verified against pinned authority keys before admitting pipeline execution.

4. **Hosted CI Pipeline Activation**:
   - Configure an approved private Git remote.
   - Trigger the GitHub Actions workflow (`.github/workflows/ci.yml`) on the qualification branch.
   - Validate clean checkout, locked dependency builds, and publish third-party cryptographic test receipts to flip the `hosted_ci` release gate from `BLOCKED` to `PASS`.

5. **Production Distribution Decision**:
   - Establish a clear deployment path for MCPGate: either hosted as a reverse proxy on `mcpgate.online` or distributed as a compiled, auditable appliance.

---

## 2. Architecture & Modules Planned

| Module | Purpose | Security Controls |
|---|---|---|
| `cain_worker_pool.py` | Disposable process launcher for gateway tools | Landlock ABI 8, seccomp, RLIMIT_AS, RLIMIT_NPROC |
| `cain_distributed_nonce.py` | Cross-instance atomic replay cache | SQLite WAL / BFT consensus check, monotonic sequence |
| `cain_hosted_authenticator.py` | Cryptographic principal binding for hosted endpoints | Ed25519 DID signature verification, tenant isolation |

---

## 3. Exit Criteria for Evolution 4

- Zero in-process tool execution inside the gateway monolith.
- Cross-process replay attacks verified blocked across multiple worker instances.
- Hosted CI passing 100% of regression and adversarial tests on an independent runner.
- Release gate updated with verified production routing evidence.
