# Designing out shared fate in an agent runtime

Author: Chris Chabot
Canonical URL: https://chabot.dev/blog/designing-out-shared-fate-in-an-agent-runtime/
Published: 2026-11-19

Why process-per-agent is affordable once idle agents unload, how to fence a single SQLite writer, and why a plan that resends history makes the cached prefix the cost model.

Put dozens of agents onto a single event loop and one long garbage-collection pause stalls every other agent in that process. The same goes for a CPU-bound tool step or a held SQLite lock. When sandboxes are scarce in the cloud, multiplexing agents in one shared process is still a reasonable trade-off, even if you spend a good deal of effort afterwards scheduling around blocking work. On machines you control yourself, nothing forces that topology.

Hosting agents inside a desktop application is simpler, until closing the window kills everything in flight. Putting a workflow engine such as Temporal beside an agent runtime buys durable execution at the cost of a second source of truth and another server to operate. A single shared process avoids both, yet its one real advantage, low memory overhead for idle agents, disappears once they unload. The cleaner design isolates failure domains and lets the resources that are actually scarce, memory and the prompt cache, govern the runtime.

In November 2026, I built a personal agent platform in TypeScript on Bun around that principle, running durable agent threads across my Mac and Linux servers. Each thread uses the durable harness from Pi, an open-source coding agent, to journal every turn and tool call in SQLite.

## Storing a thread in one file

Durability and host portability collapse into the same mechanism when a thread's entire state lives in one directory and one SQLite file. Each database runs in WAL mode with synchronous writes, including `F_FULLFSYNC` on macOS, because preventing a repeated external effect after a crash requires the intent to be durable on disk before the action runs.

Putting live state in a portable file creates a split-brain risk whenever two local processes overlap or a thread moves between hosts. Single-writer ownership rests on three fences: an exclusive `flock` to prevent concurrent local writers, a writer epoch verified inside every commit transaction to reject a stalled process that lost ownership, and a placement epoch advanced by compare-and-swap when ownership moves to another machine.

Once ownership is fenced at the storage layer, rewinding a thread is a fork inside the SQLite database, and moving a running thread between machines becomes a file operation with one commit point, leaving any stale copy on the old host as a fork rather than a competing writer.

## Process-per-agent with idle unloading

A launcher under `launchd` on macOS or `systemd` on Linux supervises one host daemon per user. That daemon handles scheduling and client connections, and never executes a model request or a tool, so a CPU-bound step or a memory leak in agent code cannot stall other threads. Each loaded thread gets its own short-lived runner process.

Process-per-agent is usually rejected for the memory cost of idle runtimes, and unloading removes that case. When a thread has been idle for a minute with no client attached, its runner exits and the thread shrinks to a directory on disk and one row in the daemon's wake table. Because scheduled timers live inside the thread's SQLite file, they survive unloading and move with the thread. An idle compiled runner still uses about 160 MB on the Mac, and more on Linux, against a 30 MB target, which makes that one-minute unload timer all the more useful.

Because runners are short-lived, commands started by tools run detached with their output and exit status journaled to disk, so a runner crash or an upgrade neither kills a long build nor loses its result.

## Admission by memory pressure

Static concurrency limits force a bad guess up front, either leaving a server underused or pushing a laptop into swap. Rather than gating runners behind a fixed slot count, the daemon admits threads according to measured memory pressure, reading macOS memory pressure levels and Linux PSI.

While the host has headroom, every ready thread gets a runner. Under warning pressure, idle threads are evicted first; under critical pressure, background work queues while interactive threads can still start. In a burst test with 100 threads due at the same moment and no slot limit, all 100 finished in 2.3 seconds on a Linux server and in 15 seconds on my Mac, which remained under memory warning throughout.

## The prompt cache as the cost model

Running always-on background agents on per-token API pricing turns a personal platform into an open-ended bill, so every model call runs through my ChatGPT subscription instead. The host daemon manages the session credentials, and a runner aborts at startup if an API key is present.

Because the subscription endpoint keeps no server-side conversation state, every turn resends the full thread history, and cached input costs roughly a twentieth of fresh input. Any mutation to an earlier turn or tool list breaks prefix reuse on every step that follows. Maintaining an append-only, byte-stable prefix therefore becomes the cost model for everything above the runtime, determining how updates to instructions, tools, and context enter a thread.
