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/dump.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/dump.zig') diff --git a/src/dump.zig b/src/dump.zig index 0da2513f..f9f01950 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -880,12 +880,16 @@ fn applySettings(p: *Pardes, lines: []const []const u8) void { /// The replacement core for a Restore of the dump at `from`, whose log says /// so after its panes' `new`s, for a client that reconnects to read. pub fn restore(p: *Pardes, zon_bytes: []const u8, from: []const u8) !*Pardes { + const taped = pardes.tape.enter(p, .{ .restore = .{ .bytes = zon_bytes, .from = from } }); + defer pardes.tape.leave(p, taped); var opts = p.opts; opts.cols = p.screen_w; opts.rows = p.screen_h; var old: OldSerials = .{}; const replacement = try initDump(p.gpa, opts, zon_bytes, p, &old); replacement.pointRestoreAt(from); + // The tape follows the replacement from here (it is the session). + pardes.tape.adopt(replacement); pardes.ctlfs.events.notePath(replacement, "restore", from); // Which serial each pane and column had, for a script that held them. for (replacement.panes, old.panes) |slot, was| if (slot) |pane| if (was != 0) { @@ -900,7 +904,14 @@ pub fn restore(p: *Pardes, zon_bytes: []const u8, from: []const u8) !*Pardes { } pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8) !*Pardes { - return initDump(gpa, opts, zon_bytes, null, null); + pardes.tape.startFromEnv(); + const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = zon_bytes } }); + const p = initDump(gpa, opts, zon_bytes, null, null) catch |err| { + pardes.tape.leave(null, taped); + return err; + }; + pardes.tape.leave(p, taped); + return p; } /// The serials a dump's panes and columns had, read as it is restored. -- cgit v1.3 From 70de5ec5ff3dad01afcc45244ad5e5a481486da6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 17:01:35 -0300 Subject: dump: one walker dump of the whole session, by name across builds, for Restore, -l, Handover and the store; dump.zig's hand-written schema gone A dump is walk.zig's walk of the core with a table of every type it reaches (fields, enum and union names, number widths), read back by name; terminals are ghostty's snapshot (screens, history, kitty images); a failed load frees what it made. Co-Authored-By: Claude Opus 5.5 --- build.zig | 3 + build/snap.zig | 10 +- docs/typ/building.typ | 4 +- docs/typ/reference.typ | 35 +- src/File.zig | 387 --------------- src/Handover.zig | 112 +++-- src/Output.zig | 34 +- src/Pipe.zig | 4 + src/Query.zig | 9 +- src/Store.zig | 57 +-- src/builtins.zig | 2 +- src/dump.zig | 1176 +++++++++++----------------------------------- src/file_watch.zig | 57 +-- src/image.zig | 63 --- src/ninep/ctl.zig | 64 +-- src/ninep/events.zig | 24 +- src/panes.zig | 4 +- src/pardes.zig | 55 +-- src/pdf.zig | 4 +- src/pdf_view.zig | 14 + src/tagline.zig | 8 - src/tape.zig | 40 +- src/terminal.zig | 316 ++++++------- src/walk.zig | 1120 ++++++++++++++++++++++++++++++++++++++++++- test/fs.py | 5 +- test/fs_namespace.zig | 44 +- test/kitty.zig | 6 +- test/monkey.zig | 9 +- test/output.zig | 17 - test/panes.zig | 61 +-- test/pdf.zig | 39 -- test/snapshot.zig | 9 +- test/snapshots/dump.snap | 9 +- 33 files changed, 1851 insertions(+), 1950 deletions(-) (limited to 'src/dump.zig') diff --git a/build.zig b/build.zig index 1a5dd200..962b6322 100644 --- a/build.zig +++ b/build.zig @@ -1950,6 +1950,9 @@ pub fn build(b: *std.Build) void { run_shell_test.has_side_effects = true; unit_step.dependOn(&run_shell_test.step); if (unit_match) |check| check.addArtifactArg(shell_test); + // The native shell's tests alone, without the perf gate's + // ReleaseFast build: what a -Dtest-filter iteration wants. + b.step("shell-test", "run the native shell's unit tests (src/main.zig's)").dependOn(&run_shell_test.step); const run_profile = b.addRunArtifact(unit_profile); run_profile.addArtifactArg(shell_test); run_profile.addPassthruArgs(); diff --git a/build/snap.zig b/build/snap.zig index d74767d3..c1a26e64 100644 --- a/build/snap.zig +++ b/build/snap.zig @@ -69,19 +69,21 @@ pub fn addTty(b: *std.Build, opts: struct { // The replay-divergence gate (src/tape.zig, docs/next-daemon.md): every // snapshot script and `replay-seeds` monkey seeds with each session's // tape recorded, each replayed into two replicas at different - // addresses and one that never draws, every digest checked. + // addresses and one that never draws, every digest checked; and at each + // session's end its dump loaded, which must be that session, digest for + // digest, and dump again to the same bytes (phase 2). const tapes = ".zig-cache/tapes"; const run_replay = b.addRunArtifact(snap); run_replay.addArtifactArg(opts.exe); run_replay.addPrefixedFileArg("--lspmock=", lspmock.getEmittedBin()); - run_replay.addArg("--tape=" ++ tapes); + run_replay.addArgs(&.{ "--tape=" ++ tapes, "--dump" }); run_replay.setCwd(b.path(".")); run_replay.has_side_effects = true; const seeds = b.option(u32, "replay-seeds", "monkey seeds `zig build replay` records and replays (default 20)") orelse 20; const run_monkey_replay = b.addRunArtifact(monkey); run_monkey_replay.addArtifactArg(snap); run_monkey_replay.addArtifactArg(opts.exe); - run_monkey_replay.addArgs(&.{ b.fmt("{d}", .{seeds}), "70", "--tape=" ++ tapes ++ "/monkey", "--out=" ++ tapes ++ "/monkey" }); + run_monkey_replay.addArgs(&.{ b.fmt("{d}", .{seeds}), "70", "--tape=" ++ tapes ++ "/monkey", "--dump", "--out=" ++ tapes ++ "/monkey" }); run_monkey_replay.setCwd(b.path(".")); run_monkey_replay.has_side_effects = true; // One pardes-snap run at a time (its lock): the scripts, then the seeds. @@ -95,7 +97,7 @@ pub fn addTty(b: *std.Build, opts: struct { run_views_replay.setCwd(b.path(".")); run_views_replay.has_side_effects = true; run_views_replay.step.dependOn(&run_monkey_replay.step); - b.step("replay", "record every snapshot script's and -Dreplay-seeds monkey seeds' tapes (one terminal and three) and require each to replay without diverging").dependOn(&run_views_replay.step); + b.step("replay", "record every snapshot script's and -Dreplay-seeds monkey seeds' tapes (one terminal and three) and require each to replay without diverging, and each session's dump to load to its digest").dependOn(&run_views_replay.step); const monkey_tests = b.addTest(.{ .root_module = monkey.root_module }); b.step("monkey-test", "test the monkey's generator and panic detector").dependOn(&b.addRunArtifact(monkey_tests).step); const run_driver_test = b.addRunArtifact(snap); diff --git a/docs/typ/building.typ b/docs/typ/building.typ index 00088d7b..e42702c6 100644 --- a/docs/typ/building.typ +++ b/docs/typ/building.typ @@ -19,7 +19,7 @@ builds MuPDF and is on by default (`-Dmupdf=false` drops it). 9P over QUIC [`zig build`], [the terminal shell and the SDL window together, *installed into `~/.local/bin`* (`pardes`, `pardes-gui`, and `pardes-v9fs`, the #word("Tty9p") helper)], [`zig build -Dplatform=tty`], [the terminal shell alone], [`zig build -Dplatform=gui`], [the SDL3 window alone], - [`zig build web -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=`], [a freestanding wasm core plus vanilla JavaScript (`docs/web.md`)], + [`zig build web -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=`], [a freestanding wasm core plus vanilla JavaScript (`docs/web.md`)], [`zig build -Dplatform=macos`], [an AppKit and CoreText app over a static `libpardes.a` (`docs/macos.md`)], [`zig build -Dplatform=esp32p4`], [a freestanding riscv32 editor object for the ESP32-P4, with a 384 KiB heap], ) @@ -59,7 +59,7 @@ there; its namespace is in `src/esp32p4_gpio.zig`. [`-Dprebuilt-shaders`], [bool: embed the committed SPIR-V; on for a bare `zig build`, off with `-Dplatform`; `zig build shaders` refreshes it with glslc], [`-Dtracy`], [path to a Tracy checkout; off], [`-Dmacos-identity`], [codesigning identity for `pardes.app`; `-` (ad hoc)], - [`-Ddump`], [a `dump.zon` to embed in the web shell], + [`-Ddump`], [a Dump to embed in the web shell], [`-Dtest-filter`], [run only tests whose name contains it; a filter that matches nothing fails], [`-Dtest-rebuild`], [bool: fresh Zig test compilation], [`-Dhelix-harness`], [reference executable for live differential tests; `HX_HARNESS`, else `hx-harness` on `PATH`], diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index ce2a45f1..2e395cc6 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -368,22 +368,20 @@ Writes take settings and session builtins (`scope = .session` in #word("Delcol") and a pane's `get` refuse the same way with their own word, except that #word("Delcol") opens no `+Unsaved` pane: it names the panes only in its `unsaved` records and its notice. -- #word("Dump") writes `pardes--