diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 20:47:38 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 22:47:08 -0300 |
| commit | 91076bdb892fe898a8b07325867a1d29c1d65862 (patch) | |
| tree | 20d7254ebf9809a905f344f7d46442e77c210b73 /runtime | |
| parent | 0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (diff) | |
| download | pardes-91076bdb892fe898a8b07325867a1d29c1d65862.tar.gz pardes-91076bdb892fe898a8b07325867a1d29c1d65862.zip | |
dev, runtime: a session's ptys once (dev/Ptys.zig, a working name), the session loop's with the one queue they post to (the Inbox, now the loop's): spawn, take an adopted shell, write, resize, signal, close, the three questions Kill asks and Adopt (Ptys.Calls fills both frontends' Host tables), the readers on the Inbox in both frontends (the terminal's own reader, its two-reads back-pressure and its pty_read/pty_eof messages deleted; it still takes one read a step, the rest kept for the next wait, so a frame shows a command's last line before its exit scrolls it away, as process-test's headersweep watches), end of file and a command's exit, the cwd poll, an Upgrade's pause/record/readOn (a window whose Upgrade failed no longer trips acceptReader's assert), an upgraded session's shells and a Restore's stop (the loop's: the frontend call resumePtys is gone, eleven calls to ten); where the copies differed the window's behaviour stays (the daemon told at a shell's end of file, a reader that cannot start said in its pane, the session's end hangs each shell up and waits out its grace) but the tty's for where a new shell is asked (only one given no directory) and the window's reconcile of ptys against panes is deleted (the core asks every retired terminal pane's pty closed); tui core-test 848/991 (143 skipped), shell-test 1031/1034 (4 Ptys tests, 3 of them moved from gui.zig), term 15/15, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, the frame corpus 77/77 Debug; on this change's first form (all of a wait's output in one step) the soak 0 diverged, 0 unequal, quiet checks 618/0 835/0 771/0, unlisted 0, corpus scene 22/22, no leak, and gui unit-test 1626/1630 with only the perf check's BaselineHarnessMismatch; the rest of the gate was stopped with the disk under 10 GB (report pardes-services.md)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/session.zig | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/runtime/session.zig b/runtime/session.zig index f401c85a..3942aa83 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -2,23 +2,24 @@ //! (dev/gui `runNative`) alike, each with a frontend of its own. It holds //! the session's allocators and workers, its core (an upgrade's, a dump's //! or a new one), the prompt files its shells start with, its 9P listener -//! and its replica clients (`Peers`): a step, its unit to the clients and -//! theirs taken in, an Upgrade or a Restore between steps; and the order -//! its parts end in. Its devices (the ptys and their readers, the files -//! watched, the LSP's and the pipes' and addons' jobs, the queue they post -//! to, the session's own input) are still its frontend's (each `Shell`, -//! the services step's to make one). What a frontend does is: +//! its replica clients (`Peers`), its queue (the workers' and readers' +//! posts, `Inbox`) and its ptys (`Ptys`): a step, its unit to the clients +//! and theirs taken in, an Upgrade or a Restore between steps; and the +//! order its parts end in. Its other devices (the files watched, the LSP's +//! and the pipes' and addons' jobs, the session's own input) are still its +//! frontend's (each `Shell`). What a frontend does is: //! //! - `options(o)`: before the core: what it gives the core it starts (a //! window's size, for a dump's layout). //! - `open(l) Host`: its devices made over the session's core and parts, -//! the host the core steps with (the core's, set there); what it does -//! before the core's first effects (an upgraded terminal's panes its -//! own again, whether anyone looks). +//! the host the core steps with (the core's, set there), who wakes it +//! when the queue gets a post (`l.inbox`); what it does before the +//! core's first effects (an upgraded terminal's panes its own again, +//! whether anyone looks). //! - `close(l)`: its devices stopped, after the clients are let go and -//! before the core goes. -//! - `resumePtys(rec)`: an upgraded session's shells, its own again. -//! - `start(l)`: after the first effects: its input, its readers, the +//! before the ptys, the queue and the core go. +//! - `start(l)`: after the first effects, the ptys read: its input, its +//! readers, the //! listener's wake, a detached session's first wait (`l.watch`). //! - `sent()`: after each step's unit went to the clients. //! - `upgradeAsked()`: an Upgrade asked in the step, done (it execs). @@ -32,6 +33,7 @@ const std = @import("std"); const pardes = @import("core"); const replica = pardes.replica; const host_io = @import("dev").host_io; +const Ptys = host_io.Ptys; const file_watch = @import("dev").file_watch; const daemon = @import("daemon.zig"); const upgrade = @import("upgrade.zig"); @@ -52,6 +54,10 @@ pub fn Loop(comptime Frontend: type) type { frames: pardes.FrameStats = .{}, core: *pardes.Pardes = undefined, prompt_rcs: host_io.Shell.PromptFiles = undefined, + /// What the session's workers and readers post, for the frontend + /// to take in its wait. + inbox: host_io.Inbox = undefined, + ptys: Ptys = undefined, fs: ?*ninep_io.Listener = null, peers: replica.Peers = .{}, host: pardes.Host = undefined, @@ -83,6 +89,10 @@ pub fn Loop(comptime Frontend: type) type { l.fs = ninep_io.start(l.io, l.gpa, l.core); defer if (l.fs) |f| f.deinit(l.gpa); l.peers = .{ .gpa = l.gpa, .io = l.io, .name = daemon.name() }; + l.inbox = .{ .io = l.io, .gpa = l.gpa, .lsp_allocator = l.allocs.lsp }; + defer l.inbox.deinit(); + l.ptys = .{ .queue = &l.inbox, .prompt_rcs = &l.prompt_rcs }; + defer l.ptys.deinit(); l.host = try fe.open(&l); defer fe.close(&l); @@ -93,9 +103,10 @@ pub fn Loop(comptime Frontend: type) type { // ...and its shells, once a fresh session's own has a directory // to adopt them in. if (upgrade.resumed) |*rec| { - fe.resumePtys(rec); + l.ptys.resumeFrom(l.core, rec); l.effects(); } + l.ptys.start(l.core); try fe.start(&l); while (!l.core.quit) { @@ -140,11 +151,13 @@ pub fn Loop(comptime Frontend: type) type { } /// A Restore: the core its dump makes replaces this one, its clients - /// let go (host_io.restoreCore); the frontend's devices with it. + /// let go (host_io.restoreCore); its shells and the frontend's + /// devices with it. fn restore(l: *L, path: []const u8) void { const w = l.fe.watched(); const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, w.fd, w.table) orelse return; l.fe.restoring(nc); + l.ptys.stop(); nc.host = l.host; if (l.fs) |f| f.reset(nc); l.core.deinit(); |
