RFC-004: Determinism & verification

A service that reads the wall clock or the operating system's entropy cannot be replayed, and a test that runs only a model of the system proves only the model. Plurics answers the first problem by keeping I/O out of the core service crates so tests can run them over a deterministic simulator. It answers the second by proving each rung on real, unmodified programs before any model. This RFC specifies the simulator seam, crash points, the order of proof, the black-box conformance kit, the model-based suites, and the gates between rungs.

The Env seam#

The core services do no I/O of their own. They reach storage, time, and the network through traits that pluricsd fills in with the real system and tests fill in with a simulator. Env, in plurics-core, defines the simulator's surface:

pub trait Env {
    type Clock: Clock; // now_ns, wall_ns, sleep_until
    type Rng: Rng;     // a seeded stream, re-keyed per world at fork
    type Disk: Disk;   // files, fsync, rename
    type Net: Net;     // outbound connections
    type Spawn: Spawn; // named tasks

    fn clock(&self) -> &Self::Clock;
    fn rng(&self) -> &Self::Rng;
    fn disk(&self) -> &Self::Disk;
    fn net(&self) -> &Self::Net;
    fn spawner(&self) -> &Self::Spawn;
}

pub trait Rng {
    fn fill_bytes(&self, buf: &mut [u8]);
    /// An independent child stream, domain-separated by `domain`
    /// (a world lineage, say). Deterministic given the parent's
    /// seed and position.
    fn fork(&self, domain: &[u8]) -> Self where Self: Sized;
}

The host implements Env over the real operating system. The simulator implements it deterministically, in one process, from one u64 seed: no host clocks, threads, sockets, or entropy, and every map a BTreeMap.

PartBehavior
SimClockVirtual time. Sleeping advances the clock instead of waiting; idle periods jump.
SimRngxoshiro256**, seeded per run and forked per world
SimDiskAn in-memory file tree with buffered and synced tiers. A seeded crash drops unsynced writes.
SimNetIn-memory endpoints with stand-in responders and fault injection: partitions, delays, cuts
SimSpawnA cooperative executor with a pluggable picker, so a test harness chooses which task runs next

A lint enforces the seam. Outside the crates that touch the host directly (the host substrate, the runners, the virtual machine monitor, the daemon, the appliance's init, and the command-line tools), no production crate may use std::time::Instant, SystemTime, std::thread, std::net, tokio::time, thread-local and ambient rand generators, and getrandom, outside comments and strings. Another lint keeps every crate to its layer, so a service crate cannot reach around the seam through a crate that can.

Crash points#

A crash point is a named place where a test may kill a service:

plurics_core::crashpoint!("ledger.after-intend"); // a no-op unless armed

Names must match [a-z][a-z0-9_-]*(.[a-z0-9_-]+)+, checked at compile time. An unarmed point costs one relaxed atomic load. A test arms a point on its own thread with arm, arm_nth, or a custom hook. When execution reaches an armed point, it unwinds: the service's tasks are dropped, SimDisk discards unsynced writes, and the services restart from disk.

cargo xtask crashpoints lists every point in the workspace, sorted, so a campaign can cover them all. The crash-safety test arms the ledger and effect points while the effect service opens draft pull requests on a stand-in forge.

Outside-in verification#

A model-based test compares the system with a model someone wrote. If the model shares a mistake with the code, both agree, and the test passes. A real sqlite3 or rustc has no such blind spot. So every rung proves itself first on real, unmodified programs, under the real daemon, in real sandboxes. Model-based and property-based tests then harden the paths those programs cross. Every rung runs at least two unlike workloads, so no single workload shapes the core.

Workload 1: Unix programs. Real sh, plsh, sqlite3, and rustc run in closed worlds of a real pluricsd, under bwrap, on btrfs subvolumes where the host has them.

  • A closed world cannot read the host's home directory or ~/.ssh, and cannot reach 1.1.1.1.
  • A script inside a running world uses plsh over /run/plurics/port.sock to fork two worlds, run competing changes in each, seal one, verify it in a zero-grant copy, merge it, and discard the other (RFC-001).
  • The daemon freezes a live CPU-bound process with cgroup.freeze, thaws it, kills it with cgroup.kill, and reaps its whole subtree.
  • sqlite3 migrates a database in a fork, and discarding the fork rolls the migration back. rustc builds inside the world.
  • A world out of compute_ms cannot start a process, and a crashed daemon takes its worlds' processes with it.

Workload 2: agents over TLS. Real HTTPS upstreams speak the Anthropic and OpenAI streaming formats byte for byte over TLS 1.3. Credentials go in through plsh vault add and live only in the sealed vault.

  • Three agents run in parallel, each in its own closed world, through plurics-relay and the egress gateway. The gateway injects the real key, scrubs reflected secrets from the stream, and meters each response's usage fields into units with a JsonFieldMeterSpec.
  • A world that runs out of quota gets 402 and freezes, and plurics-tui shows it frozen. A plsh quota grant top-up thaws it, and the waiting agent retries the same turn.
  • The real keys reach the upstreams over TLS 1.3. No fragment of them appears in any world's environment, output, or files, or anywhere under the data root.
  • The winner is sealed, verified offline in a zero-grant copy, and exported with the real /usr/bin/git onto a branch, without touching the repository's working tree.
  • An unmodified agent binary found on the host boots inside a closed world.

Separate suites check four more boundaries: the sealed vault survives a daemon restart with no plaintext on disk, a CONNECT to an unlisted host gets 403, a nested execution cannot widen its parent's egress, and the gateway refuses an untrusted upstream certificate.

The conformance kit#

The workload suites drive the reference daemon. A rung gate needs more: proof that a different daemon, or the same daemon on a different runner, keeps the four laws. verif/conformance-kit builds plurics-conformance, a black-box suite that links no daemon code. It speaks JSON-RPC 2.0 over a Unix socket or over TCP after the PLURICS1 handshake, and it reaches inside a world only through the world's own port: /run/plurics/port.sock, or /dev/vport0p2 in a virtual machine. It reads Status.runner_caps and skips the checks a runner cannot support, such as terminals or freeze. Each check works in a fresh repository and discards its worlds, so the kit can run again and again against a live daemon.

LawWhat the checks establish
L1 ClosureA world sees no host home directory and has no network route; a base image hides the host's /usr; no host working-copy path leaks into a world
L2 DescentA port's grants only shrink; a world reaches only its own subtree; images and host binds stay confined
L3 CustodyA world forks, verifies, and merges its own children through its port; output streams live, and a terminal carries input and resizes; freeze, thaw, and kill act on a running process
L4 MonotonicityAn exhausted quota freezes and a grant thaws it; a world cannot release its own outbox, and a refused release leaves the outbox in place
StoreThe daemon's state stays consistent, the ledger verifies, and collection runs cleanly

Model-based suites#

Each suite drives the real composed crates and a small reference model side by side with a model-based testing library and compares them after every step. Each suite must also find its own planted bugs, called canaries. A suite that cannot find its canaries checks nothing. Every failure shrinks to a short witness and replays from a printed token.

SuiteDrivesCanaries, for example
mbt-world-ledgerThe world store, the SQLite ledger, the vault, and the effect service, composed over SimDiskA fork that shares its parent's working copy; a harness that resurrects a consumed linear approval
mbt-quotaThe quota service over the ledger: local and remote nodes, reservations, escrow leases, partitions, and broker restarts; concurrent rounds on real threads released by a barrier must linearizeCheck-then-act; an extend that skips ancestors; a partition that leaks a lease

Property suites cover the pure parts, including:

  • Protocol. Port grants attenuate as a lattice, provenance marks form a semilattice, PLURICS1 frames survive any read split and refuse any tampered byte, and metered units do not depend on how a response was cut.
  • World. The conflict algebra, history-independent tree hashes, receipt validity, and the line and JSON merge drivers.
  • Vault. Scrubbing leaves zero encoded occurrences, streaming scrub gives the same result however the stream is cut, mint capture, wildcard host binding, and sealed snapshots that refuse any flipped bit.
  • Ledger. EffectId is injective, and in_history agrees with a journal model.
  • Effects. The HTTP/1.1 codec frames chunked bodies at any split and refuses malformed framing, and an approval signs exactly what its preview shows.
  • Quota. All-or-nothing reservations, deterministic breakers, escrow conservation, and idempotent settlement.
  • Simulator. The same seed gives the same execution, a crash keeps every synced byte, and entropy forks are deterministic and domain-separated.
  • Monitor. Guest memory stays in bounds, the serial port matches a register model, and hostile kernel images are refused.

Rung gates#

Plurics moves down the stack one rung at a time (Architecture). The order is fixed. The pace is not: a rung starts only when the rung above has passed its gate.

Every gate has four parts.

  • Same programs. Both workloads and the conformance kit pass on the new rung. The pluricsd, plsh, and plurics-conformance binaries are the ones that passed on the rung above, byte for byte.
  • Same answers. A world sealed on the new rung has the same value identifier as the same world sealed on the rung above.
  • A canary. Each gate names one thing whose removal must make it fail. A gate that passes without the thing it claims to test tests nothing.
  • A measurement. Each rung reports fork latency and memory per world, and must beat the rung above on a number that a real workload depends on.
RungGateCanary
HostedBoth workloads pass on real programs. The model-based suites and the structural lints pass.Without bwrap or the vault, the run fails.
ApplianceThe image boots in QEMU to a serving pluricsd. A world's programs come from a value, not from the host's /usr. pluricsd runs under a system-call allowlist.The image has no shell outside a world. A system call outside the list kills the daemon.
VM worldsA world with a running database forks, memory included, and both copies keep serving. A kernel panic inside one world stops only that world.A counter held only in memory continues from the same value in parent and child.
Plurics kernelThe same daemon, monitor, and guest kernel run on it unchanged. The kernel is at most 20,000 lines, holds no device driver, and implements no Linux system call. A live fork is at least ten times faster than on KVM on the same machine.With hardware virtualization hidden from the kernel, no world starts.
Bare metalThe same suite passes for 72 hours on one named machine.Restarting the driver guest stalls I/O and nothing else.

The hosted rung has passed its gate. Pieces of the next gates are already built:

  • Appliance. Base images let a world's programs come from a value. pluricsd serves authenticated TCP, so a client can reach a daemon inside an appliance image. The image itself boots under QEMU with pluricsd behind a minimal init and no shell outside a world, and pluricsd serve --seccomp puts the daemon, and every world under it, behind a seccomp-bpf system-call allowlist. The gate has not passed yet.
  • VM worlds. QemuKvmRunner boots each execution in its own KVM micro-VM. The VM runner can also fork a running machine, memory included: a SQLite database with a live write-ahead log and a table held only in memory forks under load, and each copy then takes its own writes. The daemon does not offer that fork as a world verb yet.
  • Plurics kernel. plurics-vmm, a small virtual machine monitor in Rust, boots a Linux kernel and initramfs directly on /dev/kvm, with no QEMU. Nothing in the daemon uses it yet.

The measurements so far are for the hosted rung. On btrfs, a debug build of plsh bench fork --files 100000 --derived-mib 10240 --forks 25 measures p50 11.2 ms and p95 16.0 ms per fork of a world that holds 100,000 tracked files and 10 GiB of build output. The cost does not grow with the derived data. That fork copies files, not a running program's memory.