From b23665597fcfd486e8f15942da25ce5708b77226 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 18:43:09 -0300 Subject: docs: next-run.md, the ruled direction not built: an attach is always a client (a session's own frontend only the one it was born with), what it removes with this tree's lines (the upgrade record's terminal and window fields stay, against the plan), what a client lacks today checked (+25 MB measured 2026-11-06; an addon's code runs in no replica; a window client's notch is whole rows, but its touchpad's fractions are local and it follows the session's font by name now), a session registering again with a restarted daemon, --detach forking, Rex beside pardes, and the figure of today's four meanings of attach beside the one after (next-run.typ, rendered to next-run.svg) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/next-run.md | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/next-run.svg | 1 + docs/next-run.typ | 9 +++ 3 files changed, 186 insertions(+) create mode 100644 docs/next-run.md create mode 100644 docs/next-run.svg create mode 100644 docs/next-run.typ (limited to 'docs') diff --git a/docs/next-run.md b/docs/next-run.md new file mode 100644 index 00000000..4d9de291 --- /dev/null +++ b/docs/next-run.md @@ -0,0 +1,176 @@ +# 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. + +- **+25 MB a client.** Measured on 2026-11-06 for the one-client-path step + (`.scratch/arch/client-report.md:21-22`): idle RSS, median of 3 after + 4 s idle, a session with a second local attach: the session 34.6 to + 38.0 MB, the second process 18.6 MB as a stub to 43.8 MB as a client. + "A second local view costs a second core: about +25 MB in its own + process and +3.4 MB in the session." The build mode is not stated there. + 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.** Half + true. Read: a wheel's notch in a client is whole rows with no glide + (`gui.zig:2147-2150`), as `docs/next-daemon.md`'s GUI replica notes say; + but a touchpad's fractions are the client window's own picture now, only + its whole rows going to the session (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. +- **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/`; nothing else of Rex was 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`): a view of the server's state | a process with a whole replica core: its own view, speculation, 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 `attached` for a session with a frontend of its own. + After the change that frontend can only be the first one: keep the word, + or say `detached` / `with its 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). diff --git a/docs/next-run.svg b/docs/next-run.svg new file mode 100644 index 00000000..fdfc705a --- /dev/null +++ b/docs/next-run.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/next-run.typ b/docs/next-run.typ new file mode 100644 index 00000000..91461b25 --- /dev/null +++ b/docs/next-run.typ @@ -0,0 +1,9 @@ +// The figure of docs/next-run.md: what `pardes attach` does today beside +// what it does once "an attach is always a client" is built. Drawn by +// docs/typ/figures.typ, the one file of the docs that imports cetz. +// typst compile --root . --ignore-system-fonts -f svg docs/next-run.typ docs/next-run.svg +#import "typ/style.typ": palette +#import "typ/figures.typ": run-attach-before-after +#set page(width: 17.2cm, height: auto, margin: 0.4cm, fill: palette.paper) +#set text(font: "Libertinus Serif", size: 10pt, fill: palette.ink) +#run-attach-before-after() -- cgit v1.3