From 89f4b611e4e6e1732595d070184daf167b53bfb3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:51:01 -0300 Subject: tape: the budget is a count, step 7 (reports/pardes-handle-69-design.md section 2, P33's lean 3): Names.rescore stops after 3,000,000 of the scorer's cells (a key's bytes times the query's and one, what `match` can visit of a candidate, so a long query's slice is no longer than a short one's) and a tick's Places.fill after 512 KiB read, the places an insert above the view moves charged as read (with many places below it, the moving was what only the clock bounded), so no clock is read in a step: Tape.over, the free over, overNow, the budget site and the two clock reads are deleted, and a far client's guess of a key into a big name query is the session's step by construction (test/daemon.py --far's new scene, a Find over 40,000 names typed into: mispredicted 1, 1, 1 and 4 in four runs of the base, 0 in four of this); the constants measured by pardes-perf's new --search (ReleaseFast, this machine at a load of 12 to 24, every call's instructions counted): a tick's fill on the 18 MB text at most 23-24M instructions where the clock's 4 ms ticks took 47-75M, a rescore's scan on a long query at most 31.5M where the clock's took 32.6M; the longest rescore is not the scan but its sort of every hit at each call (about 125-145M instructions, 16-22 ms, with the clock and with the count alike: not bounded by either, left); the semantics word moves (the site's number goes: 7a610621b2f37456 -> df1f0502317ed362), so cross_replay across this change diverges at the first site after it, as it must; tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test 0 of 144 failed, both soaks diverged 0 unequal 0 corpus 22 of 22 no leak (bytes: the base's one unlisted `now` stop at 30 ms), daemon.py plain, --far, --games (alone, at load 24), --window-clients, --upgrade both ways against merge31 (new->old alone after the Adopt race); gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch); frames 77/77, perfab +0.055%, the 121 counts within 0.1% against tree2 (key-down on medium 10,039,595, render on medium 11,454,507; the base 10,039,283 and 11,454,252) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/tape.zig | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'core/tape.zig') diff --git a/core/tape.zig b/core/tape.zig index f9303d67..934bc499 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -114,7 +114,6 @@ pub const Site = enum(u16) { fonts, // Read in place (`value`). clock, - budget, wake, env, interpreter, @@ -768,12 +767,6 @@ pub const Tape = struct { return t.value(.authority, f, args); } - /// A budget of `budget_ns` from `since_ns` on the monotonic clock is spent: - /// what the clock said is taped, so a replica stops its work where this did. - pub fn over(t: *Tape, since_ns: u64, budget_ns: u64) bool { - return t.value(.budget, overNow, .{ since_ns, budget_ns }); - } - /// A body whose first parameter is an `std.Io` its caller does not pass /// is handed the tape's (`args` are the rest): the only way core/ comes /// to hold one. @@ -1324,14 +1317,6 @@ pub fn resync(t: *Tape) void { t.real = .{}; } -pub fn over(since_ns: u64, budget_ns: u64) bool { - return (on orelse &none).over(since_ns, budget_ns); -} - -fn overNow(since_ns: u64, budget_ns: u64) bool { - return pardes.FrameStats.nowNs() -| since_ns > budget_ns; -} - /// One host call, `f(args)`, made out of the turn (pardes.turn). pub fn out(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? { pardes.turn.yield(); -- cgit v1.3 From ff183922e78f04eee85043d29f1bd5e5ba43a6cd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 06:35:16 -0300 Subject: tape: the turn's check is a count, step 9a (reports/pardes-handle-69-design.md section 3.2): Turn.yield no longer asks the global tape whether a replica steps, it counts (Turn.yields, and Turn.zig no longer imports the tape); a speculation's tape notes the count at beginSpeculation and endSpeculation compares it, and apply compares it around each replayed input (the divergence still names the input; not around a session's end, whose dump check reads through no tape), with the same verdicts as before (a speculation poisoned, a replay diverged: Tape.stray, which now takes the count it started from); the free stray goes, the free replaying stays (the terminal's emulatorGpa reads it); the stray test drives a yield through both; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7: 29 and 27 digests agree x3); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed at a load of 37 (tagalign, exec-bigdrag) and both pass alone, the bytes soak as the base (diverged 0, unequal 0, corpus 22 of 22, the base's one now stop), the plain soak cut short after rtt 80 (diverged 0, unequal 0, corpus 22 of 22; its 207 is the next change's gate); gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Turn.zig | 10 +++++----- core/tape.zig | 32 ++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'core/tape.zig') diff --git a/core/Turn.zig b/core/Turn.zig index 687e287f..249c6795 100644 --- a/core/Turn.zig +++ b/core/Turn.zig @@ -17,7 +17,6 @@ //! come from a shell performing a save between steps -- so a parked request //! is never the syscall's own. const std = @import("std"); -const tape = @import("tape.zig"); const Turn = @This(); @@ -46,6 +45,10 @@ restores: u64 = 0, lsp_answers: u64 = 0, /// All of the above, and `out` reaching zero. settled: std.Io.Condition = .init, +/// Every `yield`, ever: a replica's step makes none (each syscall of its +/// core is a tape site), which its tape checks by this count across a +/// speculation and a replayed input (core/tape.zig `stray`). +yields: u64 = 0, /// The editor's thread takes the turn for good; it has it until `stop`. pub fn start(t: *Turn, io: std.Io) void { @@ -79,10 +82,7 @@ pub fn wake(t: *Turn) void { /// a step. Nests: a directory listing that resolves each entry yields /// inside a yield, and only the outermost one lets go. pub fn yield(t: *Turn) void { - // A replica makes no syscall: each is a site of the tape's. One that - // is none stops a speculation and diverges a replay (it joins - // again), never the process (a window client's `Term fish`, H17). - if (tape.replaying()) tape.stray(); + t.yields +%= 1; const io = t.io orelse return; yield_depth += 1; if (yield_depth != 1) return; diff --git a/core/tape.zig b/core/tape.zig index 934bc499..c32c4453 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -280,6 +280,8 @@ pub const Tape = struct { /// checks. speculating: bool = false, poisoned: bool = false, + /// The turn's yields when the speculation began (`stray`). + yields: u64 = 0, /// What stopped it: a host function's or a site's name, or a poison's /// reason (PARDES_REPLICA_STATS counts them). poisoned_by: []const u8 = "", @@ -664,6 +666,9 @@ pub const Tape = struct { defer t.applying = outer; t.host_side = true; defer t.host_side = true; + // Not at the end: the dump checked there reads through no tape. + const yields = pardes.turn.yields; + defer if (input != .deinit) t.stray(yields); switch (input) { .init, .init_from_dump => { var opts = switch (input) { @@ -858,11 +863,13 @@ pub const Tape = struct { return t.replay or t.speculating; } - /// A syscall of the core's that is no site, made by a replica: what it - /// returns is the authority's to say. A speculation waits for it, and a - /// replay has diverged. - pub fn stray(t: *Tape) void { - if (t.through) return; + /// A syscall of the core's that is no site, made by a replica since the + /// turn's count of yields was `since`: what it returned is the + /// authority's to say. A speculation waits for it, and a replay has + /// diverged (it joins again), never the process (a window client's + /// `Term fish`, H17). + fn stray(t: *Tape, since: u64) void { + if (pardes.turn.yields == since) return; if (t.speculating) t.poisoned = true else t.diverge("a syscall that is no tape site, made replaying", .{}); } @@ -1328,10 +1335,6 @@ pub fn replaying() bool { return (on orelse &none).replaying(); } -pub fn stray() void { - (on orelse &none).stray(); -} - /// A replica speculating (core/replica.zig): state only the authority /// changes (a terminal's emulator) is left alone, and the input waits. pub fn speculating() bool { @@ -1462,12 +1465,14 @@ pub fn beginSpeculation(t: *Tape) void { t.poisoned_by = ""; t.touched = false; t.no_digest = true; + t.yields = pardes.turn.yields; t.buf.clearRetainingCapacity(); t.seeFields(); } /// Whether it stayed clean (no host call, no syscall, no authority state). pub fn endSpeculation(t: *Tape) bool { + t.stray(t.yields); t.speculating = false; t.no_digest = false; return !t.poisoned; @@ -1642,16 +1647,19 @@ test "a syscall that is no site, made replaying, diverges the replay and poisons defer t.scratch.deinit(); defer t.arena.deinit(); defer if (t.diverged) |why| gpa.free(why); - on = &t; - defer on = null; + const since = pardes.turn.yields; + t.stray(since); + try std.testing.expect(t.diverged == null); pardes.turn.yield(); pardes.turn.back(); + t.stray(since); try std.testing.expect(t.diverged != null); t.replay = false; t.speculating = true; + t.yields = pardes.turn.yields; pardes.turn.yield(); pardes.turn.back(); - try std.testing.expect(t.poisoned); + try std.testing.expect(!endSpeculation(&t)); } test "a replay that finds no answer where its core reads one diverges, and the read goes on harmless" { -- cgit v1.3 From 6cf477bd75d242c7f7fea653d5f433872f7ca66f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 09:14:40 -0300 Subject: tape: the idle rule checked beside the global, step 9b-0 (reports/pardes-handle-69-design.md section 3.4): in a safe build every entry computes the rule 9b reads the field by (tapeOf: the core's tape, or for a session not made yet its options' or create's; records: not the tape nobody records, nor a replica's between its steps) and panics where it and tape.on disagree; run first printing every disagreement through all the suites and both soaks (logs under reorg/pardes-handle-7/logs/9b0x), it found two kinds, both the rule's to keep and excepted by name in the check: a client's core freed (Replica.deinit inside a Stepping scope: today a deinit record into a buffer let go at once, the rule records nothing; every client of every suite and soak), and tests that drive an authority's core outside a Stepping scope (today unrecorded, the rule records them as a real session's every entry: test/panes.zig's jobs() and renders at :3749, :3809, :3824, :3899, :3913, core/replica.zig :5094's shows(a.core, ..)); no other; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7 agree); with the print: tui core-test, shell-test, pane-test, term-test 17/17, kitty-test 45/45, behaviour-test 275/275, process-test --replay 0 of 102 failed, process-test 1 of 144 (msg, at a load of 22; passes alone), both soaks diverged 0 unequal 0 corpus 22 of 22 (bytes: the base's one now stop at 30 ms; the plain soak's three rtts are also 9a's soak again, which another agent's kill cut short); as committed (the panic): core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, behaviour-test 275/275 and --replay 275/275 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/tape.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'core/tape.zig') diff --git a/core/tape.zig b/core/tape.zig index c32c4453..ddfaa4b1 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1041,10 +1041,40 @@ pub inline fn enter(p: ?*Pardes, input: Input) Entered { // fails when it does. if (std.debug.runtime_safety) if (p) |core| if (if (on) |t| core.tape != t else core.tape.stepping()) @panic("tape: a core's field is not the tape being stepped (tape.on)"); + // The rule the field is read by next (9b), checked beside `on` first. + // Where they disagree (9b-0's list, both the rule's to keep): a + // client's core freed (Replica.deinit, inside a Stepping scope: `on` + // records its `deinit` into a buffer let go at once; the rule records + // nothing), and a test that drives an authority's core outside a + // Stepping scope (no `on`: unrecorded; the rule records it, as a real + // session's every entry is). + if (std.debug.runtime_safety) { + const t = tapeOf(p, &input); + const listed = if (on != null) input == .deinit and t.replica else !t.replica; + if (records(t) != (on != null) and !listed) @panic("tape: the idle rule and tape.on disagree"); + } const t = on orelse return .{}; return t.enterInput(p, &input); } +/// The tape an entry steps: its core's; for a session not made yet, the one +/// its options name, or the one `Pardes.create` takes. +fn tapeOf(p: ?*Pardes, input: *const Input) *Tape { + if (p) |core| return core.tape; + const opts = switch (input.*) { + .init => |o| o, + .init_from_dump => |d| d.opts, + else => return &none, + }; + return opts.tape orelse on orelse &none; +} + +/// Whether an entry on `t` is recorded: not on the tape nobody records, nor +/// on a replica's between its steps (a client's frame drawn, its core freed). +fn records(t: *const Tape) bool { + return !(t.through or (t.replica and !t.replaying())); +} + pub inline fn leave(p: ?*Pardes, e: Entered) void { if (e.outer) on.?.leaveInput(p); } -- cgit v1.3 From 1d92d0151bf8206823074f73b9fa90e0220bff15 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 10:37:44 -0300 Subject: tape: enter and leave read the field, step 9b (reports/pardes-handle-69-design.md sections 3.3, 3.4): an entry is recorded on the tape of the core it enters (for a session not made yet, its options' or, until 9c, the global's), unless nobody records it or it is a client's between its steps (the idle rule 9b-0 checked), and Entered carries the tape it entered, so leave needs neither the global nor a core that init did not make or deinit freed; the safe build still checks that a core stepped is the one the global says while the global is set; as 9b-0's list said, a client's core freed records nothing now, and an authority's core driven outside a Stepping scope records its entries as a real session's: one test leaned on that being unrecorded (test/panes.zig, a client's guessed PDF view: the effects its `jobs` drained after the open landed in the client's next unit and read as a misprediction; the drain is handed to the client as a unit of the session's own first, 2 lines); test/daemon.py --restore (new): a Restore with a client attached, the client let go, one attached after agrees and its keys reach the restored session (passes on step 7 and here); the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7: 27 digests agree x3); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test --replay 0 of 102, process-test 1 of 144 (pagercolor, on the known list), both soaks diverged 0 unequal 0 corpus 22 of 22 (bytes: the base's one now stop at 30 ms), daemon.py plain, --far (the Find: 0 mispredicted), --games, --window-clients, --upgrade both ways against merge31, addon-test 5/5; gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch); frames 77/77, perfab +0.051%, the 121 counts within 0.1% against tree2 (key-down on medium 10,039,587, render on medium 11,454,498: the extra load an entry is inside the noise) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/tape.zig | 47 ++++++++++++++--------------------------- test/daemon.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/panes.zig | 4 ++++ 3 files changed, 86 insertions(+), 31 deletions(-) (limited to 'core/tape.zig') diff --git a/core/tape.zig b/core/tape.zig index ddfaa4b1..1c9368d0 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -411,7 +411,7 @@ pub const Tape = struct { if (!t.host_side) return .{}; t.host_side = false; t.depth += 1; - if (t.replay) return .{ .outer = true }; + if (t.replay) return .{ .tape = t }; if (p) |core| { if (t.core == null) t.core = core; t.noteWrites(); @@ -423,7 +423,7 @@ pub const Tape = struct { bare.update.args[0].output.bytes = &.{}; t.record(.input, Input, &bare); } else t.record(.input, Input, input); - return .{ .outer = true }; + return .{ .tape = t }; } fn leaveInput(t: *Tape, p: ?*Pardes) void { @@ -1023,37 +1023,22 @@ fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []cons return said.items; } -/// A call into the core: the host's, and recorded, or the core's own. -pub const Entered = struct { outer: bool = false }; +/// A call into the core: the host's, and recorded, or the core's own. The +/// tape it entered (null: the core's own, or nobody records), so `leave` +/// needs neither the global nor a core `init` did not make or `deinit` freed. +pub const Entered = struct { tape: ?*Tape = null }; pub inline fn enter(p: ?*Pardes, input: Input) Entered { - // A core's tape is the one `on` says while both are (P20: the global - // goes at the last step): every entry a safe build makes checks it. - // With none on, a client's core is entered between its steps (its own - // frame drawn, Replica.draw), its tape idle. - // - // The idle tape, the rule for the step that has this read the field - // (P20's last): a client's tape between its steps is neither replaying - // nor speculating, and its core is entered all the same (its frame); - // `enter` must not record into an idle replica's tape. Only a tape - // stepping its core records. The test "a client's frame drawn between - // its steps records nothing into its idle tape" (this file's end) - // fails when it does. - if (std.debug.runtime_safety) if (p) |core| if (if (on) |t| core.tape != t else core.tape.stepping()) + // While the global is (P20: the terminal's questions read it), a core + // stepped is the one it says: every entry a safe build makes checks it. + if (std.debug.runtime_safety) if (p) |core| if (on) |was| if (core.tape != was) @panic("tape: a core's field is not the tape being stepped (tape.on)"); - // The rule the field is read by next (9b), checked beside `on` first. - // Where they disagree (9b-0's list, both the rule's to keep): a - // client's core freed (Replica.deinit, inside a Stepping scope: `on` - // records its `deinit` into a buffer let go at once; the rule records - // nothing), and a test that drives an authority's core outside a - // Stepping scope (no `on`: unrecorded; the rule records it, as a real - // session's every entry is). - if (std.debug.runtime_safety) { - const t = tapeOf(p, &input); - const listed = if (on != null) input == .deinit and t.replica else !t.replica; - if (records(t) != (on != null) and !listed) @panic("tape: the idle rule and tape.on disagree"); - } - const t = on orelse return .{}; + const t = tapeOf(p, &input); + // A client's tape between its steps records nothing (its frame drawn, + // its core freed: the test "a client's frame drawn between its steps + // records nothing into its idle tape"); an authority's records every + // entry, in a Stepping scope or not, as a real session's. + if (!records(t)) return .{}; return t.enterInput(p, &input); } @@ -1076,7 +1061,7 @@ fn records(t: *const Tape) bool { } pub inline fn leave(p: ?*Pardes, e: Entered) void { - if (e.outer) on.?.leaveInput(p); + if (e.tape) |t| t.leaveInput(p); } // The entry points on `on`, the methods' (`Tape.site` and the rest). diff --git a/test/daemon.py b/test/daemon.py index 887e6d0d..52c7d1e6 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -1493,6 +1493,70 @@ def far_find(binary): shutil.rmtree(root, ignore_errors=True) +def restore_client(binary): + """A Restore while a client is attached: the client is let go (its link + ends), the replacement core is the session's (its tape adopts it, its + options keep none), and a client attached after agrees with it, its + keys reaching it.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch)) + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(300))) + started, terms = [], [] + try: + sess = subprocess.Popen([binary, '--detach=back', str(notes)], env=env, cwd=root, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) + started.append(sess.pid) + wait_for('the replica socket', (root / 'pardes-replica.sock').exists) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-back.sock').exists) + nine = Client(root / 'pardes-9p-back.sock') + text = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + def client(name): + t = Term(30, 100) + terms.append(t) + c = t.spawn([binary, f'--attach={root / "pardes-replica.sock"}:back'], + dict(env, PARDES_REPLICA_CHECK=str(root / f'{name}.check'))) + started.append(c.pid) + wait_for(f'client {name}\'s first frame', lambda: b'line 3 of the notes' in t.text(), timeout=30) + time.sleep(.3) + return t, c + t, c = client('a') + nine.write(f'/pane/{text}/exec', b'Dump\n') + nine.write(f'/pane/{text}/exec', b'Restore\n') + wait_for('client a let go at the Restore', lambda: c.poll() is not None, timeout=30) + # The 9P link was the old core's. + nine.socket.close() + nine = reconnect(root / 'pardes-9p-back.sock') + text = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + t, c = client('r') + os.write(t.master, b'Oafter the restore\x1b') + texts = lambda: b''.join(nine.read(f'/pane/{row.split()[0].decode()}/body') for row in nine.read('/index').splitlines() + if row.split()[1] == b'text') + wait_for('the client\'s keys in the restored session', lambda: b'after the restore' in texts(), timeout=30) + seen = len(checks(root / 'r.check')) + wait_for('the client agrees once quiet', lambda: agreed(root / 'r.check', seen), timeout=60) + assert c.poll() is None, 'the client ended' + print(f'daemon: a Restore with a client attached: it was let go, and one attached after agreed ({len(checks(root / "r.check"))} checks), its keys in the restored session') + exit_session(nine, text) + sess.wait(timeout=60) + nine.socket.close() + finally: + for term in terms: + term.close() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + def far_joins(sock, session, binary, n): """`n` far joins of one session in a row, each read whole (its blobs asked for by none, its zstd frames unpacked) and answering a ping, then @@ -2309,6 +2373,8 @@ if __name__ == '__main__': far_find(sys.argv[2]) elif sys.argv[1:2] == ['--far-find']: far_find(sys.argv[2]) + elif sys.argv[1:2] == ['--restore']: + restore_client(sys.argv[2]) elif sys.argv[1:2] == ['--window-clients']: window_clients(sys.argv[2], sys.argv[3]) pdf_window(sys.argv[2], sys.argv[3]) diff --git a/test/panes.zig b/test/panes.zig index dbdbec2f..f4061590 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -3961,6 +3961,10 @@ const PdfAddon = struct { } }; const id = try opened(a, Land{ .a = a, .r = r }); + // The effects `jobs` took last are the session's steps: a unit of + // its own before the client's input. + a.seq += 1; + r.confirm(try a.unit(0, a.seq)); const guessed = r.stats.mispredicted; const stopped = r.stats.stopped; const told = a.core.panes[id].?.addon.?.views; -- cgit v1.3 From 579763e3aaca684ef638d621fe1b427ae96743df Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 12:01:49 -0300 Subject: tape: a session's tape is handed in by whoever starts it, step 9c (reports/pardes-handle-69-design.md section 3.4, P33's lean 5): PARDES_RECORD is read by the starter (tape.fromEnv, the old startFromEnv returning the tape: runtime/session.zig's start, one line, and the Mac's, one line) and handed in Options.tape, so Pardes.init and dump.initFromDump no longer start a tape and Pardes.create takes its options' tape or none, never the global; current, forget and adopt are the field's (deinit and restoreInner call p.tape's; the three free ones are deleted); restoreInner loads the replacement on the session's own tape and does not leave it in the replacement's kept options (a session with clients has its tape from no options, and Peers.stop puts the options' back); Authority.init hands its tape in the options; the in-process runner (test/session.zig) keeps the tape recordTape starts and hands it to each session it makes; the global is still set beside a recording tape (fromEnv, recordTape, Stepping, Peers) while the terminal's questions read it: after this change those are its only readers, 18 calls in 12 functions (core/panes.zig scrollBy, feedOutput, followRows, the positions value, feedLost, followOutput, resizeGrid x4, reloadTerminals x3, emulatorGpa; core/term Term.digest, Term.media; core/edit.zig shellRows; core/ninep/pty.zig finish's prompt value), besides Stepping, Peers and enter's safe-build check; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7 agree); a real session still records from its first call (process-test --replay 0 of 102 failed, behaviour-test --replay 275/275); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275, process-test 1 of 144 (delask, passes alone), both soaks diverged 0 unequal 0 corpus 22 of 22 (bytes: the base's one now stop at 30 ms), daemon.py plain, --far (the Find: 0 mispredicted), --games, --window-clients, --restore (a Restore with a client attached), --upgrade both ways against merge31 (both failed once at the Adopt race in the chain and pass alone), addon-test 5/5; the macOS library (x86_64, aarch64) and FreeBSD build; gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 15 +++++++-------- core/dump.zig | 7 +++++-- core/replica.zig | 1 + core/tape.zig | 38 +++++++++++++------------------------- runtime/macos.zig | 1 + runtime/session.zig | 1 + test/session.zig | 15 ++++++++++----- 7 files changed, 38 insertions(+), 40 deletions(-) (limited to 'core/tape.zig') diff --git a/core/Core.zig b/core/Core.zig index e2f8cd8a..a92d35ae 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -528,9 +528,9 @@ pub const perform = @import("Effect.zig").perform; /// second copy of this drifted once, leaving restored tags without an /// allocator and every 9P mtime 0. pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { - // The global still set beside the field (P20): a core made while - // a tape records (PARDES_RECORD, a replica's step) is its. - const tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none; + // Its options' (a recording session's, an authority's, a replay's), or + // the one nobody records. + const tape = opts.tape orelse &pardes.tape.none; const p = try gpa.create(Pardes); p.* = .{ .gpa = gpa, @@ -561,10 +561,9 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { return p; } -/// A new session, its tape written from here when PARDES_RECORD asks. +/// A new session, recorded from here on its options' tape. pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { // By hand, not `taped`: no core yet to enter on; the tape adopts the one made. - pardes.tape.startFromEnv(); const taped = pardes.tape.enter(null, .{ .init = opts }); // The tape adopts the core made, none on a failure. var made: ?*Pardes = null; @@ -821,8 +820,8 @@ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry { pub fn deinit(p: *Pardes) void { // By hand, not `taped`: what it records is no argument (`current`), and it leaves on no core. - const taped = pardes.tape.enter(p, .{ .deinit = pardes.tape.current(p) }); - pardes.tape.forget(p); + const taped = pardes.tape.enter(p, .{ .deinit = p.tape.current(p) }); + p.tape.forget(p); defer pardes.tape.leave(null, taped); if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path)); // Every file open now is closed with its dot, and the list kept. @@ -2290,7 +2289,7 @@ pub const Options = struct { /// A client's: the kinds it caught breaking PA_PLAIN, its frontend's /// list, which outlives each core it joins with. In no tape and no dump. distrusted: ?*pardes.Addon.Distrusted = null, - /// The core's tape (`Pardes.tape`); null: `tape.on`'s, or `tape.none`. + /// The core's tape (`Pardes.tape`); null: `tape.none`. tape: ?*pardes.tape.Tape = null, /// What the host's scan of the addon directories found (Addon.scan). addons: []const pardes.Kind.Loaded = &.{}, diff --git a/core/dump.zig b/core/dump.zig index eb0ef263..3d248010 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -532,17 +532,20 @@ fn restoreInner(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes { var opts = p.opts; opts.cols = p.view().screen_w; opts.rows = p.view().screen_h; + // Loaded on the session's tape (one with clients has it from no + // options), which the replacement's options do not keep. + opts.tape = p.tape; const replacement = try loadAndRevive(p.gpa, opts, bytes, p, null); + replacement.opts.tape = p.opts.tape; replacement.pointRestoreAt(from); // The tape follows the replacement from here (it is the session). - pardes.tape.adopt(replacement); + p.tape.adopt(replacement); pardes.ctlfs.events.notePath(replacement, "restore", from); return replacement; } pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, bytes: []const u8) !*Pardes { // By hand, not `taped`: no core yet to enter on, as `Pardes.init`. - pardes.tape.startFromEnv(); const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = bytes } }); // The tape adopts the core made, none on a failure. var made: ?*Pardes = null; diff --git a/core/replica.zig b/core/replica.zig index 31e16f46..14f441b3 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -182,6 +182,7 @@ pub const Authority = struct { a.t.whole_digest = screens and std.c.getenv("PARDES_REPLICA_TRACE") == null; // A digest at a unit's end, as the session's (Peers.unit). a.t.no_digest = true; + opts.tape = &a.t; const was = Stepping.begin(&a.t, null); defer was.end(); a.core = try Pardes.init(gpa, opts); diff --git a/core/tape.zig b/core/tape.zig index 1c9368d0..34c9f1da 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1043,7 +1043,7 @@ pub inline fn enter(p: ?*Pardes, input: Input) Entered { } /// The tape an entry steps: its core's; for a session not made yet, the one -/// its options name, or the one `Pardes.create` takes. +/// its options name (`Pardes.create`'s). fn tapeOf(p: ?*Pardes, input: *const Input) *Tape { if (p) |core| return core.tape; const opts = switch (input.*) { @@ -1051,7 +1051,7 @@ fn tapeOf(p: ?*Pardes, input: *const Input) *Tape { .init_from_dump => |d| d.opts, else => return &none, }; - return opts.tape orelse on orelse &none; + return opts.tape orelse &none; } /// Whether an entry on `t` is recorded: not on the tape nobody records, nor @@ -1064,20 +1064,6 @@ pub inline fn leave(p: ?*Pardes, e: Entered) void { if (e.tape) |t| t.leaveInput(p); } -// The entry points on `on`, the methods' (`Tape.site` and the rest). - -pub fn adopt(p: *Pardes) void { - (on orelse &none).adopt(p); -} - -pub fn current(p: *const Pardes) bool { - return (on orelse &none).current(p); -} - -pub fn forget(p: *Pardes) void { - (on orelse &none).forget(p); -} - /// An entry written once (P22): its public name made from the private /// body directly under it, `pub const setCwd = pardes.tape.taped(setCwdInner);`. /// The same parameters; the call recorded as the variant of `Input` whose @@ -1593,19 +1579,21 @@ pub fn digestOf(p: *const Pardes) u64 { return walk.digest(Pardes, p); } -/// PARDES_RECORD set: the tape is written from the session's first call. -pub fn startFromEnv() void { - if (on != null) return; - const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return); - if (prefix.len == 0) return; +/// PARDES_RECORD set: the tape a session is written to from its first +/// call, which whoever starts it hands in `Options.tape` (runtime/session.zig, +/// the Mac's start). `on` too, while the terminal's questions read it (P20). +pub fn fromEnv() ?*Tape { + const prefix = std.mem.span(libc.getenv("PARDES_RECORD") orelse return null); + if (prefix.len == 0) return null; const gpa = std.heap.c_allocator; var path_buf: [4096]u8 = undefined; - const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return; + const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{d}.tape", .{ prefix, libc.getpid() }, 0) catch return null; const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true, .CLOEXEC = true }, @as(libc.mode_t, 0o644)); - if (fd < 0) return; - const t = gpa.create(Tape) catch return; + if (fd < 0) return null; + const t = gpa.create(Tape) catch return null; t.* = .{ .gpa = gpa, .replay = false, .fd = fd, .scratch = .init(gpa), .arena = .init(gpa), .every = libc.getenv("PARDES_RECORD_EVERY") != null }; on = t; + return t; } /// `PARDES_REPLAY=`: the tape replayed into three replicas, each @@ -1704,7 +1692,7 @@ test "a replay that finds no answer where its core reads one diverges, and the r /// The functions of core/ that set `on` and leave a core's field be, each /// with why the field is that tape already. const sets_on_alone = [_]struct { []const u8, []const u8, []const u8 }{ - .{ "tape.zig", "startFromEnv", "no core yet: the one made next takes `on` (Pardes.create)" }, + .{ "tape.zig", "fromEnv", "no core yet: its starter hands the tape in Options.tape" }, .{ "tape.zig", "replayBytes", "its replay's core is made with this tape in its options (apply)" }, .{ "replica.zig", "begin", "Stepping: the core stepped holds this tape already (adoptCore), which `enter` checks in a safe build" }, .{ "replica.zig", "end", "Stepping: `on` put back as `begin` found it" }, diff --git a/runtime/macos.zig b/runtime/macos.zig index cfe93b13..4f9a9c33 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -348,6 +348,7 @@ fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void { pardes.syntax.start(allocs.tree_sitter); errdefer pardes.syntax.stop(); + opts.tape = pardes.tape.fromEnv(); const core = try pardes.Pardes.init(allocs.pardes, opts); errdefer core.deinit(); // The workspace tag row is the macOS menu bar's business here (see diff --git a/runtime/session.zig b/runtime/session.zig index fdd72c2b..b1558d9f 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -75,6 +75,7 @@ pub fn Loop(comptime Frontend: type) type { o.tree_sitter_allocator = l.allocs.tree_sitter; o.frame_allocator = l.allocs.frame; fe.options(&o); + o.tape = pardes.tape.fromEnv(); l.core = if (upgrade.resumed) |*rec| try upgrade.load(l.gpa, l.allocs.pardes, o, rec) else if (o.load_path) |lp| blk: { diff --git a/test/session.zig b/test/session.zig index 1cbee9df..d437ecf2 100644 --- a/test/session.zig +++ b/test/session.zig @@ -53,7 +53,7 @@ pub const Session = struct { /// A session showing one file pane holding `text`, keeping what outlives /// it in a database in memory (core/Db.zig). pub fn initFile(gpa: std.mem.Allocator, text: []const u8) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording }); errdefer p.deinit(); _ = try p.setTestFile(text); var s: Session = .{ .core = p, .arena = .init(gpa) }; @@ -75,7 +75,7 @@ pub const Session = struct { /// A session showing one file pane, its startup file `init` (as /// `~/.config/pardes/init` is read) applied first. pub fn initStartup(gpa: std.mem.Allocator, init: []const u8) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .startup_config = init, .tape = recording }); errdefer p.deinit(); _ = try p.setTestFile("x\n"); var s: Session = .{ .core = p, .arena = .init(gpa) }; @@ -85,7 +85,7 @@ pub const Session = struct { /// A session showing its terminal pane, as `pardes` starts. pub fn initTerm(gpa: std.mem.Allocator) !Session { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .tape = recording }); var s: Session = .{ .core = p, .arena = .init(gpa) }; s.drain(); return s; @@ -99,7 +99,7 @@ pub const Session = struct { var arena: std.heap.ArenaAllocator = .init(gpa); errdefer arena.deinit(); const config = try std.fmt.allocPrint(arena.allocator(), "DumpDir {s}\n", .{dir}); - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = config, .tape = recording }); var s: Session = .{ .core = p, .arena = arena }; s.drain(); return s; @@ -206,12 +206,16 @@ pub const Session = struct { s.drain(); } + /// The tape `recordTape` started: every session made after it records on it. + var recording: ?*pardes.tape.Tape = null; + /// Every session started from here on records what it consumes as a /// tape in memory, as PARDES_RECORD has a real one record it /// (core/tape.zig); `replayTape` replays it once the session is gone. pub fn recordTape(gpa: std.mem.Allocator) !void { const t = try gpa.create(pardes.tape.Tape); t.* = pardes.tape.memory(gpa); + recording = t; pardes.tape.on = t; } @@ -221,7 +225,8 @@ pub const Session = struct { /// its end loaded to its digest and dumped to its bytes again. False /// when a replica diverged (said on stderr). After `deinit`. pub fn replayTape(gpa: std.mem.Allocator) bool { - const t = pardes.tape.on orelse return true; + const t = recording orelse return true; + recording = null; pardes.tape.on = null; defer { pardes.tape.release(t); -- cgit v1.3