summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-18 23:12:37 -0300
committerGabriel Schneider <[email protected]>2026-11-19 01:07:19 -0300
commite567aadc19f58b1e36098388483294321f3502dd (patch)
treec3a9f3430f3cad2e4d9ba7d21be0e88eae16bbeb /core/replica.zig
parent250d34c1b942cd6e3726e96f6d80a9cf98d6e20e (diff)
downloadpardes-e567aadc19f58b1e36098388483294321f3502dd.tar.gz
pardes-e567aadc19f58b1e36098388483294321f3502dd.zip
core: the rollback's two faults read by the probe (pardes-probes P4 b), each shown by a test that fails on the base, and fixed: (a) a terminal's kitty-image cache (TerminalImages.converted, RGBA made of an RGB or grey image) was made with the drawing core's allocator, so on a far client, whose emulator is outside its rollback epoch, a frame drawn under a speculation left the emulator holding epoch-born memory that the rollback freed (reachable since a closed terminal brought back loads the session's dump of it, its images with it): the next frame read the freed map (SIGSEGV in TerminalImages.draw on the base), so the caches are now the emulator's own allocator's and a terminal's close takes none; (b) a far client's slot of a kind whose state is not plain was on the C heap (initDump's image_allocator), so its own Del of such a pane freed the slot outside the epoch, and the rollback by another client's unit put back a pane pointing at it (a general protection fault in Jump.trackJump on the base), so a far client's image_allocator is now its epoch, as every other of its allocators: the free is put off and the Del stays instant; two tests at the end of core/replica.zig; tui core-test 824/966 (142 skipped), shell-test 1001/1004, pane-test 183/184, behaviour-test 274/274 and --replay 274/274, process-test 2 of 144 failed (lspcomplete, lspcompletemoved; winch failed once under load and passed alone), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, gui unit-test 1598/1602 with its perf check passing, daemon.py plain, --far and --games pass (--games once timed out at its teardown and passed again; --window-clients failed on the gate's own TMPDIR, a socket path past 108 bytes, and passed on 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.zig106
1 files changed, 101 insertions, 5 deletions
diff --git a/core/replica.zig b/core/replica.zig
index b8d8f436..e4ed4e0a 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -740,10 +740,12 @@ pub const Replica = struct {
/// A replica of a session elsewhere, as its walker dump (core/dump.zig)
/// is: what a client of a socket joins with. `opts` are this process's
/// (a replica's own allocators and names); its core's allocator is the
- /// rollback epoch's, but for images and PDFs, whose workers allocate on
- /// threads of their own. ponytail: a picture's pixels freed while a copy
- /// is held are not put off; a rollback over one shows an image a frame
- /// late at worst... or reads freed pixels, which no test session has.
+ /// rollback epoch's, its `image_allocator` too (a kind's slot whose
+ /// state is not plain: a speculation that closes one frees it into the
+ /// epoch, put off, as any). ponytail: a picture's pixels (`Kind.heap`)
+ /// freed while a copy is held are not put off; a rollback over one shows
+ /// an image a frame late at worst... or reads freed pixels, which no test
+ /// session has.
pub fn initDump(gpa: Allocator, id: u16, view: u8, bytes: []const u8, opts: pardes.Options) !*Replica {
const r = try gpa.create(Replica);
r.* = .{ .gpa = gpa, .id = id, .view = view, .t = tape.memory(gpa), .guess = true };
@@ -761,7 +763,7 @@ pub const Replica = struct {
var o = opts;
o.frame_allocator = epoch;
o.tree_sitter_allocator = epoch;
- o.image_allocator = o.image_allocator orelse std.heap.c_allocator;
+ o.image_allocator = epoch;
// The session's closed panes and Recent are the authority's.
o.state = .off;
// Its emulators off the epoch, as `terminal.create` makes a screen
@@ -4929,3 +4931,97 @@ test "a kind's job answered at once inside its host's call (no worker free) is t
try std.testing.expectEqual(@as(u32, 1), std.mem.bytesToValue(u32, a.core.panes[id].?.addon.?.plain.?[0..4]));
try std.testing.expectEqualSlices(u8, a.core.panes[id].?.addon.?.plain.?, r.core().panes[id].?.addon.?.plain.?);
}
+
+test "a closed terminal with a kitty image brought back on a client: its image drawn under a speculation, rolled back by another's unit, is drawn again from what the emulator holds" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true);
+ defer a.deinit();
+ const r = try Replica.init(gpa, 1, try a.unit(0, 0), true);
+ defer r.deinit();
+ const shell: u8 = for (a.core.panes, 0..) |slot, id| {
+ if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
+ } else return error.NoShell;
+ // A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA
+ // of its own (TerminalImages.converted).
+ a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } });
+ r.confirm((try a.pending()).?);
+ // Closed and brought back: the client loads the session's dump of it,
+ // its image with it.
+ a.core.view().active = shell;
+ r.confirm(try a.local(.{ .command = "Del" }));
+ var line: [32]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look @p{d}", .{a.core.store.closed.items[0].serial}) }));
+ const back = for (r.core().panes) |slot| {
+ if (slot) |pane| if (pane.terminal) |state| break state;
+ } else return error.NotBack;
+ try std.testing.expect(pardes.Term.hasImages(back));
+ // Typing goes to the text pane (the host's write of `active`, taped).
+ a.core.view().active = for (a.core.panes, 0..) |slot, id| {
+ if (slot) |pane| if (pane.file != null) break id;
+ } else return error.NoTextPane;
+ r.confirm(try a.local(.{ .focus = true }));
+ const Seen = struct {
+ px: ?[4]u8 = null,
+ fn take(ctx: ?*anyopaque, s: *const pardes.Surface) void {
+ const seen: *@This() = @ptrCast(@alignCast(ctx.?));
+ for (s.placements.items) |pl| seen.px = pl.raster.bytes()[0..4].*;
+ }
+ };
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| gpa.free(m);
+ sent.deinit(gpa);
+ }
+ // Its own key, at once, a copy held; a frame drawn over it.
+ try key(r, 'o', &sent);
+ try std.testing.expect(r.copy.held);
+ var seen: Seen = .{};
+ r.draw(.{ .ctx = &seen, .f = Seen.take });
+ try std.testing.expectEqual([4]u8{ 0x11, 0x22, 0x33, 0xff }, seen.px.?);
+ // The session's own key first: back to the copy, the key applied again.
+ r.confirm(try a.local(.{ .key = .{ .cp = 'l', .text = "l" } }));
+ r.settle();
+ seen = .{};
+ r.draw(.{ .ctx = &seen, .f = Seen.take });
+ try std.testing.expectEqual([4]u8{ 0x11, 0x22, 0x33, 0xff }, seen.px.?);
+ r.confirm(try a.take(sent.items[0]));
+ r.settle();
+ try agrees(a, r);
+}
+
+test "a far client's own Del of a pane whose kind's state is not plain, rolled back by another's unit: the pane comes back whole, and is closed again with the session's order" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);
+ defer a.deinit();
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words);
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } });
+ _ = try a.local(.{ .command = "Counter" });
+ // Joined from the dump: the kind's pane is a line here (no code), its
+ // slot the dump's.
+ const r = try joinedNow(a, 1, 0);
+ defer r.deinit();
+ const id = r.core().view().active;
+ try std.testing.expect(r.core().panes[id].?.addon != null);
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| gpa.free(m);
+ sent.deinit(gpa);
+ }
+ // Its own Del at once, and a key after it: the pane's teardown (its
+ // slot freed) is that key's step's (`reapPanes`).
+ try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .command = "Del" })));
+ try key(r, 'j', &sent);
+ try std.testing.expectEqual(@as(usize, 2), r.applied);
+ try std.testing.expect(r.core().panes[id] == null);
+ // The session's own key first: back to the copy, the pane with it.
+ r.confirm(try a.local(.{ .key = .{ .cp = 'l', .text = "l" } }));
+ r.settle();
+ for (sent.items) |m| {
+ r.confirm(try a.take(m));
+ r.settle();
+ }
+ try agrees(a, r);
+ try std.testing.expect(r.core().panes[id] == null);
+}