summaryrefslogtreecommitdiff
path: root/docs/typ/running.typ
diff options
context:
space:
mode:
Diffstat (limited to 'docs/typ/running.typ')
-rw-r--r--docs/typ/running.typ148
1 files changed, 68 insertions, 80 deletions
diff --git a/docs/typ/running.typ b/docs/typ/running.typ
index 1500845e..74eb8cbd 100644
--- a/docs/typ/running.typ
+++ b/docs/typ/running.typ
@@ -4,31 +4,32 @@
// 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
+#import "figures.typ": run-legend, run-terminal, run-window, run-detach, 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.
-// runtime/daemon.zig:8-16 (nobody's parent; dups; hands terminals,
-// windows, replicas); core/replica.zig:1-19, :747-794 (a client's core
+// runtime/daemon.zig:8-17 (nobody's parent; dups; lists the sessions,
+// hands a client's connection on); core/replica.zig:1-19, :747-794 (a client's core
// from the dump); dev/host_io.zig:548-551 (the shells are the session's
-// children); runtime/9p_io.zig:57 (the socket); runtime/daemon.zig:546-698
-// (the stub).
+// children); runtime/9p_io.zig:57 (the socket); runtime/daemon.zig forkSession,
+// stubWait (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.],
+ [*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, and it hands each client's connection to the session it names. The first session that finds none starts it, and it exits a second after it holds nothing. Killed, it is started again by its sessions, which register with the next one.],
[*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.],
)
-// dev/tui/tui.zig:590 (a session's terminal: one or none);
-// dev/gui/gui.zig:2433-2436 (the window, or none while detached);
-// runtime/daemon.zig:901-905 ("a session shows one frontend of its own").
+// dev/tui/tui.zig Screen (a session's terminal: the one it was born
+// with, or none); dev/gui/gui.zig Shell.gui (the window, or none once
+// detached); runtime/main.zig attachTo (an attach is a client).
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.
+frontend of its own: the one it was started with. Once it lets that one go
+(a #word("Detach"), its terminal closing) it is *detached*, for good; it
+may still have clients. To *attach* is to show a session here, and an
+attach is always a client.
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
@@ -41,11 +42,11 @@ travels on it.
#run-terminal()
-// runtime/main.zig:1570-1595, runtime/daemon.zig:663-698 (the fork,
-// setsid, the stub); runtime/daemon.zig:550-559, :567-616 (what the stub
-// forwards and how it ends); dev/tui/tui.zig:1685-1709 (the terminal's
-// end: detached while kept, else the end); runtime/daemon.zig:305-314
-// (kept: the daemon answered and is still there).
+// runtime/main.zig, the fork (daemon.forkSession: setsid, the stub);
+// runtime/daemon.zig forward, stubWait (what the stub forwards and how it
+// ends); dev/tui/tui.zig, the `.quit` arm (the terminal's end: detached
+// while kept, else the end); runtime/daemon.zig 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
@@ -54,7 +55,7 @@ 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.
+daemon it ends the session and its shells.
= `pardes-gui` <run-window>
@@ -80,9 +81,9 @@ terminal hangs up.
// 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")).
+the same). It draws nothing and is 160×50 until the root #file("ctl")'s
+`size` sizes it; a client shows its own view, at its own size. Until a
+client attaches, 9P is the only way in (#doc("scripting")).
// runtime/main.zig, the --detach branch (the exec of the pardes beside it).
`pardes-gui --detach` runs the `pardes` installed beside it in its place:
@@ -95,55 +96,42 @@ a daemon keeps it; a window's binary's ends on it, as any job does. With no daem
`--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()
-
-// runtime/main.zig:1812-1842 (attachTo); runtime/daemon.zig:883-897
-// (handed on); dev/tui/tui.zig:1354-1382 (the terminal entered as the
-// first was); dev/gui/gui.zig:3384-3402, :2588-2601 (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.
-
-// runtime/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>
+= Attach <run-attach-client>
#run-attach-client()
-// runtime/main.zig:1844-1850 (crossAttach); runtime/daemon.zig:974-1008
-// (the hello, the same build, handed on); core/replica.zig:1-19
-// (speculation and rollback); core/replica.zig:2204-2214, core/views.zig:31,
+// runtime/main.zig attachTo, bareAttach (a client, through the replica
+// socket; bare: the one detached session, else the one session);
+// runtime/daemon.zig hear (the hello, the same build, handed on);
+// core/replica.zig:1-19 (speculation and rollback); core/views.zig:31,
// core/Core.zig:1163-1203 (four views, the session's own among them);
-// core/replica.zig:2303-2325 (a client leaving); core/replica.zig initDump,
-// core/Addon.zig plainOps (a plain kind's code runs in the client that has
-// it; another's in the session alone); dev/gui/gui.zig:2200-2214 (a
-// client's notch: whole rows sent), :3673 (glideFrame: the picture on the
-// client's clock); dev/gui/gui.zig:595-623 (a client's font: the session's
-// request, by the face's name on this machine). Measured 2026-11-17
+// core/replica.zig closeViewOf (a client leaving); core/replica.zig
+// initDump, core/Addon.zig plainOps (a plain kind's code runs in the
+// client that has it; another's in the session alone);
+// dev/gui/gui.zig:2200-2214 (a client's notch: whole rows sent),
+// glideFrame (the picture on the client's clock); dev/gui/gui.zig
+// syncReplicaFont (a client's font: the session's request, by the face's
+// name on this machine). Measured 2026-11-17
// (.scratch/sketch/reports/pardes-measure.md sections A, C and E): a
// client's notch glides as the session's window does (5 frames, 0 to
// -22 px); a terminal's client 10-16 MB PSS idle, a window's about 110 MB
// (187 MB RSS), as a window session's, three quarters of it the GPU and
// display libraries.
-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.
+`pardes attach work` is a client of session work, whatever the session was
+started in and whether or not it still has its own frontend: in a terminal
+for `pardes`, a window for `pardes-gui`. A session never takes a frontend
+of its own back: the one it was born with is the only one it ever has.
+Bare, `pardes attach` takes the one detached session; with none detached,
+the only session there is; with several, it names them and asks which.
+`--attach=work` is the older spelling of `attach work`.
+
+The client says its hello on the daemon's replica socket: the session's
+name, and the client's build (a client must be the build its session is).
+The daemon refuses a name no session has, and hands the 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.
// core/replica.zig:5316-5395 (may_wait: what a client waits for, each
// row's why); core/tape.zig:1163-1193 (keeps_stopping); core/Core.zig:1763-1778
@@ -163,7 +151,7 @@ opens here.
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
+client only (it says the session let it go, and exits 1); 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 whose state
is plain (`PA_PLAIN`: the games, the picture, the PDF) runs in the client
that shows it, from that client's own addons; one the client lacks
@@ -202,18 +190,18 @@ of the session or a divergence of its own. `pardes attach /run/x.sock:work`
#run-no-daemon()
-// runtime/daemon.zig:52-61 (PARDES_DAEMON, PARDES_TEST), :34 (Linux and
-// FreeBSD only); runtime/main.zig:1576-1592 (no daemon reached: no fork);
-// dev/tui/tui.zig:1333-1334, dev/gui/gui.zig:2537, dev/host_io.zig:85
-// (Detach and Adopt refused); core/replica.zig:2087-2092 (a client only
-// through the daemon); core/root.zig:118 (can_attach);
-// runtime/main.zig:1513-1515 (a far attach needs no daemon here).
+// runtime/daemon.zig wanted (PARDES_DAEMON, PARDES_TEST), supported
+// (Linux and FreeBSD only); runtime/main.zig, the fork (no daemon reached:
+// no fork); dev/tui/tui.zig detach, dev/gui/gui.zig detachWindow,
+// dev/host_io.zig (Detach and Adopt refused); runtime/main.zig attachTo (a
+// client only through the daemon); core/root.zig can_attach;
+// runtime/main.zig, `attach HOST:NAME` (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]).
+daemon died is not: it starts the next one itself (#link(<run-survives>)[below]).
`pardes-gui` built for a Mac has no daemon either, but can still be a far
client.
@@ -234,8 +222,7 @@ client.
[`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 work`], [client, session, daemon], [`pardes attach work` (the client), the session as it was], [the session; the client has a replica], [the client, this terminal (`pardes-gui`: a window); the session its own frontend, if it still has it], [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],
)
@@ -247,13 +234,14 @@ started it. After an #word("Upgrade"), a session's command line starts with
= What survives what <run-survives>
-// core/replica.zig:2303-2325 (a client leaving); runtime/daemon.zig:485-502,
+// core/replica.zig closeViewOf (a client leaving); runtime/daemon.zig hangUp, quit,
// runtime/9p_io.zig:704-729, dev/tui/tui.zig:928-940 (TERM, HUP, INT: the
-// shells go); runtime/daemon.zig:755-765, :770-789 (killed outright: kept
+// shells go); runtime/daemon.zig Daemon.hangUp, Daemon.kill (killed outright: kept
// for Adopt; `kill`: not); dev/tui/tui.zig:598-600 (a HUP kept by a daemon
-// is a terminal's end, not the session's); runtime/daemon.zig:397,
-// runtime/main.zig:1566-1593 (registered at the start and at an Upgrade
-// only); runtime/upgrade.zig:1-15, core/replica.zig:2370-2393, :2988-3008
+// is a terminal's end, not the session's); runtime/daemon.zig readNotes,
+// redial, relinked, dev/Ptys.zig tellDaemon (the next daemon dialled by
+// the link's end alone, the hello and the shells' masters told it
+// again); runtime/upgrade.zig:1-15, core/replica.zig:2370-2393, :2988-3008
// (Upgrade); core/Db.zig:1-17, :385-410 (the state file: Recent, the dumps).
#{
set text(size: 0.85em)
@@ -268,7 +256,7 @@ started it. After an #word("Upgrade"), a session's command line starts with
[#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],
+ [the daemon is killed], [runs on, and dials the next daemon at once, starting it if none answers: `pardes ps` lists it again, clients attach, #word("Detach") and #word("Adopt") work], [stay, their terminals held by the next daemon too; the shells of sessions killed earlier, held only by the dead daemon, hang up], [the ones joined stay; new ones join through the next daemon],
[#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],
)
@@ -282,8 +270,8 @@ started it. After an #word("Upgrade"), a session's command line starts with
[*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],
+ [*detached*], [a session with no frontend of its own, for good once it has let go the one it was born with (it may have clients)],
+ [*attach*], [show a session here: always a client],
[*daemon*], [the per-user switchboard, `pardes --daemon`],
[*stub*], [the process your shell waits on when the session is not it],
)
@@ -295,7 +283,7 @@ and `headless` for detached):
// core/replica.zig:1-19 (authority); core/replica.zig:2006-2062, :3013
// (Peers, Link, Joining); dev/tui/tui.zig:1162, dev/gui/gui.zig:2431
// (Shell); core/Core.zig:313-315, core/replica.zig:2028-2030 (unattended
-// against detached); runtime/daemon.zig:283, :363, :799 (the daemon's
+// against detached); runtime/daemon.zig hello, setDetached, Daemon.list (the daemon's
// attached and detached), runtime/main.zig:1647 (`ps` says "has a
// frontend"); runtime/session.zig:1-30, runtime/client.zig:1-35 (the
// loops and what a frontend gives each).