summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:38:35 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:49:16 -0300
commit020a7d24103a7c6f788db1091fd921d41d0df9e8 (patch)
tree3ba9602a41c896cf54d8b11f9a89919baada589d /src
parent5af775e9817395af39792cc609b832394d4a4fb8 (diff)
downloadpardes-020a7d24103a7c6f788db1091fd921d41d0df9e8.tar.gz
pardes-020a7d24103a7c6f788db1091fd921d41d0df9e8.zip
views: a view opened or closed settles in its own input: a unit taped outside a step (a leave's close_view, a join's open_view) ended with effects queued, which a replica's copy asserted on and a joiner's dump dropped
A client's leave is the session's closeView, whose sync sizes again a terminal the closed view sized (`sizes`) and queues its pty's resize; the session did it at its next pump, another unit. A replica that replayed the close was left with the effect queued between steps, and its next idle copy (Replica.ready, rollback.Copy.take's assert) aborted it: a client killed when another left (H10). A client joining at that boundary was dumped with the effect still queued, which a core loaded from a dump has none of (Replica.initDump), and diverged at the session's next pump (H6: "the core called poll_frame where the tape has a host (12)"). closeView and openView settle now, inside their own taped input, so every side does the same there; openView's covers what else was queued since the last pump (a 9P request's step). Test (failing before at each of the two asserts): a client leaves, and one joins: what the leave queued is done in its unit, on every side, before the join's dump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/pardes.zig10
-rw-r--r--src/replica.zig55
2 files changed, 65 insertions, 0 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 36ce6bdb..5b37342e 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -5669,6 +5669,11 @@ pub const Pardes = struct {
pub fn openView(p: *Pardes) ?u8 {
const taped = tape.enter(p, .open_view);
defer tape.leave(p, taped);
+ // What was queued since the last pump (a leaving client's view
+ // closed, a 9P request's step) done first, as every client of the
+ // tape does it here: a join dumps the session next, and a core
+ // loaded from a dump has no queue (Replica.initDump).
+ p.settle();
p.needs_frame = true;
return views.open(p);
}
@@ -5680,6 +5685,11 @@ pub const Pardes = struct {
defer tape.leave(p, taped);
views.close(p, k);
p.sync();
+ // What its sync queued (a terminal it sized, sized again) done here,
+ // in its own unit on every side: the session's next pump is another
+ // unit, and a replica takes a copy only of a core with nothing
+ // queued (rollback.Copy.take).
+ p.settle();
}
/// Into view `k`, before the input its client sent.
diff --git a/src/replica.zig b/src/replica.zig
index 8b1d84f4..22de375f 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -3439,3 +3439,58 @@ test "a replica's Del of a file its session's Recent knows asks the host what th
try agrees(a, r);
}
+/// A host with ptys whose pump polls for a frame, as a client's does.
+const PtyHost = struct {
+ fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {}
+ fn poll(_: ?*anyopaque) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll };
+ fn host() pardes.Host {
+ return .{ .vtable = &vtable };
+ }
+};
+
+fn inputOf(buf: []u8, client: u16, seq: u32, ev: pardes.Event) ![]const u8 {
+ const n = (try wire.encodeClient(buf[head_len..], .{ .event = ev })).len;
+ header(buf, client, seq);
+ return buf[0 .. head_len + n];
+}
+
+test "a client leaves, and one joins: what the leave queued (a terminal's resize) is done in its unit, on every side, before the join's dump" {
+ if (comptime !terminal.enabled) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, PtyHost.host(), true);
+ defer a.deinit();
+ const first = try gpa.dupe(u8, try a.unit(0, 0));
+ defer gpa.free(first);
+ const old = try Replica.init(gpa, 1, first, true);
+ defer old.deinit();
+ // A second client, bigger, types into the terminal: it sizes it.
+ const opened = try a.openView(2);
+ old.confirm(opened.unit);
+ var buf: [256]u8 = undefined;
+ old.confirm(try a.take(try inputOf(&buf, 2, 1, .{ .resize = .{ .cols = 120, .rows = 40 } })));
+ old.confirm(try a.take(try inputOf(&buf, 2, 2, .{ .key = .{ .cp = 'x', .text = "x" } })));
+ // It leaves: the terminal is the first view's size again, its pty's
+ // resize queued for the next pump; and a client joins at that boundary.
+ var was = Stepping.begin(&a.t, null);
+ a.core.closeView(opened.view);
+ was.end();
+ old.confirm(try a.unit(0, 100));
+ // The client left idle takes its copy ahead (Replica.ready): of a core
+ // with nothing queued.
+ old.ready();
+ was = Stepping.begin(&a.t, null);
+ const k = a.core.openView() orelse return error.NoView;
+ was.end();
+ old.confirm(try a.unit(0, 101));
+ const joiner = try joinedNow(a, 3, k);
+ defer joiner.deinit();
+ try std.testing.expectEqual(digestOf(a), joiner.digest());
+ // The next pump's unit, every client's.
+ const u = try gpa.dupe(u8, try a.local(.tick));
+ defer gpa.free(u);
+ old.confirm(u);
+ joiner.confirm(u);
+ try agrees(a, old);
+ try agrees(a, joiner);
+}