summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 03:43:49 -0300
committerGabriel Schneider <[email protected]>2026-11-20 11:16:32 -0300
commit23de206007ebae87007460afa993338781a03076 (patch)
tree683ccf2e6e0ac34ba1f1f3eb85a96f734cdb2eae /core/replica.zig
parentb58e9b3123aaa72dff67631e7f5c0b5a55b64075 (diff)
downloadpardes-23de206007ebae87007460afa993338781a03076.tar.gz
pardes-23de206007ebae87007460afa993338781a03076.zip
term: a join reloads only the terminals written since their last reload (step 3's way 1): `Term.State.written` (a feed, a reflow, a load, a revive; cleared by a reload), the session's choice taped before each terminal's hash at the `reload` site (`tape.value`), each replica reloading exactly those and comparing each hash as before; exact: one written by nothing since holds the pages its last reload's snapshot loads to on every side, and the joiner loads that snapshot again; FIRST the test (two terminals, both reloaded at a join, the shell alone written since: the next join reloads it alone on the session (1, the base 2) and on the replica, then 40,000 lines into both until each prunes its history: the replica and the joiner hold the session's snapshot bytes and digest, and a join after agrees); ReleaseFast, bytes, 2 seeds at 80 ms (load 8-18): the flooding shell alone, a join's unit on a client already there 9.9 ms p50, 13.6 ms at worst, the session's join step 1.4/14.8 ms (step 3's report: 9.6/17.7 and 1.4/14.3); with four idle shells each a full scrollback beside it (the soak patched for the measure, not landed): reloads 2,910 -> 659, the client's join unit 58.7 -> 20.3 ms p50 and 219 -> 122 ms at worst, the session's step 86.0 -> 38.2 ms p50 and 211 -> 106 at worst (the first join still reloads all); the soak, bytes, `--clients 5 --bytes --seeds 8` at 30/80/207 ms with the `cat` whole (Debug, load 25-44): 2 of 4 whole runs clean (diverged 0, unequal 0, quiet checks agreed, unlisted 0, corpus 22 of 22, no leak); in the other two, seed 2 at 80 ms (two clients at one session unit) and seed 0 at 30 ms (one client): OPEN, not root-caused (reports/pardes-term-join.md), never under a probe; seed 0 at 30 ms, 19 of 20 clean, one run hung spinning (killed, no trace); on the base seed 0 at 30 ms diverged every time and 9 of 24 runs; tui core-test 859/1011 (152 skipped), shell-test 1047/1050
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.zig68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index b4d8edfa..6dcc0281 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4480,6 +4480,74 @@ test "bytes: a join refused for want of a view reloads every terminal and moves
try sameTerminals(b.a, b.r);
}
+test "bytes: a join reloads only the terminals written since their last reload: one idle since the last join is reloaded on no side, and through a prune of both every side holds the session's terminals, the joiner too" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const b = try BytesPair.init();
+ defer b.deinit();
+ b.r.confirm(try b.a.local(.{ .command = "Term" }));
+ b.r.settle();
+ const second: pardes.Pane.Id = for (b.a.core.panes, 0..) |slot, id| {
+ if (id != b.shell.index() and (slot orelse continue).terminal != null) break .at(id);
+ } else return error.NoTerminal;
+ const both = [_]pardes.Pane.Id{ b.shell, second };
+ // Both written, and a join reloads both.
+ for (both) |id| b.a.output(.{ .output = .{ .pane = id, .bytes = "written\r\n" } });
+ b.r.confirm((try b.a.pending()).?);
+ const first = (try b.a.join(2, null)).?;
+ gpa.free(first.dump);
+ b.r.confirm(first.unit);
+ // The shell alone written since: the next join reloads it alone, on
+ // every side; the joiner loads the other's snapshot as it was.
+ try b.output("the shell's\r\n");
+ const before = pardes.Term.reloads.n;
+ const joined = (try b.a.join(3, null)).?;
+ defer gpa.free(joined.dump);
+ try std.testing.expectEqual(1, pardes.Term.reloads.n - before);
+ b.r.confirm(joined.unit);
+ try std.testing.expectEqual(2, pardes.Term.reloads.n - before);
+ const late = try Replica.initDump(gpa, 3, joined.view, joined.dump, .{ .cols = 80, .rows = 24 });
+ defer late.deinit();
+ late.t.screen_state = false;
+ late.core().echo = null;
+ try std.testing.expectEqual(joined.digest, late.digest());
+ // Output into both until each has pruned its history (whole pages, by
+ // the history of its pages), a unit every few reads.
+ var read: std.ArrayListUnmanaged(u8) = .empty;
+ defer read.deinit(gpa);
+ const lines = 40_000;
+ var n: usize = 0;
+ while (n < lines) : (n += 100) {
+ read.clearRetainingCapacity();
+ for (n..n + 100) |i| try read.print(gpa, "\x1b[3{d}m{d}\x1b[0m line\r\n", .{ i % 8, i });
+ for (both) |id| b.a.output(.{ .output = .{ .pane = id, .bytes = read.items } });
+ if (n % 2000 == 1900) {
+ const u = (try b.a.pending()).?;
+ b.r.confirm(u);
+ late.confirm(u);
+ }
+ }
+ if (try b.a.pending()) |u| {
+ b.r.confirm(u);
+ late.confirm(u);
+ }
+ for (both) |id| try std.testing.expect(pardes.Term.grid(b.a.core.panes[id.index()].?.terminal).total < lines);
+ try agrees(b.a, b.r);
+ try sameTerminals(b.a, b.r);
+ try agrees(b.a, late);
+ try sameTerminals(b.a, late);
+ // And a join after: both written, both reloaded, every hash compared.
+ const left = try b.a.leave(2, false);
+ b.r.confirm(left);
+ late.confirm(left);
+ const third = (try b.a.join(4, null)).?;
+ gpa.free(third.dump);
+ b.r.confirm(third.unit);
+ late.confirm(third.unit);
+ try agrees(b.a, b.r);
+ try agrees(b.a, late);
+}
+
test "bytes: a session's output past a unit's bound is cut into units under it, between two reads" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;