From bbae7225e939daf4b6360d3de7af06c0fd95ce8d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 06:21:57 -0300 Subject: pair: the process suite as pairs from 13 of 145 failing to 7 that stay (the goldens of one cause, open): the harness dials a pair's session, the launched client's child (test/process.zig `of`, `childOf`: it dialled the launched pid's socket); a Restore in a pair no daemon keeps is refused in words, as its Upgrade is (P42: runtime/session.zig `restore`: it let the client go and the session ended with its last link), and the three cases that Restore a pair run it with a daemon of their own root's (tty.zig `privateDaemon`, e2e_harness `PARDES_HARNESS_DAEMON`, process.zig `Detached.tty_daemon`, ended by `--kill-all` at its deinit); a pair's launch with no terminal says what the own path says and forks no session (main.zig `pair`, `noTerminal`: it said "pardes: NoDevice" after forking one); a terminal client ended by TERM or HUP dies of the signal once its goodbye is said and its terminal put back, as the own path's stub does (tui.zig `dieOfQuitSignal`: it exited 0 since pair-3), and the kill test takes a pair's hang-up as the close P36 ruled; PARDES_PAIR=1 process-test 8 of 145 (7 goldens of one family: resizes=2, a terminal panned in a view shorter than the one that sized it, a restored terminal's history; winch once), without the variable 0 of 145 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/tui/tui.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'dev') diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 09704424..7e5a75fb 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -731,6 +731,10 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, posix.sigaddset(&winch_set, posix.SIG.HUP); posix.sigaddset(&winch_set, posix.SIG.TERM); hangup_quits = true; + // Last of all, after its goodbye and its terminal put back: dead of the + // TERM or HUP that ended it, as the own path's stub dies (the shell's + // $? is 128+N), not exit 0. + defer dieOfQuitSignal(); if (comptime builtin.os.tag == .freebsd) posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null); posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null); @@ -808,6 +812,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var status: c_int = 0; while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} } + dieOfQuitSignal(); std.process.exit(code); }, .failed => { @@ -1954,6 +1959,22 @@ fn keepSignal(_: posix.SIG) callconv(.c) void {} /// A replica client's (`runClient`): a hangup or a TERM is its end. var hangup_quits = false; +/// The signal a client's `.quit` came of (`winchWatch`), 0 for none. +var quit_signal: std.atomic.Value(c_int) = .init(0); + +/// A client ended by TERM or HUP dies of it, its goodbye said and its +/// terminal put back first; no other way out. +fn dieOfQuitSignal() void { + const sig: posix.SIG = @enumFromInt(quit_signal.load(.acquire)); + if (@backingInt(sig) == 0) return; + const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 }; + posix.sigaction(sig, &default, null); + var set = posix.sigemptyset(); + posix.sigaddset(&set, sig); + posix.sigprocmask(posix.SIG.UNBLOCK, &set, null); + _ = std.c.raise(sig); +} + fn winchWatch(loop: *Loop) void { var set = posix.sigemptyset(); posix.sigaddset(&set, posix.SIG.WINCH); @@ -1965,6 +1986,7 @@ fn winchWatch(loop: *Loop) void { // The terminals are the loop's: it asks each its size, and takes a // hangup as the end of the one that hung up. const ev: Msg = if (sig == @backingInt(posix.SIG.WINCH)) .winched else if (hangup_quits) .quit else .hangup; + if (ev == .quit) quit_signal.store(sig, .release); loop.postEvent(ev) catch {}; } } -- cgit v1.3 From 5ad6067936f306271b875aaf182d4866055da10d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 07:50:25 -0300 Subject: client: an Upgrade from the installed build (main 6d937cd125ca) to this one, the coordinator's release stage: a window exec'd at an Upgrade takes its size from PARDES_JOIN_SIZE (runtime/client.zig `execAgain`; dev/gui/gui.zig where `--geometry` is read), a string a test finds in the binary as PARDES_JOIN_VIEW is: test/daemon.py `knows_size`, and `pair_window_geometry` skips with a line said when the old window cannot pass its size (the installed build's: by design, its exec is the old client's); a far link cut with no last word dials again too (`replica.cutListed(why, session, far)`: the dial is the asking, the far daemon's "no session called" ends it), as near ones do since item 0: from the installed build `far_exec` lost its client before (2 of 6 runs) and still does once in five (the old far client is the installed build's code); a far client whose ssh link drops now dials again for up to 20 s before it says so Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 17 ++++++++++------- dev/gui/gui.zig | 4 +++- runtime/client.zig | 17 +++++++++++------ test/daemon.py | 11 ++++++++++- 4 files changed, 34 insertions(+), 15 deletions(-) (limited to 'dev') diff --git a/core/replica.zig b/core/replica.zig index edab01ee..97da9c74 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -3112,13 +3112,16 @@ pub fn ended(why: []const u8) bool { /// What an Upgrade tells its clients (`Peers.refuseAll`): each dials again. pub const upgrading = "the session is upgrading to another build of pardes"; -/// A near link cut with no last word (`why` its hang-up) whose session this -/// machine's daemon lists still: an Upgrade's exec cut it, a dump on the -/// way past the clients' flush (`Peers.refuseAll`), not the session's end, -/// which the daemon sees as its link's: so the client joins again as one -/// told `upgrading` does, whatever the flush's bound let through. -pub fn cutListed(why: []const u8, session: []const u8) bool { +/// A link cut with no last word (`why` its hang-up) whose session its +/// daemon lists still: an Upgrade's exec cut it, a dump on the way past the +/// clients' flush (`Peers.refuseAll`), whichever build the session is, not +/// the session's end, which the daemon sees as its link's: so the client +/// joins again as one told `upgrading` does, whatever the flush's bound let +/// through. Near, this machine's daemon is asked; far, the dial again is +/// the asking (the far daemon's "no session called" ends it: `redial`). +pub fn cutListed(why: []const u8, session: []const u8, far: bool) bool { if (!std.mem.startsWith(u8, std.mem.sliceTo(why, 0), "the session hung up")) return false; + if (far) return true; var buf: [8192]u8 = undefined; const list = daemon.ask("list", &buf) orelse return false; var lines = std.mem.tokenizeScalar(u8, list, '\n'); @@ -3170,7 +3173,7 @@ pub fn join(gpa: Allocator, j: *Joined, path: []const u8, session: []const u8, o sameBuild(gpa, (dial(gpa, path, session, why, have, null) orelse // Handed to the session as it upgraded, or cut by its exec with // its dump on the way: it is there again soon. - if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading) or (have == null and cutListed(why, session))) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why)) orelse return null; + if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading) or cutListed(why, session, have != null)) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why)) orelse return null; defer { if (have) |h| h.store(gpa, j) else gpa.free(j.dump); j.dump = &.{}; diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index d779cf47..aa28a3f0 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -808,7 +808,9 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di var want_w: c_int = 1120; var want_h: c_int = 720; var want_at: ?[2]c_int = null; - if (opts_in.geometry) |spec| geometry: { + // ...or the size an Upgrade's exec says its window had (client.zig + // `execAgain`). + if (opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry; const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len; want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384); diff --git a/runtime/client.zig b/runtime/client.zig index 789cac27..49ebbc6e 100644 --- a/runtime/client.zig +++ b/runtime/client.zig @@ -129,24 +129,29 @@ pub fn execAgain(s: *Start, view: u8, size: ?[2]c_int) []const u8 { const path = upgrade.exe() orelse return "Upgrade: this client does not know the path it was started from"; var at_buf: [4200]u8 = undefined; const at = std.fmt.bufPrintSentinel(&at_buf, "--attach={s}:{s}", .{ s.dial.path, s.dial.session }, 0) catch return "Upgrade: the session's socket's path is too long to attach again by"; - // A window's new window the size it had (`--geometry`), not the default. + const argv = [_:null]?[*:0]const u8{ path, at }; + // A window's new window the size it had (gui.zig reads it as a + // `--geometry`), not the default. var size_buf: [48]u8 = undefined; - const geometry: ?[*:0]const u8 = if (size) |wh| (std.fmt.bufPrintSentinel(&size_buf, "--geometry={d}x{d}", .{ wh[0], wh[1] }, 0) catch unreachable).ptr else null; // two c_ints fit 48 - const argv = [_:null]?[*:0]const u8{ path, at, geometry }; + const sized: ?[*:0]const u8 = if (size) |wh| (std.fmt.bufPrintSentinel(&size_buf, "PARDES_JOIN_SIZE={d}x{d}", .{ wh[0], wh[1] }, 0) catch unreachable).ptr else null; // two c_ints fit 48 var view_buf: [32]u8 = undefined; const joining = std.fmt.bufPrintSentinel(&view_buf, "PARDES_JOIN_VIEW={d}", .{view}, 0) catch unreachable; // a u8 fits 32 var n: usize = 0; while (libc.environ[n] != null) n += 1; - const envp = s.gpa.allocSentinel(?[*:0]const u8, n + 2, null) catch return "Upgrade: no memory for this client's environment"; + const envp = s.gpa.allocSentinel(?[*:0]const u8, n + 3, null) catch return "Upgrade: no memory for this client's environment"; var k: usize = 0; for (libc.environ[0..n]) |e| { const entry = std.mem.span(e.?); - if (std.mem.startsWith(u8, entry, "PARDES_JOIN_VIEW=") or std.mem.startsWith(u8, entry, "PARDES_REPLICA_FAR=")) continue; + if (std.mem.startsWith(u8, entry, "PARDES_JOIN_VIEW=") or std.mem.startsWith(u8, entry, "PARDES_JOIN_SIZE=") or std.mem.startsWith(u8, entry, "PARDES_REPLICA_FAR=")) continue; envp[k] = e; k += 1; } envp[k] = joining.ptr; k += 1; + if (sized) |e| { + envp[k] = e; + k += 1; + } if (s.have != null) { envp[k] = "PARDES_REPLICA_FAR=1"; k += 1; @@ -220,7 +225,7 @@ pub fn Loop(comptime Frontend: type) type { s.joined.rest.deinit(s.gpa); // Its link cut with no word by a session that is there still // (an Upgrade's exec): joined again, as when told so. - if (link.gone and link.refused == null and link.ended == null and !link.left and s.have == null and replica.cutListed("the session hung up", s.dial.session)) + if (link.gone and link.refused == null and link.ended == null and !link.left and replica.cutListed("the session hung up", s.dial.session, s.have != null)) link.refused = std.heap.c_allocator.dupe(u8, replica.upgrading) catch null; // Why it joins again is in its notice until a key. if (!link.rejoins()) { diff --git a/test/daemon.py b/test/daemon.py index 88e11062..49e9ff99 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -3277,6 +3277,12 @@ def upgrades(old, new): shutil.rmtree(root, ignore_errors=True) +def knows_size(gui_binary): + """Whether a build's window exec'd at an Upgrade comes back the size + it had (PARDES_JOIN_SIZE: client.zig `execAgain`).""" + return b'PARDES_JOIN_SIZE' in Path(gui_binary).read_bytes() + + def knows_exec(binary): """Whether a build's client execs the build at its start path at an Upgrade, for the view it is handed (PARDES_JOIN_VIEW).""" @@ -3507,7 +3513,10 @@ if __name__ == '__main__': if all(a.with_name('pardes-gui').exists() for a in (old, new)): upgrade_clients(old, new) if knows_exec(old): - pair_window_geometry(old.with_name('pardes-gui'), new.with_name('pardes-gui')) + if knows_size(old.with_name('pardes-gui')): + pair_window_geometry(old.with_name('pardes-gui'), new.with_name('pardes-gui')) + else: + print('pair window geometry: skipped: the old build\'s window passes no size at its exec (no PARDES_JOIN_SIZE)') elif sys.argv[1:2] == ['--upgrade-clients']: upgrade_clients(Path(sys.argv[2]).resolve(), Path(sys.argv[3]).resolve()) elif sys.argv[1:2] == ['--clients']: -- cgit v1.3