From f52b6256927431e90af58af2f91eaac7e9799bf5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 23:53:14 -0300 Subject: dump: a join's dump and its digest are one moment: the dump asks the host nothing and hands back the digest it was made at: a client that came back while 9P requests were live (a script reading /screen, the /mnt/9p mount) loaded the session's dump and refused it as another session's, exiting for good while its session was there (fault D, reports/pardes-upgrade-back.md: the upgrade row's rejoin, about 3 in 75 on one CPU, and its family in pair_exec_reaps): the join's dump stat'd each pane's file for which were on disk (core/dump.zig `dumpWith` -> `onDisk` -> exec.kindOf, a `.kind` tape site that gives up the turn, tape.out), a 9P open, read or release (none waits for quiet: ninep/tree.zig `needsQuiet`) was answered in that gap by a connection task, and `Peers.join` then took the welcome's digest over the moved `fs` (tape.digestOf after the dump): the client's load, from before the request, could not be it; and the request, recorded after the join's cut, was in the client's next unit too; `fs` is ruled replicated state, as it was: every 9P request is a taped input each replica replays (Core.zig `serveFs`), a write on an open reads its record (the half line, the results, the lock, the held writes: the previous change's fifteen kinds, the tests at the replica's surface below them), and its dump carries what its digest hashes (the property's 300 joins); what was wrong was the moment, not the field; now `dumpJoin` returns `.{ bytes, digest }`, the digest taken in it after the dump with nothing between, `Peers.join` and `Authority.join` take it from there (no caller can take it at another moment), a join's dump writes `on_disk` as none (only a revival reads it, from an image: `image` keeps its stat; a client's load discards it: loadKnowing's `on_disk` is null for `load`), and a turn given up while the dump is made fails it (`error.TurnGivenUp`: the join is refused in words, `that session could not be dumped`, never loaded otherwise); `byteDump` (tests only) is the join's dump with its blobs in place, as its tests take it; the previous change's moment test passes (the join asks the host nothing: the stat that let the request in is never made, the turn's yields do not move); core-test under the filter `join` 52/61 (9 skipped) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/dump.zig | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'core/dump.zig') diff --git a/core/dump.zig b/core/dump.zig index c3742a21..82098449 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -259,13 +259,26 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { /// out and noted in `deferred` (they are the session's, alive while pinned: /// memory.zig `pin`), each terminal whole (as the join's step reloaded it /// on every side: panes.reloadTerminals), its sequence in flight with it. -/// What is left is the session's mutable state, made in its step. -pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { +/// What is left is the session's mutable state, made in its step. With it +/// the session's digest at that moment, which the client checks its load +/// by. +/// +/// One moment: nothing in it gives up the turn (pardes.turn: a host call +/// does, tape.out), or a 9P request answered meanwhile is in the dump and +/// in the client's next unit both, and moves the core between the dump and +/// the digest: the client then refused its own load and went (a script +/// reading /screen at a rejoin, 2026-11-22). So a join's dump asks the host +/// nothing (`on_disk`, a revival's, is none in it). +pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) !struct { bytes: []u8, digest: u64 } { // The join's file reads are the session's host's, between its steps: // with its io, which the core's tape holds (a walk's hook takes no more). join_files = p.tape.io; defer join_files = null; - return dumpWith(p, deferred); + const yields = pardes.turn.yields; + const bytes = try dumpWith(p, deferred); + errdefer p.gpa.free(bytes); + if (pardes.turn.yields != yields) return error.TurnGivenUp; + return .{ .bytes = bytes, .digest = pardes.tape.digestOf(p) }; } /// `dumpExit`'s: a terminal dumps its size, not its emulator. @@ -281,10 +294,9 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 try d.put(Pardes, p); const mounts: []const filesystem.Mount = p.fs.mounts.items; try d.put([]const filesystem.Mount, &mounts); - var on_disk: OnDisk = @splat(false); - for (p.panes, &on_disk) |slot, *on| if (slot) |pane| { - on.* = onDisk(p.tape, pane); - }; + // Which files were on disk is a revival's (`image`): a client's load + // never reads it, and a join asks the host nothing. + const on_disk: OnDisk = @splat(false); try d.put(OnDisk, &on_disk); const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name; try d.put([]const u8, &theme); -- cgit v1.3 From 961e4cc938615de45294c78d42792706376c577e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 23:56:41 -0300 Subject: walk, dump, replica: a field's dump and its digest cannot disagree unseen: what one walk cannot hold is listed and tested, and a client refused its own load names the field: the copy, the digest and the dump of the core already come from one walk with one declaration a struct (core/walk.zig `replica`: local, derived and authority fields in none of the three, every other in all three), so a field cannot be in the digest and out of the dump; what escapes that walk is a type that walks itself by hand, a `digest` or a dump of its own (eight reach the core: fs.Namespace, tree.Open.What, the pane's 9P state, Term.State, Kind.Slot, locations.Row, jj.Session, File.Layers), and the moment the two are taken at (the previous change); `walk.handWalked(roots)` lists at comptime every type the walk reaches that walks itself by hand, and replica.zig's `hand_walked` names, for each, the test that joins a client from a dump of a session holding it and checks the load by the welcome's digest: the test of that name fails for a type that walks itself by hand with no line (dropping File.Layers' line: "File.Layers walks itself by hand and no test joins a client over it") and for a line whose type no longer does; jj.Session and File.Layers had none (their tests replay a client from the start): `loadsAsSession` (any test's session, a client joined from its dump, the fields named) ends the jj test that replays Changes, its pins and lanes crossing a join whole; and a join's dump ends with the session's digest a field at a time (tape.digestParts, after the walk with nothing between; `dump.joinParts` reads it; the loader reads its roots and stops before it), so a client whose load is not the session says which field in its words and its log (`fromDump`: "the session's dump loaded as another session: fs differs", a warning line `client N: ...`), the diagnostic build's naming kept in the product, tested by a dump made before a 9P open checked by the digest after it; what this cannot hold: a hand walk's body (the list makes it seen and tested, a reviewer reads the walk), a load's own changes after it reads (Replica.made, loadKnowing's fixups: the roundtrip tests catch them only for the state the tests build), a host call in the join's dump on a road no test session reaches (`error.TurnGivenUp` refuses that join in words), and the dump of a type a test session never holds; its gate (this tree, .scratch/sketch/reorg/pardes-dump-digest/g1, loads 0.6-13.5): IN THE WORKSPACE core-test 922/1082 (160 skipped), shell-test 1124/1127 (3 skipped), each the base's plus the five new tests, addon-test 5/5, term-test 17/17, kitty-test 45/45, process-test 0 of 146 failed, pane-test 182/183, behaviour-test and --replay 275/275, consumer-test; the soak --clients 5 three times: diverged 0, unequal 0, unlisted 0 at 30/80/207 ms, quiet checks all agreeing, the corpus 22 of 22, no leak; daemon.py on Debug and ReleaseSafe: plain 3/3, --clients 3/3, --far, --restore; --upgrade from the installed build (wire 30) 3/3, --upgrade --gui 3/3, between the tree's own builds 3/3 each way; cross-builds 3/3; the frame and perf gate against tree4: 77/77 frames, perfab corpus2x -0.009% (noise 0.021%), 121 counts within 0.1% (largest terminal on all +0.0786%; no key's path changed, no field left the digest); the one-CPU upgrade rows: every run past the rejoin step fault D failed, 28 of 30 whole (the next change) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/dump.zig | 26 ++++++++++- core/jj.zig | 2 + core/replica.zig | 132 ++++++++++++++++++++++++++++++++++++++++++++----------- core/walk.zig | 16 +++++++ 4 files changed, 149 insertions(+), 27 deletions(-) (limited to 'core/dump.zig') diff --git a/core/dump.zig b/core/dump.zig index 82098449..547f9f7d 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -261,7 +261,8 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { /// on every side: panes.reloadTerminals), its sequence in flight with it. /// What is left is the session's mutable state, made in its step. With it /// the session's digest at that moment, which the client checks its load -/// by. +/// by, and after it that digest a field at a time (`joinParts`), which +/// names what a load that is not the session has otherwise. /// /// One moment: nothing in it gives up the turn (pardes.turn: a host call /// does, tape.out), or a 9P request answered meanwhile is in the dump and @@ -281,6 +282,22 @@ pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) !s return .{ .bytes = bytes, .digest = pardes.tape.digestOf(p) }; } +/// What a join's dump ends with: the session's digest a field at a time +/// (tape.digestParts), their count, this word. +const parts_word = "parts\x00\x00\x01"; + +/// The session's digest a field at a time that a join's dump `bytes` ends +/// with, in `gpa`; null for a dump with none. +pub fn joinParts(gpa: std.mem.Allocator, bytes: []const u8) ?[]u64 { + const tail = parts_word.len + 8; + if (bytes.len < tail or !std.mem.endsWith(u8, bytes, parts_word)) return null; + const n = std.mem.bytesToValue(u64, bytes[bytes.len - tail ..][0..8]); + if (n > (bytes.len - tail) / 8) return null; + const out = gpa.alloc(u64, @intCast(n)) catch return null; + @memcpy(std.mem.sliceAsBytes(out), bytes[bytes.len - tail - out.len * 8 ..][0 .. out.len * 8]); + return out; +} + /// `dumpExit`'s: a terminal dumps its size, not its emulator. pub var slim_terminals = false; /// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file), @@ -307,6 +324,13 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 } const kept: []const views.Shares = others; try d.put([]const views.Shares, &kept); + const parts = try p.gpa.create(pardes.tape.Parts); + defer p.gpa.destroy(parts); + const each = pardes.tape.digestParts(p, parts); + const w = &d.out.writer; + try w.writeAll(std.mem.sliceAsBytes(each)); + try w.writeAll(std.mem.asBytes(&@as(u64, each.len))); + try w.writeAll(parts_word); return d.finish(); } diff --git a/core/jj.zig b/core/jj.zig index a0dfec10..4687a89e 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -1965,6 +1965,8 @@ test "a client replays Changes from what the session's jj answered and ends equa try testing.expectEqualStrings("@--::@-", answered(r.core(), r.core().panes[id].?.serial).?.pinned()); try testing.expect(r.core().panes[id].?.layers.lanes > 0); try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core())); + // Its pins and lanes cross a join whole (replica.zig `hand_walked`). + try R.loadsAsSession(a, 2); } /// A session whose `Changes` runs on a worker (Stream.start), as a shell's diff --git a/core/replica.zig b/core/replica.zig index 75aa94e1..0d1802b5 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2834,14 +2834,33 @@ fn fromDump(gpa: Allocator, j: *Joined, o: pardes.Options, have: ?*Have, why: [] return null; }; if (!r.loaded(j.digest)) { + var named: [400]u8 = undefined; + const fields = loadDiffers(r, j.dump, &named); r.deinit(); - _ = std.fmt.bufPrint(why, "the session's dump loaded as another session (a build's dump is not complete)\x00", .{}) catch {}; + log.warn("client {d}: the session's dump loaded as another session: {s}", .{ j.client, fields }); + _ = std.fmt.bufPrint(why, "the session's dump loaded as another session: {s}differs\x00", .{fields}) catch {}; return null; } takeJoined(r, j, have, t0); return r; } +/// The fields a replica loaded from the join's dump `bytes` has other than +/// the session as it dumped them (the digest a field at a time the dump +/// ends with: dump.joinParts), named in `out`. +fn loadDiffers(r: *Replica, bytes: []const u8, out: []u8) []const u8 { + const want = pardes.dump.joinParts(r.gpa, bytes) orelse return "(the dump names no field) "; + defer r.gpa.free(want); + var arena: std.heap.ArenaAllocator = .init(r.gpa); + defer arena.deinit(); + const got = arena.allocator().create(tape.Parts) catch return ""; + const was = Stepping.begin(&r.t, &r.epoch); + const parts = tape.digestParts(r.core(), got); + was.end(); + const fields = tape.partsDiffer(parts, want, arena.allocator()); + return std.fmt.bufPrint(out, "{s}", .{fields[0..@min(fields.len, out.len)]}) catch out; +} + /// What a replica joined by `j` takes of it, and of the environment. fn takeJoined(r: *Replica, j: *Joined, have: ?*Have, t0: u64) void { // PARDES_NO_ECHO: no predicted echo (the gates' baseline). @@ -7609,36 +7628,97 @@ const NinepJoin = struct { _ = try n.serve(.{ .tag = 2, .op = .write, .node = at, .handle = h, .data = data }, true); } - /// A client joined now and let go: its load is the session as dumped, - /// at the welcome's digest, the fields that differ named. fn loadsSame(n: *NinepJoin) !void { - const gpa = std.testing.allocator; - const joined = (try n.a.join(1, null)) orelse return error.NoView; - defer gpa.free(joined.dump); - const r = try Replica.initDump(gpa, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); - defer r.deinit(); - if (!r.loaded(joined.digest)) { - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); - std.debug.print("the client's load is not the session: {s}\n", .{try loadDiffers(n.a, r, arena.allocator())}); - return error.LoadedAnother; - } - _ = try n.a.leave(1, false); + try loadsAsSession(n.a, 1); } }; -/// The fields a client's core has other than the session's, named -/// (tape.partsDiffer). -fn loadDiffers(a: *Authority, r: *Replica, arena: Allocator) ![]const u8 { - const want = try arena.create(tape.Parts); - const got = try arena.create(tape.Parts); - const w = tape.digestParts(a.core, want); - const g = parts: { - const was = Stepping.begin(&r.t, &r.epoch); - defer was.end(); - break :parts tape.digestParts(r.core(), got); +/// A client `client` of the session `a` joined now, as `Peers.join` joins +/// one, and let go: its load is the session as dumped, at the welcome's +/// digest; the fields that differ named (`loadDiffers`) when it is not. +/// A test's session ends with it to say its state crosses a join whole. +pub fn loadsAsSession(a: *Authority, client: u16) !void { + const gpa = std.testing.allocator; + const joined = (try a.join(client, null)) orelse return error.NoView; + defer gpa.free(joined.dump); + const r = try Replica.initDump(gpa, client, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); + defer r.deinit(); + if (!r.loaded(joined.digest)) { + var named: [400]u8 = undefined; + std.debug.print("the client's load is not the session: {s}\n", .{loadDiffers(r, joined.dump, &named)}); + return error.LoadedAnother; + } + _ = try a.leave(client, false); +} + +/// Every type the core's walk reaches that walks itself by hand +/// (walk.handWalked: a `digest` or a dump of its own, which can take what +/// the other does not), and the test that joins a client from a dump of a +/// session holding it and checks the load by the welcome's digest. The one +/// walk holds every other field: its digest, its dump and its rollback copy +/// are the same fields by one declaration (walk.zig `replica`). +const hand_walked = .{ + .{ pardes.filesystem.Namespace, "a client joined while 9P requests hold each kind of state the core keeps for them" }, + .{ pardes.ctlfs.Open.What, "a client joined while 9P requests hold each kind of state the core keeps for them" }, + .{ pardes.ctlfs.pane.State, "a client joined after a script set a pane's addr, its limit, or truncated its dot" }, + .{ Term.State, "bytes: a client joins from a dump with its terminals whole" }, + .{ pardes.Kind.Slot, "a client joined from a dump numbers a kind's next job as the session does" }, + .{ @import("locations.zig").Row, "a client joined from a dump makes a `/` query's rows as the session does" }, + .{ @import("jj.zig").Session, "a client replays Changes from what the session's jj answered and ends equal" }, + .{ pardes.panes.File.Layers, "a client replays Changes from what the session's jj answered and ends equal" }, +}; + +test "every type the core's walk reaches that hashes or dumps itself by hand has a test joining a client over it (hand_walked)" { + inline for (comptime walk.handWalked(&.{Pardes})) |T| { + const listed = comptime for (hand_walked) |entry| { + if (entry[0] == T) break true; + } else false; + if (!listed) { + std.debug.print("{s} walks itself by hand and no test joins a client over it: one, and its line in hand_walked\n", .{@typeName(T)}); + return error.NotListed; + } + } + // ...and every line is a type that does: one that walks itself by the + // one walk again leaves no line behind. + inline for (hand_walked) |entry| { + const reached = comptime for (walk.handWalked(&.{Pardes})) |T| { + if (entry[0] == T) break true; + } else false; + if (!reached) { + std.debug.print("{s} no longer walks itself by hand: its line in hand_walked goes\n", .{@typeName(entry[0])}); + return error.Stale; + } + } +} + +test "a client whose load is not the session says which field, in its words and its log" { + const gpa = std.testing.allocator; + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const before = (try n.a.join(1, null)).?; + defer gpa.free(before.dump); + _ = try n.a.leave(1, false); + _ = try n.serve(.{ .tag = 1, .op = .open, .node = @backingInt(pardes.ctlfs.TopFile.screen) }, true); + const after = (try n.a.join(1, null)).?; + defer gpa.free(after.dump); + // The dump before the open, checked by the digest after it and named + // by its fields: what a dump made at one moment and a digest taken at + // another said. + const Tail = struct { + fn at(dump: []const u8) usize { + const parts = pardes.dump.joinParts(std.testing.allocator, dump).?; + defer std.testing.allocator.free(parts); + return dump.len - parts.len * 8 - 16; + } }; - return tape.partsDiffer(g, w, arena); + var spliced: std.ArrayListUnmanaged(u8) = .empty; + defer spliced.deinit(gpa); + try spliced.appendSlice(gpa, before.dump[0..Tail.at(before.dump)]); + try spliced.appendSlice(gpa, after.dump[Tail.at(after.dump)..]); + var j: Joined = .{ .fd = -1, .pid = 0, .client = 1, .view = before.view, .gmtoff = 0, .dump = spliced.items, .digest = after.digest, .semantics = wire.semantics }; + var why: [600]u8 = @splat(0); + try std.testing.expect(fromDump(gpa, &j, .{ .cols = 80, .rows = 24 }, null, &why, nowNs()) == null); + try std.testing.expectEqualStrings("the session's dump loaded as another session: fs differs", std.mem.sliceTo(&why, 0)); } /// Each kind of state 9P requests leave in the core between two requests diff --git a/core/walk.zig b/core/walk.zig index 9b760144..d870052d 100644 --- a/core/walk.zig +++ b/core/walk.zig @@ -711,6 +711,22 @@ fn graph(comptime roots: []const type) []const type { } } +/// The types the walk of `roots` reaches that walk themselves by hand (a +/// `digest` or a `dumpWrite` of their own): the ones whose digest can take +/// what their dump does not carry, which the one walk holds for the rest. +pub fn handWalked(comptime roots: []const type) []const type { + comptime { + var out: []const type = &.{}; + for (graph(roots)) |T| switch (@typeInfo(T)) { + .@"struct", .@"union" => if (@hasDecl(T, "dumpWrite") or (@hasDecl(T, "digest") and @TypeOf(T.digest) == fn (*const T, *Hasher) void)) { + out = out ++ .{T}; + }, + else => {}, + }; + return out; + } +} + fn indexIn(comptime types: []const type, comptime T: type) u32 { comptime { @setEvalBranchQuota(100_000_000); -- cgit v1.3