diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 03:20:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 04:00:32 -0300 |
| commit | a6c258bec5808ac2b6ef9d3362134e34e759c1c9 (patch) | |
| tree | f785b15b2a3bcd0f7d3e8f92d7948af634c52b69 /docs/next-run.md | |
| parent | 1967cf64dc6d7490d386db874cf1866b764f235c (diff) | |
| download | pardes-a6c258bec5808ac2b6ef9d3362134e34e759c1c9.tar.gz pardes-a6c258bec5808ac2b6ef9d3362134e34e759c1c9.zip | |
docs: an attach is always a client, and a session registers again with a restarted daemon, in the documents: the manual's "How pardes runs" (docs/typ/running.typ: one Attach section, its figure of the in-place attach deleted from figures.typ, the glance and survival tables, the words), the guide's Sessions, the reference's /sessions and command line, the building chapter's daemon, the cheatsheet's line, `pardes help attach` (runtime/main.zig, docs/typ/command-line.txt from builtins-json), the Detach word's doc (core/builtins.zig, both builtins JSONs), docs/next-run.md as built (what went, counted on the change: 305 lines deleted, 94 added; the re-registration as built; --detach forking still not) with its figure (Before / Now), and the changelog's Unreleased; the book and the cheatsheet render (typst), tui shell-test 1046/1049 (3 skipped), core-test 855/1005 (150 skipped: the base's 856/1006 less the deleted `find` test)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'docs/next-run.md')
| -rw-r--r-- | docs/next-run.md | 143 |
1 files changed, 82 insertions, 61 deletions
diff --git a/docs/next-run.md b/docs/next-run.md index 06941026..74eab197 100644 --- a/docs/next-run.md +++ b/docs/next-run.md @@ -1,4 +1,4 @@ -# Running pardes: an attach is always a client (ruled, not built) +# Running pardes: an attach is always a client (ruled; built 2026-11-20, all but `--detach` forking) > 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, @@ -7,69 +7,84 @@ 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" +stays as built; the vocabulary and the manual's page first, the code +after. Built on 2026-11-20 (agent pardes-attach, report +`.scratch/sketch/reports/pardes-attach.md`): an attach is always a client, +the in-place attach deleted, and a session registering again with a +restarted daemon. Not built: `--detach` forking (below). What runs, 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-19. ## 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. +replica core, as the second attach to a session already was. 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; + death no longer leaves its sessions unlisted for good (built); - `--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. + returns at once and `ps` always shows a session the same way (not + built). -## Today, and after +## Before, and now - + 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` -(`runtime/daemon.zig:901-972`) and by `main.zig`'s `attachTo` -(`runtime/main.zig:1806-1842`): 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. +Before, `pardes attach` was four mechanisms, picked by the daemon's `find` +and by `main.zig`'s `attachTo`: a terminal handed to a detached terminal's +session, which drew on it in its own process while the attach process +waited as its stub; a window's detached session asked to open its own +window again, while the attach process exited; a client here, when the +session had a frontend or was of the other kind; a far client through +`ssh -L`. Now it is the last two only: a client, here or far. +`runtime/main.zig`'s `attachTo` goes to this machine's replica socket with +the name (the daemon refuses one no session has); bare, `bareAttach` takes +the one detached session from the daemon's `list`, else the one session, +else names them and asks which. -## What it removes +What a user who relied on the in-place attach does now: `pardes attach +work` (or `pardes-gui attach work`) is a client of the detached session, +its own process in this terminal or window. What differs from having the +session's own frontend back: the client is a second process (a terminal's +10-16 MB, a window's about 110 MB); an addon that is not plain runs in the +session alone (its panes show a line saying so); its Detach, or its +terminal closing, ends the client with "'work' let this client go" and exit +1, where the stub said "detached from 'work'" and exit 0 (the last word a +session sends its client, and exit codes, are the next steps: "B" in +`.scratch/sketch/reports/pardes-last-step-design.md`). -The reorganisation plan's option b, checked against this tree: +## What it removed -| 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 | `runtime/daemon.zig:400-403`, `:431-437`, `:504-533`, `:883-897`; `dev/tui/tui.zig:107-109`, `:1037-1040`, `:1135-1140`, `:1354-1387`, `:1711`; `runtime/main.zig:1821-1842` | 110 | -| A window opened again in place | `dev/gui/gui.zig:550-557` (what it reopens with), `:1004-1022` (`reopenWindow`), `:2588-2601` (`openTheWindow`), `:2823`, `:3388-3394` | 50 | -| The daemon choosing which session takes a frontend: `find`, its `other` answer, the use of `daemon.Kind` to match | `runtime/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) | `runtime/daemon.zig:561-616` in part (`:593-597`, `:613-615`) | 10 | +Counted on the change itself (deleted lines, comments with them; a +function's added replacement in brackets): -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 (`dev/tui/tui.zig:1438-1446`, `runtime/upgrade.zig:101-117`), and a window's still -says whether it had its window (`dev/gui/gui.zig:2656`). Only the record's other -terminals (`dev/tui/tui.zig:1487-1506`, 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 (`dev/tui/tui.zig:1327-1352`, -`dev/gui/gui.zig:2530-2539`, `:2575-2586`): it is how a session becomes detached. -`daemon.Kind` stays in the hello and in `pardes ps` (`tty` or `gui`). +| What went | Where | Lines | +|---|---|---| +| The daemon choosing which session takes a frontend: `find`, its `other` answer, the `attach` verb and its test | `runtime/daemon.zig` `Daemon.find`, `Daemon.take` | 99 | +| The attach request: `daemon.attach`, `Answer`, `Note.attach` and the reader's arm | `runtime/daemon.zig` | 36 | +| The stub's second use: `stubWait`'s `child` and its `r` and `x` words, `tellStubExit` | `runtime/daemon.zig`, `runtime/main.zig` | 37 | +| `attachTo`'s two hand-offs and `crossAttach` | `runtime/main.zig` | 41 (+16: `attachTo`; +33: `bareAttach` and its test, what `find` chose, done here) | +| A terminal handed to a session: `attachTerminal`, `refuse`, the `.attach` message and its three arms | `dev/tui/tui.zig` | 52 | +| A window opened again in place: `openTheWindow`, `Shell.detached`, the queue's `.window` and its arms | `dev/gui/gui.zig`, `dev/Inbox.zig`, `runtime/macos.zig` | 34 | +| `setState(false)`, which nothing says now | `runtime/daemon.zig` (`setDetached`) | 2 | +| **in all** | | **305 deleted, 94 added** | -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 did not go: the upgrade record's terminal and window fields (a +session born with a terminal still takes it across an Upgrade); Detach of +the session's own frontend (it is how a session becomes detached); +`reopenWindow`, which a WindowOpacity under 100 makes a window again with; +`daemon.Kind` in the hello and in `pardes ps` (`tty` or `gui`). -## What a client lacks today, which the change makes work +## What a client lacked, which the change made work The ruling turns these from objections into work. Each is checked here: what is true, and whether it was measured. @@ -86,7 +101,7 @@ what is true, and whether it was measured. 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 + window's with addon panes). Before, only a second attach paid it; now 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.** No longer so for an @@ -121,23 +136,31 @@ what is true, and whether it was measured. Not measured here: a keystroke to its frame, local client against own frontend, on the soak gate. -## A session registering again +## A session registering again (built) -Today a session says hello once, at its start (`runtime/main.zig:1567-1595`), or -on its link after an Upgrade (`runtime/daemon.zig:392-398`). When the daemon dies -the session's reader sees the link end (`runtime/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 -(`dev/tui/tui.zig:1699-1709`, `dev/gui/gui.zig:1839`). The next daemon knows only the -sessions that start after it. +Before, a session said hello once, at its start, or on its link after an +Upgrade; when the daemon died the session's reader saw the link end and +nothing dialled again, so the session ran on unlisted: `pardes ps` and +attach did not find it, Detach and Adopt refused, and its frontend closing +ended it. With "an attach is always a client" that would have meant no +attach to any session after a daemon's death. -The work: when `gone` is set, the session's loop (which calls -`daemon.watch` each iteration already, `runtime/session.zig:115`, `:133-135`) -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, `runtime/daemon.zig:37`), and its clients' pids. What -cannot come back: the shells of sessions killed earlier, which only the -dead daemon held. +Now (`runtime/daemon.zig` `readNotes`, `redial`, `relinked`; +`runtime/session.zig` `watch`; `dev/Ptys.zig` `tellDaemon`): the reader +thread, blocked in its read, is woken by the link's end alone. If the +daemon had taken the hello (an `ok` came) and the session is not ending, +it dials the next daemon, starting one if none answers +(`daemon.connect(true)`: the lock decides which of several sessions starts +it), puts the new connection on the link's own fd (`dup3`, so the session +loop's own sends never race a new fd) and says the hello with its kind, +name and whether it is detached. It then posts a note that wakes the +session loop once, which tells the new daemon a dup of every pty master it +holds and its clients' pids. Nothing polls and nothing waits on a timer: an +idle session is at 0 wakeups before and after (`test/daemon.py --relink`, +2 s each). A link the daemon never took (another build's daemon refuses +the hello) is not dialled again, so two builds cannot loop. What cannot +come back: the shells of sessions killed earlier, which only the dead +daemon held. ## `--detach` forking @@ -166,10 +189,10 @@ binary's strings (`/usr/sbin/rex` links libghostty); Rex was not run. | 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 | +| Attach | no user's verb; in the API "start receiving its events and get its current view" | one: a client (four mechanisms until 2026-11-20) | | 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 | +| The server or daemon dies | "Stopping the server ends every program" (`help-server-stop.txt`) | a killed daemon ends nothing; its sessions start the next and register with it again | 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 @@ -182,8 +205,6 @@ 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 (`runtime/main.zig:1567-1569` ignores the failed registration). Refuse, or keep it as a 9P-only session? @@ -191,6 +212,6 @@ session takes back. 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). +- A client's Detach exits 1 with "let this client go", where the stub's + said "detached from" and exited 0: the session's last word to a client + (step B of the last-step design) would let it say which. |
