From 30c6341ea868fc22deca16a5fb51fc19828cc2dc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 22:06:32 -0300 Subject: test/replicas: --bytes, the soak's clients as replicas of the bytes kind (each terminal fed the pty's bytes its units carry): a client dialling 100 ms into the flood, and at the shell session's end DA, DSR, CSI 16 t, a kitty query (answered on the session's pty once whatever the clients), an image by direct data shown and one by a file stored (a=t; shown, it moves the session's cursor and not a client's: a divergence until the file is taped); a join's cost and the reloads printed; --clients 5 --bytes --seeds 8 at 30/80/207 ms: diverged 0, unequal 0, quiet checks 1691/0 1303/0 1797/0, stops off may_wait 0, corpus 22 of 22, no leak, 2,168-2,321 reloads a run at 24-35 ms each (Debug), a join's step median 75 ms, dumps median 904 KB; the screen-state run beside it: diverged 0, unequal 0, deltas 1916/0 2028/0 1812/0, quiet 618/0 835/0 771/0 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/replicas.zig | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/replicas.zig b/test/replicas.zig index 910c6e57..70edea75 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -53,6 +53,10 @@ const gpa = std.heap.c_allocator; pub const std_options: std.Options = .{ .log_level = .warn }; extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; var trace = false; +/// `--bytes`: its clients are replicas of the bytes kind, each terminal fed +/// the pty's bytes its units carry into an emulator of its own, joined from +/// a dump with every emulator whole (core/replica.zig `Peers.bytes`). +var bytes_kind = false; /// The PDF the soak opens (`--pdf`), absolute. var pdf_path: ?[]const u8 = null; const frame_us = 16_667; @@ -791,6 +795,9 @@ const Soak = struct { /// encoding cost. framed: bool = false, encode_ns: u64 = 0, + /// The session's pty told the answer to the program's kitty query + /// (`questions`): once, whatever the clients. + kitty_answers: u32 = 0, /// A Peer's queue, swapped out as its writer swaps it (the Peers' /// allocator's). sending: std.ArrayListUnmanaged(u8) = .empty, @@ -809,6 +816,9 @@ const Soak = struct { fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { const pane = id.index(); const s = of(ctx); + // Only the session's emulator answers its program: a client's + // answers are its tape's, never written (`questions`). + if (std.mem.indexOf(u8, bytes, "\x1b_Gi=31;OK") != null) s.kitty_answers += 1; s.echo.append(gpa, .{ .pane = pane, .bytes = gpa.dupe(u8, bytes) catch return }) catch {}; } @@ -873,6 +883,7 @@ const Soak = struct { pub fn open(s: *Soak, l: *SessionLoop) !pardes.Host { s.l = l; l.peers.threads = false; + l.peers.bytes = bytes_kind; l.peers.flushed = .{ .ctx = s, .f = flushed }; const host: pardes.Host = .{ .ctx = s, .vtable = &vtable }; l.core.host = host; @@ -941,6 +952,9 @@ const Soak = struct { const at: u64 = switch (c) { 0, 1 => s.random.uintLessThan(u64, 100_000), 2 => 1_200_000, + // One joins in the middle of the flood, its emulators loaded + // whole and every other side's reloaded. + 3 => if (bytes_kind) flood_at + 100_000 else 2_300_000, else => 2_000_000 + c * 100_000, }; try net.send(.{ .at = at, .n = 0, .kind = .dial, .who = @intCast(c + 1), .bytes = &.{} }); @@ -1412,6 +1426,11 @@ const Soak = struct { } const rp = try replica.Replica.initDump(gpa, cl.id, cl.view, m.bytes, .{ .cols = cl.cols, .rows = cl.rows, .distrusted = &cl.distrusted }); cl.r = rp; + // Its terminals its own emulators, fed what the units carry. + if (bytes_kind) { + rp.t.screen_state = false; + rp.core().echo = null; + } rp.stats.samples = true; rp.t.local_files = true; rp.echo.now = m.at * 1000; @@ -1449,6 +1468,11 @@ const Soak = struct { totals.flood_us += s.flood_end -| flood_at; for (s.flood_deltas[0..s.clients.len]) |d| totals.flood_deltas += d; const want = pardes.tape.digestOf(core); + if (bytes_kind) std.debug.print("seed {d} rtt {d} ms: a join's step at worst {d} us (the session's reloads and its dump), the last dump {d} KB ({d} KB of state)\n", .{ s.r.seed, s.r.rtt_ms, s.l.peers.join_ns / 1000, s.l.peers.dump_bytes >> 10, s.l.peers.state_bytes >> 10 }); + if (bytes_kind and s.kitty_answers != 1) { + totals.unequal += 1; + std.debug.print("seed {d} rtt {d} ms: the program's kitty query was answered {d} times on the session's pty\n", .{ s.r.seed, s.r.rtt_ms, s.kitty_answers }); + } for (s.clients, 1..) |*cl, id| { totals.resizes += cl.resizes; totals.wakes += cl.wakes; @@ -1560,7 +1584,11 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { // flood of `yes`, read 4 KB at a time as a pty gives it. const tui = try screen_state.tuiStream(gpa); defer gpa.free(tui); - const shell_session = try screen_state.shellStream(gpa); + const session_only = try screen_state.shellStream(gpa); + defer gpa.free(session_only); + const asked = if (bytes_kind) try questions(dir) else ""; + defer if (bytes_kind) gpa.free(asked); + const shell_session = try std.mem.concat(gpa, u8, &.{ session_only, asked }); defer gpa.free(shell_session); const yes = try screen_state.yesStream(gpa, @intCast(r.flood_mb * (1 << 20) / 3)); defer gpa.free(yes); @@ -1584,6 +1612,23 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { if (soak.err) |err| return err; } +/// What the shell's program asks its terminal at the end of its session +/// (`--bytes`): device attributes, the cursor's place, the cell's size in +/// pixels, a kitty query; then a kitty image by direct data, shown, and one +/// by a file of the session's machine, stored (a=t), which no client loads +/// (P32): absent there, as every live terminal's image is under screen +/// state. Shown (a=T) it would move the session's cursor past it and not a +/// client's: a divergence until the file's bytes are taped (a later step). +fn questions(dir: []const u8) ![]u8 { + var path_buf: [300]u8 = undefined; + const path = try std.fmt.bufPrintSentinel(&path_buf, "{s}/pixels.rgb", .{dir}, 0); + try writeText(path, &@as([12]u8, @splat(0x7f))); + var b64: [400]u8 = undefined; + const name = std.base64.standard.Encoder.encode(&b64, path); + return std.fmt.allocPrint(gpa, "\x1b[c\x1b[6n\x1b[16t\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\r\n" ++ + "\x1b_Ga=T,i=5,f=24,s=2,v=2;AAAAAAAAAAAAAAAA\x1b\\\r\n\x1b_Ga=t,i=6,t=f,f=24,s=2,v=2;{s}\x1b\\\r\n$ ", .{name}); +} + /// A typist: keys 50-200 ms apart, a pause now and then. fn typistGap(random: std.Random) u64 { return if (random.uintLessThan(u8, 12) == 0) random.intRangeAtMost(u64, 300_000, 1_500_000) else random.intRangeAtMost(u64, 50_000, 200_000); @@ -2722,6 +2767,10 @@ pub fn main(init: std.process.Init) !void { echo_mode = true; continue; } + if (std.mem.eql(u8, name, "--bytes")) { + bytes_kind = true; + continue; + } if (i + 1 >= args.len) return error.MissingValue; i += 1; const value = args[i]; @@ -2787,7 +2836,9 @@ pub fn main(init: std.process.Init) !void { defer stop_lines.deinit(gpa); for (rtts) |rtt| { var t: Totals = .{}; + pardes.Term.reloads = .{}; for (first..first + seeds) |seed| try run(init, .{ .seed = seed, .rtt_ms = rtt, .steps = steps, .clients = clients, .flood_mb = flood_mb }, dir, &t); + if (bytes_kind) std.debug.print("rtt {d}: {d} reloads of a terminal at joins, every side (the session's own too), {d} us each, {d} us at worst\n", .{ rtt, pardes.Term.reloads.n, pardes.Term.reloads.ns / @max(1, pardes.Term.reloads.n) / 1000, pardes.Term.reloads.worst_ns / 1000 }); const rollbacks = t.mispredicted + t.foreign; std.debug.print("{d:>4} {d:>6} {d:>7} {d:>7} {d:>6} {d:>6} {d:>6} ({d}+{d}) {d:>5.1}% {d:>6} {d:>5}/{d:<6} {d:>5}/{d:<5} ({d}) {d:>7}/{d:<7} {d:>8} {d:>7}\n", .{ rtt, t.inputs, t.speculated, -- cgit v1.3