Architecture
What the daemon is, where its boundaries are, and which invariants hold. This page is the entry point; the topic pages carry the detail. modules.md is the generated per-module index and performance.md holds the measurements. Code is named by file and symbol, never by line number: line numbers rot, symbol search does not.
The problem being solved
omp is a terminal coding agent that keeps each conversation in an append-only JSONL
session file. This daemon lets a phone read those conversations live and send prompts
into them, without the desktop giving up ownership. Everything hard about it follows
from two facts:
- omp rewrites a session file wholesale from memory. Two writers therefore destroy history. This is why ownership detection exists at all, and why the daemon refuses rather than guesses.
- A file append is not an event stream. Tailing a file gives coarse, committed content; token-level streaming only exists inside the process that is generating it. Hence several live paths: three token-level producers and one file tail, described below.
Shape
One process. src/bin/omp-pulse/main.rs builds every module, then runs exactly one
router task that serializes events onto the client hub. Requests arrive over
HTTP/WebSocket (src/server/http.rs), content arrives from four sources, and
everything converges on the hub in src/server/ws.rs. Paths in the diagram are
relative to src/.
phone ──HTTP/WS──> server/http.rs ──> server/ws.rs (hub) ──> phone
│ ▲ ▲ ▲ ▲
│ │ │ │ └── omp/collab.rs (desktop relay, token level)
│ │ │ └───── omp/bridge.rs (desktop extension, token level)
│ │ └──────── omp/child.rs (phone-driven, token level)
└───────────────>│ sessions/watcher.rs (file tail, coarse)
│
server/delta.rs (wire encoding) authority/activity.rs (what runs now)
Where the code lives
The library (src/lib.rs) has one module per subsystem directory, plus a few
crate-wide modules at the top level. A large module is a parent file plus a
directory of parts named for what they hold: the parent keeps the module's
header, its public types and API, and the parts hold the implementation
(http.rs is the router; http/prompt.rs, http/files.rs and http/socket.rs
are handlers). Every file starts with a //! header stating its job;
modules.md lists them all.
src/server/: what the phone talks to.http.rsbuilds the router and itshttp/parts hold the handlers by area (auth and pairing, history, prompt, control, files, sockets, receipts, rpc, search, notifications, status);ws.rsis the bounded per-client fan-out hub anddelta.rsits streaming-text encoding;assets.rsserves the embedded web app;device_auth.rsenrols devices;push.rs(withpush/for turn bookkeeping, alerts and the RFC 8291 Web Push code) builds notifications for Web Push and the Android stream;asr.rsand itsasr-server.pysidecar do dictation;git_changes.rsbacks the Changes tab.src/omp/: driving omp processes.child.rs(andchild/) is the pool ofomp --mode rpc-uichildren the daemon spawns, including the helper extension they load;collab.rs(andcollab/) is the collab guest and the self-hosted relay;bridge.rsreads the desktop extension's event stream;desktop_control.rsdrives desktop model settings;native_collab.rsasks omp for collab links;ui_dialog.rsbuilds dialog replies;autotitle.rsnames new sessions;ansi.rsstrips terminal escapes.src/sessions/: omp's session files on disk.jsonl.rsis the only parser (withjsonl/usage.rsfor cost and context tallies);watcher.rstails files as they grow;index.rs(andindex/) is the listing index and its memos;branch.rsforks a session;model_usage.rsreads omp's model-usage index.src/authority/: who may write each session and what it is doing.guard.rsandowner.rsdetect ownership;session_state.rsis the canonical per-session record;activity.rstracks what runs now;command_ledger.rsandreceipt_proof.rskeep durable delivery receipts;interrupted.rsrecords turns cut off by an exit or restart.src/terminal/: the laptop's terminals.adopt.rsadopts a TUI already running in kitty, tmux or herdr and adopts an already-sharing Tern omp through its native Collab (adopt/tern.rs, which refuses rather than typing) andlinkscrape.rsreads its collab link;handoff.rsmoves a conversation into a herdr tab;herdr_startup.rsstarts herdr safely;herdr_state.rspolls herdr's per-pane agent state.- Top level:
cli.rs(the command line),types.rs(configuration and the shared vocabulary),paths.rs,metrics.rs,service.rs(login service install) anddoctor.rs(self-test). src/bin/omp-pulse/: the binary.main.rsdispatches the CLI, wiresserveand runs the router task;term.rsis the pty host behindomp-pulse term.
Outside src/: web/ is the React client the binary embeds, mobile/ the Android
app, extensions/ the two omp extensions the daemon ships, and phone-harness/ the
phone agent's tooling seed.
The live paths, and why there are four
- Desktop bridge (
src/omp/bridge.rs, preferred): the desktop omp runs the bundledextensions/omp-pulse-control.ts, which streams the same eventsomp --mode rpc-uiprints. The daemon republishes them into the child-event channel, so a laptop turn reaches the phone through the child pipeline unchanged, and phone prompts go back through the extension, which keeps the desktop the only writer. - Phone-driven (
src/omp/child.rs): the phone prompts a session the desktop is not holding. The daemon spawnsomp --mode rpc-uias a child, and that child's event stream is authoritative: token-level, ordered, complete. The pool is capped and never stops a busy child to make room. - Desktop relay (
src/omp/collab.rs): a TUI already owns the session but runs no bridge-capable extension. The daemon joins that session's collab room as a guest and forwards the host's frames. Without a bridge this is the only way to see desktop typing at token level. - File tail (
src/sessions/watcher.rs): no live producer. The session file is the only truth, read incrementally and paged over HTTP.
The bridge and relay are described in desktop-integration.md; the child pool, its admission and reaping in session-state.md.
INVARIANT: the file tail is suppressed only while a child is streaming. Not merely while a child is alive. The user's own prompt row reaches the phone through the file, and suppressing on liveness dropped it: a bug the browser suite caught as a pill that never appeared.
Boundaries (stated as absences, because that is what is load-bearing)
- Nothing except the
childmodule (src/omp/child.rsandsrc/omp/child/) spawns an omp process that writes a session: it owns the only--mode rpc-uispawn (ChildManager'sspawn, inchild/spawn.rs). The other omp invocations write no session file: version probes (the drift check inmain.rs,doctor.rs), the one-shotomp -p --no-sessiontitle request inautotitle.rs, theomp collab list|link --jsonqueries innative_collab.rs, andterm.rs, which launches the user's own TUI under a daemon-owned pty. The laptop handoff spawns no omp itself: it asks herdr to start the user's TUI, after our child has exited. - Nothing at all writes a session JSONL file. Fresh sessions from
/api/newmaterialize when the child first writes, which is why that endpoint is lazy and a phone list can 404 a path it just created. - Nothing except the
httpmodule (src/server/http.rsand its parts) speaks HTTP, and nothing exceptsrc/server/ws.rsholds a client socket. A module that wants to reach a phone publishes an event. - Nothing except the
collabmodule (src/omp/collab.rsand its parts) knows the collab wire protocol or its AES-256-GCM envelope; nothing exceptsrc/server/delta.rsknows the delta format; nothing except thejsonlmodule (src/sessions/jsonl.rsand its parts) parses a session file. src/types.rsis the shared vocabulary. It importsstd,serdeandcrate::paths(forPaths), and names one more crate type by path:authority::session_state::SourceStamp, the producer stamp aChildEventcarries. Nothing else in the crate; every other module may depend on it.- There is no OpenSSL in the dependency tree, on any target, deliberately (see
the dependency rules in
AGENTS.md). Web Push encryption and VAPID signing are implemented insrc/server/push.rsfor that reason. - There is no runtime read of
public/outsidesrc/server/assets.rs: the web app is compiled in.--public-diroverrides it for development only, andassets.rsis the single place that consults the override. - Process-wide mutable state is NOT absent: there are 94 statics across 25 modules
(counted over every file of a module, tests included), and pretending otherwise
would mislead. They fall into six categories, and a new one should fit an existing
category or justify itself:
- Caches keyed by content, path or file identity.
index.rs(the listing index, the lock that coalesces cold scans, and the snippet, metadata, model, activity and per-file usage memos behind the cost and context meters),jsonl.rs(the session tree keyed by path+len+mtime, so scrolling a 44 MB file back does not re-parse it: measured 105 ms cold against 17 µs cached, and a header memo),assets.rs(the embedded tree and the development override),child.rs(command catalogues keyed by cwd, mirrored on disk, plus the per-key gate that makes concurrent misses share one fetch),child/extension.rs(the content-hashed extension file name),collab/transcript.rs(a connection prefix),adopt.rs(the newest-herdr choice keyed by install path+mtime),http.rs(the prebuilt heartbeat frame) andplugins/sources.rs(the latest reading of each declared plugin source, keyed by plugin id, plugin hash and source id, so one command run serves every device for its interval). - Short-lived dedup, debounce and per-turn holding maps.
http.rs(recent/api/newcalls, owner verdicts, adoption attempts, the per-chat gates that keep a held send ahead of later ones),autotitle.rs(sessions with a title request in flight),push.rs(the per-(kind, session) notification debounce, the last assistant reply held betweenmessage_endand theagent_endthat turns it into the notification body, aborted and failed turns),adopt.rs(submit cooldown) andhandoff.rs(the sessions mid-move). - Process-lifetime registries.
collab.rs(link registries, the weak collab and relay manager handles, through which a tapped room gets the same write path a guest attach does, the pending-dialog store a phone with no socket is replayed from, the answers held while the desktop's link is reconnecting and the wake that parks their expiry sweep while none are held, the per-session desktop-link state the phone's badge reads, and the session authority handle and active source stamps),bridge.rs(the pid→session link registry and its reconcile wake: the truth the bridged desktops report about themselves),activity.rs(the live activity map with its hub, authority handle and notification wake: one small entry per working session, removed at turn end),index.rs(the listing socket hub, refresh notification and discovery flag),interrupted.rs(the in-flight turn journal),ui_dialog.rs(a phone child's typedaskanswers held until its last question) andherdr_state.rs(herdr's pane→status snapshot polled at 1 s, a registry of herdr's view rather than ours, its change wake, and the answers the phone has typed into each pane's current multi-questionask, the only record of which question the laptop is on until omp writes the result). - Locks and gates that make a multi-step operation atomic.
http(the lock inhttp/socket.rsthat makes a socket's attach and the last socket's detach-and-unwatch one step, and the one inhttp/dialog.rsthat keeps a question's position check and its delivery together),http/files/file_io.rs(the two-slot admission gate for blocking file work, see io-bounds.md),handoff.rs(the lock that serializes moves so two taps cannot both take a workspace's last tab),http/providers.rs(the oneomp loginallowed at a time, machine-wide, since omp's credential store is per user),plugins/registry.rs(the lock that makes a plugin decision's read-modify-write ofplugins.jsonone step),plugins/sources.rs(the daemon-wide limit on plugin source and action commands running at once),plugins/actions.rs(the plugins with a host action running, so one plugin runs one action at a time), and the test-only environment locks inpaths.rsandcollab.rs. - Diagnostics and compiled regexes.
metrics.rs,linkscrape.rs, and the boot timestamp inindex.rs. - Unique identities. The provider sign-in generation in
http/providers.rs(so a poll never reads a newer sign-in as its own); counters for temporary-file names (herdr_startup.rs,child/spawn.rs,child/extension.rs,http/export.rs,http/files/file_write.rs), producer generations and binding epochs (bridge.rs,collab.rs), request IDs (collab/transcript.rs) and test fixtures (including the scratch-folder counter inplugins/testkit.rs).
- Caches keyed by content, path or file identity.
Back-pressure, which is where the subtlety lives
A phone on cellular is slow; a session file can grow by megabytes in a second.
src/server/ws.rs gives each client a bounded queue with two ceilings, frame
count and total bytes, because count alone is not a memory bound when one frame can
be megabytes. Past either ceiling the client is handed exactly one resync order and
stops accumulating; it then refetches history over HTTP, which is paged and
compressed. Deltas are keyed by base_seq, so a client that fell behind gets a full
snapshot, never a delta it cannot apply.
Two refinements were forced by measurement, not design:
- A resync frame is tiny, so it always fits the socket, so the gate reopened immediately and oscillated 123 times under a storm. A stall flag now holds it.
- The watcher skips the read and the parse when no client can receive it: no client with queue headroom, or only hidden ones (a locked phone keeps its socket open). A 150 MiB append with no audience cost 320 MiB of RSS before that gate and 0 after. A hidden client that missed a skipped tail gets one resync order when it reports visible, and with no audience at all the watcher's 250 ms tick parks.
The measurements and the full mechanism are in performance.md.
Ownership, and honesty about it
src/authority/guard.rs and src/authority/owner.rs answer one question: does
another process own this session? Three layers, each with a stated blind spot: a
sidecar file (works everywhere, including Windows, and is the only layer that sees a
TUI which never wrote), process arguments via sysinfo (cross-platform), and open
file handles (/proc on Linux, libproc on macOS, nothing on Windows).
src/doctor.rs reports which layers are live on this platform instead of implying
protection that is absent.
INVARIANT: our own RPC children are never treated as foreign owners, and when no layer can prove ownership the daemon refuses to spawn a writer.
Platform gating
src/bin/omp-pulse/term.rs compiles only on Unix: raw parent stdin, TIOCGWINSZ and
SIGWINCH have no Windows equivalent, so main.rs supplies a stub module there.
Native collab discovery runs on all platforms. The terminal-control fallback in
src/terminal/adopt.rs is unreachable on Windows but stays compiled so the
cross-check catches platform drift, including the past macOS ProcFdinfo/Clone
FFI break.
What is deliberately not done
- No compression of small WebSocket frames. Deltas made streaming frames 100–200 B,
where per-frame deflate measured only 0.34×, and a shared-dictionary scheme would
need a WASM decoder on the phone. Frames of at least
ws_deflate_minbytes (default 4096,OMP_PULSE_WS_DEFLATE_MIN) go as raw-DEFLATE binary to clients that advertisedefl; the on-phone daemon's own loopback WebView gets none (see F3 in performance.md). - No session multiplexing over one child:
switch_sessionaccumulates RSS (291–582 MiB over five switches), so a warm child is retargeted only when the pool is full, and recycled pastchild_rss_mb.
Topic pages
- session-state.md: the per-session authority record, turns (stop, interrupted, mid-turn delivery) and the daemon's pool of omp children.
- delivery.md: command ledger, receipts and receipt binding, device enrolment, browser and Android outboxes, drafts and migration.
- desktop-integration.md: desktop bridge, collab relay, desktop control, laptop handoff and herdr.
- dialogs-and-controls.md:
askdialogs on both transports, finding blocked conversations, and the phone controls (plan mode, Go here, labels,!!). - web-client.md: web client internals: read state, session status, listing, usage meters, workspace tabs, images, file saves, offline cache, HTTPS.
- io-bounds.md: daemon I/O and memory bounds: file-I/O admission, session-index memos, watcher boundaries, socket queue accounting.
- notifications.md: Web Push and the Android native stream: one payload, two transports.
- dictation.md: local speech-to-text.
- phone-mode.md: the phone-mode runtime (proot, Alpine guest, install and upgrades, phone harness wiring).
- performance.md: measured baseline and findings F1–F13.