summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 03:54:49 -0300
committerGabriel Schneider <[email protected]>2026-11-06 04:13:33 -0300
commit3f4df1363d3051bf8c4665fdf4898d59ab365b27 (patch)
treea87851c8db6f4a7588156b923eaf6e4262a1dc71
parent4c2125ecf47588d33f9894c1fdf2833d0512f3b4 (diff)
downloadpardes-3f4df1363d3051bf8c4665fdf4898d59ab365b27.tar.gz
pardes-3f4df1363d3051bf8c4665fdf4898d59ab365b27.zip
client #3, wire 21: the views in the dump and the digest (client #1) are another replica stream, which the semantics hash did not see (it hashes the tape's types, not the core's), so a replica of the base could join and load a dump by names that no longer hold its views; daemon.py's Replica dials an older daemon again in its protocol (as across an Upgrade), and its Upgrade case, run from the base onto this build, takes the base's second terminal of its own being let go (its stub told, two fds fewer) and the base's client told to run the same pardes; gates: core-test 956/956, unit-test 1487/1488 tui and 1530/1531 gui, replicas ok, daemon.py main, --window-clients, --gui and --upgrade <base> <this> ok
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/wire.zig4
-rw-r--r--test/daemon.py38
2 files changed, 30 insertions, 12 deletions
diff --git a/src/wire.zig b/src/wire.zig
index fda526ce..91e805e7 100644
--- a/src/wire.zig
+++ b/src/wire.zig
@@ -9,6 +9,8 @@ const builtin = @import("builtin");
const pardes = @import("pardes.zig");
const config = @import("pardes_config");
+/// 21: a session's views are `Pardes.views` in its dump and its digest
+/// (src/views.zig), the panes' shares of the others under `shares`;
/// 20: a digest takes a blob of 4 KiB and up (a file's text, a register's,
/// an undo entry's bytes) by its length, not its bytes (src/walk.zig): a
/// text's revision says what it holds;
@@ -27,7 +29,7 @@ const config = @import("pardes_config");
/// 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 = 20;
+pub const version: u16 = 21;
/// The terminal's build and the window's step alike (`semantics`).
const family = switch (config.platform) {
diff --git a/test/daemon.py b/test/daemon.py
index c53405db..e7fee37b 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -31,6 +31,7 @@ private HOME and runtime directory:
"""
import fcntl
import os
+import re
import select
import shutil
import signal
@@ -227,9 +228,10 @@ class Replica:
"""A replica's connection (src/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 = 20
+ WIRE = 21
def __init__(self, path, timeout=10):
+ self.path, self.timeout = path, timeout
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.s.settimeout(timeout)
self.s.connect(os.fspath(path))
@@ -250,11 +252,12 @@ class Replica:
tag, n = struct.unpack('<BI', self.take(5))
return tag, self.take(n)
- def hello(self, session, build):
+ def hello(self, session, build, wire=None):
"""('welcome', pid, name) or ('refused', why); a welcome's dump
- is read, whole."""
+ is read, whole. A daemon of another replica protocol (an older
+ build's, across an Upgrade) is dialled again in its own."""
name = session.encode()
- self.send(0x01, struct.pack('<HQH', self.WIRE, build, len(name)) + name + b'\xff')
+ self.send(0x01, struct.pack('<HQH', wire or self.WIRE, build, len(name)) + name + b'\xff')
self.send(0x06, b'\x00')
tag, body = self.read()
if tag == 0x01:
@@ -269,7 +272,13 @@ class Replica:
return 'welcome', pid, body[6:6 + n].decode()
assert tag == 0x02, (tag, body)
n, = struct.unpack_from('<H', body)
- return 'refused', body[2:2 + n].decode()
+ why = body[2:2 + n].decode()
+ other = re.search(r'replica protocol \d+, and this daemon (\d+)', why)
+ if other and wire is None:
+ self.close()
+ self.__init__(self.path, self.timeout)
+ return self.hello(session, build, int(other.group(1)))
+ return 'refused', why
def ping(self, value):
"""One round trip, in ms (the session's units and terminal
@@ -1469,7 +1478,7 @@ def upgrades(old, new):
assert client.read(f'/pane/{text}/body') == b'one\ntwo\nunsaved\n'
client.write(f'/pane/{shell}/pty/data', b'sleep 1000; echo done-after-upgrade\r')
sleeper = wait_for('the sleep', lambda: [p for p in processes(root) if cmdline(p)[:2] == [b'sleep', b'1000']])[0]
- # A second terminal: a view of its own.
+ # A second terminal: a view of its own (an older build's), or a client.
term2 = Term(30, 100)
stub2 = term2.spawn([str(binary), '--attach=work'], env)
started.append(stub2.pid)
@@ -1510,7 +1519,7 @@ def upgrades(old, new):
wait_for('the daemon on the new build', lambda: exe_of(daemon) == (str(binary), True))
else:
wait_for('the daemon exec\'d again', lambda: any(a.startswith(b'--upgraded=') for a in cmdline(daemon)))
- assert alive(daemon) and stub.poll() is None and stub2.poll() is None
+ assert alive(daemon) and stub.poll() is None
# A replica of the old build is told why it is let go, after what it
# was sent (units, terminals).
tag, body = replica.read()
@@ -1519,7 +1528,8 @@ def upgrades(old, new):
assert tag == 0x02 and b'upgrading to another build' in body, (tag, body)
replica.close()
stale.wait(timeout=30)
- assert b'upgrade this client too' in term3.text(), term3.text()[-400:]
+ # (Across a change of the replica protocol, it says that instead.)
+ assert b'upgrade this client too' in term3.text() or b'run the same pardes at both ends' in term3.text(), term3.text()[-400:]
term3.close()
print('upgrade: a replica client of the old build was let go, dialled again and was told to upgrade too')
# The old image's prompt files swept, the new one's made.
@@ -1529,8 +1539,11 @@ def upgrades(old, new):
# (The replicas' connections are two fewer; the state file's one
# more after a build that opened Recent's file for each use, and
# only one: a session holds it once.)
+ # A second terminal an older build kept as a view of its own is let
+ # go (its terminal and its stub's pipe): two fewer again.
def level():
- return fds_before[0] - 2 + min(state_fds(session), 1) - state_before, fds_before[1]
+ gone = 2 if stub2.poll() is not None else 0
+ return fds_before[0] - 2 - gone + min(state_fds(session), 1) - state_before, fds_before[1]
try:
wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level(), timeout=5)
except TimeoutError:
@@ -1544,7 +1557,10 @@ def upgrades(old, new):
assert alive(shell_pid) and ppid(shell_pid) == session and alive(sleeper)
# Both terminals drawn again, each its own view.
wait_for('the first terminal redrawn', lambda: b'\x1b[?1049h' in term.text()[before[0]:])
- wait_for('the second terminal redrawn', lambda: b'\x1b[?1049h' in term2.text()[before[1]:])
+ # The second: a client again, or, a view of an older build's own, let
+ # go (a session shows one frontend of its own now), its stub told.
+ wait_for('the second terminal redrawn or let go', lambda: b'\x1b[?1049h' in term2.text()[before[1]:] or
+ (stub2.poll() is not None and b'detached from' in term2.text()))
wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client))
# The daemon lists the session under its new build.
said = Replica(root / 'pardes-replica.sock').hello('work', new_build)
@@ -1553,7 +1569,7 @@ def upgrades(old, new):
assert said[0] == 'refused' and 'another build' in said[1], said
os.kill(sleeper, signal.SIGTERM)
wait_for('the shell carrying on', lambda: b'done-after-upgrade\n' in client.read(f'/pane/{shell}/body'))
- print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and two terminals on the new build '
+ print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and its terminal on the new build (a second one an older build kept let go, or a client again) '
f'(the word to its 9P again: {took * 1000:.0f} ms); the edit, its undo and the job kept')
# A build that cannot load the dump: back to the one running (a copy