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 --- core/Core.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index 7ebcc020..c08eb883 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2284,6 +2284,10 @@ pub const Options = struct { /// first effects (runtime/session.zig); a client's session is on it, /// its first join made there with no hello (replica.join). pair: ?c_int = null, + /// A client exec'd at an Upgrade (runtime/client.zig `execAgain`, + /// PARDES_JOIN_VIEW): the view it had, which the session kept for it + /// (views.away), joined again for as a rejoin dials (replica.join). + join_view: ?u8 = null, mounts: []const filesystem.Mount = &.{}, config_dir: ?[]const u8 = null, /// Where what outlives the session is kept (Db.zig): the user's state -- cgit v1.3 From 579763e3aaca684ef638d621fe1b427ae96743df Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 12:01:49 -0300 Subject: tape: a session's tape is handed in by whoever starts it, step 9c (reports/pardes-handle-69-design.md section 3.4, P33's lean 5): PARDES_RECORD is read by the starter (tape.fromEnv, the old startFromEnv returning the tape: runtime/session.zig's start, one line, and the Mac's, one line) and handed in Options.tape, so Pardes.init and dump.initFromDump no longer start a tape and Pardes.create takes its options' tape or none, never the global; current, forget and adopt are the field's (deinit and restoreInner call p.tape's; the three free ones are deleted); restoreInner loads the replacement on the session's own tape and does not leave it in the replacement's kept options (a session with clients has its tape from no options, and Peers.stop puts the options' back); Authority.init hands its tape in the options; the in-process runner (test/session.zig) keeps the tape recordTape starts and hands it to each session it makes; the global is still set beside a recording tape (fromEnv, recordTape, Stepping, Peers) while the terminal's questions read it: after this change those are its only readers, 18 calls in 12 functions (core/panes.zig scrollBy, feedOutput, followRows, the positions value, feedLost, followOutput, resizeGrid x4, reloadTerminals x3, emulatorGpa; core/term Term.digest, Term.media; core/edit.zig shellRows; core/ninep/pty.zig finish's prompt value), besides Stepping, Peers and enter's safe-build check; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7 agree); a real session still records from its first call (process-test --replay 0 of 102 failed, behaviour-test --replay 275/275); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275, process-test 1 of 144 (delask, passes alone), both soaks diverged 0 unequal 0 corpus 22 of 22 (bytes: the base's one now stop at 30 ms), daemon.py plain, --far (the Find: 0 mispredicted), --games, --window-clients, --restore (a Restore with a client attached), --upgrade both ways against merge31 (both failed once at the Adopt race in the chain and pass alone), addon-test 5/5; the macOS library (x86_64, aarch64) and FreeBSD build; gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 15 +++++++-------- core/dump.zig | 7 +++++-- core/replica.zig | 1 + core/tape.zig | 38 +++++++++++++------------------------- runtime/macos.zig | 1 + runtime/session.zig | 1 + test/session.zig | 15 ++++++++++----- 7 files changed, 38 insertions(+), 40 deletions(-) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index e2f8cd8a..a92d35ae 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -528,9 +528,9 @@ pub const perform = @import("Effect.zig").perform; /// second copy of this drifted once, leaving restored tags without an /// allocator and every 9P mtime 0. pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { - // The global still set beside the field (P20): a core made while - // a tape records (PARDES_RECORD, a replica's step) is its. - const tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none; + // Its options' (a recording session's, an authority's, a replay's), or + // the one nobody records. + const tape = opts.tape orelse &pardes.tape.none; const p = try gpa.create(Pardes); p.* = .{ .gpa = gpa, @@ -561,10 +561,9 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { return p; } -/// A new session, its tape written from here when PARDES_RECORD asks. +/// A new session, recorded from here on its options' tape. pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { // By hand, not `taped`: no core yet to enter on; the tape adopts the one made. - pardes.tape.startFromEnv(); const taped = pardes.tape.enter(null, .{ .init = opts }); // The tape adopts the core made, none on a failure. var made: ?*Pardes = null; @@ -821,8 +820,8 @@ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry { pub fn deinit(p: *Pardes) void { // By hand, not `taped`: what it records is no argument (`current`), and it leaves on no core. - const taped = pardes.tape.enter(p, .{ .deinit = pardes.tape.current(p) }); - pardes.tape.forget(p); + const taped = pardes.tape.enter(p, .{ .deinit = p.tape.current(p) }); + p.tape.forget(p); defer pardes.tape.leave(null, taped); if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path)); // Every file open now is closed with its dot, and the list kept. @@ -2290,7 +2289,7 @@ pub const Options = struct { /// A client's: the kinds it caught breaking PA_PLAIN, its frontend's /// list, which outlives each core it joins with. In no tape and no dump. distrusted: ?*pardes.Addon.Distrusted = null, - /// The core's tape (`Pardes.tape`); null: `tape.on`'s, or `tape.none`. + /// The core's tape (`Pardes.tape`); null: `tape.none`. tape: ?*pardes.tape.Tape = null, /// What the host's scan of the addon directories found (Addon.scan). addons: []const pardes.Kind.Loaded = &.{}, diff --git a/core/dump.zig b/core/dump.zig index eb0ef263..3d248010 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -532,17 +532,20 @@ fn restoreInner(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes { var opts = p.opts; opts.cols = p.view().screen_w; opts.rows = p.view().screen_h; + // Loaded on the session's tape (one with clients has it from no + // options), which the replacement's options do not keep. + opts.tape = p.tape; const replacement = try loadAndRevive(p.gpa, opts, bytes, p, null); + replacement.opts.tape = p.opts.tape; replacement.pointRestoreAt(from); // The tape follows the replacement from here (it is the session). - pardes.tape.adopt(replacement); + p.tape.adopt(replacement); pardes.ctlfs.events.notePath(replacement, "restore", from); return replacement; } pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, bytes: []const u8) !*Pardes { // By hand, not `taped`: no core yet to enter on, as `Pardes.init`. - pardes.tape.startFromEnv(); const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = bytes } }); // The tape adopts the core made, none on a failure. var made: ?*Pardes = null; diff --git a/core/replica.zig b/core/replica.zig index 31e16f46..14f441b3 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -182,6 +182,7 @@ pub const Authority = struct { a.t.whole_digest = screens and std.c.getenv("PARDES_REPLICA_TRACE") == null; // A digest at a unit's end, as the session's (Peers.unit). a.t.no_digest = true; + opts.tape = &a.t; const was = Stepping.begin(&a.t, null); defer was.end(); a.core = try Pardes.init(gpa, opts); diff --git a/core/tape.zig b/core/tape.zig index 1c9368d0..34c9f1da 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1043,7 +1043,7 @@ pub inline fn enter(p: ?*Pardes, input: Input) Entered { } /// The tape an entry steps: its core's; for a session not made yet, the one -/// its options name, or the one `Pardes.create` takes. +/// its options name (`Pardes.create`'s). fn tapeOf(p: ?*Pardes, input: *const Input) *Tape { if (p) |core| return core.tape; const opts = switch (input.*) { @@ -1051,7 +1051,7 @@ fn tapeOf(p: ?*Pardes, input: *const Input) *Tape { .init_from_dump => |d| d.opts, else => return &none, }; - return opts.tape orelse on orelse &none; + return opts.tape orelse &none; } /// Whether an entry on `t` is recorded: not on the tape nobody records, nor @@ -1064,20 +1064,6 @@ pub inline fn leave(p: ?*Pardes, e: Entered) void { if (e.tape) |t| t.leaveInput(p); } -// The entry points on `on`, the methods' (`Tape.site` and the rest). - -pub fn adopt(p: *Pardes) void { - (on orelse &none).adopt(p); -} - -pub fn current(p: *const Pardes) bool { - return (on orelse &none).current(p); -} - -pub fn forget(p: *Pardes) void { - (on orelse &none).forget(p); -} - /// An entry written once (P22): its public name made from the private /// body directly under it, `pub const setCwd = pardes.tape.taped(setCwdInner);`. /// The same parameters; the call recorded as the variant of `Input` whose @@ -1593,19 +1579,21 @@ pub fn digestOf(p: *const Pardes) u64 { return walk.digest(Pardes, p); } -/// PARDES_RECORD set: the tape is written from the session's first call. -pub fn startFromEnv() void { - if (on != null) return; - const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return); - if (prefix.len == 0) return; +/// PARDES_RECORD set: the tape a session is written to from its first +/// call, which whoever starts it hands in `Options.tape` (runtime/session.zig, +/// the Mac's start). `on` too, while the terminal's questions read it (P20). +pub fn fromEnv() ?*Tape { + const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return null); + if (prefix.len == 0) return null; const gpa = std.heap.c_allocator; var path_buf: [4096]u8 = undefined; - const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return; + const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return null; const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true, .CLOEXEC = true }, @as(libc.mode_t, 0o644)); - if (fd < 0) return; - const t = gpa.create(Tape) catch return; + if (fd < 0) return null; + const t = gpa.create(Tape) catch return null; t.* = .{ .gpa = gpa, .replay = false, .fd = fd, .scratch = .init(gpa), .arena = .init(gpa), .every = libc.getenv("PARDES_RECORD_EVERY") != null }; on = t; + return t; } /// `PARDES_REPLAY=`: the tape replayed into three replicas, each @@ -1704,7 +1692,7 @@ test "a replay that finds no answer where its core reads one diverges, and the r /// The functions of core/ that set `on` and leave a core's field be, each /// with why the field is that tape already. const sets_on_alone = [_]struct { []const u8, []const u8, []const u8 }{ - .{ "tape.zig", "startFromEnv", "no core yet: the one made next takes `on` (Pardes.create)" }, + .{ "tape.zig", "fromEnv", "no core yet: its starter hands the tape in Options.tape" }, .{ "tape.zig", "replayBytes", "its replay's core is made with this tape in its options (apply)" }, .{ "replica.zig", "begin", "Stepping: the core stepped holds this tape already (adoptCore), which `enter` checks in a safe build" }, .{ "replica.zig", "end", "Stepping: `on` put back as `begin` found it" }, diff --git a/runtime/macos.zig b/runtime/macos.zig index cfe93b13..4f9a9c33 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -348,6 +348,7 @@ fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void { pardes.syntax.start(allocs.tree_sitter); errdefer pardes.syntax.stop(); + opts.tape = pardes.tape.fromEnv(); const core = try pardes.Pardes.init(allocs.pardes, opts); errdefer core.deinit(); // The workspace tag row is the macOS menu bar's business here (see diff --git a/runtime/session.zig b/runtime/session.zig index fdd72c2b..b1558d9f 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -75,6 +75,7 @@ pub fn Loop(comptime Frontend: type) type { o.tree_sitter_allocator = l.allocs.tree_sitter; o.frame_allocator = l.allocs.frame; fe.options(&o); + o.tape = pardes.tape.fromEnv(); l.core = if (upgrade.resumed) |*rec| try upgrade.load(l.gpa, l.allocs.pardes, o, rec) else if (o.load_path) |lp| blk: { diff --git a/test/session.zig b/test/session.zig index 1cbee9df..d437ecf2 100644 --- a/test/session.zig +++ b/test/session.zig @@ -53,7 +53,7 @@ pub const Session = struct { /// A session showing one file pane holding `text`, keeping what outlives /// it in a database in memory (core/Db.zig). pub fn initFile(gpa: std.mem.Allocator, text: []const u8) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording }); errdefer p.deinit(); _ = try p.setTestFile(text); var s: Session = .{ .core = p, .arena = .init(gpa) }; @@ -75,7 +75,7 @@ pub const Session = struct { /// A session showing one file pane, its startup file `init` (as /// `~/.config/pardes/init` is read) applied first. pub fn initStartup(gpa: std.mem.Allocator, init: []const u8) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init, .tape = recording }); errdefer p.deinit(); _ = try p.setTestFile("x\n"); var s: Session = .{ .core = p, .arena = .init(gpa) }; @@ -85,7 +85,7 @@ pub const Session = struct { /// A session showing its terminal pane, as `pardes` starts. pub fn initTerm(gpa: std.mem.Allocator) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording }); var s: Session = .{ .core = p, .arena = .init(gpa) }; s.drain(); return s; @@ -99,7 +99,7 @@ pub const Session = struct { var arena: std.heap.ArenaAllocator = .init(gpa); errdefer arena.deinit(); const config = try std.fmt.allocPrint(arena.allocator(), "DumpDir {s}\n", .{dir}); - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config, .tape = recording }); var s: Session = .{ .core = p, .arena = arena }; s.drain(); return s; @@ -206,12 +206,16 @@ pub const Session = struct { s.drain(); } + /// The tape `recordTape` started: every session made after it records on it. + var recording: ?*pardes.tape.Tape = null; + /// Every session started from here on records what it consumes as a /// tape in memory, as PARDES_RECORD has a real one record it /// (core/tape.zig); `replayTape` replays it once the session is gone. pub fn recordTape(gpa: std.mem.Allocator) !void { const t = try gpa.create(pardes.tape.Tape); t.* = pardes.tape.memory(gpa); + recording = t; pardes.tape.on = t; } @@ -221,7 +225,8 @@ pub const Session = struct { /// its end loaded to its digest and dumped to its bytes again. False /// when a replica diverged (said on stderr). After `deinit`. pub fn replayTape(gpa: std.mem.Allocator) bool { - const t = pardes.tape.on orelse return true; + const t = recording orelse return true; + recording = null; pardes.tape.on = null; defer { pardes.tape.release(t); -- cgit v1.3