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(-) 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