Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

111 KB
Raw Blame

harnessd

harnessd is the Harness daemon rebuilt around one rule: the process that keeps your agents reachable never fails because of a feature. It is a small supervisor, a lean core that owns sessions, terminals and turns, and separate service processes for everything else. The harness command and every app stay clients, the way docker is a client of dockerd.

This document records the design requested on October 3, 2026, and what has been built against it. It is the one document the rebuild is reviewed against. It changes as decisions land, and says which ones are still open.

Why

The daemon today is one Node process that does everything. Its startup is a single 5,200-line function in cli.ts; backendSocket.ts routes 54 request types for local and remote clients alike through about 30 callbacks that cli.ts assigns after construction. Nearly every subsystem is constructed on every start. The only gates are environment flags, sign-in, a connected device, or a state directory existing.

That shape turns any feature's bug into everybody's outage:

  • 2026-10-03. Opening a pane read the agent's whole transcript into memory. An 803 MB Codex rollout took 1.9 GB of heap on its own; the daemon died at its 4 GB limit seconds after every start, and every pane on the machine dropped about every ten seconds (PR #705). Nothing restarted it but the desktop app running harness start again, up to a minute later.
  • Optional features run inside the process that holds the sessions: the USB dial's ioreg probe every 2 s whether or not a dial was ever plugged in, warm claude/codex recap workers that the default recap mode never uses, the search indexer over every transcript, one viewer process per harness, headless Chrome for shared viewers, a 15 s backend poll for tab channels, and a 10-minute check that keeps the managed grid on its pin.
  • Work grows with history, not activity. Besides attach, whole histories are read by a client's session_get (before it windows) and sessions_list (to count lines), every engine's recap but Claude Code's and Codex's, the Cursor watcher, the first search pass, Change agent's handoff, the Codex resume repair, and the database engines' first load: OpenCode, Kilo, Hermes and Devin read every message of a session in one synchronous query on the core's event loop.

PR #684 moved Companions and Memory out as a library. harnessd finishes that direction for the whole daemon and gives the extracted parts somewhere to run.

Rules

  1. Stability first. No feature runs in the process that owns sessions. A service can crash, hang or leak without dropping a pane, losing a question or blocking input.
  2. Work follows activity, never history. No hot path (attach, a request, a turn ending) may read in proportion to a conversation's length. Reads are bounded and streamed; caches have budgets; queues have limits.
  3. Nothing waits on a service. The core starts, serves and stops without any service. An unavailable service fails only its own capability, with a retryable error.
  4. One contract, narrow authority. Services use the same authorized local API clients use, with a scoped role. No unrestricted extension RPC; every addition to the contract is reviewed on its own (CONTRIBUTING.md).
  5. Port proven logic. The normalizers, tmux handling and transport carry hundreds of measured fixes. The architecture is rebuilt; that logic moves with its tests.
  6. No flag day. The desktop app, web, phone, hn, engine hooks, the device and the backend keep working throughout. Protocol changes are additive.
  7. Learn from the daemons that work. Where a well-run daemon has solved a problem we have, we take its answer unless we can say why ours differs (What other daemons do).

Processes

The design the rollout below works toward. What runs today, and what changed since the last release, is in 2026-10-04-harnessd-before-after.md.

 desktop app · hn · `harness` · engine hooks                         phone · web · other machines
  │                                                                                         │
  │ unix socket + 127.0.0.1:18473                                             relay server  │
┌─┴─────────────────────────────────────────────────────────────────────────────────────────┴────┐
│ │ harnessd                     supervised by launchd / systemd (opt-in)                   │    │
│ │                                                                                         │    │
│ │  ┌────────────────────────────────────────────────────────────────────────────────┐     │    │
│ │  │ MASTER · the supervisor                                                        │     │    │
│ │  │  does        start · readiness and heartbeat watch · memory budget             │     │    │
│ │  │              restart with backoff · safe mode on a crash loop · updates        │     │    │
│ │  │              status file · log caps                                            │     │    │
│ │  │  never       feature code · network · sockets                                  │     │    │
│ │  └────────────────────────────────────────────────────────────────────────────────┘     │    │
│ │              │ runs and watches it; restarts it in about a second                       │    │
│ │  ┌────────────────────────────────────────────────────────────────────────────────┐     │    │
│ │  │ CORE · the part that must never go down                                        │     │    │
│ │  │  agents      registry · create / fork / restart / resume / stop / close        │     │    │
│ │  │  terminals   tmux backend · discovery (5 s) · live streams · reboot restore    │     │    │
│ │  │  engines     hooks server for 13 engines · launch commands                     │     │    │
│ │  │  transcripts attach from the end · live tail · history pages                   │     │    │
│ │  │  turns       working / idle · model chips · activity · recap excerpts          │     │    │
│ │  │  input       what you type, delivered to the pane, confirmed                   │     │    │
│ │  │  questions   agent waiting on you · your answer back                           │     │    │
│ └─►│  local API   the one door · request gate until start-up is done                │     │    │
│    └────────────────────────────────────────────────────────────────────────────────┘     │    │
│                │ local API, service role: the same door, narrower rights                  │    │
│    ┌────────────────────────────────────────────────────────────────────────────────┐     │    │
│    │ SERVICES · their own processes, light ones sharing a host                      │     │    │
│    │  relay       backend link · sign-in · E2EE pairing · trust group · P2P         │◄────┘    │
│    │              sharing · view other machines · machine list  (self-hostable)     │          │
│    │  devices     driver host: the round unit (USB) · Wi-Fi device · more types     │          │
│    │  models      Grid · local models (Ollama, LM Studio, llama.cpp) · API keys     │          │
│    │  search      session index across all engines                                  │          │
│    │  viewers     harness viewers · Store installs · headless Chrome (shares)       │          │
│    │  teams       tab channels · mailbox · orchestrator                             │          │
│    │  workspaces  worktrees · git and PRs · project folders · file previews         │          │
│    │  companion   characters · growth          ┐ a package since #684;              │          │
│    │  memory      coding memory · recall       ┘ nothing starts them today          │          │
│    │  light host  usage · machine resources                                         │          │
│    └────────────────────────────────────────────────────────────────────────────────┘          │
│                                                                                                │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
   your agents live in tmux: they keep running through every restart above

The master (harnessd/supervisor.ts) is the process harness start launches (harness __harnessd). It claims the pid file, keeps its children running and stops them. It contains no feature code, opens no network connection and holds no sockets, so there is almost nothing in it that can fail. It is generic: it knows a service by its manifest entry, not by what it does.

The core owns everything a session needs and nothing else, and it binds the listening sockets itself. Passing them through the master would buy a refused connection's worth of time during a core restart, which every client already retries, at the price of complexity in the one process that must stay simple; on Linux, systemd socket activation can hold them later without the master doing anything (see Supervision). If the core crashes, hangs or outgrows its memory budget, the master starts a new one. Clients reconnect as they do today; agents keep running throughout, because they live in tmux, not in the daemon. A core whose master is gone stops, so nothing is left holding the port.

Services are separate processes, each started from the same bundle as harnessd <service> with its own process title. Each connects to the core's local socket like any other client, under the service role, and reconnects with backoff when the core restarts. A service never writes to tmux, never reads the registry file, and never holds a credential the core can hold for it. Isolating a feature costs a process: an idle Node process is about 40 MiB, and one that loads today's 4.4 MB bundle peaks near 125 MiB. So the risky services — relay, devices, viewers, search, models — get their own processes, and the light ones share one host.

What the core owns

Today harnessd
Registry, stopped agents, session sync core
tmux backend, terminal streams, discovery, restore after reboot core
Engine hooks (/api/hook/*) and hook installation core
Transcript tailing, normalizers, turn lifecycle, activity, model chips core: the transcript service
Recap excerpts (turn_summary, agent_recent): the last answer, cut at turn end core, with the turns
Input queue, delivery confirmation, questions on the pane core
Agent create, fork, restart, retarget, resume, stop, close, purge, checkpoints core
Worktrees, project folders and pre-trust, git and PRs, file and media preview workspaces
Local socket and loopback API, /api/local-ws core
Backend link, sign-in token, control-plane proxy, machine list, E2EE, pairing, trust group and device key log, peers, remote relay pool, P2P, sharing relay
USB dial, cable fleet, device link, Wi-Fi device, firmware push, dial↔window bridge, voice router devices
Grid access, local models, fleet RPC, API connections models
Session search, external sessions, open sessions search
Harness viewers, verdict watcher, Store installs, interactive and shared viewers (headless Chrome) viewers
Tab channels, team service and mailbox, orchestrator teams; since replaced by Agent Messages, a service in the edge host (2026-10-12), and the orchestrator, an experiment in a process of its own
Token and account usage, machine resources light host
The worktree sweep (deletes idle worktrees on a timer) removed: cleanup becomes an app action (#711)
Companion, Memory their own services, off until used
CLI self-update, hn update, log trim master
Recap model mode (SUMMARY_MODE=model) and its warm worker pool removed
Requests kept only to refuse retired features (pair brain, the creatures desk) removed once no shipped app sends them

Questions stay in the core because they are session state: a question answered through one interface must resolve for every other one. A recap excerpt is a few hundred characters cut from the turn the core just finished, so it stays with the turns; the model that once rewrote it is gone.

Services

Relay — anyone can host one

The relay service connects this machine to its phone, the web and other machines through a relay server. Harness runs one (harness-api.autonomous.ai), and the server's code is in this repository (backend/), so anyone can run their own and point their machines and apps at it.

  • End-to-end encryption makes the server untrusted by design. Sessions travel sealed between paired devices (CPace pairing, the trust group); the relay forwards frames it cannot read. Trust comes from pairing, not from whoever runs the server.
  • The address is a setting everywhere. The daemon reads it from BACKEND_WS_URL and WEB_URL today; it becomes a harness setting and a field in the desktop app, and the phone's QR onboarding carries it, so a phone paired to a self-hosted relay never asks Harness for anything.
  • Sign-in is pluggable. A Harness account is the default. A self-hosted relay can use its own accounts (OIDC) or none: paired device keys are already an identity the trust group verifies.
  • Features are capabilities the relay advertises. Forwarding, presence and pairing rendezvous are the minimum. Desk sync, the Store, tab channels, shares and the device key log are optional, and the apps hide what a relay does not offer instead of failing.
  • The protocol is documented — adapter-ws for machines, web-ws, device-ws and observer-ws for clients — with versioned frames, and TURN for peer-to-peer terminals is configurable.

Devices — a host for drivers

The round unit is the first device type, not the only one. The devices service hosts one driver per device type: usb-dial (the round unit over USB serial), autonomous-device (Wi-Fi and LAN), and whatever comes next. A driver finds its devices, owns their transport — one owner per physical port — and speaks to the core only through the local API: agent, turn and question events in; input, answers and agent actions out. Firmware push, the dial↔window bridge and the voice router are shared utilities drivers use. Adding a device type adds a driver and its manifest capabilities; the core does not change.

From today's code to there (mapped on 2026-10-04). The device code is about 7,200 lines: cable/ 5,800, device/ 1,200 and devices/ 100, beside about 6,000 lines of tests. Another 400 lines wire it inside runForeground. Every call the core makes into it is guarded already (outsideConsumers('devices')), so an exception there costs one call. A native crash in the serial port code, or a leak, would still cost the whole core. Three couplings decide the order:

  1. The dial's host also routed turns between machines (until D0). ⌘K and the window's voice route sent a turn through DaemonCableHost.sendTurn. It knew a local agent from a remote one by the agent lists it learned from the fleet (DeviceFleet over DeviceLink, the lane to the owner's other machines). With the dial off, ⌘K would have answered "no agent list yet". So the router, and the fleet and machine list it reads, left the dial's host first, as a fleet service of their own that ⌘K and the dial both use.
  2. The Wi-Fi device rides the relay's encrypted sessions. AutonomousDeviceService and AutonomousDeviceDirect pair, attach and receive through BackendSocket, so they move with the relay, after it has a boundary of its own.
  3. The window bridges are the desk's, not a driver's. Selection, visit, form and the voice route are shared by the dial, the Wi-Fi device and ⌘K. They stay in the core, and drivers reach them through CoreApi.

The steps, each a pull request with its end-to-end proof:

  • D0, the fleet on its own (done). The machine list refresh, the pinned peers, DeviceLink, DeviceFleet and the turn router across machines are services/fleet.ts, started by the service host. The router is services/fleetRouter.ts: which machine an agent is on, the turn, stop, answer, model switch, recap and fork sent there, the refusal for a machine whose last request did not come back, and lastRouted. Its local side is the core's own doors, new CoreApi members (turns, questions, and the runtime profile, model switch, models and fork on agents). ⌘K's route_task (with its ranking, moved out of runForeground) and route_send, which the voice route commits through, reach it through ports.fleet (FleetPort, with fallbacks). The dial's host is handed the same router until D1, so the person's last turn is one fact for all three; with the fleet off it routes this computer alone. The machine list cache itself is still built early in runForeground, for the local /api/machines answer and the trust group, and the lane still signs in and seals with the relay's credentials, handed to the service until they move with it (D3).

    Two machines, end to end (cli/e2e/fleet.e2e.ts). Two real daemons are two machines on one account (e2e/harness/fleet.ts): each has its own computer id, machine id, E2EE identity and signed-in session, and A is linked to B the way harness link connect leaves them. They are signed in to a fake backend on 127.0.0.1 (e2e/harness/fakeBackend.ts): the machine list, each daemon's adapter socket, and a blind device relay, so the encrypted session between the machines is the real one. A's dial is a fake dial on a pseudo-terminal (e2e/harness/fakeDial.ts) speaking the cable protocol with the daemon's own frame codec; HARNESSD_TEST_DIAL_PORT is the one test switch in the daemon, because a pseudo-terminal is not on the USB bus that discovery reads. Proven: ⌘K on A picks B's agent and delivers to it; the dial on A stops, answers and forks on B; B going away is refused ("did not come back") and B coming back is used again; and A's fleet service failing costs A only its routing. Every URL setting points at the fake, and the harness refuses a daemon whose environment names any other server.

    Still to decide: the lane follows the dial. A's lane to the other machines opens only when a dial attaches (onDialAttached → fleet.online()) or selects a machine. With no dial, ⌘K weighs this computer's agents alone and never sees another machine's, so cross-machine ⌘K works today only with a dial plugged in. Opening the lane for ⌘K changes what the backend counts as a commander watching each machine, so it is a decision, not a refactor.

  • D1, the dial behind the boundary, in process. Its first part is done: the dial reaches the fleet's router through the core's port, never holding it. ports.fleet carries the router's whole routing contract (FleetRouting, core/api.ts): the agent lists, which machine an agent is on, the turn, stop, answer, model switch, recap and fork sent there, the person's last turn, and the lane (hasLane, online, select, release). The host reads the port at every call. It keeps a router of its own for this computer and asks it when the fleet cannot answer (off, or the call failed): the routing members FAIL rather than make an answer up. Refusals are answers, not throws, so they do not count against the fleet. ⌘K's send is routeSend; the dial hears remote cards through the port too. D1's remainder (done, 6 October): services/devices.ts owns the serial ports, the dial's host, its log, the window bridges, the fleet (router and lane, now one of its parts), the voice router and the harness_devices_* requests. The core reaches it through DevicesPort, each member with its fallback: the desk, the swarms, what is unread, focus, what was seen, the cards teed to it, settings, the window bridges' answers, ⌘K, and stop. The devices reach the core through CoreApi: this computer's ids and name, the sign-in (the transcriber and the lane ask the core for a token; the dial's host no longer holds a session manager of its own), a pane's activity line, recent turns, sending and stopping a turn, answering, the runtime profile and models, fork, and the windows: the dial_* frames (clients.sendLocal, only the devices' own types), a bridge's ask (clients.sendToWindow), whether a window is there, and whether a dial is watching (clients.dialWatching, which the core keeps for the cards it makes). The pane writer lock and the card text moved into the core (core/deviceInput.ts, core/cardText.ts). Inside, each part answers for itself (services/devicesGuard.ts): a dial throwing costs ⌘K nothing, a fleet that cannot start costs the dial nothing. ⌘K's answers are sent off the window's ordered chain, so they can come from another process without holding the window's typing.

  • D2, the dial in its own process (done, 6 October). harness __service devices (services/devicesProcess.ts; the core's side is core/devicesLink.ts) runs the dials, the window bridges, the fleet's router and lane, the voice router and the Devices tab. The ten routing reads stay in line: the router is in the same process as the dial, and what it reads of the core (the agents with their names and models, this computer, the sign-in, whether a window is there) is a copy asked of the core as the dial's tick or ⌘K builds a list. The core never waits on the process: what it tells it is a notice, what it asks (⌘K, the Wi-Fi device's walk) has a deadline and a fallback, and ⌘K is answered off the window's ordered chain. The core keeps what the windows said, says it again when the process connects, and keeps whether a dial is watching; a dial attaching is shown the open questions and the working tiles. One device failing is that device's alone: its session's faults and a flood on its port drop it, with a wait before its port is looked at again (cable/cableFleet.ts). The original sizing: Sized on 2026-10-05 against the viewers' process (#775): it is several times larger. Viewers cross the link in about five calls; the dial needs about fifteen from the core (the desk, swarms, unread, focus, seen, settings, status, the six kinds of turn and question card teed to it, the remote cards) and about twenty-five back (the local doors, seven window frames, seven window bridges that wait on a person, and the routing). About ten routing reads are synchronous today (which machine an agent is on, whether it is known, who it is, a send's answer, whether it can speak a question, the total, the lane), read by the session while it builds a frame. Over a socket they need a mirror the core keeps current, or the session made asynchronous where it reads them; the window's dial_status at handshake needs the same. The Wi-Fi device borrows the dial's focus walk and scroll, which would cross too. The serial ports belong to harness __service dial; the same handlers answer. A crash in the native serial code then costs the dial alone, and the master starts it again. It is proven end to end with a fake dial on a pseudo-terminal, speaking the cable protocol (the fake dial and the two-machine fleet from D0's proof are there to reuse).

  • D3, the Wi-Fi device, with the dials (done, 6 October). Its service, its relay, its receipts and streams and its Store preparations run beside the dials in the devices' process, on a link of their own (services/wifi.ts, services/wifiProcess.ts; the core's side is core/wifi.ts and core/wifiLink.ts). Its sessions stay the gateway's (step 10): the core hands their requests on, in order, and seals each answer to the session it came from only while that session is still the identity's device. What the core reads of it in line is kept in the core from what the service tells it: which devices said hello (presence), which agents' transcripts and tool events it follows (only those are sent across, and an agent's lines from the moment the core types the device's prompt), and the focus revision a window's late selection is checked against. What it reads of the core in line (the agents with the Store's evidence on them, whether a window is there) is asked before each request and each move of the window's focus. A prompt is asked, not told, so the reply carries what the pane's lock said of it as it took it, as before; the Store's agent is made by the core, with the device's fixed launch arguments. Its process restarting is its devices' too: the gateway keeps their sessions, the core hands them back, and each is told to resync (the documented way back after a daemon restart) and served on without a new hello; its receipts are in its journal. Proven by e2e/wifiDevice.e2e.ts (a fake device through the fake relay, beside two fake dials) and by e2e/deviceCompat.e2e.ts, which hears the same answers and events from main's build.

  • The devices on demand (done, 6 October). The devices' process starts only once there is a device: about 72 MiB at idle that a computer with none no longer pays. The core asks the master for it (harnessd:want, protocol 4; a core of protocol 3 or older never asks, so the master starts it as that core binds) when a dial's port is in /dev (a USB modem's node, looked for every two seconds, the dial's own scan's cadence, with no ioreg and no open), when a Wi-Fi device is paired (the gateway's pairings or its direct links, read once at start), when a Wi-Fi device's session comes through the relay or a pairing begins, and when a request needs it (the Devices tab, ⌘K), which waits for it as an experiment's does (core/devicesWake.ts). What a Wi-Fi device sends meanwhile is held, in order, and handed on once its service has been resumed. Once started it stays, as every service does; stopping it when the last device leaves was measured and left out (the PR says why). HARNESSD_SERVICES=devices still starts it with the daemon, and none runs it in the core. Proven by e2e/devicesOnDemand.e2e.ts and e2e/wifiDevice.e2e.ts.

  • The viewers on demand (done, 12 October). The viewers' process (the harness viewers and the Store) started with every daemon and idled at about 96 MiB, and few harnesses have a viewer: 1 of 14 on one real machine, 2 of 35 on another. It now starts once something needs it (protocol 5; a core of protocol 4 or older never asks, so the master starts it as that core binds; a newer core under an older master asks for a process already running, which changes nothing). A harness here asks for it: an agent with a DSH in the registry as the core starts, or attached since. So does a request: the Store's, a harness's create or restore (the Store prepares its workspace and launch), a client's rendered frame, and a client's viewer stream, whose frames the core holds, bounded, until the process first connects (core/viewersLink.ts). And so does its own work at start, checked by the core: the Store puts the release's own harnesses in place (the Model Manager, Devices, the Harness Monitor, Memories) when the installed index does not have this build's revisions, which the release build computes for the core (build-bundle.mjs), since a create is checked against that index before the Store is asked and memory and models run those packages' files; and the viewers stop the viewer servers an earlier process left in their ledger (core/viewersWake.ts). The desktop still asks dsh_list with no click in three cases: the welcome composer on an empty tab, a restored Store tab (and its one-minute refresh), and a pending fork link. Measured idle with no harness, from release bundles on an isolated daemon, after the first start had put the bundled harnesses in place, three runs each, median: 526 to 531 MiB resident in all over seven processes before, 434 to 440 over six after, the viewers' 86 to 88 MiB gone. Proven by e2e/viewersOnDemand.e2e.ts.

Models

Grid is how Harness runs local AI models with Codex, Claude Code and the other engines, from the app. It is essential, so it starts by default, but it runs as its own service: a failed model download or a crashed local model server must never take sessions down with it.

Workspaces

Everything about the folder an agent works in: worktrees (created with their branch, the ignored files .worktreeinclude names copied in), project folders and their pre-trust, git and PR status, file and media previews. It runs on the machine that holds the folders, because a phone or another computer can start an agent there, but not in the core: preparing a folder fetches, checks out and copies, and is slow and can fail. A client asks workspaces for a folder, then creates the agent in it; the core only ever receives a path. Cleaning up is the person's decision, made in the app with a preview — workspaces lists what is left and removes what it is asked to, to the Trash (#711).

Companion and Memory

Both are a package since #684, and nothing starts them today. In harnessd they are two services that are off until used, and Memory never depends on Companion.

The local API

The core serves the contract documented in cli.md: a machine_select frame, then request frames with a requestId answered by <type>_result, events for agents, turns and activity, and the binary terminal channel. Nothing about it changes for existing clients.

Services use the same socket and frames with three narrow additions, each reviewed on its own:

  • A service role in machine_select (role: "service", its name and a per-boot token the master passes it). The token proves the process is the one the master started; it grants only the capabilities its manifest entry lists.
  • Request ownership. A service declares the request types it answers (search answers session_search and session_tail). The core routes those requests to it and returns its answer. If the service is down, the client gets SERVICE_UNAVAILABLE with retryable: true instead of a hang. Security checks (owner-only, sealed-only, local-only) run in the core before any routing, so moving a handler can never widen who may call it.
  • Scoped reads. Services that need more than events get bounded reads, never a file path: transcript_read returns at most a window of one agent's transcript from an offset, and only to a service whose manifest grants it.

Events reach services through the same subscription clients use, with bounded queues. A slow subscriber's queue is cut at its limit and it is sent resync; the core never blocks on it.

Clients and the daemon agree on a version range: an app newer or older than the daemon is told so, the way the Docker CLI negotiates its API version and tailscale warns when the daemon differs.

Supervision

Built for the core (harnessd/, spawn protocol 2): readiness apart from binding, with a start-up deadline; the heartbeat watch; the exit-code contract; exit reasons; crash-loop safe mode; the heap and resident budgets; the status file; log trimming in the master; and updates with probation from ready and rollback — a broken update that falls into safe mode rolls back too. HARNESS_NO_MASTER=1 runs the core on its own; harness start -f runs the master in the foreground, as launchd and systemd do. A core on its own (that switch, or a core an older release's own handoff started) hands an update to a master on the new build, which judges it (core/updateHandoff.ts); it no longer spawns and judges a core like itself. What follows is the design the master is held to; the parts still to build say so.

  • Ready is not bound. The core says bound when its port is listening and ready when start-up is done and the request gate opens. Start-up has a deadline: a core that binds but is not ready in time is killed and counted as a crash, because a start-up that hangs after binding otherwise looks healthy for ever while every request waits at the gate. Probation for an update counts from ready. A core from before ready (protocol 1, after a rollback) is held to bound alone.
  • Alive is more than a timer. The heartbeat proves the event loop turns; it also carries the longest event-loop delay since the last one, and next the age of the oldest waiting request, so a core that is slow to the point of useless is seen before it is hung. Every child's last exit is recorded with its reason: crashed, hung, did not bind, not ready, memory, update, stopped.
  • Exit codes are a contract. 75 restarts at once onto the bundle on disk (an update). 78 means stop for good — this computer was removed from the account, or it is connected from another one — and the master stops with it. Any other exit, 0 included, is a crash and is restarted: Node also exits 0 when its event loop runs out of work, and an outside SIGTERM to the core must not take the daemon down.
  • Backoff that forgives, and a way out of a loop. Restarts back off from 0.5 s to 30 s and the delay resets after a minute up, timed on a monotonic clock so sleep and clock changes do not skew it. Three crashes inside five minutes start the core in safe mode — the updater alone, so a published fix can still arrive — instead of the same crash again. When safe mode's own time runs out (15 minutes, counted while the machine is awake) the master tries a normal core again, and an update leaves safe mode at once. A core that falls into safe mode by itself, because its start-up threw, tells the master so; the master reports it, and rolls back an update whose first core does this. Chrome and VS Code break their loops the same way.
  • Memory: a clean restart before a fatal one. The core runs with an explicit V8 heap limit, and the master restarts it cleanly when its heap passes 75% of that limit, or its resident memory passes a larger ceiling that also covers buffers V8 does not count. With the two limits equal, V8's own out-of-memory abort — which skips every cleanup — would come first, as it did on October 3.
  • Status without the core. The master writes a status file (each child's state, restarts, last exit and its reason, safe mode) atomically on every change, so harness status can say what happened when nobody can ask a core that is crash-looping.
  • Logs have caps. The master trims the daemon's log, which a supervised core no longer does itself; per-process files come next with their own caps, written by the master as each child's stdio so no line is lost in a pipe.
  • Ordered stop, deadlines owned by the master. Services, then the core, then the master, each with a deadline the master enforces; harness stop waits for the master instead of killing it after a fixed three seconds. A fast stop leaves agents running in tmux; that is the only kind.
  • Updates. The core's updater stages a bundle and exits 75; the master restarts the core on it, on probation from ready, and rolls back if it fails. When the master's own code changed, it re-executes itself in the gap between the old core's exit and the new core's start, as Syncthing's monitor does — re-executing with a core running would cost that core its channel. Built (harnessd/reexec.ts): in place, keeping its pid, so launchd, systemd, the pid file and the app's owner check never see the master change; a probe of the bundle's own master first; a marker that rolls back a master that died after re-executing. A newer build staged while the last is still on probation is judged on its own, and a master that starts on an update no master finished judging (it died mid-update) judges it. Next: bundles move to versioned directories behind one pointer, so a swap is one rename. A version that was rolled back is not offered again.
  • Something supervises the supervisor. On macOS a launchd user agent (registered through SMAppService, which asks the user once) and on Linux a systemd user unit run the master in the foreground and restart it; the desktop app then watches instead of respawning, so there is one supervisor per machine. tmux must stay out of the daemon's process group and cgroup — a systemd stop kills everything in the unit's cgroup by default, and launchd kills a dead job's process group — so agents keep running when the daemon stops, the way containerd shims keep containers. Built as an opt-in, harness service install (see Rollout); not installed by default, and the desktop app still runs harness start, which then goes through the platform.
  • Versioned spawn protocol. Master and core may differ during an update. Messages are only ever added, unknown ones are ignored, and each side states its protocol in its first message.

For services the master reads a manifest bundled with the release:

{ "name": "devices", "args": ["service", "devices"], "enabled": "auto",
  "memoryMiB": 256, "capabilities": ["events:agents", "events:turns", "requests:dial_*"] }
  • Start. The core first, then enabled services, without waiting on any of them. enabled is on, off, or auto (a probe the service runs itself and exits cleanly from when it has nothing to do, such as no device ever paired).
  • Restart. Exponential backoff from 1 s to 60 s. After five crashes in ten minutes a service is parked as failed and reported, never respawned in a tight loop, and retried slowly and after every update. The core is always restarted.
  • Budgets. Every child runs with an explicit heap limit from its manifest and the memory rules above.
  • Lifetime. Children watch their spawn channel and exit when the master goes, so a crash never leaves orphans holding the socket, the serial port or a pid file.

Bounded work

Every read on a hot path is bounded by what it serves, never by a conversation's length. Built:

  • Attach walks back from the end of a transcript to the last turn opener and streams forward from there (attachTranscript.ts, merged in #705). It reaches past the opener only for the few older records the chips, a continuing /goal and calls still answering need, at most 64 MiB. A session attached again while it is tailed hands its tail over byte-exact.
  • History pages (session_get) are read by walking back from their cursor to the turn they start in, holding only the page, at most 32 MiB; a line index kept as the file grows counts lines (sessions_list) and finds Codex's line cursors (transcriptPages.ts).
  • The live tail reads what it fell behind on a chunk at a time, and a file rewritten in place with more history than one batch should hold is attached again from its end instead of replayed.

Claude Code and Codex are done. The order for the rest is OpenCode, Grok, pi, then every other engine; database engines follow the same rule with a query for the last turn instead of the whole message list, and their reads move off the event loop. A test fails the build if core code makes a whole-file read (tailFile(…, Infinity), readFile on a transcript, an unbounded createReadStream) of an agent's history.

Names and files

Thing Today harnessd
Daemon process node cli.js __run harnessd (master), harnessd core, harnessd <service>
Command harness harness, unchanged: harness start, stop, status, logs manage harnessd
State ~/.harness/cli/data/ unchanged until the core is stable; then ~/.harness/harnessd/ with a staged, verified move and the old path kept for rollback
Socket ~/.harness/cli/data/daemon-<port>.sock unchanged path, bound by the core
Loopback 127.0.0.1:18473 unchanged
Status /api/status, from the core the core's, plus the master's status file beside the pid file
Logs ~/.harness/cli/data/harness.log trimmed by the master; later one capped file per process

harnessd joins harness and hn as a command name in the Naming System; it is not a product name. Prose says "the Harness daemon".

Compatibility

Client What must keep working
Desktop app LocalCliDiscovery finds the socket and port, runs harness start, reads the pid file; the owner check in process_responsibility.dart sees the master as the daemon.
Web and phone Through the relay, now terminated in the relay service: same frames, same E2EE type sets and keys.
hn The same local frames and terminal channel.
Engine hooks notify.mjs posts to the loopback port as today.
Harness devices The same cable protocol, now spoken by the device's driver, with one owner of the serial port at a time.
Backend The same adapter-ws connection, from the relay service.
Older installs An auto-update from a daemon before harnessd starts the new core the old way, without a master, which works unchanged; the master arrives at the next harness start. Next: such a core hands itself to a master. A downgrade stops cleanly: the old harness stop signals the master named in the pid file.

Rollout

Each step ships on its own, keeps every client working, and can be turned back by configuration while it beds in.

Done so far:

  • The end-to-end harness (cli/e2e, npm run test:e2e): the real daemon under a throwaway home, a private tmux server, fake Claude Code and Codex engines that bind through the real hooks, and a client that speaks the desktop's protocol. It reproduced the October 3 crash on main and found three more defects, now fixed and kept as tests.

  • The master at 100% coverage, tested end to end: crash, hang, a start-up that hangs after binding, a SIGTERM from outside, a crash loop into safe mode and out again, killed master, clean stop inside harness stop's grace, memory budget with backoff, and the status file throughout.

  • The request gate (BackendSocket.holdRequests/openRequests): requests that arrive while the core is still starting wait, each connection's in order, instead of being refused or dropped.

  • Bounded reads for Claude Code and Codex: attach (#705, merged), history pages and line counts, and the live tail, each proven under a 256 MiB heap against a 300 MiB transcript that runs main out of memory.

  • The recap model mode is gone, with its warm worker pool: a recap is the answer's own excerpt.

  • Updates that fail stay failed. A build the master rolls back is remembered and never staged again; a newer build moves past it, and harness update installs it on purpose. Before, a release that passed its canary but crashed the core restarted every machine on it once a minute. Tested end to end on real release bundles served from a local manifest (e2e/update.e2e.ts): one kept, one rolled back and left alone, then a newer one kept.

  • The core boundary, steps 1 to 12 (#716, #717, #721, #723, #725, #727 and part 7): runForeground is down from 5,306 lines to 2,775. 31 modules under cli/src/core hold terminal control, session events, the normalizer table, input, questions, the turns (activity, heartbeats, recaps, the event funnel, stop hooks, the agy backstop, cancel), the transcripts (attach, ingest, last turn), the agent lifecycle (forget, bind, discovery, launch, new panes, adoption, create, fork, the pane swap, retarget, restart, stop, purge, resume, close) and the engines' hooks (which agent a hook belongs to, Cursor's Task hooks, installing every engine's hooks). Each file is held to 100% by npm run test:core, which CI runs; the unit and e2e suites pass at every step.

  • Services in process (step 13, parts 8 and 9): cli/src/core/api.ts holds the boundary itself. CoreApi is what a service may ask of the core; CorePorts is what the core asks of services, each port filled by its service when it starts and null while it is off, so the core never waits on one. Session search, the DSH viewers, models (grid access, the model pictures on agents' frames, the keystroke prewarm) and workspaces (branch names, the worktree sweep) stand on it under cli/src/services, held to 100% beside the core. A service holds no credential: minting the grid name and the access token go through CoreApi.account. The teams (part 16) are reached the same way: the socket's prompt scopes are installed as ports.teams through the service host, so a fault there cannot cost a message its write. The devices are guarded where the core calls them (part 12); moving them, the relay and sharing into their own processes is the next phase.

  • A failing service cannot take the core down (part 10, cli/src/core/serviceHost.ts). A service whose start throws is left off and the core starts without it. Every call into a port is guarded and answered with a fallback declared beside the port's contract, so the funnel, restore and frame building carry on; a request's failure goes back to that one request as SERVICE_UNAVAILABLE with retryable: true. Five failures in sixty seconds switch the service off until the daemon restarts: it is stopped, its port goes null and its socket bindings are unbound. The funnel calls the teams and the device service the same way. HARNESSD_TEST_FAULTS injects faults, and e2e/services.e2e.ts proves on the real daemon that agents bind, run their turns and come back after a restart with every service failing to start or failing on every call.

  • Lean processes (2026-10-05). Node parses all of the file a process starts on, and every daemon process started on the whole 4.4 MB cli.js: at idle, from the bundle, the master took 164 MiB resident and each service 118 to 131, 839 MiB with the core. So the build bundles the master and the services a second time on their own (cli/src/leanEntry.ts), split into files so that each process loads only its own code and the shared code it imports, and appends them to cli.js as a comment (cli/scripts/lib/leanBlock.mjs). A master started on cli.js writes them into lean/<sha>/ in the data folder, checks they answer the probe a re-executing master asks, and re-executes on them, same pid; it starts the services from them too (cli/src/masterProcess.ts, cli/src/harnessd/leanBundle.ts). Each master claims the folder it runs from, and a folder is removed only once no live master claims it, so two builds on one data folder never take each other's. It is only ever an optimisation: a service starts from cli.js whenever its master's lean files are gone or changed, cli.js is no longer the bundle they came from (an update the master did not re-execute on), or it died twice from them before beating (cli/src/harnessd/leanServices.ts); lean-off in the data folder turns it off for a master launchd or systemd starts; and the release script refuses a lean bundle whose master does not answer its probe or whose modules do not load (cli/scripts/check-lean-bundle.mjs). The environment is read without zod (cli/src/config/envFields.ts), which every process loads and which cost each 15 to 19 MiB. The CLI runs from cli.js, and the core did until its own entry (below). The release is still the one cli.js the updater downloads, verifies and swaps. Where Node cannot re-execute (before 22.15), the master runs from cli.js and the services still from the lean bundle; without a lean bundle that answers, everything runs from cli.js, as with HARNESSD_LEAN=off. Measured at idle, the median of three runs: the master 55 MiB resident (16 MiB physical footprint, from 113), search 77 (35), the viewers 69 (29), workspaces 61 (20), the teams 66 (26); 465 MiB with the core, against 839. e2e/lean.e2e.ts proves it on a real release bundle.

  • The core's lean entry (2026-10-06). The core parsed the whole cli.js too: every command of the CLI, the master's code and every service's. It now starts from an entry of its own in the lean bundle (cli/src/leanCoreEntry.ts, harnessd-core.mjs), which loads 3.1 MB of code against cli.js's 4.6. It is built apart from the master's and the services' (cli/build-bundle.mjs), its files named core-*: built as one more entry of the same build, the files they shared held the parts only the core uses, Node's http and net among them, and the master and every service paid about 5 MiB each for that, more than the core saved. The master hands the core the cli.js it read the bundle from (HARNESSD_CORE_SCRIPT), and to everything the core hands on that is its script: the hooks it installs, the CLI in agents' panes, a successor on an update. The core starts from it by the services' rules (cli/src/harnessd/leanServices.ts): from cli.js when the lean files are gone or changed, cli.js is no longer the bundle they came from, it died twice from them before beating, HARNESSD_LEAN=off or lean-off. The supervisor judges an update's first core as before, whichever file it started from, so the release script checks that the core's entry loads (cli/scripts/check-lean-bundle.mjs). A master hashes cli.js and the lean files before every process it starts, and now reads each a piece at a time (cli/src/harnessd/reexec.ts sha256File): read whole, the buffers stayed in the master at idle. Measured at idle from the bundle, two paired runs of three samples each against the build before, medians: the core 135 MiB resident against 159, and 88 MiB physical footprint against 95.5; every other process within 1.5 MiB of before; 638.5 MiB resident in all against 663.5, and 286 MiB footprint against 298.5.

  • Services in their own processes (step 4; on by default since 2026-10-05, HARNESSD_SERVICES=none to run them inside the core's process). The master runs each service as harness __service <name> beside the core (cli/src/harnessd/services.ts): it restarts one that crashes, with backoff from 1 s to 60 s; kills one that stops beating (hung) or outgrows its memory budget (leaking); and parks one that ends five times in ten minutes, trying it again after thirty. A service reaches the core through its local socket under a service role, with a token the master gives both on every boot (cli/src/core/serviceLinks.ts, cli/src/services/process.ts). The core routes the service's requests to it and answers SERVICE_UNAVAILABLE at once while it is down (the Store's requests wait for its process to come back instead, as long as a start: 2026-10-17), holds what it must hear (a purge's forgetting) until it is back, and never waits on it in line. Search is the first: cli/src/services/searchProcess.ts runs the same index on a core API built in its own process. e2e/serviceProcesses.e2e.ts proves on the real daemon that search killed, hung (stopped), leaking or crashing on every start costs search alone: the core never restarts and agents keep working.

  • The viewers in their own process (HARNESSD_SERVICES=viewers, alone or beside search). The core asks the viewers two things in line while it builds a frame: an agent's DSH context and where its viewer pane forwards. So the process tells the core each agent's answers whenever they change, and the core keeps the last ones (cli/src/core/viewersLink.ts). While the process is down, frames carry what the core last knew. Attach and detach are notifications; a detach is held until the process hears it, and the process asks for every agent with a harness each time it connects. The viewer servers are the process's own: a crash costs only them (the new process stops the ones the old one left running, then starts its own), and a core restart no longer restarts them. cli/e2e/viewersProcess.e2e.ts proves it on the real daemon with a real harness agent's viewer.

  • Workspaces in their own process (HARNESSD_SERVICES=workspaces, alone or beside search and the viewers). The core only gives workspaces commands: name the made-up branches, and sweep when its timer says. So nothing is kept or held for it while it is down, and frames keep their branch names meanwhile, because the core reads them itself (cli/src/core/workspacesLink.ts). The sweep's timers stay in the core and its rules (#711) are unchanged. A sweep the core decides while the process is down is skipped, never replayed. When the process starts one, it asks the core for every agent at that moment and sweeps only with that answer, and a sweep still going is never joined by a second. cli/e2e/workspacesProcess.e2e.ts proves on the real daemon that a stop, a hang, a kill, a crash loop and a core restart each cost workspaces alone. It also proves that only the process renames a branch and the new name reaches the agent's frame, and that the sweep removes an idle unused worktree, keeps one an agent works in, and skips the one decided while the process was down.

  • The teams' prompt scopes in their own process (HARNESSD_SERVICES=teams, alone or beside the others). A message's write needs one thing from them at once: the undo for a write that fails. The core makes it itself, so a write never calls into the process and teams can never cost a message its write. Every change (a message prepared or taken back, a prompt started, keys typed into a scoped terminal, an agent forgotten, a question answered) is numbered and kept in the core until the process acknowledges it (cli/src/core/teamsLink.ts). On each connection the process says what it applied and gets the rest, applied in order, once, at the time each change happened; a new core, a fresh process or a gap starts it over. The team features read an agent's scope from what the process last reported, and read no team, never a wrong one, while a change to it is on its way. cli/e2e/teamsProcess.e2e.ts proves on the real daemon that a stop, a hang, a kill, a crash loop and a core restart each cost teams alone: every message is written, and a change made meanwhile lands once the process is back.

  • Services answer their own requests (core/serviceHost.ts route). A service declares the frame types it answers (<NAME>_REQUESTS) and returns their handlers from its start. The socket hands such a request to it before its own switch, with who asked (Asker: local, owner), and never waits in line for it. While the service is off, its requests are answered SERVICE_UNAVAILABLE, not UNSUPPORTED, which the desktop reads as "update the CLI": that is why the types are declared before the start that could fail. A handler that throws, rejects or replies with nothing is answered SERVICE_FAILED and counts toward switching the service off. The same handlers answer in a service's own process, where the asker travels beside the payload, never in it.

    • Moved out of the socket: search's session_search and session_tail, whose port lost the two members only the apps called, and the store's dsh_list, dsh_install, dsh_update and dsh_remove (services/store.ts, a service with no port). Five BackendSocket slots went with them.
    • Then models' grid_models_list, models_list and the Model Manager's grid_fleet_models_list, _download, _start and _stop (services/models.ts), with two more slots. A request reaches a service without its connection, so the grid commands (grid_fleet_run, grid_fleet_cancel), each its connection's job, stay in the socket with their handshake (grid_fleet_capabilities), as does the grid_models_changed push, sent to each window in the form it asked for.
    • Adding a request to a feature now touches only that feature's service.
  • A floor under every engine's whole reads (lib/transcriptTail.ts tailFileCapped). Claude Code and Codex read pages. Every other engine still read its transcript whole, in three places that run for everyone: attach (at every daemon start), the last-turn read (at every turn's end) and session_get. Each now reads at most the newest 64 MB, from the end. One huge transcript of any engine could otherwise run the core out of memory at start, again at every restart, and take every agent's daemon down with it: the October 3 crash, on another engine.

    • Past the cap, attach folds the newest part and says so in the log. The last turn is read from the newest part. session_get shows the newest history, and its reply carries truncated: true.
    • Known limit: Cursor's watcher still re-reads Cursor's transcript whole on each change. Cursor rewrites it in place, and the watcher finds what is new by comparing whole files, so a cap there would replay everything. It needs pages of its own, as in the rollout's step 2.
  • The walls, written down and checked. The rules live in AGENTS.md files that coding agents read: cli/ and one per layer (src/core/, src/services/, src/harnessd/). A CLAUDE.md beside each imports it, so Claude Code reads the same rules as Codex. On its own, Claude Code reads AGENTS.md only from v2.1.277, and only when no CLAUDE.md is in the working directory or above it. cli/src/architecture.spec.ts enforces the walls in the unit suite. A service may reach the core only through core/api.ts. The core may import a service, cli.ts or the socket only for types. The master may use only Node and its own folder. runForeground and backendSocket.ts have size budgets.

  • What the daemon survives (e2e/robustness.e2e.ts): hostile local clients, strangers and malformed bodies at the hook door, a pane killed from outside, a turn that outlives a restart, a turn that ends while the daemon is down, and garbage state files at start.

  • The request switch's cases go to their owners (cli/src/core, each file at 100%): session_get and sessions_list (transcripts/history.ts, where the four database engines now share one windowing path), agents_list (agents/list.ts), agent_recent (turns/recaps.ts), terminal_info and theme_set (terminals/requests.ts), question_response (questions.ts), message (input.ts), cancel (turns/cancel.ts), agent_delete and the purges (agents/lifecycle.ts), agent_close and agents_cleanup_preview (agents/close.ts), agent_update (agents/update.ts), agent_handoff_prepare (agents/handoff.ts), and the launches with their receipts (agents/launches.ts). Each case is one call into a slot cli.ts binds, and every reply is unchanged, field for field, but one fix: session_get asked by agent id now reads the conversation's own id. backendSocket.ts is down from 3,482 lines to 2,524.

  • Platform supervision, opt-in (harness service install | uninstall | status; cli/src/harnessd/platform.ts, cli/src/lib/serviceCommand.ts, cli/src/lib/platformDaemon.ts). A launchd user agent (~/Library/LaunchAgents/ai.autonomous.harness.harnessd.plist) or a systemd user unit (~/.config/systemd/user/harnessd.service) runs <managed node> ~/.harness/cli/cli.js __harnessd in the foreground from login on, and starts it again after any exit but a clean one (launchd KeepAlive with SuccessfulExit false and a 10 s ThrottleInterval; systemd Restart=on-failure). Both append to harness.log, which the master trims. It is opt-in: nothing changes for anyone who does not run it, and the desktop app does not use it yet.

    • One supervisor per machine: once installed, harness start asks the platform to start the master instead of spawning a second one, and every stop (stop, logout, reset, update) asks it to stop it, since a signal from the CLI would read as a crash. The master records the platform in its status file (HARNESSD_PLATFORM, set by the definition) and harness status shows a supervisor row.
    • tmux outlives the daemon: the agent sets AbandonProcessGroup, the unit KillMode=process. Run against a real systemd 259 (a Fedora container), tmux built with systemd support put every pane in a scope PartOf the unit, so a stop job (systemctl --user stop, restart, disable --now) ended every agent whatever KillMode said. So the CLI stops the master with a signal through systemd (systemctl --user kill --kill-who=main) and lets it exit cleanly; the same container showed the agents outliving stop and uninstall, and a killed master restarted. A tmux server in a scope of its own (systemd-run --user --scope) would make stop jobs safe as well: a core change, still open.
    • Tested against a temporary home and fake launchctl and systemctl alone on PATH, never the real ones; plutil -lint checks the plist, and systemd-analyze verify the unit where it exists. e2e/cli.e2e.ts runs harness start, stop and status from the installed bundle on the managed Node: without the service no platform tool is asked and an agent outlives a stop in tmux; with it, fakes that run the master from the definition (both platforms, on any computer, through HARNESSD_TEST_PLATFORM) see start and stop go through them; another data folder's definition is ignored.
  • The master re-executes itself on the bundle on disk (cli/src/harnessd/reexec.ts, at 100%). Before, an update replaced the core and left the master on its old code until something restarted it. Now, in the gap before any core starts (an update's exit 75, a rollback, a bundle replaced by hand), a master whose code is not the bundle on disk replaces itself with it (process.execve).

    • In place, not by handing over to a fresh master: launchd and systemd follow the pid they started, and to them a master that exits is a job that ended; the pid file, harness stop and the desktop app's owner check follow it too. Only in the gap, with the services stopped and reaped first: no core loses its channel and nothing is orphaned. The agents live in tmux, out of reach of it all.

    • The state handed on (HARNESSD_RESUME, kept from every child): restarts, the last exit, the update on probation, the pid file's claim, and re-executions since a core last came up (after three, the master keeps its code). The status and /api/status gain the master's version and that count.

    • Exec gives up the old master as a fallback, so: a probe (harness __harnessd-probe) asks the bundle's own master first, and one that fails it fails the update, rolled back and remembered in update-rejected.json like a failing core; a bundle from before this answers "Unknown command" and is never started as a probe. And a marker (harnessd-reexec.json), removed once the new master's first core is up: a master that starts and finds one left by a process that is gone rolls back and moves onto the bundle before. Without process.execve (before Node 22.15 and 23.11) the master keeps its code, as before.

    • e2e/reexec.e2e.ts, on real bundles: the pid stays through every swap while the master's version follows the bundle; the core and an agent at work carry on; a build whose master fails its probe is rolled back and not staged again; one whose master dies after re-executing is rolled back at the next start; every core is the master's child throughout. With a released bundle (MIGRATION_FROM): an older master supervises the newer core an update brings until it restarts, and this master runs an older bundle's core without re-executing on it.

    • Round 40 (e2e/updateHostile.e2e.ts, on real bundles): the update path under hostile conditions, since it is how every fix reaches every machine. A link that drops mid-download, a download cut short, a release published broken, a manifest whose hash or version lies, a newer build published while the last is on probation, an update with both agents mid-turn, a build whose master answers its probe but whose core crashes at start, and a master killed mid-update. After each, the daemon runs a working build under its master, both agents are back and take a turn, nothing is left in the install or the data folder, and a build that failed here is remembered. Defects found and fixed:

      • A newer build staged while the last was still on probation, or still starting, was taken for that update failing: rolled back, and remembered as bad. A fix published soon after a release was refused that way by every machine still judging the release. The master now judges the newer build on its own when the bundle on disk changed since the core started (SupervisorDeps.bundle).
      • A manifest naming an older build's bytes under a newer version installed it; it came up, still reported the older version, and installed itself again, a restart a minute. The canary now requires the version the manifest names (scripts/upload-cli.sh already checks the same).
      • A build that failed its canary, or whose bytes did not match the manifest, was downloaded again at every check: 13 downloads in 13 seconds at a one-second interval, once a minute on every machine in production. Such a build now waits two intervals, then four, eight, up to an hour; a new entry in the manifest is tried at once, and a dropped link at the next check.
      • A master killed mid-update (a crash, a kill, a power cut) left the update unjudged: the next start ran it unwatched, and a build whose core crashes at start crash-looped for good, with no updater running to fix it. update-pending.json now records the sha256 of the cli.js it put in place, and a fresh master started on that bundle puts its first core on probation.

      With DISKFULL=1 the install and the data folder share a 96 MB disk image, filled while the build downloads, between the canary and the swap (the test holds the spawn lock the updater waits on), just after the swap, and while a build that crashes is rolled back. More defects, all fixed:

      • Staging was not all or nothing: a write that failed left its temporary file (up to a whole bundle, on a disk already full) behind, package.json was rewritten in place, and a failure after cli.js was swapped left a mixed bundle with no pending note, which the retry then backed up over the old build's backup. Everything new is now written beside what it replaces first, and only renames touch what runs; backups are hard links, so a swap needs room for one copy, not two.
      • The spawn lock's owner record, cut short by a full disk, was never reclaimed: every update, start and stop after it waited 45 seconds and gave up, long after the space came back. The writer removes its own lock, and a record that names no one is debris after five seconds.
      • The master's re-execution marker, unwritable on a full disk, threw out of a promise and would end the master between cores. It keeps its code instead, and judges the new bundle itself.
      • A canary that could not be written was reported as the build failing; it is now retried at the next check without downloading again. A rollback that could not write the rejected list forgot the build (the rollback frees the room the list needs, so this takes a disk filled again at once, as by a log storm); its pending note now names the build until the list can be written.

      Left after round 40, and fixed since (round 40b), each with a test that fails without it:

      • A core that could not start for want of room on its disk (listen ENOSPC claiming its socket) was read as the new build failing: rolled back, the rollback freeing the room the build before needed, and a good build remembered as bad. A failure that names the disk (ENOSPC, EDQUOT, EROFS) is no verdict on the build now: the master keeps the update on trial and starts the core again, backing off, without counting it as a crash (namesTheDisk, harnessd/supervisor.ts). End to end, the build staged just before the disk filled is kept once there is room, nothing rejected.
      • A handoff whose teardown threw stayed on the old build, its servers half closed, the new bundle staged and never judged. The handoff is its own core module now (core/updateHandoff.ts, out of runForeground, 89 lines shorter): under harnessd every step is tried, one that fails is said and passed, one that hangs is given up on after 15 s, and the core exits 75 regardless. End to end, a build whose teardown throws still hands over, and the next build is kept.
      • Downloads had no deadline of their own: a link that stalled without dropping held the check on undici's five-minute body timeout, and a trickle for as long as it lasted. A transfer now gives up after a minute without a byte or a quarter of an hour in all (ADAPTER_UPDATE_IDLE_MS, ADAPTER_UPDATE_DEADLINE_MS; the manifest at most 30 s and a minute), and the next check tries again. End to end, a download that stalls halfway is given up on and the build lands.
      • A turn that ended while the disk was full, on a data folder that had never run a project, was lost: OrchestratorService.roleOf, asked at every turn's end, makes its state folder to read it, and the mkdir threw out of the transcript's line handler; once open, the orchestrator watches every frame sent, and the same mkdir threw out of every send after it. Neither depends on it now: a role that cannot be read is anyone's (core/turns/recaps.ts), and a frame goes out whatever the orchestrator makes of it (BackendSocket.send). End to end in e2e/diskfull.e2e.ts.

      Left, larger:

      • The manifest is not signed. Its sha256s are only as good as the TLS connection to the manifest host: one that served a matching manifest and bundle would be installed, its canary run first. Signing needs a release key and its public half pinned in the bundle.
      • A master that dies while a disk-starved update waits for room leaves its re-execution marker, and the next start rolls the update back as a re-execution that never came up.
      • Bundles in versioned directories behind one pointer (above) would make the swap a single rename.
      • After the release (the orchestrator is out of scope until then): OrchestratorService should read its state without making its folder, which only its first save needs.

Next, in order:

  1. Removals: requests kept only to refuse retired features, once no shipped app sends them.
  2. Bounded reads for every other engine, in the order above, each with a conformance suite.
  3. Core boundary, in process. Turn runForeground into a composition root over explicit modules: registry, terminals, transcripts, input, questions, local API. Replace the callback properties with a typed core API. No behaviour change; the existing suites pass unmodified. The plan is below.
  4. Services out of process, one at a time, each behind its manifest entry and able to fall back to in-process for one release: devices first, then relay (with the self-hosting settings), models, workspaces, search, viewers, teams, the light host, Companion and Memory.
  5. Platform supervision by default (built as an opt-in above; the desktop app watching instead of respawning, registered through SMAppService on macOS). The other half of this step, the master re-executing itself on update, is built (above).
  6. State directory move, last, once nothing else is changing.

The core boundary, step by step

runForeground is 5,306 lines. About 4,600 of them move into modules under cli/src/core/. What stays, about 700 lines, is the composition root: the guards and updaters that must run first, the terminal backend, BackendSocket and its gate, the hook server and pid file, the boot sequence (restore, then the first reconcile), restart-for-update and shutdown, and openRequests, ready last. startupOrder.spec.ts already pins those in place.

Each module is a factory, createX(deps), that returns closures, the pattern createStopAgentService already uses.

Module What moves into it
terminals/control Control leases, capture, submit, type, keys, pinning
terminals/bootstrap The tmux backend, terminals, the host theme, pane titles
agents/events Session sync and announcements
transcripts/normalizers The 14 per-engine normalizer and reader maps, as one table
transcripts/attach, ingest Attach, the attach tracker, watcher wiring, line ingest
turns/funnel The one place session events fan out from
turns/* Heartbeats, recaps, stop hooks, runtime profiles, reconcile timers
input The input controller and the pane writer lock
questions The question watcher, answers, open questions
agents/* Forget, bind, discovery, launch; create, fork, retarget, restart, resume, stop, close, purge
engines/hooks Hook handlers and hook installs
api CoreApi, CorePorts, and binding BackendSocket

Two typed interfaces replace the 53 callback assignments on BackendSocket:

  • CoreApi, services to core: agents (list, resolve, create, fork), input (submit, cancel), questions (answer, open), recaps (recent turns, asks), runtime profiles (models, set), and events (agent, question, turn, stream, delivery). Each member is an existing request or event. There is no generic call(name, args).
  • CorePorts, core to services, in process only: the synchronous calls the core makes into features today: audience (which devices are watching), teams, devices, search, models, viewers and workspaces. Each port is a contract decision to make before its service leaves the process.

The order. Each step moves code verbatim and keeps the old names as aliases, so call sites and the start-up lint stay as they are; each is checked by tsc, the unit suites and the e2e suite.

  1. A spec that pins the start-up order: requests held from construction, every port bound before openRequests, then ready, then [cli] ready.
  2. Terminal control.
  3. Session events.
  4. The normalizer table.
  5. Input, with the pane writer lock.
  6. Questions.
  7. Heartbeats, activity and recaps.
  8. The event funnel.
  9. Attach, ingest and the stop hooks.
  10. Agent discovery and binding.
  11. The agent lifecycle.
  12. Engine hooks.
  13. Services in process, each behind start(core, ports): search, viewers, models, workspaces and the teams; the devices guarded where the core calls them. Relay, sharing and the devices move with the next phase, into processes of their own.
  14. Every slot BackendSocket calls into the core through is bound, and stays so: socketBindings.spec.ts reads the class's slots and fails on any that cli.ts leaves unbound (three are unbound on purpose, each with its reason). The bindings stay where start-up puts them: gathering them into one call would reorder a start-up startupOrder.spec.ts pins, for nothing a test cannot give.

After that, the request switch's case bodies move into a file per owner. What the switch held on 5 October, beyond the requests services answer themselves, and where it went:

  • Moved to the core, each to the module that owns it, one slot each (see "Done so far"):
    • agents: agents_list, agent_recent, agent_update, agent_create_status, agent_create, agent_fork, agent_resume and agent_restart, agent_delete, agent_close, agents_cleanup_preview, agent_purge and agent_worktree_delete, agent_handoff_prepare;
    • transcripts: session_get, sessions_list;
    • terminals: terminal_info, theme_set;
    • input, turns and questions: message, cancel, question_response.
  • Core, staying for now: agent_retarget, whose target resolution reads the socket's grid state and the API store, which is the models service's to answer first; and remote_terminal_handoff, whose logic is transport: which local clients, and how many windows, can hear the swap.
  • Not core: telemetry (machine_resources), models and grids (grid_*, models_list, engines_probe), pairing and E2EE, voice_route, the project and folder readers (git_*, project_preview, fs_list_dir, agent_read_file), Codex profiles, usage_read, harness_devices_*, speaking (a device's presence, echoed to the others) and the legacy claude_login_status.

What has to survive the move exactly:

  • The funnel's order. Each event goes to the backend, then search, input, teams, the pane writer, devices, the heartbeat and the question watcher, in that order. Recaps come after the loop, and the devices stream comes last and never on replay. A bus that notified subscribers afterwards would reorder frames.
  • The input, pane writer and turns cycle. Every pane write goes through the device input lock, which calls back into input, which re-enters the funnel. They move together.
  • Start-up windows. Hooks arrive before the request gate opens and are not gated. Stopped-agent frames are published during restore, outside the gate, so their providers must be bound before restore. Relay callbacks are bound after connect() today, which is safe only because nothing awaits in between; they move before it.
  • Log lines that tests read: [cli] ready, transcript rewritten in place — attaching it again, [backend] machine busy.

Found while mapping, and fixed on their own rather than inside a move:

  • Kilo's reader was skipped on cancel and on shutdown, so a cancelled Kilo agent could keep showing as working. Fixed once the readers became one table (step 4).
  • BackendSocket.onLocalClient is never wired.
  • Found by the end-to-end suite, and fixed (part 10):
    • A registry no version could load left the daemon refusing every write, so it could not start an agent until someone repaired the file. Such a file is now moved aside, kept byte for byte, and the daemon starts empty; a newer version's rows are still never touched.
    • A pane closed with kill-pane was never counted missing: tmux 3.7 answers an unknown pane with an empty line, which was read as "could not ask". Its agent now stops counting as active.
    • The hook server answered nothing when a handler threw outside its proxy routes, which held an engine's turn until its hook timed out. Every request is answered now.
    • One throwing teams or device consumer cost an event its heartbeat, question watcher and recaps.
  • Found by the second round (e2e/core.e2e.ts: six agents of both engines at once, stop and restart mid-turn, an engine that exits, missing agents, client churn, a hook storm, a deleted transcript), and fixed (part 11):
    • A resumed conversation was replayed live as its agent's first turn for ten minutes after the agent was created, so a Claude Code agent stopped in the middle of its first turn and resumed read as working for good. A resumed conversation is history now.

    • A message sent as a resume or restart was confirmed was refused by the pane's control lease and lost. A write the lease refuses before a byte is written now waits for it, up to fifteen seconds.

    • Kept as it is, on purpose: a transcript deleted and recreated at the same path is read as a rewrite, so the first burst in the new file is history and every turn after it is live. Reading a shrunken file as new content once replayed a rewrite as fresh turns (42 in one second).

    • Part 12: the local socket closes a connection whose frame handler throws, and its window handlers called the dial, the window bridges and the WiFi device service in line, so a fault in any of them disconnected the desktop, again on every pane change. Every such call, and the commander tee that runs before a frame is queued for the WiFi device, is guarded now; with all three failing on every call the desktop stays connected and its agents run their turns.

    • Part 12, found by the third round (e2e/edges.e2e.ts): messages sent faster than an agent answers were written into its pane at the same time, so their pastes interleaved and the engine received prompts made of two messages, out of order (five messages became two turns). Each agent's messages are now written one after another, in the order they arrived; they still never wait for a turn.

    • Part 13, found by the fourth round (e2e/turns.e2e.ts): a turn cancelled from the app left every other window, and every agents_list, reading the agent as working for thirty seconds and then as unknown, because a cancel never told the activity tracker. It reads as idle at once now, still with no turn_ended (which would recap a killed turn). The fifth round (e2e/questions.e2e.ts) proves an agent's question end to end for both engines: the dialog reaches the window, the answer chosen there is the one the agent gets, and a stale answer types nothing.

    • Part 14: a permission prompt the same way (Yes in the window runs the command, No does not), and a soak (e2e/soak.e2e.ts): 2,400 turns across two Claude Code and two Codex agents left the core's memory flat (246.7 → 244.7 MiB) and its open files at 33.

    • Part 15: step 14 as described above, and coming back (e2e/recovery.e2e.ts): five restarts in a row while agents work, the master killed outright, an engine missing from the machine (its launch fails with ENGINE_NOT_INSTALLED and the reason), and a registry lock left by a crash.

    • Part 16, found by the soak on a loaded machine: four agents created at once, and one was retired 22ms after its engine was found. A discovery scan that began before that engine started counted its second "missing" when it landed, and the agent was archived; the next scan then minted a second agent for the same pane, and the first never bound. A scan now judges an agent only by what it could have seen: an agent created, a pane given to one, or an engine identified while the probe ran is left to the next scan, and misses count against one engine identity at a time.

    • Part 17, found by the seventh round (e2e/terminal.e2e.ts, the terminal stream for both engines: open, type, paste, resize, take over and watch, four terminals on one connection, a window that goes, freezes or floods, a stopped and resumed agent, a daemon restart, bad opens and garbage frames): a turn an engine took before the daemon attached its transcript was filed as history, and reached no window as a turn. It happened after a resume, to a message typed the moment the terminal reopened, and after a daemon restart, whose request gate opens before the restored agents' attaches run. The transcript's size is now noted where the engine's writing becomes live (by a resume just before it launches the engine, and by the daemon at start for every conversation it restores), and the first attach folds only up to it (core/transcripts/relaunch.ts).

    • Part 18. History read back page by page (e2e/history.e2e.ts) returns every message once and in order, whatever the page size: while turns are being written, from two windows at once, across a daemon restart, a resume and a compaction. A new conversation in the same pane (e2e/rotation.e2e.ts, Claude Code's /clear and Codex's /new) keeps the agent and its id, and the agent comes back on the new conversation after a restart or a resume. Neither round found a defect. Lifecycle requests that race (e2e/races.e2e.ts) found two, both in a Stop pressed while an agent is still starting. The stop refused with "Try stopping again", because the engine the agent launched, identified mid-stop, read as a replacement. And when it did go through, a discovery probe taken before it opened a second agent for the engine it had seen starting, on a pane that no longer existed. A stop now compares a row that had no process yet without one. A probe is no longer evidence for a route held or released after it began.

    • Part 19, found by the eleventh round (e2e/compaction.e2e.ts, /compact and an automatic compaction mid-turn). Claude Code announces its session again when it compacts, and the daemon re-reads the transcript while taking over its live tail. The re-read found the turn still open and replayed its start, which the tail had already delivered, so every window saw a compacting turn start twice. A re-read that takes over a held tail no longer replays it. The twelfth round (e2e/questions-edges.e2e.ts) found nothing to fix. It covered a question asked with no window open (asked once one can answer), one answered by hand in the terminal (every window lets go, and a late answer types nothing), two windows answering at once (one answer lands), Esc, and a question still open across a restart. Kept as it is, for now: a question's id is named from its dialog so that it survives a restart. So a dialog asked again word for word has the same id, and an answer delayed past the first one could land on the repeat.

    • Part 20. Rounds 13 and 14 found no defect, and pin what had no end-to-end test before. e2e/input-safety.e2e.ts: a message never reaches the shell an exited engine leaves in its pane, including one sent right behind the message that makes the engine exit (refused by the pre-paste check); typing by hand in the terminal still goes to the shell; a client that stops reading is cut off alone within the 40 s heartbeat, with memory bounded meanwhile. e2e/forks.e2e.ts: a fork asked for mid-turn is refused with the reason, then made after it; a fork of a fork; a source stopped under its fork; both back after a restart.

    • Part 21, found by the fifteenth round (e2e/chaos.e2e.ts, a seeded random run of messages, slow turns, restarts, stops, resumes, creates, forks, compactions, reconnects and daemon restarts, then the daemon's picture checked against tmux and the process table). A Codex fork whose start-up hook fell into a daemon restart never bound its conversation. codex fork <id> names only its source in argv, and the repair's scan of the folder found the fork's siblings born beside it and refused to guess. The repair now asks the process first, by the rollout it holds open, as it already asked Claude Code by its per-process record. The fake engines now leave those same traces, and Claude's sends its UserPromptSubmit catch hook on every prompt as Claude Code does.

    • Upgrading from a released build (e2e/migration.e2e.ts, run with MIGRATION_FROM set to a released bundle, and skipped otherwise). A daemon of the released build, with a Claude Code and a Codex agent at work, takes this checkout's build from its update manifest and hands over the way that release does, by spawning the new __run and exiting. The new core comes up on its own, without a master, with both agents and their conversations, and they take turns. The next start brings up the master over the same agents. Passed from v0.3.57, three runs of three.

    • What the apps see, compared with the released build (e2e/compat.e2e.ts, run with COMPAT_FROM set to a released bundle). A daemon of the released build and one of this checkout's bundle run the same scenario, and every answer is compared once ids, times, paths and counters are made comparable. The scenario covers:

      • a Claude Code and a Codex agent created, with a turn each;
      • a question and a permission, answered;
      • search;
      • every read the apps make, well formed and malformed;
      • rename, cancel, fork, restart, stop, resume and close.

      A field this build adds is allowed, because the apps ignore what they do not read. Anything else is explained or a regression. From v0.3.57 nothing differs, across 90 answers and the shape of every frame a turn, a question and a permission push. The only addition is ready on session_search's reply. Two differences turned out to be timing on both builds, and the test now waits them out:

      • where an agent worked is read at most every 15 s;
      • how far a launch has got when agent_create replies is a race with the engine starting.

      One finding, fixed since: hn asks terminal_info (what a pane runs and where), and no build has ever answered it. Every terminal_* frame went to the terminal streams, which pass this one over, and the socket dropped it there instead of answering it, so hn waited out three seconds each time. It is answered now (e2e/terminal.e2e.ts), and the comparison lists it as changed on purpose.

      Compared again with v0.3.58 and v0.3.57 once #805 had moved every core request into its module. The scenario now also sends each moved request malformed, and reads a stopped agent's conversation, list and recaps. Against v0.3.58 three things differ, each on purpose and listed as changed:

      • terminal_info is answered;
      • a permission dialog's question carries permission (#764);
      • session_get reads a stopped conversation (#797).

      Against v0.3.57, agent_handoff_prepare differs too: that release did not have the request. One run differed in agent titles. The machine's network name had changed during it, and the released daemon had read its own name once, at start. The panes made after the change took the new name as their title, on that side only. The test now fails such a run with that reason, rather than reporting a difference.

      The same thing happens to anyone whose laptop changes network: tmux titles a new pane with the machine's name, and an agent whose engine sets no title was named after the machine. The daemon now reads the name at every title sweep and whenever it has tmux make a pane, and every name the machine has had while it ran is refused, the last 16 kept (lib/machineNames.ts). End to end (e2e/hostname.e2e.ts), HARNESSD_TEST_HOSTNAME_FILE stands in for the machine's name.

    • The sixteenth round (e2e/ends.e2e.ts), how an agent's life ends, for both engines:

      • closed now, then opened again with its conversation;
      • closed only when idle, which leaves a working agent working;
      • closed after its task, which finishes the turn and then closes;
      • closed after its task and cancelled, which leaves it open;
      • closed after its task across a daemon restart;
      • closed against an identity that changed, which changes nothing;
      • purged, after which search no longer finds it and its transcripts are gone.

      No defect was found.

    • Scale (e2e/scale.e2e.ts, SCALE_AGENTS). Many agents, half of each engine, are created at once, take a turn each, go through a restart and come back.

      • 24 agents: the core went from 219 MiB empty to 230 MiB after the restart, and all were back in 4.6 s.
      • 50 agents, the design's bar: the core went from 222 MiB to 268 MiB, and all were back in 8.3 s.
    • Part 22, found by the seventeenth round (e2e/machine.e2e.ts): what the machine does to the daemon. Two defects:

      • A dead tmux server went unnoticed. tmux says "no server" two ways. One of them, error connecting to <socket> (No such file or directory), is what kill-server, a tmux crash and a reboot all leave, and it was read as "tmux unavailable". So the daemon never took an agent off, and the apps showed dead agents as active until a new server happened to start.
      • A restore replayed recent turns live. After a daemon restart, a restored agent whose transcript was under ten minutes old had its turns sent out again as live, with their notifications. The first-turn rule excused a resume but not a restore. An attach that takes a relaunch mark now never replays live.

      After a reboot, the daemon brings every agent back on its own, with its conversation.

    • Part 23, found by the eighteenth round (e2e/diskfull.e2e.ts, DISKFULL=1): the data folder on a 64 MB disk image of its own, filled while agents work. Two defects:

      • A rename the daemon answered while the disk was full was lost to a restart that came before the next rename. Names were written only on a rename; a failed names write is now tried again on every save.
      • Saving the resume record threw out of a binding after the agent was bound, so the windows never heard of it. The record is best effort there; a stop still saves first and refuses on failure.

      The core never restarted, and agents kept taking turns throughout.

    • The nineteenth round (e2e/folders.e2e.ts), for both engines:

      • folders named with spaces, quotes, $HOME and backticks, accents and emoji: each holds an agent that works, comes back after a restart and is closed;
      • a folder deleted under a running agent, or while the daemon is down: it costs that agent at most.

      No defect was found.

    • The twentieth round (e2e/frozen.e2e.ts): an engine stopped (SIGSTOP) rather than exited.

      • A message sent to it is taken once when it wakes, and the other agents go on meanwhile.
      • A cancel leaves it able to work.
      • A stop does not wait on it forever.

      No defect was found.

    • The thirty-fourth round (e2e/relay.e2e.ts): the relay link under stress, as a phone sees it. A phone is paired with a signed-in daemon and reaches it through the fake backend's blind relay (e2e/harness/fakeBackend.ts, e2e/harness/relayPhone.ts, the CLI's own relay client role). The relay drops mid-turn and comes back, the backend restarts, the relay is slow by seconds, it sends garbage or replays old sealed frames, and the daemon restarts while the phone is connected. Every message is in the phone's re-read history once, nothing announces a turn it has already read, and a message tried with no session is refused at once. Found and fixed:

      • A broadcast the relay replayed into a client's next session opened as news, because the replay record for the machine's group key was the session's. The CLI's relay client now carries it from one session to the next (lib/e2ee/relayClient.ts, lib/remoteRelay.ts).
      • A frame a client sealed for a session the daemon no longer had was dropped without a word: a message vanished, and a request waited out its timeout. That happens when the daemon restarted while the relay kept the client's socket, as the phone app does. The daemon now answers e2e_session_unknown, naming the frame (terminal bytes by their clear kind and counter), and the CLI's relay client opens a new session on it.

      Left, larger: no message is acknowledged end to end, so one lost inside the relay is found only by reading the conversation again; and the phone app has both of the above to learn.

    • Every request the apps send is answered: all 39 of the desktop's, all 21 of the phone's and all 20 of hn's, checked against the daemon's sources.

      • The desktop's lessons is answered UNSUPPORTED on purpose, for a feature not yet built.
      • hn's terminal_remain is a feature of hn's own local shells.
      • hn's terminal_info had never been answered, and is now (part of the comparison above).

Testing

The bar for the core is total: 100% statements, branches, functions and lines, enforced in its vitest configuration, as the orchestrator, sharing and resume suites already do.

  • Engine conformance, for every agent we support. Each engine has a suite that checks attach and history pages against the whole-history reads they replace at every cut point, its turn lifecycle, questions and model chips, on fixtures, plus an opt-in run against a machine's own transcripts (ATTACH_REAL_TRANSCRIPTS=1 today for Claude Code and Codex), plus the real-CLI checks for installed engines (test:tmux-real).
  • End to end, out of process. The harness boots the master, core and services under a throwaway home and a private tmux server, drives them with a client that speaks the desktop's protocol, and runs scripted engines that write transcripts and call hooks: create, stream, type, deliver, question, answer, turn end, recap, restart, resume, stop.
  • Failure. Kill, hang and overload each service and the core under load: crash loops, a start-up that hangs after binding, a heap that grows to its limit. Panes, questions and input must stay within an agreed baseline, and nothing respawns in a loop. Corrupt each state file, fill the disk, stall a subscriber.
  • Budgets as tests. The regression from October 3 is a permanent test: a transcript larger than the heap, attached, paged and rewritten in place, and 50 panes attaching at once, under a fixed memory and time budget. A soak run holds a desk of agents for hours and fails on memory growth.
  • The apps. The desktop app against harnessd in an isolated profile, never against the person's own harnesses.

Open decisions

  • Platform supervision by default. Whether the launchd agent and systemd unit are installed on every install, which on macOS asks the user once (Login Items).
  • tmux server. Agents on the user's default tmux server, or a dedicated one that tmux kill-server cannot reach; and under systemd, whether the core starts it in a scope of its own, so a stop job on the unit no longer reaches the panes (see Rollout, platform supervision).
  • Service defaults. Which services start on a new install and which wait to be needed (a device paired, sharing used, a viewer installed), and which light ones share the host.
  • Safe mode. Whether three crashes in five minutes is the right trigger, and what a degraded core keeps beyond the updater.
  • A healthy update. Ready plus a number of crash-free minutes, or a first successful attach.
  • The relay protocol's stability promise, once self-hosting is documented.
  • State directory. Whether moving to ~/.harness/harnessd/ is worth its migration at all.

Appendix: what other daemons do

Studied on October 4, 2026, from each project's own documentation and source. The decisions above cite what they take from here.

Erlang/OTP supervisors

  • A restart strategy for each group. one_for_one restarts only the failed child; one_for_all and rest_for_one also restart its dependents (OTP).
  • Intensity and period. More than MaxR restarts in MaxT seconds and the supervisor stops its children and itself; its parent decides what happens next. Default: 1 restart in 5 s.
  • Limits multiply across levels: "do not set the restart intensities to the same values on all levels".
  • transient children are restarted only after an abnormal exit. Children stop in reverse start order, each with its own timeout.

systemd

  • Exit codes are a contract (RestartForceExitStatus=, SuccessExitStatus=). Exponential restart delay arrived in version 254, but it does not reset after a healthy run (systemd.service, #43813).
  • Start limit. By default a unit started more than 5 times in 10 s is no longer restarted automatically (systemd.unit, defaults).
  • Readiness and liveness are separate signals. READY=1 means start-up is done. WATCHDOG=1 is sent from the event loop every half WatchdogSec; a missed one means SIGABRT (sd_notify, watchdog).
  • Sockets outlive the service. "If a service dies its listening socket stays around, not losing a single message" (socket activation). FDSTORE=1 keeps other fds across restarts (sd_listen_fds).
  • Memory limits. MemoryHigh= slows a unit down and MemoryMax= triggers the OOM killer inside it (resource-control). User units can use both ([email protected]). By default, stopping a unit kills everything in its cgroup (systemd.kill).

launchd

  • User agents run while their user is logged in, and they must not daemonize: "If you do, launchd thinks your process has died" (Apple).
  • KeepAlive can restart a job after a clean exit, a crash, or both. By default a job is spawned at most once every 10 s (ThrottleInterval) (launchd.plist, Apple's man page).
  • Sockets are created by launchd, and the job collects them with launch_activate_socket(3).
  • ProcessType Background jobs get resource limits; Interactive jobs do not. By default launchd kills a dead job's process group.
  • SMAppService (macOS 13+) registers an agent shipped inside the app bundle, "subject to user approval" (SMAppService, agent).

nginx

  • The master does the privileged setup (config, ports) and manages workers, which "do all of the work" (NGINX).
  • Signals control it. TERM is a fast stop, QUIT a graceful one, HUP reloads, USR1 reopens logs and USR2 loads a new binary (control). A graceful stop has a time limit (worker_shutdown_timeout).
  • Reload validates first. If the new config fails, nginx "rolls back changes and continues to work with old configuration".
  • An upgrade keeps the old master as the rollback. It starts the new binary but keeps its own listening sockets open, so it can bring its workers back if the new one misbehaves.

PostgreSQL postmaster

  • The supervisor keeps away from shared state. It "as a rule does not touch" shared memory, so a backend crash can't take it down (postmaster.c).
  • One crash resets everything. The postmaster stops the other children and reinitializes (restart_after_crash).
  • Children watch a pipe to notice when the postmaster dies. There are three stop modes: smart, fast and immediate (shutdown).
  • The OOM killer must not pick the supervisor. The postmaster gets oom_score_adj −1000 and its children 0 (docs).

Syncthing

  • A monitor process restarts the real one. Exit code 3 means restart and 4 means upgrade (docs).
  • Loop guard. After 4 restarts within 60 s, the monitor gives up (monitor.go).
  • Upgrade. When the child exits with "upgrade", the monitor execs the new binary, which starts the new child. Panics go to a panic log; logs rotate by size and count.
  • Under systemd: --no-restart, RestartForceExitStatus=3 4, and StartLimitBurst=4 in 60 s (unit).

Docker and containerd

  • Live-restore: "containers remain running if the daemon becomes unavailable". It only works across patch releases, and a full 64K log FIFO blocks containers (live-restore).
  • Shims are the containers' parents. containerd reconnects to them at boot and cleans up any it can no longer reach (runtime v2).
  • The unit files let workloads survive: KillMode=process ("kill only the docker process, not all processes in the cgroup"), a negative OOMScoreAdjust, and socket activation (docker.service, containerd.service).
  • Version skew is planned for: the API version is negotiated (Engine API), and unknown shim extensions are ignored.
  • Logs: the local driver caps them at 100 MB per container (local); json-file does not (json-file).

Chrome

  • The network service runs in its own process, which is "preferred for isolation and stability". After a crash it is restarted and clients reconnect (network service).
  • It degrades instead of looping. About 3 GPU-process crashes switch Chrome to a more stable mode, and one crash is forgiven every 5 minutes (fallback, gpu_process_host.cc).
  • The number of processes depends on available memory (process model).

VS Code

  • Extensions run together in a separate extension host process (one per local, web or remote host), each loaded only when needed (docs, extension host).
  • Crash budget: automatic restarts until 3 crashes in 5 minutes, then a Restart button (source).
  • Terminals live in a pty host process that survives window reloads (1.54): a 5 s heartbeat, a second timer against false alarms after sleep, and capped restarts (MaxRestarts = 5) (terminal.ts, ptyHostService.ts).
  • Agent sessions live in one Agent Host and are "not tied to the lifetime of the window"; clients replay missed actions on reconnect (agent host, blog).

tmux

  • One server owns all sessions. Clients connect to it over a socket, and -L or -S runs a separate server (tmux(1)).
  • The server daemonizes (daemon(3)), leaving its launcher's process group (proc.c).
  • The protocol version is strict. A client built for a different version gets "protocol version mismatch" (client.c).

PM2

  • Backoff that forgives: delays grow to 15 s and reset after 30 s of uptime (restart strategies). After 16 unstable restarts the app is marked "errored" (ecosystem). Memory is checked every 30 s.
  • The app says when it is ready. wait_ready waits for process.send('ready'). Stopping sends SIGINT, then SIGKILL after 1.6 s (signals).
  • Zero-downtime reload in cluster mode, where the Node cluster primary owns the port and accepts connections for the workers (cluster, Node).
  • Logs don't rotate by default (logs). pm2 startup leaves boot to systemd or launchd (startup).

s6, runit, daemontools

  • One tiny supervisor per service, waiting at least a second between restarts (s6-supervise, runsv, supervise).
  • State is kept in files. The supervisor writes supervise/status, which svstat reads.
  • Readiness is reported explicitly. The daemon writes a newline to notification-fd, because started is not the same as ready (notifywhenup).
  • The supervision tree owns the log pipe, so restarting the service or its logger loses nothing (s6-svscan). s6-log rotates by size and count (s6-log).

Tailscale (tailscaled)

  • Supervised by systemd: Type=notify, Restart=on-failure, a private state directory (unit).
  • State is written atomically: write a temp file, sync it, rename it (atomicfile).
  • The local API checks the connecting process's user (safesocket), and the CLI warns when its version differs from the daemon's (cli.go).
  • Saying ready too early is a bug. READY=1 once went out before the daemon could actually serve (#11504).

Caddy, HAProxy, Kubernetes

  • Atomic reload. "If the new config fails for any reason, the old config is rolled back into place without downtime" (Caddy).
  • The master re-executes itself. HAProxy's master re-execs on SIGUSR2, and with -x a new process takes over the old one's listening sockets so it doesn't miss new connections (HAProxy).
  • Three probes: a failed liveness probe restarts the container, a failed readiness probe stops its traffic, and a startup probe holds both off until start-up finishes. Dependency checks belong in readiness (probes).
  • CrashLoopBackOff: 10 s doubling to 5 minutes, reset after 10 crash-free minutes; 30 s to stop (pod lifecycle).