From 0ad6da7f9bf22136694e6015c93ccaf81dc12380 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 09:16:07 -0300 Subject: replica: a view kept for a client's rejoin is let go after its 30 s in a session nobody types in, and a join refused meanwhile is told for how long: a wake by mail alone (a join, a client's input) moves no time (tui.zig `clockNow`), so in an idle session with a client in it the core's clock stood where it last moved and Core.openView judged the kept views by it forever (test/daemon.py `kept_views`, new, in plain mode: at the four views, two raw replicas leave saying they join again, and a join 31 s later, nothing typed, was refused on pardes-merge50); Peers.join now moves the clock (`advance` with the host's `now`, on the tape) when no view is free, before the views are judged, and its refusal says "(one is kept N s more for a client joining again)" while one is kept; test/daemon.py `upgrades`, from a build that keeps views with their time (`keeps_views`: `away_ns` in its binary), waits as long as the first join's refusal says, saying so, for the two views kept for clients that never return (the raw replica and the old build's client, refused by the daemon for its build); kept_views passes; `--upgrade` between this tree's Debug and ReleaseSafe builds 3 of 3 each way (each says "the join waited 30 s"), from the installed build 3 of 3 (it keeps no time: its views load already expired); the soak (--clients 5) diverged 0, unequal 0; core-test 893/1053 (160 skipped), shell-test 1095/1098 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'test/daemon.py') diff --git a/test/daemon.py b/test/daemon.py index 5c075520..1be89d5b 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -978,6 +978,65 @@ def attach_upgrading(binary, rounds=6, dump=True): shutil.rmtree(root, ignore_errors=True) +def kept_views(binary): + """A view kept for its client's rejoin (views.away: a bye that says it + joins again, a client cut off behind, every client at an Upgrade) is + that client's for 30 s, then a join with no room takes it, in a session + nobody types in: a `new --detach` session at its four views (a client + attached, idle; raw replicas), two of them leaving to join again and + never coming back; a join at once is refused and told for how long, one + 31 s later, nothing typed in between, is welcomed.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rk-', 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'), + 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') + t = Term(30, 100) + rs = [] + try: + out = subprocess.run([binary, 'new', '--detach=kv'], env=env, cwd=root, capture_output=True, timeout=30, stdin=subprocess.DEVNULL) + assert out.returncode == 0, out + a = t.spawn([binary, 'attach', 'kv'], env) + wait_for('the client drawn', lambda: b'\x1b[?1049h' in t.text(), timeout=30) + sock, build = root / 'pardes-replica.sock', semantics(binary) + while True: + r = Replica(sock) + said = r.hello('kv', build) + if said[0] != 'welcome': + break + rs.append(r) + assert said[0] == 'refused' and 'as many views' in said[1] and len(rs) >= 2, (said, len(rs)) + for r in rs[:2]: + r.send(0x02, b'\x01') + r.close() + left = time.monotonic() + said = Replica(sock).hello('kv', build) + assert said[0] == 'refused' and re.search(r'as many views as it takes \(one is kept (\d+) s more for a client joining again\)', said[1]), said + print(f'kept views: {len(rs)} replicas and a client at the cap; two left to join again; a join at once refused: "{said[1]}"') + time.sleep(max(0, left + 31 - time.monotonic())) + said = Replica(sock).hello('kv', build) + assert said[0] == 'welcome', ('a view kept 31 s in an idle session, still kept', said) + assert a.poll() is None + print('kept views: a join 31 s after, nothing typed in between, took a kept view') + a.terminate() + a.wait(timeout=20) + assert subprocess.run([binary, 'kill', 'kv'], env=env, capture_output=True, timeout=30).returncode == 0 + wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=20) + finally: + for r in rs: + r.close() + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + t.close() + shutil.rmtree(root, ignore_errors=True) + + def pair_upgrade_views(binary): """PARDES_PAIR, two clients each in its own view (the pair's own terminal and an attach), each with its own scroll and focus: the pair's scrolled @@ -2566,6 +2625,7 @@ def main(binary, cycles): pair(binary) pair_rows(binary) attach_upgrading(binary) + kept_views(binary) pair_upgrade_views(binary) manage(binary) relink(binary) @@ -3159,6 +3219,16 @@ def upgrades(old, new): or b'run the same pardes at both ends' in term2.text())), timeout=30) wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client)) + # Two clients' views kept at the Upgrade, with the time (views.away), + # whose clients never come back (the raw replica, the old build's): + # each its client's for 30 s, and the session's views all taken. + # The first join waits as long as its refusal says. + if keeps_views(old): + said = Replica(root / 'pardes-replica.sock').hello('work', new_build) + kept = re.search(r'one is kept (\d+) s more', said[1]) if said[0] == 'refused' else None + if kept: + time.sleep(int(kept.group(1)) + .5) + print(f'upgrade: two views kept for clients that never came back; the join waited {kept.group(1)} s for one, as its refusal said') # The daemon lists the session under its new build. said = Replica(root / 'pardes-replica.sock').hello('work', new_build) assert said == ('welcome', session, 'work'), said @@ -3298,6 +3368,12 @@ def knows_size(gui_binary): return b'PARDES_JOIN_SIZE' in Path(gui_binary).read_bytes() +def keeps_views(binary): + """Whether a build keeps its clients' views at an Upgrade with the time + each was kept (View.away_ns), so that the build after holds them.""" + return b'away_ns' in Path(binary).read_bytes() + + def knows_exec(binary): """Whether a build's client execs the build at its start path at an Upgrade, for the view it is handed (PARDES_JOIN_VIEW).""" -- cgit v1.3 From 59ba1a8b24aab95cfec9046e042f3a34d5821e47 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 09:35:20 -0300 Subject: test/daemon.py: an adopted shell's `echo $$` is asked once the shell answers (`adopted_pid`, the wait plain mode's own Adopt had): on a ReleaseSafe build of pardes-merge50 `--relink` failed 3 of 10 (`relink` twice, `answer_late` once), each run answered `error not run`, not another pid: the adoption sizes the shell twice (dev/Ptys.zig `take`), it draws its prompt again, and a run sent into a prompt redrawn under it reads as not run (core/ninep/pty.zig `noteMarks`, its ponytail), which a faster build reaches more often; the same wait in `relink`, `answer_late`, `upgrades`' last Adopt and plain mode's; no product change: no output in another pane, a script's run told plainly that it did not run; after: `--relink` on this line's ReleaseSafe build 10 of 10 (loads 1.3-7.0) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'test/daemon.py') diff --git a/test/daemon.py b/test/daemon.py index 1be89d5b..fc03e3cb 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -143,6 +143,16 @@ def run(client, serial, line): client.close(fid) +def adopted_pid(client, pane): + """An adopted shell's `echo $$`, once it answers: sized twice at its + adoption (dev/Ptys.zig `take`), it draws its prompt again, and a run + sent into a prompt redrawn under it reads as not run (core/ninep/pty.zig + `noteMarks`).""" + wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n') + said = run(client, pane, b'echo $$\n') + return said.split(b'\n')[1], said + + # FreeBSD has no /proc: ps and procstat answer instead. procfs = os.path.isdir('/proc/self') @@ -1528,7 +1538,8 @@ def relink(binary): before = set(terminals(own)) own.write(f'/pane/{min(before)}/exec', b'Adopt\n') pane = wait_for('the adopted pane', lambda: set(terminals(own)) - before).pop() - assert run(own, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(own, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'relink: a client attached to the session through the new daemon; killed outright, its shell {shell_pid} was adopted') exit_session(own, pane) stub.wait(timeout=10) @@ -1602,7 +1613,8 @@ def answer_late(binary): two.write(f'/pane/{min(before)}/exec', b'Adopt\n') took = time.monotonic() - asked pane = wait_for('the adopted pane', lambda: set(terminals(two)) - before).pop() - assert run(two, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(two, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'answer late: an Adopt asked while the daemon was stopped waited {took:.1f} s for its answer, ' f'and shell {shell_pid} was adopted') exit_session(two, pane) @@ -2772,11 +2784,8 @@ def main(binary, cycles): client.write(f'/pane/{min(before)}/exec', b'Adopt\n') adopted = wait_for('the adopted pane', lambda: set(terminals(client)) - before) pane = adopted.pop() - # Sized twice (Ptys.take): a run into a prompt redrawn under it - # reads as not run (core/ninep/pty.zig). - wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n') - said = run(client, pane, b'echo $$\n') - assert said.split(b'\n')[1] == str(shell_pid).encode(), said + pid, said = adopted_pid(client, pane) + assert pid == str(shell_pid).encode(), said print(f'daemon: shell {shell_pid} outlived kill -9 of its session and was adopted') # Attached again: a client. (After the runs: a pty/run under a # client puts it off the session's state, and it joins again; one @@ -3342,7 +3351,8 @@ def upgrades(old, new): before = set(terminals(client)) client.write(f'/pane/{min(before)}/exec', b'Adopt\n') pane = wait_for('the adopted pane', lambda: set(terminals(client)) - before).pop() - assert run(client, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(client, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'upgrade: the upgraded daemon kept shell {shell_pid} through kill -9 of its session, and it was adopted') client.write(f'/pane/{pane}/exec', b'Exit\n') stub.wait(timeout=10) -- cgit v1.3 From 5a74a03fece68f6cd53ab2c8fccbd7deea345acb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 10:53:08 -0300 Subject: test/daemon.py: `--upgrade`'s rows say what they need of the old build instead of failing one run in a few: `far_exec` runs only where OLD's far client dials again when an Upgrade cuts its link with no last word (`redials_far`: PARDES_JOIN_SIZE in OLD's binary, the string of the change that brought that redial, pardes-pair-5's; the redial has no string of its own) and is skipped with a line from the installed build, whose far client took the cut for its session's end one run in five; `pair_exec_reaps` takes its mark before the Upgrade and waits for the blink (its screen left and entered again, the notes drawn after), as `far_exec` does: the mark taken after the client was seen on the new build missed a frame it had drawn by then (from the installed build 2 of 5 runs failed "drawn again" on pardes-merge50's release build and 2 of 5 on this line's, the same before the fix); after: far_exec 5 of 5 between this tree's Debug and ReleaseSafe builds, pair_exec_reaps from the installed build 6 of 6, `--upgrade` from it 3 of 3 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'test/daemon.py') diff --git a/test/daemon.py b/test/daemon.py index fc03e3cb..f4836a43 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -1186,14 +1186,17 @@ def pair_exec_reaps(old, new): wait_for('drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) install(new, binary) ino = sock.stat().st_ino + # Before the Upgrade: the exec'd client can draw before its exec is seen. + mark = len(t.text()) nine.write('/ctl', b'Upgrade\n') nine.socket.close() wait_for('the session exec\'d', lambda: sock.stat().st_ino != ino, timeout=60) wait_for('the client on the new build', lambda: exe_of(c.pid) == (str(binary), True), timeout=30) nine = reconnect(sock) assert ppid(session) == c.pid - mark = len(t.text()) - wait_for('drawn again', lambda: b'line 3 of the notes' in t.text()[mark:], timeout=30) + # The blink: its screen left and entered again, the notes drawn there. + wait_for('drawn again', lambda: (lambda x: x.rfind(b'\x1b[?1049h') > x.rfind(b'\x1b[?1049l') > mark + and b'line 3 of the notes' in x[x.rfind(b'\x1b[?1049h'):])(t.text()), timeout=30) nine.write('/ctl', b'Exit\n') nine.socket.close() assert c.wait(timeout=30) == 0, c.returncode @@ -3384,6 +3387,14 @@ def keeps_views(binary): return b'away_ns' in Path(binary).read_bytes() +def redials_far(binary): + """Whether a build's far client whose link an Upgrade cuts with no last + word dials again (core/replica.zig `cutListed`'s `far`) rather than take + it for its session's end: the change that made it gave the window its + size at its exec too (PARDES_JOIN_SIZE), the string that says so.""" + return b'PARDES_JOIN_SIZE' in Path(binary).read_bytes() + + def knows_exec(binary): """Whether a build's client execs the build at its start path at an Upgrade, for the view it is handed (PARDES_JOIN_VIEW).""" @@ -3609,7 +3620,10 @@ if __name__ == '__main__': upgrades(old, new) if knows_exec(old): pair_exec_reaps(old, new) - far_exec(old, new) + if redials_far(old): + far_exec(old, new) + else: + print('far exec: skipped: the old build\'s far client, cut at the Upgrade with no last word, takes it for its session\'s end (no PARDES_JOIN_SIZE)') # With a pardes-gui beside each: the clients carried too. if all(a.with_name('pardes-gui').exists() for a in (old, new)): upgrade_clients(old, new) -- cgit v1.3 From aefdb402b577c270111e2736e175611def0833e7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 17:47:24 -0300 Subject: tests: a plain client watching a kitty image in a terminal under screen state joins again for ever, caught twice: core/replica.zig "a terminal's program shows a kitty image under screen state: the client's emulator never has it, and its tag says what the session's does" (an Authority and a Replica, the image fed in the session's order, a step after: the digests part in pane 0.tag, pane 0.tag_lead and pane 1.cwd, the last an inherited cwd that walks to the terminal's pane; `partsApart` names them) and test/daemon.py `kitty_image` (plain mode's list, alone `--kitty-image`: a detached session, a plain attach, the corpus scene 10's 8x8 RGB image printed in its shell, the client's joins counted over 5 s, 0 expected: on this base's Debug build 16 joins, 16 of 16 checks differ; on the installed build (6d937cd125ca) the same 16, 3.2 a second, session 20-30 ms and client 50-70 ms of CPU, 80 KB to the client's terminal); shell-test 1100/1104 with this test the one failure, core-test 898/1059 (161 skipped: it needs a shell) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 51 ++++++++++++++++++++++++++++++++++++++ test/daemon.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) (limited to 'test/daemon.py') diff --git a/core/replica.zig b/core/replica.zig index 10eba502..49ae4594 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6436,6 +6436,57 @@ test "a closed terminal with a kitty image brought back on a client: its image d try agrees(a, r); } +/// The core's fields whose digests differ between the session and a +/// client, named (tape.partsDiffer); empty when they agree. +fn partsApart(a: *Authority, r: *Replica, arena: std.mem.Allocator) ![]const u8 { + const want = try arena.create(tape.Parts); + const got = try arena.create(tape.Parts); + const w = digested: { + const was = Stepping.begin(&a.t, null); + defer was.end(); + break :digested tape.digestParts(a.core, want); + }; + const g = digested: { + const was = Stepping.begin(&r.t, &r.epoch); + defer was.end(); + break :digested tape.digestParts(r.core(), got); + }; + return if (std.mem.eql(u64, w, g)) "" else tape.partsDiffer(g, w, arena); +} + +test "a terminal's program shows a kitty image under screen state: the client's emulator never has it, and its tag says what the session's does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); + defer a.deinit(); + var screens: Screens = .init(gpa); + defer screens.deinit(a.core); + const peer = try screens.addPeer(); + const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + defer r.deinit(); + const shell: u8 = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break @intCast(id); + } else return error.NoShell; + try deliver(a, &screens, peer, r, .flush); + try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); + // In the session's order: the pump's unit, then what its terminals came + // to; then a step after both, on every side. + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); + r.confirm((try a.pending()).?); + r.settle(); + try deliver(a, &screens, peer, r, .flush); + r.confirm(try a.local(.{ .focus = true })); + r.settle(); + try std.testing.expect(pardes.Term.hasImages(a.core.panes[shell].?.terminal)); + try std.testing.expect(!pardes.Term.hasImages(r.core().panes[shell].?.terminal)); + try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); + try agrees(a, r); + const prefix = try pardes.tagline.prefixIn(r.core(), arena.allocator(), r.core().panes[shell].?); + try std.testing.expect(std.mem.indexOf(u8, prefix, " petscii:") != null); +} + test "a far client's own Del of a pane whose kind's state is not plain, rolled back by another's unit: the pane comes back whole, and is closed again with the session's order" { const gpa = std.testing.allocator; const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); diff --git a/test/daemon.py b/test/daemon.py index c6ff6256..e1be141a 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -38,6 +38,8 @@ private HOME and runtime directory: python3 -B test/daemon.py --far the far clients and their blob cache alone, one under `yes` across a slow link, and a file by its hash + python3 -B test/daemon.py --kitty-image + a plain client watching a kitty image in its session's terminal python3 -B test/daemon.py --games [seconds] the games in the clients that show them, from zig build addon-test's /lib (libsnake, liblife, libliar) @@ -2608,6 +2610,76 @@ def terminals(client): return [int(row.split()[0]) for row in client.read('/index').splitlines() if row.split()[1] == b'term'] +def cpu_ticks(pid): + stat = open(f'/proc/{pid}/stat').read().rsplit(')', 1)[1].split() + return int(stat[11]) + int(stat[12]) + + +def kitty_image(binary, secs=5): + """A plain attach (screen state) watching a terminal in which a program + shows a kitty image (the corpus's scene 10's: 8x8 RGB, 10x4 cells): it + agrees with its session and does not join again (it joined again ~3.3 + times a second: the tag said ` petscii:on` on the session's side only).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='ri-', 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'), + 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') + rgb = bytes((x * 30) % 256 for x in range(8 * 8 * 3)) + (root / 'kitty.sh').write_text("printf '\\033_Ga=T,f=24,s=8,v=8,c=10,r=4;%s\\033\\\\'\nprintf '\\nKITTY\\n'\n" + % __import__('base64').b64encode(rgb).decode()) + started, terms = [], [] + try: + term = Term() + terms.append(term) + stub = term.spawn([binary, '--tty', '--9p=img'], env) + started.append(stub.pid) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-img.sock').exists) + nine = Client(root / 'pardes-9p-img.sock') + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + started.append(session) + shell = terminals(nine)[0] + nine.write(f'/pane/{shell}/exec', b'Detach\n') + assert stub.wait(timeout=10) == 0, stub.returncode + t = Term(30, 100) + terms.append(t) + c = t.spawn([binary, 'attach', 'img'], dict(env, PARDES_REPLICA_CHECK=str(root / 'c.check'))) + started.append(c.pid) + wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in t.text(), timeout=30) + wait_for('the client agrees', lambda: agreed(root / 'c.check', 0), timeout=30) + nine.write(f'/pane/{shell}/pty/data', f'clear; sh {root}/kitty.sh\r'.encode()) + wait_for('KITTY in the session\'s body', lambda: b'KITTY' in nine.read(f'/pane/{shell}/body'), timeout=30) + wait_for('KITTY in the client\'s terminal', lambda: b'KITTY' in t.text(), timeout=30) + mark, seen = len(t.text()), len(checks(root / 'c.check')) + cpu = (cpu_ticks(session), cpu_ticks(c.pid)) + time.sleep(secs) + cpu = [(cpu_ticks(p) - was) * 1000 // os.sysconf('SC_CLK_TCK') for p, was in zip((session, c.pid), cpu)] + again = t.text()[mark:].count(b'joined again') + said = checks(root / 'c.check')[seen:] + tag = nine.read(f'/pane/{shell}/tag') + print(f'kitty image: over {secs} s the client joined again {again} times ({again / secs:.1f}/s), its checks ' + f'{len(said)} ({sum(s.startswith("differ") for s in said)} differ), CPU ms session {cpu[0]} client {cpu[1]}, ' + f'{len(t.text()) - mark} bytes to its terminal; the session\'s tag {tag[:60]!r}') + assert again == 0 and c.poll() is None, (again, said[-3:]) + assert agreed(root / 'c.check', seen), said + exit_session(nine, shell) + nine.socket.close() + wait_for('the client ended with its session', lambda: c.poll() is not None, timeout=20) + print('kitty image: a plain client watching a kitty image agreed and never joined again') + finally: + for t in terms: + t.close() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + def main(binary, cycles): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) @@ -2648,6 +2720,7 @@ def main(binary, cycles): manage(binary) relink(binary) answer_late(binary) + kitty_image(binary) shell = terminals(client)[0] shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1]) started.append(shell_pid) @@ -3662,6 +3735,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] == ['--kitty-image']: + kitty_image(sys.argv[2]) elif sys.argv[1:2] == ['--restore']: restore_client(sys.argv[2]) elif sys.argv[1:2] == ['--window-clients']: -- cgit v1.3 From 0000e169c52da6d77e9cf3538896d7202d0a313b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 17:47:24 -0300 Subject: a terminal showing a kitty image no longer parts a screen-state client from its session: whether the terminal holds an image is the session's fact, `Pane.term_images`, set at its output's step (core/Core.zig `.output`: taped under screen state, tape site `images`, the session's answer replayed on every client, whose emulator is fed cells and never has the image; read directly otherwise, every side fed the same bytes) and read by the tag (core/tagline.zig, for `Term.hasImages` of each side's own emulator, whose ` petscii:on|off` made the digested `tag_lead` longer on the session's side only: every quiet check differed and a plain attach joined again 3.2 times a second for as long as the image was there, the installed build too); taped and not a bit beside the cells because the step that computes the tag is the output's own unit, which a client replays before that pump's flush reaches it; wire 28 (a pane's new field in the join's dump and the digest, the tape's new site; test/daemon.py `WIRE`); daemon.py `--kitty-image` on Debug: 0 joins in 5 s, 3 of 3 (16 before); core-test 898/1060 (162 skipped), shell-test 1102/1105 (3 skipped), term-test 18/18, kitty-test 45/45 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 6 +++++- core/Core.zig | 1 + core/panes.zig | 5 +++++ core/tagline.zig | 2 +- core/tape.zig | 3 +++ test/daemon.py | 2 +- 6 files changed, 16 insertions(+), 3 deletions(-) (limited to 'test/daemon.py') diff --git a/abi/wire.zig b/abi/wire.zig index 88a82e52..d7df7bc3 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -10,6 +10,10 @@ const pardes = @import("core"); const config = @import("pardes_options"); const build_info = @import("build_info"); +/// 28: whether a terminal holds a kitty image is the session's, taped +/// after its output (tape site `images`), and a pane's (Pane.term_images) +/// in its join's dump and its digest: a screen-state client's tag says +/// what the session's does; /// 27: a pair's first client makes its own core from the session's /// options and says its digest (`boot`) before its `far`: the session sends /// no dump when its own at the join has the same; @@ -46,7 +50,7 @@ const build_info = @import("build_info"); /// part B); 14: the hello names a session and /// carries the semantics hash, and a ping is answered (phase 5's /// groundwork); 13: the frames went (phase 3). -pub const version: u16 = 27; +pub const version: u16 = 28; /// The terminal's build and the window's step alike (`semantics`). const family = switch (config.platform) { diff --git a/core/Core.zig b/core/Core.zig index 177a6e78..73d0738a 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1684,6 +1684,7 @@ fn updateInner(p: *Pardes, ev: Event) void { pane.shell_spoke = true; ctlfs.events.notePtyOutput(p, o.pane.index(), o.bytes); pane.feedOutput(p, o.bytes); + pane.term_images = if (p.tape.screen_state) p.tape.value(.images, pardes.Term.hasImages, .{pane.terminal}) else pardes.Term.hasImages(pane.terminal); ctlfs.pty.noteMarks(p, o.pane.index(), pane); exec.flushReplEnter(p, o.pane.index(), true); }, diff --git a/core/panes.zig b/core/panes.zig index 8b152132..2f561d05 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -134,6 +134,11 @@ pub const Pane = struct { /// cell), and its kitty graphics drawn as glyph art (Petscii). term_mouse: ?Term.Coordinate = null, term_petscii: bool = false, + /// Whether its terminal holds a kitty image, as the session's emulator + /// said after its program's last output (taped under screen state: a + /// client's emulator is fed the session's cells, never an image). Its + /// tag says so (tagline.zig), on every side. + term_images: bool = false, gpa: std.mem.Allocator, serial: u32 = 0, /// What the control filesystem keeps of this pane -- addr and limit, the diff --git a/core/tagline.zig b/core/tagline.zig index afee0659..26f83fba 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -160,7 +160,7 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co if (pane.terminal != null) { const chosen = pane.term_petscii; const on = chosen or !p.view().frontend.native_images; - if (chosen or panes.Term.hasImages(pane.terminal)) + if (chosen or pane.term_images) return std.fmt.allocPrint(arena, "{s} petscii:{s}", .{ (try shownDir(arena, pane)), if (on) "on" else "off" }); } return (try shownDir(arena, pane)); diff --git a/core/tape.zig b/core/tape.zig index d32f8dd8..f231831d 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -140,6 +140,9 @@ pub const Site = enum(u16) { /// A kitty image's medium as a terminal's emulator read it (a file, a /// temporary file, shared memory: Term.media), its bytes or its failure. medium, + /// Whether a terminal holds a kitty image after its program's output + /// (Pane.term_images): a screen-state replica's emulator never has one. + images, }; /// What the sites return. wire.semantics hashes their shape with the diff --git a/test/daemon.py b/test/daemon.py index e1be141a..e334b6e8 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -258,7 +258,7 @@ class Replica: """A replica's connection (abi/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 27 + WIRE = 28 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout -- cgit v1.3