diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 18:43:09 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 18:43:24 -0300 |
| commit | 73b2fd0d3f49cbee52146f6f473962687691dd87 (patch) | |
| tree | 3ab7ff84c177f432221935bf709193d6b2450536 /docs/typ/running.typ | |
| parent | b7b6a682cd8abe63f763eb671a068b53be9600d8 (diff) | |
| download | pardes-73b2fd0d3f49cbee52146f6f473962687691dd87.tar.gz pardes-73b2fd0d3f49cbee52146f6f473962687691dd87.zip | |
docs: How pardes runs, a chapter after the guide: the four kinds of process (session, client, daemon, stub) and what each holds, a figure for each way of starting pardes (pardes in a terminal, pardes-gui, --detach, attach to a detached session, attach to one with a frontend, a far session, no daemon), the table of who holds the truth, what draws and what a closed terminal or window does, what survives what, and the words ruled on 2026-11-17 with the older ones the code still says; what is built only, each fact's file:line in a comment beside it; the cheatsheet's pointer for sessions goes there (cheatsheet-a4.pdf rendered again, still one page)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'docs/typ/running.typ')
| -rw-r--r-- | docs/typ/running.typ | 264 |
1 files changed, 264 insertions, 0 deletions
diff --git a/docs/typ/running.typ b/docs/typ/running.typ new file mode 100644 index 00000000..0686dce5 --- /dev/null +++ b/docs/typ/running.typ @@ -0,0 +1,264 @@ +// How pardes runs: which processes each way of starting pardes makes, who +// holds what, what draws, and what survives what. What is BUILT, in the +// words ruled on 2026-11-17 (session, client, far, frontend, detached, +// attach); the direction not built yet is docs/next-run.md. The file:line +// that says each fact is in a comment beside it. +#import "style.typ": word, doc, pairs, file +#import "figures.typ": run-legend, run-terminal, run-window, run-detach, run-attach-detached, run-attach-client, run-far, run-no-daemon + +A running pardes is up to four kinds of process. Which of them there are, +and what each holds, depends only on how it was started. + +// daemon.zig:8-16 (nobody's parent; dups; hands terminals, windows, +// replicas); replica.zig:1-19, :730-769 (a client's core from the dump); +// host_io.zig:2176-2179 (the shells are the session's children); +// 9p_io.zig:57 (the socket); daemon.zig:546-698 (the stub). +#pairs( + [*session*], [the process with the truth: the one core every other copy follows, the shells' pty masters (the shells are its children) and the 9P socket. There is one a session, always.], + [*client*], [any further terminal or window on a session: a process of its own, with a copy of the session's core (a replica) loaded from the session's dump and kept in step with the session's tape. It has its own view (columns, focus, cursors, scroll) and draws it. It holds no shells and no 9P socket. A client on another machine is *far*.], + [*daemon*], [`pardes --daemon`, one per user per machine: a switchboard. It spawns nothing and is nobody's parent. It keeps the list of sessions and a dup of every pty master, so that a session killed outright never hangs its shells up; clients dial its replica socket; it hands a terminal, a window's request or a client's connection to the session that takes it. The first session that finds none starts it, and it exits a second after it holds nothing.], + [*stub*], [the process your shell waits on when the session is not it. It holds nothing: it passes signals on, and ends when the session leaves its terminal.], +) + +// tui.zig:588 (a session's terminal: one or none); gui.zig:2381-2384 (the +// window, or none while detached); daemon.zig:901-905 ("a session shows one +// frontend of its own"). +A *frontend* is what draws: the terminal (`pardes`), the window +(`pardes-gui`), or the Mac's own build. A session draws at most one +frontend of its own: the one it was started with, or one attached to it +later. A session with none is *detached*; it may still have clients. +To *attach* is to show a session here. + +In the figures a box with a heavy edge is a process: its kind, then the +command `ps` shows for it, then what it holds. The core with the truth is +marked the same way each time. A line is a connection, labelled with what +travels on it. + +#run-legend() + += `pardes` in a terminal <run-terminal> + +#run-terminal() + +// main.zig:1538-1563, daemon.zig:663-698 (the fork, setsid, the stub); +// daemon.zig:550-559, :567-616 (what the stub forwards and how it ends); +// tui.zig:1697-1721 (the terminal's end: detached while kept, else the +// end); daemon.zig:305-314 (kept: the daemon answered and is still there). +`pardes` forks the session off and stays as its stub. The session runs in a +POSIX session of its own, so it can outlive the job your shell waits on. It +reads the keys from the terminal and draws on it itself; the stub only +passes signals on (a resize, a hangup, a TERM: `kill` on the stub ends the +session too) and exits when the session leaves the terminal, with the +session's status, or 0 after a #word("Detach"). + +Closing the terminal detaches the session while a daemon keeps it. With no +daemon, or after the daemon has died, it ends the session and its shells. + += `pardes-gui` <run-window> + +#run-window() + +// main.zig:1536-1537 (registered, no fork); gui.zig:1775-1788 (the +// window's close); next-daemon.md "Phase 3 notes", known gaps (a terminal's +// job). +The process you started is the session; there is no stub. Closing the +window ends the session and its shells, unless the session has clients and +a daemon: then only the window closes, and the session runs on, detached. +Started from a terminal, it stays that terminal's job, and ends when that +terminal hangs up. + += `pardes --detach` <run-detach> + +#run-detach() + +// main.zig:1502-1520 (no fork; 160x50); main.zig:1535-1537 (registered +// detached, or with no daemon not at all); tui.zig:596-603 and :1700 +// (a hangup taken, nothing to leave); 9p_io.zig:704-729 (the hangup's +// default handler in a window's process). +The process you started is the session: nothing is forked, so the `&` that +puts it in the background is yours to type (`pardes new --detach=work` is +the same). It draws nothing and is 160×50 until an attach or the root +#file("ctl")'s `size` sizes it. Until something attaches, 9P is the only +way in (#doc("scripting")). + +A terminal's detached session (`pardes --detach`) runs on through its +terminal's hangup while a daemon keeps it. A window's +(`pardes-gui --detach`) ends on it, as any job does. With no daemon, +`--detach` still starts a session, which nothing can attach to: only 9P +reaches it. + += Attach, to a detached session <run-attach-detached> + +#run-attach-detached() + +// main.zig:1780-1810 (attachTo); daemon.zig:883-897 (handed on); +// tui.zig:1373-1401 (the terminal entered as the first was); +// gui.zig:3271-3289, :2534-2547 (the window opened again). +For a terminal's session, `pardes attach work` hands its terminal and a +pipe to the session through the daemon, and stays as the stub. For a +window's, `pardes-gui attach work` asks, then exits, and the session opens +its own window again. Either way the frontend is the session's own again, +in the process that has been the session all along: what happens when +it closes is what the first two sections say. + +// daemon.zig:901-972 (find: the bare attach, and `other`). +The kind has to match. A terminal's session attached from `pardes-gui`, +or a window's from `pardes`, is joined as a client (the next section). +Bare, `pardes attach` takes the one detached session of its kind; with +none, the one session of its kind, as a client; with no session of its +kind, the only session there is, as a client. `--attach=work` is the older +spelling of `attach work`. + += Attach, to a session that has a frontend <run-attach-client> + +#run-attach-client() + +// main.zig:1812-1818 (crossAttach); daemon.zig:974-1008 (the hello, the +// same build, handed on); replica.zig:1-19 (speculation and rollback); +// replica.zig:2013-2023, views.zig:31, Core.zig:1110-1153 (four views, the +// session's own among them); replica.zig:2111-2133 (a client leaving); +// replica.zig:756-757 (a kind's code runs in no replica); gui.zig:2147-2150 +// (a client's notch: whole rows, no glide); gui.zig:580-608 (a client's +// font: the session's request, by the face's name on this machine). +A session draws one frontend of its own, so the second attach is a client. +The daemon checks the client's hello (the session's name, and the client's +build: a client must be the build its session is) and hands its +connection to the session; from then on the two talk directly. The client +loads the session's dump into its own core, applies its own keys at once, +and takes the session's tape (each step as the session took it) as the +truth, rolling back when the session ordered things differently. + +A session takes three clients: four views at once, its own among them. A +client's #word("Detach"), or its terminal or window closing, ends that +client only; the last client of a detached session leaves its layout as +the session's, for the next one to find. In a client, an addon's panes +show what the session's code drew (the code runs only in the session); a +window client's wheel moves whole rows, with no glide, and it takes the +session's font only when the same face is installed on its machine. + += A far session <run-far> + +#run-far() + +// main.zig:1498-1500, :1687-1772 (HOST:NAME, ssh -L, PARDES_SSH, +// PARDES_REMOTE_RUNTIME, a path with '/'); tui.zig:678-685 (far: blobs by +// hash, zstd); replica.zig:2516-2640 (Have: the disk cache); +// tui.zig:819-828, replica.zig:3012-3024 (no reconnect; a rejoin only +// after a divergence or an Upgrade). +`pardes attach box:work` runs `ssh -L` from a socket here to box's replica +socket and is a client through it. `PARDES_SSH` replaces `ssh`; +`PARDES_REMOTE_RUNTIME` names box's runtime directory when it is not the +same path as here. A far client is sent the session's tape in zstd and only +the texts it lacks, by hash, and keeps what it was sent on disk for its +next start. Both ends must be the same build. + +When the link ends (ssh, the network, the session) the client exits. It +does not reconnect: it joins again by itself only after an #word("Upgrade") +of the session or a divergence of its own. `pardes attach /run/x.sock:work` +(a path, with a `/`) is a client through a socket forwarded already. + += No daemon <run-no-daemon> + +#run-no-daemon() + +// daemon.zig:52-61 (PARDES_DAEMON, PARDES_TEST), :34 (Linux and FreeBSD +// only); main.zig:1544-1560 (no daemon reached: no fork); tui.zig:1352-1353, +// gui.zig:2483, host_io.zig:227 (Detach and Adopt refused); +// replica.zig:1900-1905 (a client only through the daemon); +// pardes.zig:113 (can_attach); main.zig:1498-1500 (a far attach needs no +// daemon here). +With `PARDES_DAEMON=off`, in a window under test (`PARDES_TEST`), where +none could start, and in the Mac's own build, the session is the process +you started, with no stub. #word("Detach") and #word("Adopt") refuse, no +client can join (a client comes only through the daemon), and closing the +terminal or the window ends the session and its shells. A session whose +daemon died is in the same place (#link(<run-survives>)[below]). +`pardes-gui` built for a Mac has no daemon either, but can still be a far +client. + += At a glance <run-glance> + +// The rows' sources are the sections above; `ps`: daemon.zig:241-245 +// (the daemon is whichever binary started it), main.zig:1727 (ssh's +// arguments), upgrade.zig:5-8 (an upgraded session's command line). +#{ + set text(size: 0.85em) + set par(justify: false) + table( + columns: (1.2fr, 1fr, 1.45fr, 0.85fr, 1fr, 1.45fr), + stroke: (x, y) => if y == 0 { (bottom: 0.8pt) } else { (bottom: 0.3pt) }, + inset: (x: 4pt, y: 4pt), + table.header([*you type*], [*processes*], [*`ps` shows*], [*the truth*], [*what draws*], [*its terminal or window closes*]), + [`pardes`], [stub, session, daemon], [`pardes` twice (the stub, and its child the session), `pardes --daemon`], [the session], [the session, on your terminal], [the session detaches while a daemon keeps it; else it ends], + [`pardes-gui`], [session, daemon], [`pardes-gui`, the daemon], [the session], [the session, its window], [the session ends, unless it has clients and a daemon: then it runs on, detached], + [`pardes --detach=work &`], [session, daemon], [`pardes --detach=work`, the daemon], [the session], [nothing], [it has none; its terminal's hangup ends a window's, not a terminal's while a daemon keeps it], + [`pardes attach work`, detached], [stub, session, daemon (a window's attach exits)], [`pardes attach work` (the stub), the session as it was], [the session], [the session, on this terminal (or its window)], [as for `pardes` (or `pardes-gui`)], + [`pardes attach work`, it has a frontend], [client, session, daemon], [`pardes attach work` (the client), the session], [the session; the client has a replica], [each its own: the session its frontend, the client this terminal], [the client ends; the session runs on], + [`pardes attach box:work`], [here: client, ssh; on box: daemon, session], [`pardes attach box:work`, `ssh -tt -q -o ExitOnForwardFailure=yes -L … box exec sleep 2147483647`], [the far session], [the client, here], [the client ends, and its ssh], + [no daemon], [session], [`pardes` (or `pardes-gui`)], [the session], [the session], [the session ends, with its shells], + ) +} + +The daemon is `pardes --daemon` or `pardes-gui --daemon`, whichever binary +started it. After an #word("Upgrade"), a session's command line starts with +`--upgraded=` and its record, and the daemon's ends with its list. + += What survives what <run-survives> + +// replica.zig:2111-2133 (a client leaving); daemon.zig:485-502, +// 9p_io.zig:704-729, tui.zig:949-961 (TERM, HUP, INT: the shells go); +// daemon.zig:755-765, :770-789 (killed outright: kept for Adopt; `kill`: +// not); tui.zig:596-598 (a HUP kept by a daemon is a terminal's end, not +// the session's); daemon.zig:397, main.zig:1534-1561 (registered at the start and at +// an Upgrade only); upgrade.zig:1-15, replica.zig:2178-2201, :2787-2807 +// (Upgrade); Db.zig:1-17, :385-410 (the state file: Recent, the dumps). +#{ + set text(size: 0.85em) + set par(justify: false) + table( + columns: (1fr, 1.5fr, 1.2fr, 1fr), + stroke: (x, y) => if y == 0 { (bottom: 0.8pt) } else { (bottom: 0.3pt) }, + inset: (x: 4pt, y: 4pt), + table.header([], [*the session*], [*its shells*], [*its clients*]), + [its own frontend closes], [as the table above says], [stay while the session does], [stay while the session does], + [a client leaves (its #word("Detach"), its terminal or window, its process)], [runs on; that client's view closes], [stay], [the others stay], + [#word("Detach") in its own frontend], [runs on, detached (refused with no daemon)], [stay], [stay], + [it ends (#word("Exit"), `pardes kill`, a TERM or an INT)], [gone; a terminal's stub exits with its status], [hang up with it], [each told, and exits], + [it is killed outright (KILL) or crashes], [gone, its text with it unless dumped (#word("Dump"))], [run on while a daemon holds their terminals, and #word("Adopt") in another session takes them (what they showed is lost)], [each exits], + [the daemon is killed], [runs on, but no daemon lists it again, this one or the next: `pardes ps` and attach do not find it, #word("Detach") and #word("Adopt") refuse, and its frontend closing ends it], [stay; the shells of sessions killed earlier, held only by the daemon, hang up], [the ones joined stay; no new one can join], + [#word("Upgrade")], [the same pid on the new build, its dump loaded again; every view, terminal and stub kept; the daemon moves too. A build that cannot load the dump hands it back to the one before], [stay, the session's children still], [let go, and each joins again by itself (it tries for 20 s)], + [a reboot], [gone; what is on disk stays: saved files and the state file (`pardes.xitdb`: Recent and the dumps, which #word("Restore") brings back)], [gone], [gone], + ) +} + += The words <run-words> + +// PARDES.md ruling 1 (2026-11-17). +#pairs( + [*session*], [the process with the truth], + [*client*], [any further terminal or window on a session: its own process, a replica core], + [*far*], [a client on another machine], + [*frontend*], [what draws: the terminal, the window, the Mac's own], + [*detached*], [a session with no frontend of its own (it may have clients)], + [*attach*], [show a session here], + [*daemon*], [the per-user switchboard, `pardes --daemon`], + [*stub*], [the process your shell waits on when the session is not it], +) + +The code, its messages and the older notes still use other words for the +same things, until the code is renamed: + +// tui.zig:622-667, gui.zig:769-776, main.zig:1683-1687 (remote); +// main.zig:1523, gui.zig:765-829, :2381-2384 (headless, parked); +// replica.zig:1850-1852 (alone_unattended); replica.zig:1-19 (authority); +// tui.zig:1189, gui.zig:2379 (Shell); replica.zig:1832-1876, :2809-2812 +// (Peers, Link, Joining); daemon.zig:799 (ps's attached and detached). +#pairs( + [`remote`, `Remote`], [a client, on this machine too; another machine's is *far*], + [`headless`, `parked`, `unattended`, `alone_unattended`], [detached, or nobody looking], + [`authority`], [the session's core, inside the replica engine; `replica`, a client's core], + [`Peers`, `Peer`; `Link`, `Joining`, `Joined`], [a session's clients, seen from the session; a client's connection, seen from the client], + [`Shell`], [a frontend's host object (`tui.zig`, `gui.zig`); elsewhere the user's shell], + [`attached`, `detached` in `pardes ps` and #file("/sessions")], [whether the session has a frontend of its own], + [a daemon that "keeps" a session], [one it has on its list], +) |
