summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 02:26:15 -0300
committerGabriel Schneider <[email protected]>2026-11-19 03:05:27 -0300
commit24fbb1e611b32924039faa2ee4886d27025a3012 (patch)
tree6c00b21f1d6a3e00bbe9ecd98c91693dac0895cc /core/replica.zig
parent7ec51e48d430d4bc06869c09c6cc1325124ac338 (diff)
downloadpardes-24fbb1e611b32924039faa2ee4886d27025a3012.tar.gz
pardes-24fbb1e611b32924039faa2ee4886d27025a3012.zip
tape: a host call that returns nothing no longer stops a client's speculation (the reorganisation's 12a, S1; the user's rulings P14 and P16): in tape.hostCall a speculating client records such a call as made and goes on, and the session's unit confirms the record, or records more where its host wrote the core during the call (an input it made inside it, a watched field) and the client rolls back as for any misprediction; one list, `keeps_stopping`, names the entries that still stop, each with its reason (pty_write: a shell's input, a device by P14 and off the tape with screen-state terminals; spawn, write_file, write_dump, dump_themes: their hosts write the core on every call, write_file also outside any record; upgrade, hand_over, detach: the session's own; search: a host with no worker writes the rows outside any record and a client cannot know which host the session has; wait_input, present, post_present, poll_frame: the loop's), and watch_theme stops only turned on (its host loads the theme file into the core outside any record); and a client's yank, paste and link are its own frontend's (P16): Effect.perform counts each in the view the step is in (View.yanks, pastes, links and the link itself, digested, the same on both sides), and the session's host is not called for a view a client draws (`undrawn`), the record unchanged so nothing mismatches; the frontends that act on those counts are another agent's files (the lines are in reports/pardes-seam-a.md); four tests at the end of core/replica.zig through the replica's surface (a ClipYank goes on at once and is confirmed fast; the same with a host that says something into the core during the call rolls back once and agrees; ThemeFile stops and the Theme after it does not; a joined client's ClipYank and ClipPaste move its view's counts on both sides and the session's host is asked neither, while the session's own view's yank is still its host's); the semantics word did not move (adacca2db2b39264); tui core-test 829/971 (142 skipped), shell-test 1006/1009, pane-test 183/184, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed (lspcomplete, lspcompletemoved, the base's), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, stopped 104/133/147 -> 96/114/140, mispredicted 44/33/29 -> 44/34/29, gui unit-test 1604/1608 (its perf check's BaselineHarnessMismatch the base's), daemon.py plain, --far, --games, --window-clients pass; gate-w seam-a-1 against tree1: 77/77 frames byte-identical in Debug, perfab corpus2x -0.106%, perfops 97 counts within 0.1% (largest +0.0173%)
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.zig139
1 files changed, 139 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 8b63ed51..dc5d99a4 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5024,3 +5024,142 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b
try agrees(a, r);
try std.testing.expect(r.core().panes[id] == null);
}
+
+/// A session's host whose fire-and-forget entries a test counts: a
+/// clipboard set, a paste asked, a link opened; with `tell`, a clipboard
+/// set says so into the core during the call, as a host's `saved` does.
+/// A client joined from the session's dump in its view, the unit after the
+/// join taken (the session's host said to it, as at any join's first), at
+/// the start of a second (`freshSecond`).
+fn joinedFresh(a: *Authority) !*Replica {
+ _ = try a.unit(0, 0);
+ const r = try joinedNow(a, 1, 0);
+ errdefer r.deinit();
+ r.confirm(try a.local(.tick));
+ r.settle();
+ freshSecond();
+ return r;
+}
+
+const SeenHost = struct {
+ core: ?*Pardes = null,
+ yanked: u32 = 0,
+ asked: u32 = 0,
+ linked: u32 = 0,
+ tell: bool = false,
+ fn of(ctx: ?*anyopaque) *SeenHost {
+ return @ptrCast(@alignCast(ctx.?));
+ }
+ fn setClipboard(ctx: ?*anyopaque, _: []const u8) void {
+ const h = of(ctx);
+ h.yanked += 1;
+ if (h.tell) h.core.?.setMessage(h.core.?.view().active, "yanked");
+ }
+ fn readClipboard(ctx: ?*anyopaque) void {
+ of(ctx).asked += 1;
+ }
+ fn openLink(ctx: ?*anyopaque, _: []const u8) void {
+ of(ctx).linked += 1;
+ }
+ fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme };
+ fn host(h: *SeenHost) pardes.Host {
+ return .{ .ctx = h, .vtable = &vtable };
+ }
+};
+
+test "a client's step that asks the session's host for something that returns nothing goes on at once, and the session's unit confirms it: nothing rolled back" {
+ const gpa = std.testing.allocator;
+ var h: SeenHost = .{};
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false);
+ defer a.deinit();
+ h.core = a.core;
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = "ClipYank" }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(@as(usize, 1), r.applied);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try std.testing.expectEqual(@as(u32, 1), h.yanked);
+ try std.testing.expectEqual(@as(u32, 1), r.stats.fast);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted);
+ try agrees(a, r);
+}
+
+test "a client's step whose session's host says something into the core during the call it made: its speculation rolled back, then the session's state" {
+ const gpa = std.testing.allocator;
+ var h: SeenHost = .{ .tell = true };
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false);
+ defer a.deinit();
+ h.core = a.core;
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = "ClipYank" }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try std.testing.expectEqual(@as(u32, 1), r.stats.mispredicted);
+ try agrees(a, r);
+}
+
+test "a client's ThemeFile waits for the session, whose host loads the file into the core; a Theme after it lets the file go at once" {
+ const gpa = std.testing.allocator;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "t.zon", .data = ".{ .name = \"seen\" }\n" });
+ var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var line: [std.Io.Dir.max_path_bytes + 16]u8 = undefined;
+ var h: SeenHost = .{};
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false);
+ defer a.deinit();
+ h.core = a.core;
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ for ([_][]const u8{ try std.fmt.bufPrint(&line, "ThemeFile {s}/t.zon", .{dir}), "Theme acme" }, [_]u32{ 1, 0 }) |cmd, stops| {
+ const before = r.stats.stopped;
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = cmd }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(stops, r.stats.stopped - before);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try agrees(a, r);
+ }
+ try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted);
+}
+
+test "a client's yank and paste of the system clipboard are its own frontend's: its view counts them, at once and as the session does, and the session's host is asked neither" {
+ const gpa = std.testing.allocator;
+ var h: SeenHost = .{};
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false);
+ defer a.deinit();
+ h.core = a.core;
+ _ = try a.unit(0, 0);
+ const j = (try a.join(1, null)) orelse return error.NoView;
+ defer gpa.free(j.dump);
+ const r = try Replica.initDump(gpa, 1, j.view, j.dump, .{ .cols = 80, .rows = 24 });
+ defer r.deinit();
+ r.confirm(try a.local(.tick));
+ r.settle();
+ freshSecond();
+ for ([_][]const u8{ "ClipYank", "ClipPaste" }) |cmd| {
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = cmd }));
+ defer gpa.free(msg);
+ r.confirm(try a.take(msg));
+ r.settle();
+ }
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted);
+ try std.testing.expectEqual(@as(u32, 0), h.yanked + h.asked);
+ for ([_]*Pardes{ a.core, r.core() }) |c| {
+ try std.testing.expectEqual(@as(u32, 1), c.views[j.view].?.yanks);
+ try std.testing.expectEqual(@as(u32, 1), c.views[j.view].?.pastes);
+ }
+ try agrees(a, r);
+ // The session's own view's yank is its host's, as before.
+ _ = try a.own(.{ .command = "ClipYank" });
+ try std.testing.expectEqual(@as(u32, 1), h.yanked);
+}