Skip to content

The Drift Log · Certifying that code does something

Verifying State Invariants Across Process Boundaries

19 November 2026 · 3 min read · 648 words · established

A crystal artifact under orange probe beams inside a test rig

In-memory test suites mask serialization drops and prototype loss across IPC boundaries. Real contract verification requires multi-process execution.

In-memory unit tests lie by sharing an address space. When two modules communicate within the same test runner, they share memory references, prototype chains, and garbage collection lifecycles. An object passed from a caller to a receiver does not undergo serialization, type coercion, or schema truncation unless you explicitly force it to.

In production, these components frequently run in separate processes—worker pools, isolated sandboxes, or child CLI invocations. At that process boundary, shared state disappears. If your verification relies solely on in-process test fixtures, your green suite only proves that the caller and receiver agree when they share memory. It does not prove that your state invariant survives the wire.

The Invariant That Vanishes Across the Wire

Consider a simple execution state: a task manager that dispatches jobs to isolated worker processes. In code, a job has an invariant: once marked FAILED, it must contain a non-empty errorDetails object containing a stack trace and a non-zero exit code.

In an in-memory unit test, a mock runner dispatches the job:

// The unit test passes because it shares the same object instance
const task = new JobTask({ id: "101", state: "PENDING" });
mockRunner.execute(task);

// Inside mockRunner:
task.markFailed(new CustomRuntimeError("SIGTERM received", 143));

// Back in the test assertion:
assert(task.state === "FAILED");
assert(task.errorDetails instanceof CustomRuntimeError);
assert(task.errorDetails.exitCode === 143);

This passes. But in production, the task object is passed to a child process via an IPC pipe, serialized as standard JSON:

{"id":"101","state":"FAILED","errorDetails":{"name":"CustomRuntimeError"}}

The exitCode property was non-enumerable on the error class. JSON serialization stripped it. The receiver receives a valid JSON payload, constructs an incomplete object, and evaluates downstream logic on an undefined exit code.

The state invariant was violated not because the business logic was wrong, but because the serialization boundary destroyed the contract.

Process Boundary Verification Without Mocks

To catch this class of failure, a test harness must exercise the exact boundary the code runs across in production. Mocks must be removed from the transport layer entirely.

An effective IPC contract test isolates both sides of the boundary into actual OS processes and validates three conditions:

  1. Schema enforcement on ingress and egress: Raw buffers passing through standard I/O or domain sockets must be validated against a formal contract on both ends before domain logic touches them.
  2. Lossless reconstitution: The hydrated object in the receiver must satisfy every invariant asserted on the sender.
  3. Failure symmetry: When one side of the process boundary violates the invariant, the other side must transition into a predictable, non-hanging error state.
// A true process boundary verification test
test("job failure invariant holds across child process IPC", async () => {
  const worker = fork("./worker-entrypoint.js", { stdio: ["pipe", "pipe", "pipe", "ipc"] });
  const payload = { id: "101", command: "trigger-timeout" };

  worker.send(payload);
  const response = await once(worker, "message");

  // Verify the hydrated state invariant directly
  assert.equal(response.state, "FAILED");
  assert.equal(typeof response.errorDetails?.exitCode, "number");
  assert.ok(response.errorDetails.exitCode > 0);
  
  worker.kill();
});

Running real child processes introduces overhead, but that overhead is the price of reality. If your code is designed to cross process boundaries, testing it in-memory is testing a scenario that never runs in production.

Where This Sits on the Ladder

At SHPBL, our verification doctrine treats in-memory passing tests as necessary, but insufficient. A component whose invariants have only been checked within a single process context earns no higher than a PROVISIONAL status.

Our certification harness executes code across its actual boundaries. The harness runs artifacts in isolated runtimes, pipes data over real IPC channels, and asserts that post-serialization state conforms to the published contract. If an invariant breaks during transport, the harness returns a FAILED verdict. If the harness cannot establish the required IPC environment, it reports INCONCLUSIVE rather than guessing.

You can see this ladder of verdicts defined in detail in our post on certifying software invariants across the verification ladder. You can evaluate how your own components hold up by running a free repository evaluation.

What to Do on Monday

Look at the places where your system forks, dispatches workers, or calls internal CLI binaries.

  1. Find one in-memory mock covering an IPC call. Identify the mock that replaces child process execution with an in-memory method call.
  2. Replace the mock with a real fork. Write an explicit IPC contract test that spawns the actual entrypoint in a sub-process and sends the serialized payload.
  3. Assert the invariant on the receiver's output. Verify not just that the sub-process exited with code zero, but that every property required by downstream business logic survived serialization and hydration intact.

This post supports the longer argument in Certifying Software Invariants Across the Verification Ladder.

Keep reading

Next in the log

The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.