From 044da0f75ab5fb5be0213e512741860d95dad8e5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 11:14:38 -0300 Subject: tape: every input the core consumes recorded in turn order, replayed into replicas that must reach the same digests; the core's leaks of render, clock and host closed The recorder (src/tape.zig) is null unless PARDES_RECORD= names a tape (.tape); the local path pays a null check a call. It records a tree at the host boundary, both ways: each call the host makes into the core (`Input`: update, serveFs, pump, perform, the shell's acknowledgements and failures, a Restore, ...) with its arguments, and each call the core makes out -- a Host function (the vtable wrapped generically while recording) or a syscall of its own (`tape.site` for every old `turn.yield()`, `tape.value` for a clock or environment read) -- with its result; `done`/`ret` close each, a 9P request served while a step is out lands inside that step's syscall, and fields a host writes between calls (native_images, present_skipped, ...) are found by a diff at every crossing. After each call the host made at the top, the session's digest (src/walk.zig), one per field of the core, its stream and each pane, file and places. `PARDES_REPLAY= pardes` (main.zig) replays it with the same build into three replicas: two at different addresses (the first's memory held while the second runs) and one that never draws. A host call answers what it answered, a site returns what it returned, nothing is performed and no syscall is made; `turn.yield` panics in a replica, so a syscall no site covers is a stack trace; a call the recording did not make, or a digest that differs, is a divergence that names the fields. The headless replica steps over the presents it does not make, applying what the host told the core inside them. What the replicas found, fixed: - Render wrote core state. The view's geometry (wrap map, context rows, body layer rows) is File.geometry, a lazy cache keyed by a hash of what it is made of (revision, scroll, size, tags, tables read, context declarations, the session's view: wrap, layered context, row metrics, rect); the render makes it afresh, a step reading it makes it on demand (wrapAt, wrapRow, ensureCursorVisible). Context declarations, notice bands and the header's reveal are the step's (sync), the tables' reading the tick's (a first look of 4096 lines, a count, wherever it is asked; the rest a frame's clock budget a tick), and a view's paint-ahead is asked of the host as the frame is drawn rather than queued as an effect. - The clock: advance's wakes are the recording session's (a picture decoding or a fade adds no tick to a replica), as are the budgets of Places, Names and Tables (`tape.over`), a message's time of day (the stamp; msg_said_ms and the unattended expiry use the session clock), File.mtime, and the pump reads its clock whether or not it waits. - The host: the session directory (getcwd, asked once at init), $SHELL and its existence, $HOME for `~`, `Shell` naming one that is not there, a missing interpreter, a directory refused above, a deleted file, a pointer seen through a sliding pane (Pardes.pointerCell). - Worker handles (futures, the Io), the 9P server's state, the store file every window shares (a replica keeps its own in memory) and Recent read from it are authority-only; frames, animations and the render's caches local. Query rows' paints count apart from a view's. Terminals replay from their taped pty bytes and are digested as their active screen, cursor and scroll; kitty images are left out until phase 5's screen-state terminals. tagnav.golden: the header's caret reveal now runs every step, as a pane's does, not once per frame drawn, so after `g l B B` typed in one burst the bar stays scrolled as a human typing it sees it. Co-Authored-By: Claude Opus 5.5 --- src/Places.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Places.zig') diff --git a/src/Places.zig b/src/Places.zig index cff7c22e..3dca3adf 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -67,6 +67,10 @@ pub fn nowNs() u64 { return @as(u64, @intCast(ts.sec)) *| std.time.ns_per_s +| @as(u64, @intCast(ts.nsec)); } +/// What the replay digest leaves out (src/walk.zig): the rail's ticks, +/// made again from the places when they are drawn. +pub const replica = .{ .derived = .{ "ticks", "ticks_gen", "re" } }; + started: bool = false, provenance: Provenance = .search, /// The query pane that fed them, by serial; 0 for `*` and the register. @@ -477,7 +481,9 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi if (short) break; // A frame's time spent (a whole search's for n and N, whose steps // are mvzr's whole budget). - if (started_ns != 0 and bytes != std.math.maxInt(usize) and nowNs() - started_ns > frame_ns) break; + // The clock's verdict is the session's (src/tape.zig): a replica + // finds as many places a frame as this did. + if (started_ns != 0 and bytes != std.math.maxInt(usize) and pardes.tape.over(started_ns, frame_ns)) break; } if (set.hits.items.len != found_before) { set.gen +%= 1; -- cgit v1.3 From 470b8098a53ad3b3b0a2ef90f0d43416ea50a9b0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 15:38:35 -0300 Subject: Places: the lowered copy a smart-case search reads is zeroed where it is made: its pieces not lowered yet were whatever the heap held, in every digest and a join's dump, so two processes' places differed (H5's and H17's `places.hits|hay`) freshHay took `memory.unfilled` and lowered a piece at a time as the search reached it; the digest and the dump take the whole slice. Zeroing it costs 20 us for 1 MB, 0.4 ms for 10 MB and 10 ms for 100 MB in one frame (ReleaseFast, page faults included; lowering the same text is four times that, spread over frames), the order of the copy an edit of that text already makes. Test (failing before): two sessions searching one text, each heap handing out other bytes (rollback.Epoch.fill), digest the same places. Co-Authored-By: Claude Opus 5.5 --- src/Places.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/Places.zig') diff --git a/src/Places.zig b/src/Places.zig index 3dca3adf..818ca1d7 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -264,6 +264,14 @@ fn freshHay(set: *Places, gpa: std.mem.Allocator, f: *File.State) bool { if (set.hay.len > 0) gpa.rawFree(set.hay, .of(u8), @returnAddress()); set.hay = &.{}; set.hay = memory.unfilled(gpa, f.content.len) catch return false; + // What is not lowered yet is in the digest and a dump as well: zeros, + // the same in every process, not whatever its heap held (a replica's + // diverged). A pass over the text, as the edit that made it was. + // ponytail: 0.4 ms for 10 MB, 10 ms for 100 MB in one frame (ReleaseFast, + // page faults and all; lowering it is four times that, over frames). A + // digest and a dump of the lowered pieces alone if a huge text's first + // search ever shows. + @memset(set.hay, 0); set.low.resize(gpa, (f.content.len + chunk_bytes - 1) / chunk_bytes, false) catch return false; set.low.unsetAll(); set.hay_revision = f.revision; @@ -880,3 +888,27 @@ test "zz stress analysis cost" { std.testing.allocator.free(a.colors); std.debug.print("decls {d} us ({d}), analysis with colours {d} us\n", .{ (t1 - t0) / 1000, d.len, (t2 - t1) / 1000 }); } + +test "a lowered copy's pieces not searched yet are the same in every process: a digest and a dump take them" { + // Two sessions searching one text, each heap handing out other bytes in + // what is not written yet (rollback.Epoch.fill): their places agree. + const rollback = @import("rollback.zig"); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (0..2000) |i| try text.print(std.testing.allocator, "line {d} of a text in four pieces\n", .{i}); + var digests: [2]u64 = undefined; + for (&digests, [_]u8{ 0x11, 0x5a }) |*d, b| { + var e: rollback.Epoch = .{ .child = std.testing.allocator }; + defer e.deinit(); + rollback.Epoch.fill = b; + defer rollback.Epoch.fill = null; + const p = try Pardes.init(e.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile(text.items); + // The view's piece found now, the rest a frame at a time after. + pane.places.search(p, pane, .typed, 0, "piece", false, null, false); + try std.testing.expect(!pane.places.complete() and pane.places.fold); + d.* = pardes.walk.digest(Places, &pane.places); + } + try std.testing.expectEqual(digests[0], digests[1]); +} -- cgit v1.3 From 782b1ef2e40b83e115c460f55e31c5c6bde2b62f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 18:11:57 -0300 Subject: Places: its regex made again from its pattern when a set holds none: `re` is derived (in no dump and no rollback copy), so a client that joined took a loaded search for a list's and found nothing an edit made, and diverged at the next edit, again at every rejoin (the soak's local207 cell: pane 3.places.hits, and pane 17.cwd, which inherits pane 2's and hashes it whole); a test loads a session's dump and makes the same edit in both Co-Authored-By: Claude Opus 5.5 --- src/Places.zig | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'src/Places.zig') diff --git a/src/Places.zig b/src/Places.zig index 818ca1d7..a60a0d65 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -182,6 +182,7 @@ pub fn firstFrom(hits: []const Hit, at: usize) usize { pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, from: u32, pattern: []const u8, literal: bool, seek: ?usize, moves: bool) void { const f = if (pane.file) |*file| file else return; const gpa = p.gpa; + set.derive(gpa); // The same question again (a key that left the pattern as it was): // the places stand, the current one too. if (set.started and set.re != null and set.literal == literal and std.mem.eql(u8, set.pattern, pattern)) { @@ -198,14 +199,12 @@ pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, fro if (std.ascii.isUpper(c)) break false; } else true; set.literal = literal; - const arena = p.scratch.allocator(); - const folded = if (set.fold) std.ascii.allocLowerString(arena, pattern) catch return else pattern; - set.re = if (literal) null else normal.SearchRegex.compile(gpa, folded) catch null; + set.derive(gpa); if (set.re == null) { + // It does not compile: the characters it is. set.literal = true; - var escaped: std.ArrayList(u8) = .empty; - normal.appendSearchLiteral(&escaped, arena, folded) catch return; - set.re = normal.SearchRegex.compile(gpa, escaped.items) catch return; + set.derive(gpa); + if (set.re == null) return; } set.started = true; set.revision = f.revision +% 1; // `fill` starts it over for the text as it is @@ -215,6 +214,25 @@ pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, fro set.fill(p, pane, 0, frame_steps); } +/// `re` made from the pattern: derived (Places.replica), so neither a dump +/// nor a rollback copy holds it, and a set loaded with a pattern and none +/// was a list's to `fill` (a client that joined found no places an edit +/// made, 2026-10-30). A list's places have no pattern. +fn derive(set: *Places, gpa: std.mem.Allocator) void { + if (set.re != null or set.pattern.len == 0) return; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + const folded = if (set.fold) std.ascii.allocLowerString(a, set.pattern) catch return else set.pattern; + if (!set.literal) { + set.re = normal.SearchRegex.compile(gpa, folded) catch null; + return; + } + var escaped: std.ArrayList(u8) = .empty; + normal.appendSearchLiteral(&escaped, a, folded) catch return; + set.re = normal.SearchRegex.compile(gpa, escaped.items) catch null; +} + /// A list's places in this text, as it gives them (sorted here), in place /// of whatever fed them before: a language server's references, say. /// `current`: the one at or after this offset is current. @@ -397,6 +415,7 @@ fn restart(set: *Places, p: *Pardes, f: *File.State) void { pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) void { const started_ns = nowNs(); if (!set.started) return; + set.derive(p.gpa); const f = if (pane.file) |*file| file else return set.clear(p.gpa); const gpa = p.gpa; if (f.revision != set.revision or f.content.len != set.len) { @@ -912,3 +931,28 @@ test "a lowered copy's pieces not searched yet are the same in every process: a } try std.testing.expectEqual(digests[0], digests[1]); } + +test "a session's places loaded from its dump find what an edit makes as the session's do" { + // A client's core is the session's dump; `re` is derived, in no dump: + // made again from the pattern, else the loaded set took itself for a + // list's and found nothing an edit made (a soak's rejoin loop). + const gpa = std.testing.allocator; + const a = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer a.deinit(); + const pane = try a.setTestFile("alpha beta\ngamma alpha\n"); + typeKeys(a, "e*"); + try std.testing.expectEqual(@as(usize, 2), pane.places.hits.items.len); + const bytes = try pardes.dump.dumpBytes(a); + defer gpa.free(bytes); + const b = try pardes.dump.load(gpa, a.opts, bytes, null); + defer b.deinit(); + try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b)); + for ([_]*Pardes{ a, b }) |p| { + const pn = p.panes[p.active].?; + const new = try gpa.dupe(u8, "alpha beta\ngamma alpha alpha\n"); + File.setContentSpan(p, &pn.file.?, new, null); + pn.places.fill(p, pn, 0, frame_steps); + try std.testing.expectEqual(@as(usize, 3), pn.places.hits.items.len); + } + try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b)); +} -- cgit v1.3