# Running pardes: an attach is always a client (ruled, not built) > the way it's distributed with client/server and detached and stuff, it's > confusing to me now and I think it must be confusing in the code too, > the way Rex does things is a good parameter to compare Ruled by the user on 2026-11-17, answering the reorganisation plan's questions: the words of distribution (*session*, *client*, *far*, *frontend*, *detached*, *attach*); "attach is always a client"; the daemon stays as built; the vocabulary and the manual's page first, no code moved yet. Nothing in this note is built. What runs today, with a figure for each way of starting pardes, is the manual's "How pardes runs" (`docs/typ/running.typ`); the daemon's history is `docs/next-daemon.md`. Line numbers are this tree's, 2026-11-17. ## The ruling A session's own frontend is only the one it was born with. Once it has let that go (a Detach, its terminal or window closing), it stays detached, and every attach after that is a client: a process of its own with a replica core, as the second attach to a session is today. Two more things go with it (the coordinator's, put to the user with the question): - a session registers again with a daemon that was restarted, so a daemon's death no longer leaves its sessions unlisted for good; - `--detach` forks as a terminal's session does, so the process you typed returns at once and `ps` always shows a session the same way. ## Today, and after ![What `pardes attach` does today, and after](next-run.svg) The figure is `docs/next-run.typ`, drawn by `docs/typ/figures.typ` (`typst compile --root . --ignore-system-fonts -f svg docs/next-run.typ docs/next-run.svg`). Today `pardes attach` is four mechanisms, picked by the daemon's `find` (`src/daemon.zig:901-972`) and by `main.zig`'s `attachTo` (`src/main.zig:1774-1810`): a terminal handed to a detached terminal's session, which draws on it in its own process while the attach process waits as its stub; a window's detached session asked to open its own window again, while the attach process exits; a client here, when the session has a frontend or is of the other kind; a far client through `ssh -L`. After, it is the last two only: a client, here or far. ## What it removes The reorganisation plan's option b, checked against this tree: | What goes | Where today | Lines, about | |---|---|---| | A terminal handed to a session: the daemon's `attach` request and answer, the session's `attachTerminal`, the `attach` note and message | `daemon.zig:400-403`, `:431-437`, `:504-533`, `:883-897`; `tui.zig:105-107`, `:1065-1068`, `:1162-1167`, `:1373-1406`, `:1723`; `main.zig:1789-1810` | 110 | | A window opened again in place | `gui.zig:540-544` (what it reopens with), `:982-1000` (`reopenWindow`), `:2534-2547` (`openTheWindow`), `:2753`, `:3275-3281` | 50 | | The daemon choosing which session takes a frontend: `find`, its `other` answer, the use of `daemon.Kind` to match | `daemon.zig:901-972`, `:506-509` | 75 | | The stub's second use: an attach process waiting on a session that is not its child (`stubWait`'s `child = false`, its `r` refusals) | `daemon.zig:561-616` in part (`:593-597`, `:613-615`) | 10 | What does not go, against the plan's list: the upgrade record's terminal and window fields. A session born with a terminal still takes it across an Upgrade (`tui.zig:1455-1463`, `upgrade.zig:101-117`), and a window's still says whether it had its window (`gui.zig:2600`). Only the record's other terminals (`tui.zig:1504-1523`, a build's from before 2026-11-06, when a second local terminal stopped being the session's) are already dead weight. Detach of the session's own frontend stays too (`tui.zig:1346-1371`, `gui.zig:2476-2485`, `:2521-2532`): it is how a session becomes detached. `daemon.Kind` stays in the hello and in `pardes ps` (`tty` or `gui`). The plan counted 87 + about 60 + 67 lines for the first three rows; the counts above include each piece's comments and its callers' lines. ## What a client lacks today, which the change makes work The ruling turns these from objections into work. Each is checked here: what is true, and whether it was measured. - **What a client costs in memory.** Measured on 2026-11-17 (`.scratch/sketch/reports/pardes-measure.md` section A; PSS from `smaps_rollup` after 4 s idle, the installed 0.24 ReleaseFast): a terminal's client is 10-16 MB (20-25 after typing: tree-sitter data the session grows by as much), a window's about 110 MB (187 MB RSS), the same as any window session: three quarters of it the GPU and display libraries and the window's buffers. Its core and the rollback copy it keeps are about 1-2 MB of that. So the "+25 MB a client" measured on 2026-11-06 (`.scratch/arch/client-report.md:21-22`) holds for a terminal's client and is four or five times too small for a window's; what would shed it is a lighter way to draw, not a lighter core. A client adds about 1.3 MB to its session (a terminal's), 13 MB (a window's with addon panes). Today only a second attach pays it; after, every attach to a detached session does, which is the tmux habit (`pardes --detach=work`, then `pardes attach work`). - **An addon's code does not run in a replica.** True, read: a client's core is loaded with no kind's operations (`replica.zig:756-757`, `c.kinds.ops = @splat(null)`), so its addon panes are Shadows, drawn from what the session's code drew and sends (`replica.zig:309`, `:418-470`; `Replica.screen` at `:1140-1160`). Not measured: what a Shadow costs a local client against the session's own frontend drawing the pane. - **A window client scrolls whole rows and keeps its own fonts.** Not so for the wheel, measured (`.scratch/sketch/reports/pardes-measure.md` sections C and E): a notch in a client glides as it does in the session's own window (5 frames, 0 to -22 px, in both). Only whole rows go to the session (`gui.zig:2147-2161`; its comment and `docs/next-daemon.md`'s GUI replica notes still say "no glide"); the picture moves between them on the client's own clock (`glideFrame`, `gui.zig:3544`). A touchpad's fractions are the client window's own picture too (the test "detached trackpad scrolling keeps fractions local and queues whole rows for replication", `gui.zig:8042`). Fonts: a client follows the session's font request by the face's name when that face is installed on its machine (`gui.zig:580-608`, `syncReplicaFont`); its opacity is its own (not in the client's per-frame chores, `gui.zig:1311-1323`). The note said "keeps its own font"; it is corrected there. Measured: a face the client lacks leaves it at its old face and its old size, and it diverged and joined again (2 runs of 2, cause not found). - **Speed.** "The regular tty and GUI get no slower" is the daemon's first rule (`docs/next-daemon.md`, decided by the user). After the change, a reattached session is the client path, not the session's own frontend. Not measured here: a keystroke to its frame, local client against own frontend, on the soak gate. ## A session registering again Today a session says hello once, at its start (`main.zig:1535-1563`), or on its link after an Upgrade (`daemon.zig:392-398`). When the daemon dies the session's reader sees the link end (`daemon.zig:419-425`) and nothing dials again, so the session runs on unlisted: `pardes ps` and attach do not find it, Detach and Adopt refuse, and its frontend closing ends it (`tui.zig:1711-1721`, `gui.zig:1784`). The next daemon knows only the sessions that start after it. The work: when `gone` is set, the session's loop (which calls `daemon.watch` each iteration already, `tui.zig:1115`, `gui.zig:1154`) dials again, starting a daemon if none answers (`daemon.connect(true)`), says its hello with its state, sends a dup of every pty master it holds (at most 64 fds a message, `daemon.zig:37`), and its clients' pids. What cannot come back: the shells of sessions killed earlier, which only the dead daemon held. ## `--detach` forking Today `--detach` is the launch process itself (`main.zig:1502-1537`): it blocks the shell unless backgrounded by hand, it stays the job of the terminal it was typed in, and a window's detached session ends on that terminal's hangup (no handler of its own: `9p_io.zig:704-729`). The work: fork as `daemon.forkSession` does (`daemon.zig:663-698`), `setsid` in the child, its stdin, stdout and stderr on `/dev/null`, and the parent printing the session's name and exiting 0, with no stub (nothing waits on it). For the window's build the fork comes before SDL starts. Then `pardes --detach=work` returns at once, `&` is not needed, and every session in `ps` is either its stub's child or a process of its own. ## Rex beside pardes From Rex's own help (captured under `.scratch/sketch/reorg/pardes-plan/rex/`), and for the client row its binary's strings (`/usr/sbin/rex` links libghostty); Rex was not run. | | Rex | pardes | |---|---|---| | Who holds the programs | one server an account holds every session and runs every program (`skill-show.txt`) | each session is its own process, with the truth; the daemon holds a dup of each pty master and a list | | What starts it | any command starts a missing server (`--autostart`) | the first session starts the daemon; what you start is the session | | A client | "one program connected to the server" (`help-client.txt`); not a thin view: it replays the server's stream into its own libghostty and draws locally (the binary links libghostty; the help text does not say so, and this row first called it a view of the server's state: the user's correction, 2026-11-17) | the same principle, the stream shipped and the state derived where it is shown, into a whole replica core with its own view; what pardes adds is a client applying its own input before the session confirms it (speculation, rolled back when the session ordered things otherwise) and a predicted echo | | Attach | no user's verb; in the API "start receiving its events and get its current view" | today four mechanisms; after this note, one: a client | | The last client leaves | "the session keeps running" (`api-session.detach.txt`) | the same for a client; today a session's own frontend closing depends on its kind and the daemon | | Another machine | the same commands with `-S HOST` | `attach HOST:NAME`; a far session's 9P is not reached that way | | The server or daemon dies | "Stopping the server ends every program" (`help-server-stop.txt`) | a killed daemon ends nothing; today its sessions run on unlisted | What pardes bought that Rex does not have: a deterministic core replicated in each client, so a far session feels local (a key is applied at once, and rolled back when the session ordered things otherwise); a view of its own for each client; and shells that outlive the editor's own death (Adopt) and an Upgrade in place. What it paid: a session that may also be a frontend, which is where `attach`'s four meanings came from. The ruling keeps the replicas and the shells and removes the frontend a session takes back. ## Open questions - Re-registration: dial again at once and back off, or only when something needs the daemon (a Detach, an Adopt, the frontend closing)? - `--detach` with no daemon starts a session nothing can attach to (`main.zig:1535-1537` ignores the failed registration). Refuse, or keep it as a 9P-only session? - `pardes ps` says "has a frontend" for a session with a frontend of its own (the daemon's list, and so /sessions, still says `attached`, a wire word). After the change that frontend can only be the first one: is "has a frontend" the word, or "with its first frontend"? - When: the order the user ruled is this vocabulary and the page first, and the code after sketchbook's steps land (`.scratch/sketch/PARDES.md`, ruling 4).