summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 02:43:34 -0300
committerGabriel Schneider <[email protected]>2026-11-20 11:16:31 -0300
commit4c5edb516c6c866fe6039037636804f4e868f4bb (patch)
tree2818181f8a9c1a9697e8646f418be7606185d7e9
parentc9ac46755632d5cd1bdc34fe211112d730ffc77f (diff)
downloadpardes-4c5edb516c6c866fe6039037636804f4e868f4bb.tar.gz
pardes-4c5edb516c6c866fe6039037636804f4e868f4bb.zip
replica: a join's reloads are never taken as moving nothing (the one rule, which `tape.feedsTerminal` kept for a pty's output alone): a join refused for want of a view still reloads every terminal on every side (Core.zig `openViewInner`: `reloadTerminals` before `Views.open` returns null) and moves nothing a digest covers, so a near client with a key of its own on top took that unit as neutral (`confirm`, the same digest and no pty output: kept in `since`, not replayed), its key's fast path then left nothing on top, and the next output unit let the copy go and dropped `since` (`ahead`): that client never made the reload, held other pages than every other side, and once the flood pruned its history a page at a time it diverged: "digest N differs in panes pane 0.terminal pane 1.cwd" (pane 1's cwd is `.inherited: *Pane`, walked into pane 0's terminal) or, at the next join, "a terminal reloaded at a join is not the session's"; found by a ring of each replica's units and paths printed at its failure (seed 0 at 30 ms: the refused join `0/442` taken neutral, then the client's mouse `2/30` fast-pathed, then `0/443` released the copy); FIRST the test (a fifth client refused while every view is taken and a key of the client's is on top: the replica made 0 reloads where the session made 1, `expected 2, found 1` on the base), THEN `feedsTerminal` also names a unit with a `Site.reload` record; a user could not hit it today (real clients are screen state, which never reloads), and after the switch would have, whenever a fifth client was refused while another typed; and a third, seen once (seed 6 at 30 ms, the far client: "its digest, quiet, is not the session's"): a client that let its link go for its lag drops the units after it (`Link.lags`), but a check answered after the let-go was still judged (`Link.checked`) against a core behind on purpose: FIRST the lag test takes a check after its let-go (diverged on the base), THEN `checked` judges nothing once the link is let go; the soak, bytes, `--clients 5 --bytes --seeds 8` at 30/80/207 ms with the `cat` whole (Debug, load 25-44): 2 of 4 whole runs clean (diverged 0, unequal 0, quiet checks agreed, unlisted 0, corpus 22 of 22, no leak); in the other two, seed 2 at 80 ms (two clients at one session unit) and seed 0 at 30 ms (one client): OPEN, not root-caused (reports/pardes-term-join.md), never under a probe; seed 0 at 30 ms, 19 of 20 clean, one run hung spinning (killed, no trace); on the base seed 0 at 30 ms diverged every time and 9 of 24 runs; tui core-test 859/1011 (152 skipped), shell-test 1047/1050
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/replica.zig49
-rw-r--r--core/tape.zig10
2 files changed, 51 insertions, 8 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 8fd0a251..b4d8edfa 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -963,9 +963,10 @@ pub const Replica = struct {
r.last_digest.clearRetainingCapacity();
if (ends) |d| r.last_digest.appendSlice(r.gpa, d) catch {};
}
- // A terminal's output is never taken so (the one rule): what it
- // writes outside the copy is applied once, at its place, and much
- // of it no digest covers (a colour set, a mode).
+ // A terminal's output, or a join's reloads, never taken so (the one
+ // rule): what it writes outside the copy is applied once, at its
+ // place, and much of it no digest covers (a colour set, a mode, the
+ // pages a reload remakes).
if (r.applied > 0 and u.origin != r.id and ends != null and std.mem.eql(u8, ends.?, r.last_digest.items) and
(r.t.screen_state or !tape.feedsTerminal(u.tape)))
{
@@ -3295,8 +3296,9 @@ pub const Link = struct {
fn checked(c: *Link, theirs: u64) void {
c.asked = false;
// Not quiet now, the answer is let go: it covers nothing, and the
- // next quiet asks again.
- if (!c.r.quiet() or c.r.diverged != null) {
+ // next quiet asks again. Nor once its link is let go: a lag's let-go
+ // drops the units after it (`lags`), and the core is behind them.
+ if (c.quit or !c.r.quiet() or c.r.diverged != null) {
c.changed = true;
return;
}
@@ -4445,6 +4447,39 @@ test "bytes: a client joins from a dump with its terminals whole, and every side
try sameTerminals(b.a, late);
}
+test "bytes: a join refused for want of a view reloads every terminal and moves nothing a digest covers: a client with a key on top reloads too, at its place, never taking that unit as moving nothing" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const b = try BytesPair.init();
+ defer b.deinit();
+ try b.output("a line of the program's\r\n");
+ // Every view taken: the session's, then three clients'.
+ for (2..pardes.views.max + 1) |client| b.r.confirm((try b.a.openView(@intCast(client))).unit);
+ try b.output("and one since the last join\r\n");
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| gpa.free(m);
+ sent.deinit(gpa);
+ }
+ // A key of its own on top; a fifth client refused, its step reloading
+ // every terminal in the unit of the pump the others take next; the key
+ // confirmed; the program prints on.
+ try key(b.r, 'l', &sent);
+ try std.testing.expectEqual(@as(usize, 1), b.r.applied);
+ const before = pardes.Term.reloads.n;
+ try std.testing.expect(try b.a.join(pardes.views.max + 1, null) == null);
+ const session = pardes.Term.reloads.n - before;
+ try std.testing.expect(session > 0);
+ b.a.pump();
+ b.r.confirm((try b.a.pending()).?);
+ b.r.confirm(try b.a.take(sent.items[0]));
+ b.r.settle();
+ try b.output("and on\r\n");
+ try std.testing.expectEqual(2 * session, pardes.Term.reloads.n - before);
+ try agrees(b.a, b.r);
+ try sameTerminals(b.a, b.r);
+}
+
test "bytes: a session's output past a unit's bound is cut into units under it, between two reads" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
@@ -5116,6 +5151,10 @@ test "a client whose session's units come more than two seconds later than its q
try std.testing.expect(!link.quit);
try Late.take(&link, a, 1_100, 8_300);
try std.testing.expect(link.quit);
+ // A check answered after it let go, behind the unit it let go of: its
+ // core is behind on purpose, no divergence.
+ link.take(.{ .checked = digestOf(a) +% 1 });
+ try std.testing.expect(r.diverged == null);
try std.testing.expect(link.rejoins());
try std.testing.expectEqualStrings("joined again: 2.1 s behind", link.notice());
try std.testing.expect(!link.rejoins());
diff --git a/core/tape.zig b/core/tape.zig
index d977b53e..ea1a5691 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -1520,15 +1520,19 @@ pub fn endSpeculation(t: *Tape) bool {
/// a message may be (replica.zig `lag_max`'s neighbour, wire's bound).
pub const unit_max = 1 << 20;
-/// Whether a unit feeds a terminal its program's output (a pty's read; an
-/// input kept by hash is taken to): never taken as moving nothing (the
-/// replica engine's one rule, core/replica.zig `confirm`).
+/// Whether a unit writes a terminal's emulator: feeds one its program's
+/// output (a pty's read; an input kept by hash is taken to), or reloads
+/// every one at a join (`Site.reload`; a join refused too, which moves
+/// nothing a digest covers): never taken as moving nothing (the replica
+/// engine's one rule, core/replica.zig `confirm`).
pub fn feedsTerminal(bytes: []const u8) bool {
const Tag = std.meta.Tag(Input);
const EventTag = std.meta.Tag(pardes.Event);
+ const reload: u16 = @as(u16, host_fns.len) + @backingInt(Site.reload);
var r: walk.Reader = .{ .bytes = bytes };
while (nextRecord(&r)) |rec| switch (rec.kind) {
.blob => if (rec.payload.len > 0 and rec.payload[0] == @backingInt(Kind.input)) return true,
+ .host => if (rec.payload.len >= 2 and std.mem.bytesToValue(u16, rec.payload[0..2]) == reload) return true,
.input => {
if (rec.payload.len < @sizeOf(Tag) + @sizeOf(EventTag)) continue;
if (!std.mem.eql(u8, rec.payload[0..@sizeOf(Tag)], std.mem.asBytes(&@as(Tag, .update)))) continue;