From 4ffe5c93b3087f245f5b57a822ab0ecf41cc085c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 10:48:56 -0300 Subject: sessions register with the daemon: a terminal's session forked off its stub, Detach and --attach in place for terminals and windows, pty masters kept, Adopt pardes in a terminal reaches (or starts) the daemon, opens /dev/tty and forks: the child is the session, in a session of its own (setsid), drawing on that terminal (tty.Term.fd, a raw vaxis Tty made from the fd); the parent stays as its stub, the job the shell waits on. Not the daemon spawning it from a passed fd, env and argv: the user's terminals each run in a 9ns user and mount namespace, which a session spawned by a per-user daemon would not share, and a fork costs one small process's page tables where the spawn cost an IPC and an exec. GUI windows and --detach sessions just register. tty: Detach (and a terminal's end: EOF, EIO, a hangup the stub passes on, taken on the signal thread) puts the terminal back, drops it and the stub's stdio, tells the stub (which ends, exit 0), and leaves the session running with nothing drawn (Host.watched), its messages on the clock and `size` its own. pardes --attach[=name] hands its terminal through the daemon; the session enters it as the first one, sized, queried and drawn whole, and that process is its stub until it leaves. A hangup never ends a kept session; TERM and INT do, telling the daemon so the shells go with it (one async-signal-safe send). gui: Detach closes the window (its swapchain or renderer) and keeps the device, atlas and pipelines; the loop sleeps on SDL's queue; pardes-gui --attach[=name] opens a window again. Closing a window still quits. --detach is a session started detached: the tty host with no terminal yet, the GUI with a hidden window closed at once. forkShell sends the daemon a dup of every master and the hosts tell it what they close, so a session killed outright leaves its shells running; the new Adopt word takes them in as terminal panes (the Tty word's pane, its spawn taking the pty, a 1x1 size then the pane's to make it redraw). The Attach word, which switched a session's own terminal to a detached session through the frames, goes, with its effect and request in the core. PARDES_DAEMON=off (the e2e harness's) runs a session as before. test/daemon.py: 50 detach/attach cycles at a level fd count with no stale socket, kill -9 and Adopt, and nothing left; --gui the same for a window. test/fs.py: a forked session's socket is found by its own pid, and a hangup leaves a kept session running. Co-Authored-By: Claude Opus 5.5 --- src/macos.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/macos.zig') diff --git a/src/macos.zig b/src/macos.zig index 8d372432..e07955a1 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -1105,7 +1105,8 @@ fn drainInbox(st: *State) bool { .search => |b| st.core.update(.{ .search = b }), // The SDL shell's: this one's file watches and 9P are its own. // ponytail: no hand_over host entry on macOS yet, so none comes. - .files_changed, .fs_ready, .handed => {}, + // No daemon on macOS (daemon.supported): neither ever comes. + .files_changed, .fs_ready, .handed, .window, .adopted => {}, } } for (0..pardes.MAX_PANES) |pane| { -- cgit v1.3 From 84b673d6c01e647c2eaeb6464d1f0a0004b7bd20 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 18:18:44 -0300 Subject: dump: a pane another build cannot give a terminal for is a terminal still; a session read by name is tested; nothing of a load goes to stderr Co-Authored-By: Claude Opus 5.5 --- src/dump.zig | 50 ++++++++++++++++++++++++++++++++++++-------------- src/macos.zig | 2 +- src/main.zig | 2 +- src/walk.zig | 13 +++++++++---- 4 files changed, 47 insertions(+), 20 deletions(-) (limited to 'src/macos.zig') diff --git a/src/dump.zig b/src/dump.zig index 20299b79..abc52f5a 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -1,11 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); const limits = @import("memory.zig").limits; - -// scoped, not bare std.log: main.zig's logFn drops the unscoped .default scope -// wholesale (ghostty and uucode log there too), and a corrupt dump's parse -// diagnostic is the only thing that says WHICH field went bad. -const log = std.log.scoped(.dump); const pardes = @import("pardes.zig"); const walk = @import("walk.zig"); const Handover = @import("Handover.zig"); @@ -252,13 +247,25 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: } if (l.notes.items.len > 0) { // A pane another build could not give is left out: so is its - // place in the layout. + // place in the layout. One whose terminal it could not give is a + // terminal still. dropMissing(p); + for (p.panes) |slot| if (slot) |pane| try ensureKind(p, pane); if (notes) |n| try n.appendSlice(gpa, l.notes.items); } return p; } +/// A pane that is none of its kinds (a terminal kept slim, or one another +/// build's dump could not give): a terminal, a new emulator for its shell. +fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void { + if (pane.terminal != null or pane.file != null or pane.image != null or pane.hasPdf()) return; + const fresh = try pardes.panes.terminal.create(p.gpa, @max(1, pane.cols), @max(1, pane.rows)); + pane.terminal = fresh.terminal; + fresh.terminal = null; + p.gpa.destroy(fresh); +} + /// The panes a column lists that are not there (another build's dump left /// them out) taken out of it, and the keyboard on one that is. fn dropMissing(p: *Pardes) void { @@ -320,8 +327,9 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ errdefer p.deinit(); for (p.panes, on_disk, 0..) |slot, was_on_disk, i| if (slot) |pane| revivePane(p, i, pane, was_on_disk); try reviveSession(p, previous); + // What another build's dump could not give, said where the user looks + // (stderr is a tty session's screen). if (notes.items.len > 0) { - log.warn("{s}", .{notes.items}); const first = notes.items[0 .. std.mem.indexOfScalar(u8, notes.items, '\n') orelse notes.items.len]; var buf: [320]u8 = undefined; p.setMessage(p.active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read"); @@ -458,13 +466,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane { f.content = text; } else |_| {} }; - if (pane.terminal == null and pane.file == null and pane.image == null and !pane.hasPdf()) { - // A terminal kept slim: a new emulator, a new shell. - const fresh = try pardes.panes.terminal.create(p.gpa, @max(1, pane.cols), @max(1, pane.rows)); - pane.terminal = fresh.terminal; - fresh.terminal = null; - p.gpa.destroy(fresh); - } + try ensureKind(p, pane); p.installPane(id, pane); revivePane(p, id, pane, false); return pane; @@ -589,3 +591,23 @@ test "a loaded terminal's history stays above its banner, the cursor where it wa try std.testing.expect(std.mem.indexOf(u8, text, "one\ntwo\n") != null); try std.testing.expect(std.mem.indexOf(u8, text, "two") .? < std.mem.indexOf(u8, text, "restored history").?); } + +test "a session read by name, field by field as another build reads it, is the same session" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\n"); + _ = ctlfs.pane.spliceBody(p, pane, 0, 0, "unsaved ").?; + try std.testing.expect(p.executeBuiltinLine(p.active, "Zerox")); + const bytes = try dumpBytes(p); + defer gpa.free(bytes); + const q = try Pardes.create(gpa, p.opts); + defer q.deinit(); + var l = try SessionLoad.init(gpa, bytes); + defer l.deinit(); + try std.testing.expect(l.same); + l.same = false; + try l.into(Pardes, q); + try std.testing.expectEqualStrings("", l.notes.items); + try std.testing.expectEqual(walk.digest(Pardes, p), walk.digest(Pardes, q)); +} diff --git a/src/macos.zig b/src/macos.zig index e07955a1..bc906dea 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -56,7 +56,7 @@ fn logFn( comptime format: []const u8, args: anytype, ) void { - if (scope != .macos and scope != .dump and std.c.getenv("PARDES_LOG") == null) return; + if (scope != .macos and std.c.getenv("PARDES_LOG") == null) return; std.log.defaultLog(level, scope, format, args); } diff --git a/src/main.zig b/src/main.zig index f310bf3c..0708e9d7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,7 +37,7 @@ fn logFn( comptime format: []const u8, args: anytype, ) void { - if (scope != .gui and scope != .dump and std.c.getenv("PARDES_LOG") == null) return; + if (scope != .gui and std.c.getenv("PARDES_LOG") == null) return; std.log.defaultLog(level, scope, format, args); } diff --git a/src/walk.zig b/src/walk.zig index ce097c0e..304fc5aa 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -1,7 +1,9 @@ //! The reflective walk over the core's state: one comptime `@typeInfo` walk //! that hashes a session into a digest (the replay harness compares two), -//! and that the complete dump and the rollback copy are to walk the same -//! way (docs/next-daemon.md). +//! encodes values for the tape, and dumps a session for another build to +//! load by name (`Dump`, `Load`: Restore, -l, the store, a handover, and +//! the join of phase 5). The rollback copy is to walk the same way +//! (docs/next-daemon.md). //! //! Values, never addresses: a pointer is followed to what it points at, a //! slice is its elements, an ArrayList its items, a hash map its entries in @@ -19,10 +21,13 @@ //! .authority = .{ "host" }, //! // A field written only as far as another says: hashed that far. //! .len = .{ .{ "jumps", "njumps" } }, +//! // What a field holds is made with another allocator on a load. +//! .alloc = .{ .{ "image", "image" } }, //! }; //! -//! None of the three kinds is in a digest. A type with a `pub fn -//! digest(*const T, *Hasher) void` of its own hashes itself. +//! None of the three kinds is in a digest or a dump. A type with a `pub fn +//! digest(*const T, *Hasher) void` of its own hashes itself; one with +//! `dumpWrite`, `dumpRead` (and `dumpFree`) dumps itself as bytes. const std = @import("std"); pub const Hasher = std.hash.Wyhash; -- cgit v1.3