diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 23:56:41 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 03:37:59 -0300 |
| commit | 961e4cc938615de45294c78d42792706376c577e (patch) | |
| tree | 220a2d8e2b00059ecd9d45c01358cc88ba610505 /core/replica.zig | |
| parent | f52b6256927431e90af58af2f91eaac7e9799bf5 (diff) | |
| download | pardes-961e4cc938615de45294c78d42792706376c577e.tar.gz pardes-961e4cc938615de45294c78d42792706376c577e.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 132 |
1 files changed, 106 insertions, 26 deletions
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 |
