From 7753126756dd6a8dc371fa200e6ba84b3c0eb6f2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 10:21:51 -0300 Subject: remote client: a write to the session that fails is its hangup (a client cut off as it lags said nothing and exited 0 when its own write found the link shut before its reader did); a window client's frame is marked rendered as it presents, so the live harness reads its render as its core's time; test/daemon.py's window clients: one far (PARDES_REPLICA_FAR) put off the session's state rejoins from the core it left, and again across an Upgrade (its `refused`); a client's echo stats in PARDES_REPLICA_STATS; --ps beside them lists the session alone, a window's as (gui, attached), its clients none Co-Authored-By: Claude Opus 5.5 --- src/gui/gui.zig | 5 ++++- src/replica.zig | 16 +++++++++++----- test/daemon.py | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/gui/gui.zig b/src/gui/gui.zig index f62871c4..ff1c7793 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2669,8 +2669,9 @@ const Client = struct { const needs = core.needs_frame; core.frames.mark_start = pardes.FrameStats.nowNs(); core.frames.mark_update = core.frames.mark_start; - r.draw(.{ .ctx = s, .f = present }); + // Its render's end is marked as it presents (`present`). core.frames.mark_render = core.frames.mark_update; + r.draw(.{ .ctx = s, .f = present }); cl.link.owed = core.present_skipped; core.frames.record(pardes.FrameStats.nowNs(), false, cl.link.owed); core.present_skipped = skipped; @@ -5194,6 +5195,8 @@ test "background opacity acknowledges success and rolls back unsupported surface fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void { const s = shellOf(ctx); const core = s.core; + // A replica client draws outside the pump, which marks it there. + if (s.remote != null) core.frames.mark_render = pardes.FrameStats.nowNs(); s.follow(); const g = s.gui orelse return; frame_started_ns = monoNs(); diff --git a/src/replica.zig b/src/replica.zig index 32fd4fbe..02141f44 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -2646,7 +2646,7 @@ pub const Link = struct { if (c.notice_len > 0 and (ev == .key or ev == .paste)) c.notice_len = 0; c.input_ns = nowNs(); const msg = c.r.input(ev) catch return; - if (!sendInput(c.fd, msg)) c.quit = true; + if (!sendInput(c.fd, msg)) c.cut(); c.dirty = true; } @@ -2667,9 +2667,7 @@ pub const Link = struct { }, .screen => |bytes| { defer std.heap.c_allocator.free(bytes); - if (c.r.screen(bytes)) |reply| if (!sendScreen(c.fd, reply)) { - c.quit = true; - }; + if (c.r.screen(bytes)) |reply| if (!sendScreen(c.fd, reply)) c.cut(); c.dirty = true; }, .checked => |d| c.checked(d), @@ -2693,11 +2691,18 @@ pub const Link = struct { } c.dirty = false; while (c.r.screenRequest()) |req| if (!sendScreen(c.fd, req)) { - c.quit = true; + c.cut(); break; }; } + /// A write to the session failed: it hung up (it cut this client off, + /// lagging), as its reader will say. + fn cut(c: *Link) void { + c.quit = true; + c.gone = true; + } + /// Each pass of the frontend's loop: quiet (nothing of its own /// pending) 300 ms after its last input and its last check, and /// changed since, the session's digest is asked once, answered in @@ -2711,6 +2716,7 @@ pub const Link = struct { if (since < quiet_ns) return @intCast((quiet_ns - since) / std.time.ns_per_ms + 1); c.changed = false; c.asked = askCheck(c.fd); + if (!c.asked) c.cut(); c.asked_ns = nowNs(); return null; } diff --git a/test/daemon.py b/test/daemon.py index ebee286f..1086dac3 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -557,6 +557,14 @@ class Window: return self.p.returncode +def sessions_listed(binary, env, root): + """`pardes --ps`'s session lines, each `[name, pid, (kind, state)]`.""" + out = subprocess.run([binary, '--ps'], env=env, cwd=root, capture_output=True, timeout=30) + assert out.returncode == 0, out + rows = [line.split(maxsplit=3)[1:] for line in out.stdout.decode().splitlines() if line.lstrip().startswith('session ')] + return [[name, pid, rest] for name, pid, rest in rows] + + def window_clients(binary, gui_binary): """Window replica clients (`pardes-gui --attach=:`): of a terminal's detached session, directly and through the delay relay at @@ -587,7 +595,6 @@ def window_clients(binary, gui_binary): nine = Client(root / 'pardes-9p-files.sock') pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') body = lambda: nine.read(f'/pane/{pane}/body') - alone = fds(sess.pid) # A terminal's client beside the windows, typing as they do. ta = Term(30, 100) terms.append(ta) @@ -617,6 +624,10 @@ def window_clients(binary, gui_binary): wait_for('the terminal client normal again', lambda: normal_again(ta), timeout=20) wait_for(f'the window client agrees ({rtt} ms)', lambda: agreed(check, 0), timeout=30) wait_for('the terminal client agrees', lambda: agreed(root / 'a.check', seen), timeout=30) + if not rtt: + # Its clients are no sessions of the daemon's. + listed = sessions_listed(binary, env, root) + assert [(n, k) for n, _, k in listed] == [('files', '(tty, detached)')], listed # Moved and scrolled, its own view only: agreed again. n = len(checks(check)) w.keys(b'jjjjjkkk\x06\x06\x02') @@ -628,8 +639,12 @@ def window_clients(binary, gui_binary): relay.wait() # One put off the session's state (PARDES_TEST_DIVERGE): the next # unit it replays finds it, it joins again, and its keys after go in. + # Far (PARDES_REPLICA_FAR, as through ssh): its first join sent its + # blobs by hash, in zstd; its rejoin finds them in the core it left. dcheck = root / 'wd.check' - wd = Window(root, 'wd', [gui_binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_CHECK=str(dcheck), PARDES_TEST_DIVERGE='1')) + wd = Window(root, 'wd', [gui_binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_CHECK=str(dcheck), PARDES_TEST_DIVERGE='1', + PARDES_REPLICA_FAR='1', PARDES_REPLICA_STATS=str(root / 'wd.stats'), + XDG_CACHE_HOME=str(root / 'wd-cache'))) windows.append(wd) started.append(wd.pid) time.sleep(2) @@ -642,16 +657,30 @@ def window_clients(binary, gui_binary): wd.keys(b'Oafter-rejoin-W\x1b') wait_for('the window\'s keys after its rejoin', lambda: b'after-rejoin-W' in body(), timeout=30) wait_for('the window client agrees after its rejoin', lambda: agreed(dcheck, seen), timeout=30) + # An Upgrade (to the same build): the session lets it go in words + # (`refused`), it dials again, joins, and its keys after go in. + nine.write('/ctl', b'Upgrade\n') + wait_for('the window client joined again after the upgrade', lambda: 'joined again: the session is upgrading' in wd.said(), timeout=60) + nine.socket.close() + nine = reconnect(root / 'pardes-9p-files.sock') + seen = len(checks(dcheck)) + wd.keys(b'jjjOafter-upgrade-W\x1b') + wait_for('the window\'s keys after the upgrade', lambda: b'after-upgrade-W' in body(), timeout=30) + wait_for('the window client agrees after the upgrade', lambda: agreed(dcheck, seen), timeout=30) + assert wd.p.poll() is None # Detach typed in it: it alone goes, and says why. wd.keys(b' sD') wait_for('the window client let go', lambda: wd.p.poll() is not None, timeout=15) assert 'let this client go' in wd.said(), wd.said()[-500:] + # A link a line: the first join sent every blob, its rejoins held them. + links = joins(root / 'wd.stats') + assert len(links) == 3 and links[0]['blobs'] > 0 and links[0]['from_memory'] + links[0]['from_disk'] == 0, links + assert links[1]['from_memory'] == links[1]['blobs'] and links[1]['sent_kb'] == 0, links os.write(ta.master, b' sD') wait_for('the terminal client let go', lambda: a.poll() is not None, timeout=10) - wait_for('the session\'s fds level', lambda: fds(sess.pid) == alone, timeout=10) print(f'daemon: window clients of a terminal\'s session at 0/30/80/207 ms beside a terminal\'s, digests agreed ' - f'{agreements} and {len(checks(root / "a.check"))} times; one put off the session\'s state joined again and ' - f'agreed {len(checks(dcheck))} times; one detached') + f'{agreements} and {len(checks(root / "a.check"))} times; one put off the session\'s state joined again, ' + f'joined again across an Upgrade, agreed {len(checks(dcheck))} times and detached (far: its joins {joins(root / "wd.stats")})') try: nine.write(f'/pane/{pane}/exec', b'Exit\n') except OSError as e: @@ -690,12 +719,14 @@ def window_clients(binary, gui_binary): win.keys(b'jj') wait_for('the terminal client agrees with the window', lambda: agreed(root / 'b.check', nb), timeout=30) wait_for('the window client agrees with the window', lambda: agreed(root / 'g.check', ng), timeout=30) + listed = sessions_listed(binary, env, root) + assert [(n, k) for n, _, k in listed] == [('win', '(gui, attached)')], listed assert wg.close() == 0, wg.said()[-800:] os.write(tb.master, b' sD') wait_for('the terminal client let go', lambda: b.poll() is not None, timeout=10) assert win.p.poll() is None print(f'daemon: a window\'s session served a terminal\'s client and a window\'s, digests agreed ' - f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times') + f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times; --ps listed it alone, (gui, attached)') win.close() nine.socket.close() wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=15) -- cgit v1.3