summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 22:59:15 -0300
committerGabriel Schneider <[email protected]>2026-11-20 22:59:15 -0300
commitbf01716960a928b533c99ec9b373e35456ef18ba (patch)
tree09d74ec81e1662c3d20ff399c1f0042cceb9a108 /core/replica.zig
parent4e1432049765be6e793a3834c93c4cd5318e82bc (diff)
parent1ae6addf4590d3b9c1070f6546c29e807d272491 (diff)
downloadpardes-bf01716960a928b533c99ec9b373e35456ef18ba.tar.gz
pardes-bf01716960a928b533c99ec9b373e35456ef18ba.zip
integration: the client's double free fixed, on the typed slot fields: pardes-client-abort (a 9P open record past fs.opens_len is nothing: never read or freed: a replica client's rollback left one with freed pointers and the open's replay freed them again: a client typing while a script held a pty/run aborted with a corrupted heap, since pardes-merge40; the rollback copy walks every type that declares replica: it skipped fs.Namespace and a pane's 9P state) and pardes-merge43; no conflict; gated whole against sketchbook's main (reorg/merge44): tui core-test 875/1033 (158 skipped), shell-test 1075/1078, addon-test 5/5, term-test 17/17, kitty-test 45/45, pane-test 183/184, behaviour-test 275/275 and with --replay, process-test 0 of 145 failed, consumer-test passes; both soaks (--clients 5 and --bytes) diverged 0, unequal 0, unlisted stops 0, corpus through a client 22 scenes the same; daemon.py plain, far, games, window-clients, clients five times, relink, launch, pair, gui; macos (linux and aarch64) and freebsd build; frames 77/77 against tree2, perfab-corpus2x +0.012%, 121 per-operation counts within 0.1% (largest client-key-down +0.075%), gui unit-test 1671/1675 (no failure the base has not)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig105
1 files changed, 105 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index de58da94..e2ecc796 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -7050,6 +7050,111 @@ test "a client of screen-state terminals takes a 9P pty/run in a shell as the se
try agrees(a, late);
}
+// daemon.py --clients' client C (2026-11-20): idle, a copy taken ahead; the
+// session's script opens pty/run and its command prints, replayed over the
+// copy and kept; the client types into the shell, its speculation stops at
+// the pty write, and the rollback replays the open again over a record the
+// copy never held (it holds the opens as far as `opens_len`), whose line
+// and output the epoch had freed: freed again there, the client's C heap
+// was corrupt.
+test "a 9P open the session made over a copy taken ahead, replayed after a rollback: the record past the opens the copy holds is written over, never freed again" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const RunHost = struct {
+ fn taken(_: ?*anyopaque, _: pardes.Pane.Id) bool {
+ return false;
+ }
+ fn write(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .tty_taken = taken, .pty_write = write };
+ };
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &RunHost.vtable }, true);
+ defer a.deinit();
+ var screens: Screens = .init(gpa);
+ defer screens.deinit(a.core);
+ const peer = try screens.addPeer();
+ 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;
+ const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = prompt } });
+ r.confirm((try a.pending()).?);
+ try deliver(a, &screens, peer, r, .flush);
+ r.ready();
+ try std.testing.expect(r.copy.held and r.core().fs.opens_len == 0);
+ const node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_run);
+ const Serve = struct {
+ fn serve(s: *Authority, x: *Replica, req: pardes.ctlfs.Req) !pardes.ctlfs.Reply {
+ const was = Stepping.begin(&s.t, null);
+ const reply = s.core.serveFs(req);
+ s.core.pump(s.host) catch {};
+ was.end();
+ s.seq += 1;
+ const u = try std.testing.allocator.dupe(u8, try s.unit(0, s.seq));
+ defer std.testing.allocator.free(u);
+ x.confirm(u);
+ x.settle();
+ return reply;
+ }
+ };
+ const h = (try Serve.serve(a, r, .{ .tag = 1, .op = .open, .node = node, .omode = 2 })).handle;
+ _ = try Serve.serve(a, r, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "echo x\n" });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "echo x\r\n\x1b]133;C;aid=pardes\x07x\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt } });
+ r.confirm((try a.pending()).?);
+ r.settle();
+ // Kept over the copy: the record past its opens holds the run's output.
+ try std.testing.expect(r.copy.held and r.since.items.len > 0);
+ try std.testing.expectEqualStrings("x\n", r.core().fs.opens[h - 1].what.run.output);
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| gpa.free(m);
+ sent.deinit(gpa);
+ }
+ // A key into the shell: its speculation stops at the pty write, and
+ // the copy is put back, the units since replayed (the open again).
+ try key(r, 'e', &sent);
+ try std.testing.expect(r.applied == 0 and r.stats.stopped > 0);
+ r.confirm(try a.take(sent.items[0]));
+ r.settle();
+ try deliver(a, &screens, peer, r, .flush);
+ _ = try Serve.serve(a, r, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
+ if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why});
+ try std.testing.expect(r.diverged == null and r.quiet());
+ try agrees(a, r);
+}
+
+test "a script's half line held over a copy taken ahead, its next write run and its rest moved to the front in place, put back by a rollback: the line replayed is the session's" {
+ var n = try NinepJoin.init("one\n", TestHost.host());
+ defer n.deinit();
+ try n.join();
+ const r = n.late.?;
+ const exec = n.node(.exec);
+ const h = (try n.serve(.{ .tag = 1, .op = .open, .node = exec, .omode = 1 }, true)).handle;
+ _ = try n.serve(.{ .tag = 2, .op = .write, .node = exec, .handle = h, .data = "Ta" }, true);
+ r.ready();
+ // Replayed over the copy and kept: `Tab 8` runs, `Un` is held where
+ // `Ta` was, in the buffer the copy holds.
+ _ = try n.serve(.{ .tag = 3, .op = .write, .node = exec, .handle = h, .data = "b 8\nUn" }, true);
+ try std.testing.expect(r.copy.held and r.since.items.len > 0);
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| std.testing.allocator.free(m);
+ sent.deinit(std.testing.allocator);
+ }
+ try key(r, 'l', &sent);
+ try std.testing.expectEqual(@as(usize, 1), r.applied);
+ // The session's key first: a rollback, the write replayed again.
+ try n.send(try n.a.local(.{ .key = .{ .cp = 'j', .text = "j" } }));
+ try std.testing.expect(r.stats.foreign > 0);
+ try n.send(try n.a.take(sent.items[0]));
+ _ = try n.serve(.{ .tag = 4, .op = .write, .node = exec, .handle = h, .data = "do\n" }, true);
+ _ = try n.serve(.{ .tag = 5, .op = .release, .node = exec, .handle = h, .opened = true }, true);
+ if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why});
+ try std.testing.expect(r.diverged == null and r.quiet());
+ try n.agree();
+}
+
// Del with a pane above and below asks which way the space goes, its
// question shown once a delay is up (builtins.zig): its time was the
// host's clock read in the step, an answering entry a speculation stops at.