From 2e0eb4d7e2364a8cfe97eb56314af0b4be36be9b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 11:15:26 -0300 Subject: upgrade: an Upgrade carries near clients (the last step's design 1.4, Z3): a client let go by an Upgrade dials again as before, and when the session runs another build (or another protocol) and a newer file is installed at its own start path since it started (upgrade.replaced), the client loop ends `.upgrade` and its frontend lets its screen go and execs that file as `--attach=:` (client.zig execAgain), the same process, for the view the session kept for it (PARDES_JOIN_VIEW, Options.join_view, dialled patiently as a rejoin is): the terminal's is the blink (it leaves the alternate screen and enters it again; no record), the window a new window; a client whose start path holds no newer file keeps today's sentence "session upgraded to a newer pardes: upgrade this client too"; a far client the same, through its forward (PARDES_REPLICA_FAR=1); a pair with no daemon refuses the Upgrade in words ("no daemon keeps this session, so its client could not join it again"), since its first client has no socket to find the session again by (on the base the Upgrade cut the client off and ended the session); test/daemon.py upgrade_clients (a terminal client and a window client, each its own pane in its own view): old->new the base's clients are let go and told to upgrade too (what they do today), new->old they exec the base build and come back in a view of their own (the base reads no PARDES_JOIN_VIEW), new->(this built with -Dembed-sources, another semantics) each is back in ITS view with its own pane; `pair`'s no-daemon Upgrade refused; tui core-test 858/1013 (155 skipped), shell-test 1053/1056, term 17/17, pane 183/184, kitty 45/45, behaviour 275/275 and --replay 275/275, process-test 0 of 144 failed, both soaks diverged 0 unequal 0 corpus 22, daemon.py plain, --far, --games, --window-clients, --gui, --upgrade both ways (with clients) pass, gui unit-test 1650/1654 (the perf check's BaselineHarnessMismatch its one failure), macOS lib (Linux host), aarch64-macos, FreeBSD build (loads 3-15) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/client.zig | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- runtime/upgrade.zig | 8 ++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/client.zig b/runtime/client.zig index 1949d618..329bdab3 100644 --- a/runtime/client.zig +++ b/runtime/client.zig @@ -37,6 +37,7 @@ const std = @import("std"); const libc = std.c; const pardes = @import("core"); const replica = pardes.replica; +const upgrade = @import("upgrade.zig"); /// A wait with no wake of its own: until an input or a message. pub const forever: u32 = std.math.maxInt(u32); @@ -92,6 +93,8 @@ pub const Start = struct { s.o.distrusted = &s.distrusted; // Its frame timings, this process's (Pardes.frames). s.o.frames = &s.frames; + // Exec'd at an Upgrade (`execAgain`): for the view it had. + if (init.environ_map.get("PARDES_JOIN_VIEW")) |v| s.o.join_view = std.fmt.parseInt(u8, v, 10) catch null; s.r = replica.join(s.gpa, &s.joined, dial.path, dial.session, s.o, s.have, &s.why, null) orelse return false; return true; } @@ -111,8 +114,44 @@ pub const Start = struct { /// How a client's joins ended: it quit, the session let it go, it could /// not join again (`Start.said`), it left the session running (a Detach in -/// it), or the session ended, with its code. -pub const Ended = union(enum) { done, gone, failed, left, ended: u8 }; +/// it), the session ended, with its code, or it runs another build now and +/// one is installed at this client's start path since it started: the +/// frontend lets its screen go and execs that, for this view (`execAgain`). +pub const Ended = union(enum) { done, gone, failed, left, ended: u8, upgrade: u8 }; + +/// An Upgrade's client again (`Ended.upgrade`), its frontend's screen let +/// go: this process exec'd as the file at its start path, an attach of the +/// same session through the same socket (a far one's forward, its ssh this +/// process's child still), joining for `view` (PARDES_JOIN_VIEW; far, +/// PARDES_REPLICA_FAR). The terminal's blink: no record crosses the exec. +/// Returns only when the exec failed: why. +pub fn execAgain(s: *Start, view: u8) []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"; + const argv = [_:null]?[*:0]const u8{ path, at }; + 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"; + 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; + envp[k] = e; + k += 1; + } + envp[k] = joining.ptr; + k += 1; + if (s.have != null) { + envp[k] = "PARDES_REPLICA_FAR=1"; + k += 1; + } + envp[k] = null; + _ = libc.execve(path, &argv, envp.ptr); + return "Upgrade: the build at this client's start path would not start"; +} pub fn Loop(comptime Frontend: type) type { return struct { @@ -142,6 +181,8 @@ pub fn Loop(comptime Frontend: type) type { /// the session let it go to upgrade; the frontend stays as it is. pub fn run(l: *L, s: *Start) !Ended { const link = &l.link; + // Its start path's file, for an Upgrade's question (`upgrade`). + upgrade.locate(); while (true) { link.reset(s.r, &s.joined); l.fe.start(l); @@ -177,8 +218,11 @@ pub fn Loop(comptime Frontend: type) type { } // The session again, the core it leaves held meanwhile: its // blobs are not sent again. - s.r = replica.join(s.gpa, &s.joined, s.dial.path, s.dial.session, s.o, s.have, &s.why, s.r) orelse - return if (replica.ended(&s.why)) .gone else .failed; + s.r = replica.join(s.gpa, &s.joined, s.dial.path, s.dial.session, s.o, s.have, &s.why, s.r) orelse { + if (replica.ended(&s.why)) return .gone; + if (replica.otherBuild(&s.why) and upgrade.replaced()) return .{ .upgrade = s.joined.view }; + return .failed; + }; } } diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index dcc705a5..37d4890b 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -95,6 +95,14 @@ pub fn newer() bool { return true; } +/// Another file at its start path than the one it started from: a build +/// installed there since (`locate` first). A client's question at an +/// Upgrade (client.zig). +pub fn replaced() bool { + const was = started_inode orelse return false; + return (inodeOf(exe() orelse return false) orelse return false) != was; +} + pub fn exe() ?[:0]const u8 { return if (exe_len == 0) null else exe_buf[0..exe_len :0]; } -- cgit v1.3