diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 21:02:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 00:01:23 -0300 |
| commit | 26acd94bc20b70fe924ad76dee9c2ddaa1f4011f (patch) | |
| tree | f409d889fb3b3d0a202e4fac217b8c787ae33d42 /core | |
| parent | 987210dbff8b830203cf5f52fa0cfc9b2974a3a2 (diff) | |
| download | pardes-26acd94bc20b70fe924ad76dee9c2ddaa1f4011f.tar.gz pardes-26acd94bc20b70fe924ad76dee9c2ddaa1f4011f.zip | |
far client: a test that a click into a shell whose output queue is backed up cannot leave a client unlike its session, and why (no fix: the fault does not happen): Core.reportFocus skips the focus write in a client's speculation, and on the session the write parks behind what is already parked for the pane (`pending_write`, digested), so a client confirmed on the fast path would lack those bytes; but bytes are parked between steps only by a step that does not drain the queue (a 9P write, serveFs, past the 4096 effects the ring holds: every pump drains it whole), that step reaches the client as the session's unit, so the client holds the same queue, and its own step settles as the session's does (replica.speculate: update, then step, which drains it): the parked write into the shell stops it at `pty_write`, and it waits for the session's step, focus report and all; the test `a far client's click into a shell whose queue is backed up: ...` (end of core/replica.zig, shell-test: a 9P write of 1 MiB + 100 bytes into the shell, then the client's click) passes on the base: the click stops at pty_write alone, the program gets the parked bytes then ESC [ I, mispredicted 0, the client's digest the session's; gates on the seven together (the stack's top, load 18 to 50 beside them): tui core-test 855/999 (144 skipped), shell-test 1035/1038, pane-test 183/184, term-test 15/15, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test 3 of 144 (lspcomplete and lspcompletemoved, the base's, and headersweep-restored, which passes alone), gui unit-test 1633/1637 with the base's BaselineHarnessMismatch; replicas --clients 5 and --seeds 8: diverged 0, unequal 0, deltas wrong 0, quiet checks differed 0, unlisted stops 0, corpus 22 of 22, no leak report; the walk over every word and key passes; frame and perf gate against tree1 (farfaults): frames 77/77 byte-identical in Debug, unit-test 1633/1637, perfab corpus2x -0.087% (noise 0.092%, bar 0.4%, pictures identical), perfops 97 counts within 0.1% (largest +0.0329%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/replica.zig | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 42aae524..342913ba 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6079,3 +6079,83 @@ test "a far client's frame drawn under a speculation that rolls back asks a pict r.settle(); try agrees(a, r); } + +// A program that asked for focus events is told of a click into its shell +// by the session's step (Core.reportFocus): a client's own step writes +// nothing. Where the shell's queue is backed up (a 9P write past what the +// effects ring holds, parked until the session's next pump), the session's +// report parks behind it, into `pending_write`, which is digested, where +// the client's speculation skips the write. It cannot differ: a client's +// step settles as the session's does, draining the queue, and what is +// parked is a write into the shell, which stops it (the client holds the +// same queue: the unit that parked it is the session's, which it replays). +test "a far client's click into a shell whose queue is backed up: the session's focus report queues behind what is parked, and the client ends as the session does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const Told = struct { + var bytes: usize = 0; + var tail: [3]u8 = @splat(0); + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { + bytes += b.len; + if (b.len >= 3) @memcpy(&tail, b[b.len - 3 ..]); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; + }; + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + defer a.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.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); + _ = (try a.pending()).?; + _ = try a.local(.{ .command = "New" }); + var screens: Screens = .init(gpa); + defer screens.deinit(a.core); + const peer = try screens.addPeer(); + const r = try joinedFresh(a); + defer r.deinit(); + try deliver(a, &screens, peer, r, .flush); + r.settle(); + // A 9P write into the shell, past the ring: the rest parked, on both. + const big = try gpa.alloc(u8, pardes.memory.limits.effect_cap * pardes.effect_write_cap + 100); + defer gpa.free(big); + @memset(big, 'x'); + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + _ = a.core.serveFs(.{ .tag = 1, .op = .write, .node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_data), .data = big }); + } + a.seq += 1; + r.confirm(try a.unit(0, a.seq)); + r.settle(); + try std.testing.expect(a.core.pending_write[shell] != null and r.core().pending_write[shell] != null); + Told.bytes = 0; + const rect = r.core().view().rects[shell]; + const row = rect.y + r.core().panes[shell].?.tag_rows + 1; + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + r.stats.stops = @splat(.{}); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + 2, .row = row } }))); + // The client's own step drains the queue it holds as the session's + // does: what is parked is a write into the shell, so it stops there, + // and waits for the session's step, focus report and all. + try std.testing.expectEqual(@as(usize, 0), r.applied); + for (r.stats.stops) |st| if (st.n > 0) try std.testing.expectEqualStrings("pty_write", st.name); + for (sent.items) |m| { + try deliver(a, &screens, peer, r, .flush); + const u = try gpa.dupe(u8, try a.take(m)); + defer gpa.free(u); + try deliver(a, &screens, peer, r, .fill); + r.confirm(u); + r.settle(); + } + // The program had what was parked, then the focus. + try std.testing.expectEqual(big.len + 3, Told.bytes); + try std.testing.expectEqualStrings("\x1b[I", &Told.tail); + try std.testing.expectEqual(@as(usize, shell), r.core().view().active); + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try agrees(a, r); +} |
