From aa3ff349f840f568ea0f052c1f051cdc0dbb18c1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 09:16:28 -0300 Subject: Kind, dump, replica: a plain kind's state opened or closed in a pane that stays (a picker's preview of a PDF, Pick.showKind; a file changed under its pane; an addon reloaded) is a write outside a client's rollback copy, so a client lets the copy go with that unit and never replays it over the copy (agent T23's find, which blocked the install: the soak `replicas -- --clients 5 --rtt 30,80,207` died with `allocator leaks detected` at seed 0 rtt 80 on T1's base and on M2, MuPDF's allocations of documents a picker previewed: contexts, documents, lanes, from Kind.reopen under Pick.showKind); THE CAUSE: no path of the preview forgets its close (the next row and a source change close through Pick.preview, Esc and every roll-up through restore and putBack, ⏎ through land's roll-up, a pane's end through teardownPane, the session's through Core.deinit; a dump carries the slot and the client's join opens it, closed the same ways), but replica.confirm's `ahead` rule: a client idle with its copy taken ahead (Replica.ready) replays the session's units on it and keeps each in `since` to replay again when the copy is put back, unless the unit wrote outside the copy (Pardes.outside, counted by the emulators alone) or opened or closed a pane (its serials); a preview opens the pdf addon's state in the pane the picker lands in, which stays, and that state (the document and its lanes, MuPDF's on the kind heap, the addon's `Own` found by its block's address) is no copy's; so a rollback (another's unit before the client's own key) put the copy back, the epoch freed the block, and the replay opened the document again for a new block: the first was never closed (and its `Own`, keyed by an address the epoch hands out again, could be found for another block); THE FIX: Kind.reopen and Kind.close count a plain kind's open and close in Pardes.outside, by the registry's PA_PLAIN, on every side alike whether the kind's code runs there or not (a client without the library counts as the session does), so confirm's one question lets such a unit go with the copy; dump.plainHere, a client's own open of a plain kind's pane at its join and no step of the session's, puts the count back to the session's as dumped; Term.Outside's and Pardes.outside's docs say so; RUN (TEST FIRST): replica.zig "a picker's preview opens and closes a plain kind's state in the pane it lands in, no pane opened or closed: ..." (a plain test kind `Owned` noting each state it opens and letting it go at its close, as the pdf addon's `Own`; files `.own`): a session at notes.txt in a work tree with paper.own, a client joined in its own view running the kind, idle with its copy taken ahead while the session types `SPC f f p` (the preview through the kind in notes.txt's pane), then a key of the client's own on top and the session's own key first (a rollback), the client's key, Esc; asks the digests equal at each end and no state left noted after both cores end: fails on M2 (8959b031dc33) at the last check (expected 0, found 1), passes now; the soak with the pdf addon (`zig build replicas -Dplatform=tui -- --clients 5 --rtt 30,80,207`, every addon the build has): diverged 0, unequal 0, quiet checks 508/0 474/0 665/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak, the pdf panes the session opened 8, 6 and 5; a user could hit it as a client of a session whose picker previewed a PDF (a far client in a pair, a window joined to a terminal's session): a document leaked in the client at each rollback over such a preview, and pages drawn from another document's state where an address came back; NEW HOT PATHS: none per key or frame (a plain kind's open and close count one integer; a client lets its copy go at such a unit, as at a pane's open); GATES: core-test 1163/1337 (174 skipped: +1), its globals test (`nothing of a core is a process global`: the test kind's var in its test); no dump layout change (Pardes.outside was dumped and digested already; its values move at a plain kind's open and close, on every side alike); load 1.0 to 8.4 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dump.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/dump.zig') diff --git a/core/dump.zig b/core/dump.zig index 0cefa157..389d948f 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -1010,6 +1010,10 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) ! s.selection = try p.gpa.dupe(u8, old.selection); // (and its place: the open's own `where` is of a block not yet the session's) const kept = .{ old.next_tick, old.views, old.focused, old.state, old.where_text }; + // The count of writes outside the copy stays the session's, as dumped: + // this open is the join's, no step the session took (Kind.reopen). + const outside = p.outside; + defer p.outside = outside; if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused; // Its block the session's, byte for byte (its record), never through // the kind's load, which may tidy it. -- cgit v1.3 From 7911c53d5f08c7d8df3eb59061841daddb1d0e83 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 09:21:04 -0300 Subject: dump, replica, fuzz: a core that dump.load returns has its chrome, worked out by the load itself, so it draws as it is (the merge M2's dump fuzz at 40,000 join seeds: join seed 8324 died of a general protection fault in draw.zig's render, the debug overlay printing `p.theme().name`, a slice at 0xAAAAAAAAAAAAAAAA); THE CAUSE: the chrome (`theme_chrome`) is local, never dumped (Core.zig's replica `.local`), and dump.load left it undefined for its caller to work out: a replica's join did, right after it (replica.zig `made`, finishThemeInitialization), a restore does in reviveSession; the fuzz's `use` draws the loaded core as it comes, so it drew from an undefined chrome: before L3 only colours (0xAA bytes, drawn unseen), since L3 (tlpklysz: Pardes.theme() is the chrome's old-names view, `ChromeTheme.view`, a LegacyTheme with its `name` slice) a slice too, which the overlay prints once a damaged dump reads `debug` on; THE FIX: `load` works out the chrome before it returns (finishThemeInitialization, one Chrome.of, at a join, never a frame), and the replica's own call after it goes; RUN (TEST FIRST): fuzz.zig pins join seed 8324 beside 19224, 31554 and 6356: on the merge (ytzwsyrm 8959b031dc33) it fails at draw.zig:430 (`General protection exception` in bufPrint), passes now; a user could not hit it: every path that draws a loaded core (a replica's join, a restore) worked out the chrome before its first frame; NEW HOT PATHS: none per key or frame; a dump.load works out one Chrome.of more (the replica's, moved here), and the tape's dump round-trip check (tape.zig) one per check; GATES (tui, this change on the merge): core-test 1162/1336 (174 skipped; the merge's 1155/1329 then had the importer's 7 cached by zig), shell-test 1377/1380 (3 skipped), pane-test 184/185 (1 skipped), behaviour-test 287/287 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 149 failed (3 skipped), term-test 17/17, kitty-test 45/45; the gui unit-test 1988/1992 (4 skipped; its one failed step the perf check's BaselineHarnessMismatch, every base's); the dump fuzz at 40,000 join seeds twice and 1,779 image seeds 11/11 (on the merge alone it died at join seed 8324); the soak `replicas -- --clients 5 --rtt 30,80,207` (the pdf addon in): diverged 0, unequal 0, quiet checks 436/0 340/0 546/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak (the same soak on the merge alone died at seed 0 rtt 30 of the known MuPDF leak, Pick.showKind's documents, F1's: it comes only when a client's picker previews a PDF); load 3.5 to 9.9 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/dump.zig | 7 +++++-- core/fuzz.zig | 4 ++++ core/replica.zig | 2 -- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'core/dump.zig') diff --git a/core/dump.zig b/core/dump.zig index 0cefa157..a2b22cef 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -381,9 +381,12 @@ pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void { /// The core the dump `bytes` is, and nothing more: no shell started, no /// file watched, nothing asked of a host (`revive` does that). What another /// build's dump could not give is said in `notes` when given. `opts` are -/// this process's (its allocators, paths and name), not the dump's. +/// this process's (its allocators, paths and name), not the dump's. Its +/// chrome is the restored theme's: the colours are local, never dumped. pub fn load(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*std.ArrayList(u8)) !*Pardes { - return loadKnowing(gpa, opts, bytes, notes, null); + const p = try loadKnowing(gpa, opts, bytes, notes, null); + colors.finishThemeInitialization(p); + return p; } /// `load`, with which panes' files were on disk when it was dumped. diff --git a/core/fuzz.zig b/core/fuzz.zig index 56ded66b..d8df1d9a 100644 --- a/core/fuzz.zig +++ b/core/fuzz.zig @@ -824,6 +824,10 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan // `live` (the core read in place, its own `live` undefined), a live // message's `src` length 0xAAAA when the digest walked it. try loadSeed(bytes, .join, 6356); + // Join seed 8324: `debug` read on, and the overlay printed the theme's + // name from the chrome, which the load had never worked out (a join's + // caller did, after it): the old names' view's name 0xAAAA. + try loadSeed(bytes, .join, 8324); for ([_][]const u8{ bytes, described, image }, [_]Road{ .join, .join, .restore }, [_]u64{ 2048, 2048, 1024 }) |whole, road, n| { try loadSeed(whole, road, 0); for (1..n + 1) |seed| try loadSeed(whole, road, seed); diff --git a/core/replica.zig b/core/replica.zig index 6c037cd2..49ccd85b 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -588,8 +588,6 @@ pub const Replica = struct { r.view = Peers.viewFor(c, null, true) orelse return error.NoView; break :boot c; }; - // The chrome's colours are local, never dumped: the restored theme's. - if (dump != null) pardes.colors.finishThemeInitialization(c); // It runs a plain kind's code of its own (Addon.plainOps), loaded // at its first pane, each opened here from its record; another's // panes show a line. -- cgit v1.3