diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 09:16:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 10:58:21 -0300 |
| commit | 0ad6da7f9bf22136694e6015c93ccaf81dc12380 (patch) | |
| tree | 4618b47f1d5450c4d4d89a23df3753a9fae6ce2a | |
| parent | c4f7bb9477c7aa4c8864f14edb9e85b6c8c08437 (diff) | |
| download | pardes-0ad6da7f9bf22136694e6015c93ccaf81dc12380.tar.gz pardes-0ad6da7f9bf22136694e6015c93ccaf81dc12380.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/replica.zig | 13 | ||||
| -rw-r--r-- | test/daemon.py | 76 |
2 files changed, 88 insertions, 1 deletions
diff --git a/core/replica.zig b/core/replica.zig index 97da9c74..3c7a5cbc 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2346,10 +2346,21 @@ pub const Peers = struct { ps.recording = true; ps.samples = std.c.getenv("PARDES_REPLICA_STATS") != null; } + // A join with no room lets go a view kept past its bound by the + // core's clock (Core.openView), which a wake by mail alone, as this + // join's, does not move (tui.zig `clockNow`): moved now, on the tape. + if (@popCount(core.views_open) == pardes.views.max) if (core.host.call(.now, .{})) |now| core.advance(now); const k = viewFor(core, joining.view) orelse { core.unattended = ps.count() == 0 and ps.detached; if (ps.count() == 0) ps.stop(core); - return daemon.refuseReplica(fd, "that session has as many views as it takes"); + const full = "that session has as many views as it takes"; + var left: u64 = 0; + for (0..pardes.views.max) |i| if (pardes.views.isAway(core, @intCast(i))) { + const n = (core.views[i].?.away_ns + pardes.views.away_kept_ns) -| core.clock.now_ns; + left = if (left == 0) n else @min(left, n); + }; + var why: [128]u8 = undefined; + return daemon.refuseReplica(fd, if (left == 0) full else std.fmt.bufPrint(&why, full ++ " (one is kept {d} s more for a client joining again)", .{(left + std.time.ns_per_s - 1) / std.time.ns_per_s}) catch full); }; ps.seq += 1; ps.unit(0, ps.seq); 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).""" |
