From f8e9b68309f657ce2cd3de0d2070fb70dc525339 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 17:33:23 -0300 Subject: replicas: a markdown text's tables are the whole text's, read at once by whoever asks first, never a reading under way that a frame moved (the audit of what a frame writes and a step reads, after Pane.notices): a step read a big text's table pads (a click's byte, a `j` over a table, through File.geometry -> Tables.ensure) from `File.State.tables`, which is derived (in no digest, no dump) yet carried a reading's progress: the first look read 4096 lines, the session's ticks read on 4 ms at a time, and an edit after a look took the short way past the read point; so a core that drew a frame before an edit (the frame's geometry made the first look at that revision) read on past line 4096 where one that had not drew began again and stopped there, and a client joined from a dump began from nothing where its session had read the text whole (then its tick asked the tape for a budget its session never read); the test `tables: a click on a big text's table is the same state whichever frame this process drew last` (a session that drew once and a replica joined from its dump that drew nothing, the same paste and a click on each cell of a table at line 5001) failed on the base (`expected 4, found 5`: the click put the caret on another byte) and passes; the fix reads the whole text at once in `Tables.ensure` (an edit still reflows only its block), deleting the budgeted reading (`pending`, `step`, `busy`, `frame_ns`, `first_lines`, the tick's call and `nextWake`'s, the key's word): its cost is the read at open, measured in ReleaseFast at 40 ns a line of prose and 18 ms for 2.7 MB of 2000 tables (docs/next-tables.md's stress text, generated), where it was 4096 lines then 4 ms a frame; and the class is kept closed two ways: `root.zig`'s `kept_out` names every `.local` and `.derived` field of core/ (68) with who writes it and why a step's read of it is the step's, a test failing on a new one not listed, and `draw.zig`'s `a frame changes nothing a step reads` steps a core that draws after every input (each frame at its own later time, and `presented`) and one joined from its dump that never draws through 600 random keys, clicks, wheels, pastes, commands, ticks and disk changes over a 4500-line markdown text with a table and a second pane, their digests equal after every step (16 seeds of 3000 steps agree); the audit's table is in the report (.scratch/sketch/reports/pardes-draw-2.md); the gates on this change: tui core-test 841/984 (143 skipped), shell-test 1020/1023, term 15/15, pane 183/184, kitty 45/45, behaviour-test 275/275 and --replay 275/275, process-test the base's two (lspcomplete, lspcompletemoved), gui unit-test 1618/1622 + BaselineHarnessMismatch (the base's); replicas --clients 5, the session drawing after every pump: diverged 0/0/0, unequal 0/0/0, deltas checked/wrong 2113/0, 1773/0, 1775/0, quiet checks 800/0, 794/0, 893/0, stops not on may_wait 0/0/0 (rtt 30/80/207), corpus through a client 22/22; daemon.py plain, --far, --games, --window-clients, --upgrade both ways (against pardes-tree/pfx-base) pass; cross_replay 28 digests agree each; macOS lib and FreeBSD rc 0; the frame and perf gate ran on the three changes together (d2-i3): frames 77/77 byte-identical, corpus2x +0.005% (noise 0.044%, bar 0.4%), the 97 per-operation counts within 0.1% (largest +0.031%) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/root.zig | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'core/root.zig') diff --git a/core/root.zig b/core/root.zig index 706c833d..48c1cd6c 100644 --- a/core/root.zig +++ b/core/root.zig @@ -721,3 +721,87 @@ test "what core/ asks of the machine is where the list says, with why: a new lin }; try std.testing.expectEqual(@as(usize, 0), wrong); } + +/// Every field kept out of the digest and the dump as a process's own +/// (`.local`) or as made again from the rest (`.derived`): who writes it, +/// and why what a step reads of it is what that step's own state makes, so +/// a core that drew a frame and one that did not, or one joined since, step +/// alike (a frame writes several; a step that read one a frame left as its +/// state did not make it diverged a client: Pane.notices, then Tables' +/// reading, 2026-11-19). A file, its names, the reason. +const kept_out = [_]struct { []const u8, []const u8, []const u8 }{ + .{ "Core.zig", "surface facts frames own_frames chrome frame_arena scratch echo undrawn", "the frame's own and the views drawn here: written by frames (and chrome by a theme's step), read by frames and the runner; no step reads them" }, + .{ "Core.zig", "needs_frame", "whether to draw: steps set it, the loop reads it; no step's outcome reads it" }, + .{ "Core.zig", "effects effects_head effects_len in_q in_head in_len opts dump_out dump_export tape", "this process's queues, options and tape, drained or set by its host" }, + .{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; a terminal is in no digest (Term.zig)" }, + .{ "Core.zig", "diff_output locations_cache tty_filter_palette body_chrome", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest)" }, + .{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" }, + .{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" }, + .{ "Event.zig", "native_image_patches", "what this process's shell can take" }, + .{ "panes.zig", "pv pv_known", "the views' shares as this process parks them (views.zig)" }, + .{ "panes.zig", "wrap_line wrap_col wrap_pad wrap_n body_wrapped context_rows body_rows body_visible_rows context_row_limit geometry_key geometry_len", "File.geometry's, made by whoever asks first (a frame or a step) from everything its key hashes of the step's state; a tab change resets the key" }, + .{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" }, + .{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" }, + .{ "File.zig", "cap line_starts line_cap", "the text's line index, of its bytes" }, + .{ "File.zig", "highlights highlight_start syntax_dirty", "how a text looks, painted by frames: read by frames, and by a query's rows for colours only (out of their digest)" }, + .{ "File.zig", "context", "the declarations of the text at a revision: found in sync (refreshContext), by a parse's answer (a step) or a dump's load" }, + .{ "File.zig", "node_tree node_tree_revision node_tree_edits node_history", "the parse of the text at its revision, made by the first key that walks it" }, + .{ "File.zig", "tables", "the whole text's, read at once by whoever asks first (Tables.ensure): no reading under way that a frame could move" }, + .{ "Text.zig", "room", "a buffer's capacity" }, + .{ "Kind.zig", "ops st gpa arena plain file opened reloads jobs record", "the kind's code and memory here: a plain kind's block is in the copy, and its state hash is checked at every call (Kind.Call.end)" }, + .{ "Kind.zig", "thumb_at thumb_span pointer painted over used draws", "a frame's: written by a paint; `painted` is read by a tick of a kind that is not plain, whose calls are the authority's alone" }, + .{ "Places.zig", "ticks ticks_gen re", "the rail's ticks, made again when the places move (`gen`), and the compiled pattern, of the pattern" }, + .{ "Plumb.zig", "parsed parsed_arena", "the rules parsed, of their text" }, + .{ "Stream.zig", "parse_ns paint paint_retired paint_count ahead ahead_for painted_ahead painted_on_loop ahead_seen ahead_ask", "the workers' paints and timings: how a text looks, and numbers" }, + .{ "walk.zig", "cache", "a test's own type" }, +}; + +test "every field kept out of the digest and the dump is one the list names, with who writes it and why a step's read of it is the step's" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var dir = try std.Io.Dir.cwd().openDir(io, "core", .{ .iterate = true }); + defer dir.close(io); + var walker = try dir.walk(gpa); + defer walker.deinit(); + var unlisted: usize = 0; + var seen: usize = 0; + while (try walker.next(io)) |e| { + if (e.kind != .file or !std.mem.endsWith(u8, e.basename, ".zig")) continue; + const src = try e.dir.readFileAlloc(io, e.basename, gpa, .limited(16 << 20)); + defer gpa.free(src); + for ([_][]const u8{ ".local = .{", ".derived = .{" }) |head| { + var at: usize = 0; + while (std.mem.indexOfPos(u8, src, at, head)) |start| { + const end = std.mem.indexOfScalarPos(u8, src, start, '}') orelse break; + at = end; + // Not in a comment or a string (walk.zig's example, this test). + const before = src[(std.mem.lastIndexOfScalar(u8, src[0..start], '\n') orelse 0)..start]; + if (std.mem.indexOf(u8, before, "//") != null or std.mem.indexOfScalar(u8, before, '"') != null) continue; + var lines = std.mem.splitScalar(u8, src[start + head.len .. end], '\n'); + while (lines.next()) |whole| { + const line = whole[0 .. std.mem.indexOf(u8, whole, "//") orelse whole.len]; + var quoted = std.mem.splitScalar(u8, line, '"'); + _ = quoted.next(); + while (quoted.next()) |name| { + _ = quoted.next(); + seen += 1; + const listed = listed: for (kept_out) |k| { + var files = std.mem.tokenizeScalar(u8, k[0], ' '); + const here = while (files.next()) |f| { + if (std.mem.eql(u8, f, e.path)) break true; + } else false; + if (!here) continue; + var names = std.mem.tokenizeScalar(u8, k[1], ' '); + while (names.next()) |n| if (std.mem.eql(u8, n, name)) break :listed true; + } else false; + if (listed) continue; + std.debug.print("core/{s}: `{s}` is kept out of the digest and the dump: on root.zig's kept_out, with who writes it and why a step reads only what its own state makes\n", .{ e.path, name }); + unlisted += 1; + } + } + } + } + } + try std.testing.expect(seen > 60); + try std.testing.expectEqual(@as(usize, 0), unlisted); +} -- cgit v1.3 From 957b02838c6df8a35fccfd9aae7678d61d4f63b9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 18:38:09 -0300 Subject: addons: a load under way in another live process is no crash, so a client that starts while its session loads the same library runs the kind (`test/daemon.py --games` under load: a client's game stopping every key for the rest of the session): every pardes of the user shares one crash mark, `addon-loading` in the data directory, written around each library's load (`Addon.mark`), and a start that found it took the load for a crash (`crashedPath` renamed it to `addon-crashed`); so a client whose scan (its first plain kind's `plainOps`) fell inside the session's or another client's load of the snake listed it `skipped: it crashed its last load`, never had its code (`runsHere` false: slot ops null, the registry's null, nothing distrusted, no rejoin, as a probe in `Kind.key`, `plainOps` and `Link.rejoins` showed in 8 failing runs of 10 at load 13-30), and every key of it into the snake waited for the session (client a: at once 5, stopped 149; or client b's one key into it: stopped 1), and the false crash stayed for every later start until `Addon load`; now the mark is the loading process's (`addon-loading.`) and a start takes a mark for a crash only when its process is gone (`kill(pid, 0)`: ESRCH; the bare name, an older build's, as before); the test `a load under way in another live process is no crash: a start meanwhile lists the addon, and the mark stays the loader's` orders it by hand (this process marks a load, a scan starts before it unmarks; then a dead pid's mark is a crash) and failed on the base (the scan listed the library skipped); `--games` under 24 busy processes: 2 of 10 passed on the base's code (load 13-30), 10 of 10 with the fix (load 12-31, keys stopped 0 and 0 in every run); root.zig's machine lines for Addon.zig 48 -> 54; the gates on the three changes together (i3): tui core-test 843/986 (143 skipped), shell-test 1022/1025, term 15/15, pane 183/184, kitty 45/45, behaviour-test 275/275 and --replay 275/275, process-test the base's two, gui unit-test 1620/1624 + BaselineHarnessMismatch; replicas --clients 5: diverged 0/0/0, unequal 0/0/0, deltas checked/wrong 1907/0, 2028/0, 1812/0, quiet checks 623/0, 835/0, 771/0, stops not on may_wait 0/0/0, corpus 22/22; daemon.py plain, --far, --games, --window-clients, --upgrade both ways pass, and --games 10 of 10 under 24 busy processes (load 11-37); cross_replay 27 digests agree each; the frame and perf gate against tree1 (d2-i3): frames 77/77 byte-identical, corpus2x +0.005% (noise 0.044%), the 97 per-operation counts within 0.1% (largest +0.031%) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Addon.zig | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++------- core/root.zig | 2 +- 2 files changed, 56 insertions(+), 8 deletions(-) (limited to 'core/root.zig') diff --git a/core/Addon.zig b/core/Addon.zig index 5c23ed51..5477ed7c 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -446,11 +446,12 @@ fn markPath(buf: []u8, data: []const u8, comptime name: []const u8) ?[:0]const u return std.fmt.bufPrintSentinel(buf, "{s}/" ++ name, .{data}, 0) catch null; } -/// The load of `path` under way, on disk until `unmark`. +/// The load of `path` under way in this process, on disk until `unmark`: +/// its name says whose (every pardes of the user shares the directory). fn mark(data: []const u8, path: []const u8) void { if (data.len == 0) return; var buf: [4096]u8 = undefined; - const at = markPath(&buf, data, "addon-loading") orelse return; + const at = std.fmt.bufPrintSentinel(&buf, "{s}/addon-loading.{d}", .{ data, std.c.getpid() }, 0) catch return; const f = std.c.fopen(at, "w") orelse return; _ = std.c.fwrite(path.ptr, 1, path.len, f); _ = std.c.fclose(f); @@ -469,16 +470,33 @@ fn unmark() void { marked_len = 0; } -/// The library that crashed its session's load: a mark left by a start -/// that never finished one becomes `addon-crashed`, which it stays. +/// The library that crashed its session's load: a mark left by a process +/// that is gone, its load never finished, becomes `addon-crashed`, which it +/// stays. A live one's is a load under way (a client starting while its +/// session loads the same library), no crash: taken for one, the client +/// never ran the kind and every start after skipped it. fn crashedPath(data: []const u8) Kind.Buf(4096) { var out: Kind.Buf(4096) = .{}; if (data.len == 0) return out; - var lbuf: [4096]u8 = undefined; var cbuf: [4096]u8 = undefined; - const loading = markPath(&lbuf, data, "addon-loading") orelse return out; const crashed = markPath(&cbuf, data, "addon-crashed") orelse return out; - if (std.c.access(loading, 0) == 0) _ = std.c.rename(loading, crashed); + var dbuf: [4096]u8 = undefined; + const dz = std.fmt.bufPrintSentinel(&dbuf, "{s}", .{data}, 0) catch return out; + if (std.c.opendir(dz)) |d| { + defer _ = std.c.closedir(d); + while (std.c.readdir(d)) |e| { + const name = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&e.name)), 0); + if (!std.mem.startsWith(u8, name, "addon-loading")) continue; + // `addon-loading` alone is an older build's, whose is not known. + if (name.len > "addon-loading".len) { + const pid = std.fmt.parseInt(std.c.pid_t, name["addon-loading.".len..], 10) catch continue; + if (std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue; + } + var lbuf: [4096]u8 = undefined; + const loading = std.fmt.bufPrintSentinel(&lbuf, "{s}/{s}", .{ data, name }, 0) catch continue; + _ = std.c.rename(loading, crashed); + } + } out.set(readSmall(crashed).slice()); return out; } @@ -917,6 +935,36 @@ test "addon reload gives migration the old record version and saves the new vers try std.testing.expectEqual(@as(u32, 2), slot.version); } +test "a load under way in another live process is no crash: a start meanwhile lists the addon, and the mark stays the loader's" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const data = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + try tmp.dir.createDirPath(std.testing.io, "addons"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "addons/game.so", .data = "not a library" }); + var lib_buf: [4096]u8 = undefined; + const lib = try std.fmt.bufPrint(&lib_buf, "{s}/addons/game.so", .{data}); + var dir_buf: [4096]u8 = undefined; + const dir = try std.fmt.bufPrint(&dir_buf, "{s}/addons", .{data}); + // In order, as two processes of the user went under load (daemon.py + // --games): one marks its load of the library (this process, alive), + // another starts its scan before it unmarks. + mark(data, lib); + defer unmark(); + nfound = 0; + scanDir(data, dir, crashedPath(data).slice()); + defer nfound = 0; + try std.testing.expectEqualStrings(lib, found[0].path); + try std.testing.expect(std.mem.indexOf(u8, found[0].why, "crashed") == null); + try std.testing.expectError(error.FileNotFound, tmp.dir.access(std.testing.io, "addon-crashed", .{})); + // The loader gone with its mark left: a crash, skipped. + var name_buf: [64]u8 = undefined; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = try std.fmt.bufPrint(&name_buf, "addon-loading.{d}", .{std.math.maxInt(i32)}), .data = lib }); + nfound = 0; + scanDir(data, dir, crashedPath(data).slice()); + try std.testing.expect(std.mem.startsWith(u8, found[0].why, "skipped: it crashed its last load")); +} + test "a load that never finished is skipped at the next start, and every start after, until a load asks for it" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/core/root.zig b/core/root.zig index 48c1cd6c..2e8fe1dc 100644 --- a/core/root.zig +++ b/core/root.zig @@ -605,7 +605,7 @@ test "nothing of a core is a process global: every container-level var in core/ /// The count is a file's, so it cannot tell a step's read from its host /// half's; the reason says which the file's are. const machine_lines = [_]struct { []const u8, usize, []const u8 }{ - .{ "Addon.zig", 48, "the process's addon libraries: the start's scan of their directories, dlopen, the crash mark; the host's, never a step's" }, + .{ "Addon.zig", 54, "the process's addon libraries: the start's scan of their directories, dlopen, the crash mark (whose: the pid alive); the host's, never a step's" }, .{ "Core.zig", 5, "the session's directory read once at its start (taped), a frame log (PARDES_FRAMES), a host_io type" }, .{ "Db.zig", 18, "the state file every session of the user shares: the authority's (`db`), off in every replica" }, .{ "Dir.zig", 1, "a directory's listing, the function under tape.site(.dir_listing), its io the tape's" }, -- cgit v1.3