From 40a24ca96be07778dfac7c789d936c732c0cc567 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 17:31:13 -0300 Subject: pair: PARDES_TERM_BYTES (a working name) puts a session and its clients on the terminals' second road, the pty's bytes in the units to each client's own emulator (`Peers.bytes`), which only the soak could take (`--bytes`): the session's `Peers` is made with `.bytes` set (runtime/session.zig), every joined replica, a dump's or a pair's own boot, is turned to its own emulators as the soak turns its clients (core/replica.zig `takeJoined`: `screen_state` false, no predicted echo), and the process harness keeps the variable in a case's environment as it keeps PARDES_PAIR (test/process.zig `Child`); a client started without it against a session with it diverges: for the corpus through a pair's client window, not for a user (the switch for real clients is the terminals' line's); with it the corpus as a pair (PARDES_PAIR, a client window) is byte-identical to tree3's through frame 57, the kitty image in a terminal's pane (frame 50) included, where screen state diverges the client; frames 58-59 (WindowOpacity) differ and frame 61 (Font) never idles: only the own window applies or answers either (dev/gui/gui.zig `pollFrame`), a client window never does, and a window pair's session is the tui binary beside it; core/root.zig's machine_lines counts replica.zig's new getenv (76); core-test 896/1056, shell-test 1098/1101 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/session.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/session.zig b/runtime/session.zig index 75e8efcc..65432d97 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -86,7 +86,10 @@ pub fn Loop(comptime Frontend: type) type { defer l.prompt_rcs.deinit(); 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() }; + // PARDES_TERM_BYTES (a working name, the pair's corpus runs): its + // clients' terminals by the pty's bytes (Peers.bytes), as the + // soak's `--bytes`; its clients must be started with it too. + l.peers = .{ .gpa = l.gpa, .io = l.io, .name = daemon.name(), .bytes = std.c.getenv("PARDES_TERM_BYTES") != null }; l.inbox = .{ .io = l.io, .gpa = l.gpa, .lsp_allocator = l.allocs.lsp }; defer l.inbox.deinit(); // A search's worker may be waiting on the queue for room. -- cgit v1.3 From 27874074025f88dd9e27ece82c352c4a7c35ab51 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 21:07:11 -0300 Subject: pair: a window pair's session lists as a window's (P49): the `pardes` a window execs with `--paired=FD` is only ever a window's pair's session, so it registers as `gui` (runtime/main.zig), with no word at the join and the wire unchanged; test/daemon.py: window-clients lists it `listed_as('has a frontend', 'gui')` (under the variable a pair is listed by its kind alone, P36) and ends by name the window session a terminal client's Detach kept (P36) once its window closes; gui_pair's two `(tty)` for the window pair's session are `(gui)`; gui() reads the session's pid from its /status (the window's child as a pair) and asks that process whether it carries on; with the variable window-clients and gui pass on Debug and ReleaseSafe Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/main.zig | 5 +++-- test/daemon.py | 27 +++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'runtime') diff --git a/runtime/main.zig b/runtime/main.zig index aa35e687..02a41c2f 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -1583,11 +1583,12 @@ fn nativeMain(std_init: std.process.Init) !void { daemon.resumeLink(rec.link, rec.stub, kind, opts.ninep_name, rec.state orelse if (detached) .detached else .attached); } else if (paired) |fd| { // A window's pair's session: its first client on `fd`, the daemon - // its own to dial (and to start, when none runs). + // its own to dial (and to start, when none runs), listed as the + // window's (P49: only a window's pair execs one with `--paired`). opts.pair = fd; term = .detached; detached = true; - if (daemon.wanted()) _ = daemon.register(null, kind, opts.ninep_name, .pair); + if (daemon.wanted()) _ = daemon.register(null, .gui, opts.ninep_name, .pair); } else if (detach == null and std.c.getenv("PARDES_PAIR") != null) { // The last step's way, behind its variable until it is the default: // this terminal or window a client of a session forked off for it diff --git a/test/daemon.py b/test/daemon.py index d53e6182..aa06c76d 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -1867,15 +1867,19 @@ def window_clients(binary, gui_binary): wait_for('the terminal client agrees with the window', lambda: agreed(root / 'b.check', nb), timeout=30) wait_for('the window client agrees with the window', lambda: agreed(root / 'g.check', ng), timeout=30) listed = sessions_listed(binary, env, root) - assert [(n, k) for n, _, k in listed] == [('win', '(gui, has a frontend)')], listed + assert [(n, k) for n, _, k in listed] == [('win', listed_as('has a frontend', 'gui'))], listed assert wg.close() == 0, wg.said()[-800:] os.write(tb.master, b' sD') wait_for('the terminal client let go', lambda: b.poll() is not None, timeout=10) assert win.p.poll() is None print(f'daemon: a window\'s session served a terminal\'s client and a window\'s, digests agreed ' - f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times; --ps listed it alone, (gui, has a frontend)') + f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times; --ps listed it alone, {listed_as("has a frontend", "gui")}') win.close() nine.socket.close() + # Under the variable the window is its session's client, and the + # terminal client's Detach kept that session (P36): ended by name. + if WITH_PAIR: + subprocess.run([binary, '--kill=win'], env=dict(env, PARDES_DAEMON='on'), cwd=root, capture_output=True, timeout=30) wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=15) print('daemon: window clients\' sessions ended, nothing left behind') finally: @@ -2832,6 +2836,9 @@ def gui(binary, cycles): wait_for('the window session', sock.exists, timeout=20) client = Client(sock) shell = terminals(client)[0] + # The window's own process, or under the variable its child (a + # pair: the window a client of it). + session = int(dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines())['pid']) assert not sized(client), 'a window owns the size' # With its window: another window is a client of the session (its # own process, its captures its own), listed by --ps; closed, it @@ -2843,20 +2850,20 @@ def gui(binary, cycles): # (a pair's own window is a client too: the second's pid is what goes) wait_for('the client gone from --ps', lambda: f'client {second.pid} ' not in listed()) assert not sized(client), 'the first window stays' - assert proc.poll() is None + assert alive(session) print('daemon: a second window on a window session a client of it (in --ps), closed alone') # Detached: the window closed, the process on; every attach after it # a window client, the session detached still. client.write(f'/pane/{shell}/exec', b'Detach\n') wait_for('the window closed', lambda: sized(client)) - assert proc.poll() is None, 'the process carries on with no window' - assert f'session win {proc.pid} {listed_as("detached", "gui")}' in listed(), listed() + assert alive(session), 'the session carries on with no window' + assert f'session win {session} {listed_as("detached", "gui")}' in listed(), listed() baseline = None for cycle in range(cycles): w = Window(root, f'w{cycle}', [binary, 'attach'] if cycle % 2 else [binary, '--attach=win'], env) wait_for('the client window drawn', lambda: (root / f'w{cycle}' / 'latest.ppm').exists(), timeout=20) wait_for('the client in --ps', lambda: f'client {w.pid} ' in listed()) - assert f'session win {proc.pid} {listed_as("detached", "gui")}' in listed(), listed() + assert f'session win {session} {listed_as("detached", "gui")}' in listed(), listed() now = (fds(proc.pid), len(processes(root))) baseline = baseline or now assert now == baseline, (cycle, now, baseline) @@ -2873,14 +2880,14 @@ def gui(binary, cycles): tty_attach.terminate() tty_attach.wait(timeout=10) term.close() - assert proc.poll() is None + assert alive(session) print('daemon: a terminal attached to a window session by name, as a client') nobody = subprocess.run([binary, '--attach=nobody'], env=env, cwd=root, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert nobody.returncode == 1 and b"no session called 'nobody'" in nobody.stderr, nobody.stderr # Detached and told to end: it ends. client.write(f'/pane/{shell}/exec', b'Exit\n') - proc.wait(timeout=10) + wait_for('the session ended', lambda: not alive(session)) client.socket.close() wait_for('the daemon gone once idle', lambda: not [p for p in processes(root) if alive(p)], timeout=5) print('daemon: window session ended, nothing left behind') @@ -2936,7 +2943,7 @@ def gui_pair(gui_binary): try: w, nine, session, pane = started('gp', env) - wait_for('the window listed its client', lambda: f'session gp {session} (tty)' in listed() + wait_for('the window listed its client', lambda: f'session gp {session} (gui)' in listed() and f'client {w.pid} ' in listed()) w.keys(b'Ofrom-the-window\x1b') wait_for('its keys in the session\'s text', lambda: b'from-the-window' in nine.read(f'/pane/{pane}/body')) @@ -2954,7 +2961,7 @@ def gui_pair(gui_binary): os.kill(w.pid, signal.SIGKILL) w.p.wait(timeout=10) wait_for('the client unlisted', lambda: f'client {w.pid} ' not in listed()) - assert alive(session) and f'session gl {session} (tty)' in listed(), listed() + assert alive(session) and f'session gl {session} (gui)' in listed(), listed() nine.socket.close() assert subprocess.run([binary, 'kill', 'gl'], env=env, capture_output=True, timeout=30).returncode == 0 wait_for('the session ended', lambda: not alive(session), timeout=30) -- cgit v1.3 From 752cd81c1c5e1e91e1429cefc1c4651647981f88 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 21:19:36 -0300 Subject: pair: a pair's session puts the user's terminal back when its client dies with no word (P48): a tty pair (runtime/main.zig `pair`) keeps /dev/tty and its termios as they are before the client enters it and hands them to the session (dev/tui/tui.zig `Term.pair`, `Kept`); `Peers` marks the pair's first peer (`Peer.pair`, from `Joining.own`) and a bye (`Peer.bye`) and says at that peer's leave whether it left with no word at all (`Peers.pair_left`: no bye, not let go by the session, not cut); the session's frontend (`Own.sent`, now before a no-daemon pair's end in runtime/session.zig) writes on a loss what the own path writes when a terminal is lost under it (`Killed`'s bytes, which now also turn the in-band resize off: vaxis's terminal query turns it on) and the cooked termios, and lets the device go either way (a terminal held open keeps an ssh or its emulator waiting); not across an Upgrade (close-on-exec) nor after the pair's client joined again; daemon.py plain with the variable passes on Debug (it failed at 'the terminal is put back'), its row after a killed stub listing `(tty)` under the variable (a loss: still a pair's, P36), and --upgrade counts the device let go at the exec; core-test 896/1056, shell-test 1098/1101 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 14 +++++++++++++- dev/tui/tui.zig | 41 ++++++++++++++++++++++++++++++++--------- runtime/main.zig | 33 ++++++++++++++++++--------------- runtime/session.zig | 6 ++++-- test/daemon.py | 8 +++++++- 5 files changed, 74 insertions(+), 28 deletions(-) (limited to 'runtime') diff --git a/core/replica.zig b/core/replica.zig index 44fa922f..49dc7f7b 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -1717,6 +1717,12 @@ pub const Peer = struct { again: bool = false, /// ...or that its window was closed (Peers.closed). close: bool = false, + /// It said a bye: none, and the session let it go with no word of its + /// own (`closing`, `cut`), is a client that died (killed: P48). + bye: bool = false, + /// A pair's first client (`Joining.own`): the terminal its session + /// keeps is its (`Peers.pair_left`). + pair: bool = false, /// Its number in the session's `Screens`. sid: u16 = 0, /// Inputs read (each one's seq, as the client numbered them). @@ -1998,6 +2004,7 @@ pub const Peer = struct { const b = (wire.decodeClient(tag, payload) catch return false).bye; peer.again = b.again; peer.close = b.close; + peer.bye = true; return false; }, .ping => { @@ -2130,6 +2137,10 @@ pub const Peers = struct { /// hung up) and the session is a pair's not kept (daemon.sessionState): it /// ends there (runtime/session.zig). closed: bool = false, + /// Its pair's first client left (P48): with no word at all (killed), + /// true; its session's frontend puts the user's terminal back then, + /// and lets it go either way (tui.zig `Own.sent`), and clears this. + pair_left: ?bool = null, /// An Upgrade told its clients so (`refuseAll`): a connection handed /// over before its exec is told the same, never closed by the exec /// unanswered. Its exec failed: the next boundary takes joins again. @@ -2403,7 +2414,7 @@ pub const Peers = struct { core.gpa.free(bytes); return daemon.refuseReplica(fd, "out of memory"); }; - peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = .at(k), .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa }; + peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = .at(k), .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa, .pair = joining.own }; ps.next_id +%= 1; if (ps.next_id == 0) ps.next_id = 1; // The session's digest as dumped, for the joiner to check its load by @@ -2484,6 +2495,7 @@ pub const Peers = struct { ps.closeViewOf(core, peer, peer.again or peer.cut); if (ps.count() == 0) core.unattended = ps.detached; if (ps.count() == 0 and peer.close and daemon.sessionState() == .pair) ps.closed = true; + if (peer.pair) ps.pair_left = !peer.bye and !peer.closing and !peer.cut; ps.seq += 1; ps.unit(0, ps.seq); ps.letGo(peer); diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 92ac6a0c..25ee9075 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -559,8 +559,12 @@ fn surfaceHasKittyKey(surface: *const pardes.Surface, key: u64) bool { /// opens it; one open already (a session forked off its stub, /// daemon.forkSession); or none, detached from the start (`--detach`). /// The terminal a session starts on: /dev/tty, one its stub opened (an -/// upgraded session's is raw already, `termios` the cooked one), or none. -pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, detached }; +/// upgraded session's is raw already, `termios` the cooked one), or none: +/// a pair's (main.zig `pair`) draws on none, and keeps its client's, with +/// its modes before the client took it, to put back if that client dies +/// with no word (P48: `Own.sent`). +pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, detached, pair: Kept }; +pub const Kept = struct { fd: posix.fd_t, termios: posix.termios }; pub fn run(init: std.process.Init, opts: pardes.Options, term: Term) !void { const io = init.io; @@ -583,7 +587,7 @@ pub fn run(init: std.process.Init, opts: pardes.Options, term: Term) !void { switch (term) { .open => try screen.enter(try vaxis.Tty.init(io, &tty_buf)), .fd => |t| try screen.enter(try Screen.ttyOn(io, &tty_buf, t.fd, t.termios)), - .detached => {}, + .detached, .pair => {}, } defer screen.leave(); @@ -591,7 +595,7 @@ pub fn run(init: std.process.Init, opts: pardes.Options, term: Term) !void { defer paste_buf.deinit(); var loop: Loop = .init(io, &screen.tty, &screen.vx); - var own: Own = .{ .screen = &screen, .loop = &loop, .paste_buf = &paste_buf }; + var own: Own = .{ .screen = &screen, .loop = &loop, .paste_buf = &paste_buf, .kept = if (term == .pair) term.pair else null }; try session_loop.Loop(Own).run(init, opts, &own); } @@ -929,7 +933,9 @@ const Screen = struct { const Killed = struct { var fd: posix.fd_t = -1; var cooked: posix.termios = undefined; - const reset = "\x1b[= 0) { - _ = std.c.write(fd, reset, reset.len); - _ = std.c.tcsetattr(fd, .FLUSH, &cooked); - } + if (fd >= 0) putBack(fd, &cooked); // The 9P socket and private prompt files go too: a killed editor // leaves none behind. Its shells too, the daemon's dups let go. ninep_io.unlinkOwnSocket(); @@ -971,6 +979,9 @@ const Own = struct { paste_buf: *std.Io.Writer.Allocating, frame_arena: std.heap.ArenaAllocator = undefined, sh: Shell = undefined, + /// A pair's: its client's terminal (Term.pair), until that client + /// leaves. + kept: ?Kept = null, const Session = session_loop.Loop(Own); @@ -1027,6 +1038,7 @@ const Own = struct { o.screen.art.deinit(gpa); o.screen.glide.deinit(gpa); o.frame_arena.deinit(); + if (o.kept) |k| _ = libc.close(k.fd); } pub fn start(o: *Own, l: *Session) !void { @@ -1051,6 +1063,17 @@ const Own = struct { pub fn sent(o: *Own) void { const sh = &o.sh; if (sh.peers.recording and sh.detached()) sh.drawn_ns = @intCast(std.Io.Clock.awake.now(sh.io).nanoseconds); + // A pair's client gone: dead with no word (a kill -9), its + // terminal put back as the own path's survivor puts it back (a + // forked session's when its stub is killed), from the alternate + // screen and raw; with a word, it did that itself. Let go either + // way: a terminal held open keeps an ssh, or its emulator, waiting. + const lost = sh.peers.pair_left orelse return; + sh.peers.pair_left = null; + const k = o.kept orelse return; + o.kept = null; + if (lost) Killed.putBack(k.fd, &k.termios); + _ = libc.close(k.fd); } pub fn upgradeAsked(o: *Own) void { diff --git a/runtime/main.zig b/runtime/main.zig index 02a41c2f..5cdf5ee0 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -1593,8 +1593,7 @@ fn nativeMain(std_init: std.process.Init) !void { // The last step's way, behind its variable until it is the default: // this terminal or window a client of a session forked off for it // (`pair`). - pair(init, &opts, args); - term = .detached; + term = if (pair(init, &opts, args)) |kept| .{ .pair = kept } else .detached; } else if (daemon.wanted()) { if (detach != null or pardes.platform == .gui) { // A session started detached is kept from birth: a pair's word. @@ -1757,9 +1756,11 @@ fn pardesBeside(buf: *[4104]u8) ?[:0]const u8 { /// effects (runtime/session.zig). A window's child execs the `pardes` /// beside it (`--paired=FD` first, its arguments after), which dials the /// daemon itself: a window's session loop is woken through SDL (gui.zig -/// `sdlWake`), a terminal's needs none. Returns in a terminal's session; -/// the client exits. No fork to be had: returns, and this process is the -/// session, with no terminal: said by the caller's run. A window with no +/// `sdlWake`), a terminal's needs none. Returns in a terminal's session, +/// with the terminal its client draws on, cooked as it is now (P48: put +/// back if that client dies with no word); the client exits. No fork to +/// be had: returns, and this process is the session, with no terminal: +/// said by the caller's run. A window with no /// `pardes` beside it returns at once, its own session as before. /// A terminal's launch with no terminal to draw on (a detached pty, a /// daemon): said, not an error trace, and exit 1. @@ -1768,23 +1769,22 @@ fn noTerminal(io: std.Io) noreturn { std.process.exit(1); } -fn pair(init: std.process.Init, opts: *pardes.Options, args: []const [:0]const u8) void { +fn pair(init: std.process.Init, opts: *pardes.Options, args: []const [:0]const u8) ?@import("dev").tui.Kept { var path_buf: [4104]u8 = undefined; var fd_buf: [32]u8 = undefined; var argv: [64:null]?[*:0]const u8 = @splat(null); if (pardes.platform == .gui) { - const path = pardesBeside(&path_buf) orelse return; - if (args.len >= argv.len - 1 or std.c.access(path, std.c.X_OK) != 0) return; + const path = pardesBeside(&path_buf) orelse return null; + if (args.len >= argv.len - 1 or std.c.access(path, std.c.X_OK) != 0) return null; argv[0] = path.ptr; for (args[1..], 2..) |a, k| argv[k] = a.ptr; } // Its client draws on /dev/tty: none to be had, said as the own path - // says it, before a session is forked for nobody. - if (pardes.platform == .tui) { - const tty = std.c.open("/dev/tty", .{ .ACCMODE = .RDWR, .CLOEXEC = true }, @as(std.c.mode_t, 0)); - if (tty < 0) noTerminal(init.io); - _ = std.c.close(tty); - } + // says it, before a session is forked for nobody. The session keeps it, + // cooked as it is now. std.posix's termios: glibc's is a bigger struct. + const tty: c_int = if (pardes.platform == .tui) std.c.open("/dev/tty", .{ .ACCMODE = .RDWR, .CLOEXEC = true }, @as(std.c.mode_t, 0)) else -1; + if (pardes.platform == .tui and tty < 0) noTerminal(init.io); + const cooked = if (tty >= 0) std.posix.tcgetattr(tty) catch null else null; const conn: ?c_int = if (pardes.platform == .tui and daemon.wanted()) daemon.connect(true) else null; var fds: [2]c_int = undefined; if (std.c.socketpair(std.c.AF.UNIX, std.c.SOCK.STREAM | std.c.SOCK.CLOEXEC, 0, &fds) != 0) @@ -1816,8 +1816,11 @@ fn pair(init: std.process.Init, opts: *pardes.Options, args: []const [:0]const u // The daemon is the client's to start; the hello is this one's. daemon.startPending(false); if (conn) |c| _ = daemon.register(c, .tty, opts.ninep_name, .pair); - return; + if (cooked) |t| return .{ .fd = tty, .termios = t }; + if (tty >= 0) _ = std.c.close(tty); + return null; } + if (tty >= 0) _ = std.c.close(tty); _ = std.c.close(fds[0]); if (conn) |c| _ = std.c.close(c); daemon.startPending(true); diff --git a/runtime/session.zig b/runtime/session.zig index 65432d97..890302b1 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -23,7 +23,8 @@ //! - `start(l)`: after the first effects, the ptys and the watches //! 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. +//! - `sent()`: after each step's unit went to the clients (a pair's +//! client gone with it: before its session ends). //! - `upgradeAsked()`: an Upgrade asked in the step, done (it execs). //! - `restoring(nc)`, `restored(l)`: a Restore's new core, before it //! replaces the old one (its devices let go, what it is told of the @@ -133,11 +134,12 @@ pub fn Loop(comptime Frontend: type) type { try l.core.pump(l.host); // Its unit to each replica client, and theirs taken in. l.peers.boundary(l.core); + // Before a pair's end: its client's terminal put back (P48). + fe.sent(); // A pair's session with no daemon ends with its last link: // nothing could attach to it again; with one, when its last // client left with a close (not a loss) and it is not kept. if (l.peers.count() == 0 and (l.peers.closed or (o.pair != null and daemon.link < 0))) break; - fe.sent(); upgrade.locate(); // Asked in the step (the word), done between steps: the // session whole. diff --git a/test/daemon.py b/test/daemon.py index aa06c76d..32ff5908 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -2773,7 +2773,9 @@ def main(binary, cycles): wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in term.text()) listed = wait_for('the client in --ps', lambda: (lambda out: f'client {stub.pid} ' in out and out)( subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode())) - assert f'session fresh {session} {listed_as("detached")}' in listed, listed + # (Under the variable the killed stub was the pair's client: a loss, + # the session still a pair's, P36.) + assert f'session fresh {session} {"(tty)" if WITH_PAIR else listed_as("detached")}' in listed, listed print('daemon: a session whose stub was killed outright detached, and was attached again, as a client') # The end: the session quits, its shells hang up, its client and @@ -3186,6 +3188,10 @@ def upgrades(old, new): # (A client of a build that execs at an Upgrade comes back: its # connection is the session's again.) gone = 2 if b'detached from' in term2.text() else 0 if knows_exec(old) and stub2.poll() is None else 1 + # (Under the variable a pair's session of a build that keeps its + # client's terminal, P48, lets it go: close-on-exec, not carried; + # such a build's put-back turns the in-band resize off.) + gone += 1 if WITH_PAIR and b'\x1b[?2048l\x1b[0m' in Path(old).read_bytes() else 0 return fds_before[0] - 2 - gone + min(state_fds(session), 1) - state_before, fds_before[1] try: wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level(), timeout=5) -- cgit v1.3 From 544eee368537eea98e7552e730948c2c8fb380e9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 21:40:19 -0300 Subject: pair: a pair's user is told a newer build is installed: the words were set only by a session's own frontend at its focus in (upgrade.noticeNewer), which a pair's session has not, and its client never asks: `Peers.input` marks a focus in from the pair's first client (`Peers.pair_focused`) and the session loop asks `noticeNewer` for it between steps (runtime/session.zig), the session's binary being the one an Upgrade replaces; attach clients as on the own path; daemon.py --upgrade with the variable now passes 'the newer build said' both ways and stops later, at 'the word said' (the upgraded session's 'Upgrade: now' on /screen: not chased) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 5 +++++ runtime/session.zig | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'runtime') diff --git a/core/replica.zig b/core/replica.zig index 49dc7f7b..70335cfd 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2141,6 +2141,10 @@ pub const Peers = struct { /// true; its session's frontend puts the user's terminal back then, /// and lets it go either way (tui.zig `Own.sent`), and clears this. pair_left: ?bool = null, + /// Its pair's first client's terminal or window found again (a focus + /// in): the session asks whether a newer build is installed, as its own + /// frontend asks at its own (runtime/session.zig), and clears this. + pair_focused: bool = false, /// An Upgrade told its clients so (`refuseAll`): a connection handed /// over before its exec is told the same, never closed by the exec /// unanswered. Its exec failed: the next boundary takes joins again. @@ -2296,6 +2300,7 @@ pub const Peers = struct { // it read, its unit (part B terminal notes' order). ps.screensOut(core, .flush); core.toView(peer.view); + if (peer.pair and in.event == .focus and in.event.focus) ps.pair_focused = true; ps.t.stamp = stampOf(in); core.update(in.event); core.step(); diff --git a/runtime/session.zig b/runtime/session.zig index 890302b1..d8c7cd02 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -136,6 +136,12 @@ pub fn Loop(comptime Frontend: type) type { l.peers.boundary(l.core); // Before a pair's end: its client's terminal put back (P48). fe.sent(); + // A pair's client stands for the frontend it was started + // for: at its focus in, a newer build said (upgrade.zig). + if (l.peers.pair_focused) { + l.peers.pair_focused = false; + upgrade.noticeNewer(l.core); + } // A pair's session with no daemon ends with its last link: // nothing could attach to it again; with one, when its last // client left with a close (not a loss) and it is not kept. -- cgit v1.3