diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 23:13:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 23:25:20 -0300 |
| commit | 1ae5ae5e9201a6a942628ca57a6339bc90372317 (patch) | |
| tree | 2237127f212157bf36d444f8e0594486d237bd3c /core/replica.zig | |
| parent | 18e674964e5db67d35e1cf5ded128757ced22a98 (diff) | |
| download | pardes-1ae5ae5e9201a6a942628ca57a6339bc90372317.tar.gz pardes-1ae5ae5e9201a6a942628ca57a6339bc90372317.zip | |
tests: what a rollback puts back of the memory the core points to, and a read of a terminal kept on the fast path (pardes-term-join-12, items 1 and 2): round 11's gate aborted in its second soak ("double free or corruption (!prev)", seed 0 at 80 ms, not reproduced alone, 1 of 3 soaks), and its core, kept by systemd-coredump, says where: a client's core at its end (`Replica.deinit` <- `Soak.close`) freeing a jj `Ask` from `jj.Session.deinit`, freed before: not the rows cache round 11 suspected; the class: `jj.Session` (`Pardes.changes`) hashes itself and has no `replica` annotation, so the rollback copy never walked it (rollback.zig `unwalked`): it saved the session's bytes in the core and nothing they point to, and a write in place into that heap (jj.zig `edited` splices every pinned `Changes.lines` and `Heat.lines` at every edit of the file) stays through a put-back that frees what the speculation made; core/jj.zig "a client's own line opened over pinned changes, rolled back by the session's key first ...": a client's `o` in a file with `Changes ::@` pinned, the session's own key first, the `o` applied again: on `trmpwtso` it aborts (a use of the freed lanes, paintLanes index 926155716 of 6), and with a DebugAllocator as the epoch's child (a local diagnostic, never committed) both frees are named: allocated at jj.spliceValues under the client's speculation, freed at rollback.Epoch.discard when the copy is put back, freed again at jj.spliceValues as the `o` is applied again over the answers buffer that still holds what the put-back freed; core/replica.zig "bytes: a terminal's rows read before an idle client's copy are the copy's ...": rows read between steps (a draw's), the copy taken idle (`ready`), a key of the client's on top and the session's first: on `trmpwtso` the rows are dropped (`toConfirmed`'s `shell_rows = .{}`) and left in the epoch until the client ends, a grid's worth of text at every such rollback; core/replica.zig "bytes: a client's key that reads a terminal's rows, the session's output before it in the session's order ...": a `G` over a shell's rows, the program's output first: the output rolls it back (its count moved: never a neutral unit), the `G` is read again over the fed rows and kept on the fast path with the session's cursor: passes on `trmpwtso` (item 2's question: on the one road a kept speculation's read of an emulator is never stale, so "this input read an emulator" needs no fact of its own); shell-test filtered: 11/12 (the jj test's abort), 11/12 (the rows test: expected the cache's address, found it dropped), 12/12
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.zig | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 0ae302e8..936eb3e4 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -4012,6 +4012,68 @@ test "the count of writes outside the copy is digested: a session's emulator wri try std.testing.expectEqualStrings("outside ", try partsApart(b.a, b.r, arena.allocator())); } +test "bytes: a terminal's rows read before an idle client's copy are the copy's: a rollback puts them back, neither dropped nor freed twice" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const b = try BytesPair.init(); + defer b.deinit(); + try b.output("a line of the program's\r\nand another\r\n"); + // Its rows read between steps (a draw's), then the copy taken while it + // idles (`ready`): the rows are what the core holds at the copy. + const pane = b.r.core().panes[b.shell.index()].?; + _ = try pardes.edit.shellRows(b.r.core(), pane); + const cached = b.r.core().shell_rows.text_alloc.ptr; + b.r.ready(); + try std.testing.expect(b.r.copy.held); + // A key of the client's on top, the session's own key first: the copy + // put back, the rows with it (not left orphaned in the epoch). + try b.rollback(); + try std.testing.expectEqual(cached, b.r.core().shell_rows.text_alloc.ptr); + try agrees(b.a, b.r); + try b.output("after\r\n"); + _ = try pardes.edit.shellRows(b.r.core(), pane); + try agrees(b.a, b.r); +} + +test "bytes: a client's key that reads a terminal's rows, the session's output before it in the session's order: the output rolls it back, its read is made again over the fed rows, and the input is kept on the fast path with the session's reading" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const b = try BytesPair.init(); + defer b.deinit(); + try b.output("l1\r\nl2\r\nl3\r\n"); + // The shell's pane focused and out of its tty mode (^B): a cursor over + // its rows. + const id = b.shell.index(); + const rect = b.a.core.view().rects[id]; + for ([_]pardes.Event{ + .{ .mouse = .{ .button = .left, .kind = .press, .col = rect.x + 2, .row = rect.y + 1 } }, + .{ .mouse = .{ .button = .left, .kind = .release, .col = rect.x + 2, .row = rect.y + 1 } }, + .{ .key = .{ .cp = 'b', .ctrl = true } }, + }) |ev| { + b.r.confirm(try b.a.own(ev)); + b.r.settle(); + } + try agrees(b.a, b.r); + // G: to the last of its rows, which it reads (edit.shellRows). + const last = try gpa.dupe(u8, try b.r.input(.{ .key = .{ .cp = 'G', .text = "G" } })); + defer gpa.free(last); + try std.testing.expectEqual(@as(usize, 1), b.r.applied); + const read_before = b.r.core().panes[id].?.body.cur_row; + // The program prints two lines before the session takes the G: the + // emulator fed (its count moved, so never a neutral unit), the G + // undone and read again over the rows as fed. + b.a.output(.{ .output = .{ .pane = b.shell, .bytes = "l4\r\nl5\r\n" } }); + b.r.confirm((try b.a.pending()).?); + b.r.settle(); + try std.testing.expectEqual(@as(usize, 1), b.r.applied); + try std.testing.expect(b.r.core().panes[id].?.body.cur_row > read_before); + const fast = b.r.stats.fast; + b.r.confirm(try b.a.take(last)); + b.r.settle(); + try std.testing.expectEqual(fast + 1, b.r.stats.fast); + try agrees(b.a, b.r); + try std.testing.expectEqual(b.a.core.panes[id].?.body.cur_row, b.r.core().panes[id].?.body.cur_row); +} + test "bytes: what a terminal's emulator gains while a copy is held is its own: a rollback frees none of it" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const b = try BytesPair.init(); |
