summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 16:34:45 -0300
committerGabriel Schneider <[email protected]>2026-11-23 18:01:40 -0300
commitda4256d4bf8938d38daa1349e9b51f403bf7a937 (patch)
treed93bf2c3faebb7a61a64dddadecffb7ac54c6184
parentb58b6e6e8e67e256be7de879a212da1de699253e (diff)
downloadpardes-da4256d4bf8938d38daa1349e9b51f403bf7a937.tar.gz
pardes-da4256d4bf8938d38daa1349e9b51f403bf7a937.zip
messages: what a view kept for its client's return shows at its keyboard's pane waits for that client (the coordinator's rule for an Upgrade's outcome: kept for each view until its client is back and drawn, until its kept time for a view whose client never comes, as now for the session's own frontend): pair-10's rule "a message waits for someone to see it", which a session-wide `unattended = false` keeps for a pair's one client (dev/tui/tui.zig `Own.start`, `rec.state == .pair`), made per view for every client: `Messages.awaited(p, pane)`: a pane that the keyboard of a view kept for its client (views.away: an Upgrade's clients, a divergence's) is on, within the view's kept time (views.away_kept_ns); neither another view's key or click (`dismissMessage`) nor the unattended clock (`expireUnattended`) takes its message; the client back for its view (`rejoinView`) gets it in its join's dump; pair-10's line stays: deleted, the `--with-pair --upgrade` rows failed 3 of 3 at "brings the rest back" (a pair's session no build could load starts afresh with no view kept, its message on the unattended clock at once): that case has no view to hold it; what failed the merged gate (pardes-merge63, its row "each client's own screen saying the Upgrade's outcome" 3 of 3) was NOT a race but the test's first needle, `Upgrade: the new build`, which a message longer than its pane never shows (it shows its end: round 1's five kept runs, both clients, 0 head and 1 end each): pardes-merge63 stands on `ulztktwm` without `mntzqroy` (its needle `it goes on as`); on this tree (with `mntzqroy`) the row passed before this change 3 of 3 each way (dbg->rel, rel->dbg, a message trace in every process: every client back within 3 ms of the outcome, nothing between); the race this closes is a user's: a key in the session's own terminal, or a detached session's clock, before a client is back; TEST FIRST: runtime/upgrade.zig "an upgrade's outcome waits in each view kept for its client until that client is back for it: no other view's key and no clock take it" (two client views kept as an Upgrade keeps them, the dump loaded by `load`, MessageLinger 0: a key in the own view takes its pane's outcome and not theirs; unattended, a tick takes none; a client back has it and the next key takes it; the other's goes past its kept time): fails on the base at the first kept view (upgrade.zig:534), passes with it; the two upgrade tests share `upgradedForTest` (the dump and `load`) and `saysOutcome`
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/Messages.zig21
-rw-r--r--runtime/upgrade.zig72
2 files changed, 84 insertions, 9 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 46dab136..18b10ff8 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -192,6 +192,7 @@ pub fn expireUnattended(p: *Pardes) void {
for (p.panes) |slot| {
const pane = slot orelse continue;
if (pane.msg_len == 0 and pane.msg_older_len == 0) continue;
+ if (awaited(p, pane)) continue;
if (now - pane.msg_said_ms < p.settings.message_linger_ms) continue;
pane.msg_len = 0;
pane.msg_life = .{};
@@ -200,10 +201,30 @@ pub fn expireUnattended(p: *Pardes) void {
}
}
+/// A message waits for someone to see it, and a view kept for its client's
+/// return (views.away: an Upgrade's clients, a divergence's) is someone
+/// on the way: what its keyboard's pane says (an Upgrade's outcome,
+/// upgrade.zig `tellEveryView`) is that client's until it is back for its
+/// view (Pardes.rejoinView: its join's dump has it) or the view's kept
+/// time is up; no other view's input and no unattended clock take it. A
+/// pair's one client is such a client; the session's own frontend is
+/// none (its view is never away). A session no build could load starts
+/// afresh with no view kept: a pair's is held attended for its client
+/// instead (tui.zig `Own.start`).
+fn awaited(p: *const Pardes, pane: *const Pane) bool {
+ if (p.views_away == 0) return false;
+ for (p.views, 0..) |slot, k| if (slot) |v| {
+ if (pardes.views.isAway(p, @intCast(k)) and p.panes[v.active] == pane and
+ p.clock.now_ns -| v.away_ns < pardes.views.away_kept_ns) return true;
+ };
+ return false;
+}
+
/// The key or click that used to clear the message row now starts each
/// line's exit: it stays `message_linger_ms`, then goes. A line already
/// on its way out keeps its own timing.
pub fn dismissMessage(p: *Pardes, pane: *Pane) void {
+ if (awaited(p, pane)) return;
if (pane.msg_len > 0 and dismissLine(p, &pane.msg_life)) {
pane.msg_len = 0;
pane.msg_life = .{};
diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig
index 6cbaa750..67d16f84 100644
--- a/runtime/upgrade.zig
+++ b/runtime/upgrade.zig
@@ -497,6 +497,67 @@ test "an upgrade's outcome is said in every view, at the pane its keyboard is on
p.toView(k);
try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
try std.testing.expect(p.view().active != asked);
+ const q = try upgradedForTest(gpa, p);
+ defer q.deinit();
+ var seen: usize = 0;
+ for (q.views, 0..) |v, i| if (v != null) {
+ try std.testing.expect(saysOutcome(q, i));
+ seen += 1;
+ };
+ try std.testing.expectEqual(@as(usize, 2), seen);
+ try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active);
+}
+
+test "an upgrade's outcome waits in each view kept for its client until that client is back for it: no other view's key and no clock take it" {
+ const gpa = std.testing.allocator;
+ const p = try pardes.Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("before the upgrade\n");
+ // Two clients' views, each its keyboard on a pane of its own, kept for
+ // their clients as an Upgrade keeps them (Peers.refuseAll: away).
+ var kept: [2]pardes.Pardes.View.Id = undefined;
+ for (&kept) |*k| {
+ k.* = p.openView() orelse return error.NoView;
+ p.toView(k.*);
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
+ }
+ p.toView(.at(0));
+ for (kept) |k| p.awayView(k);
+ const q = try upgradedForTest(gpa, p);
+ defer q.deinit();
+ // As the daemon's tests run (MessageLinger 0): a dismissal is at once.
+ q.settings.message_linger_ms = 0;
+ const key: pardes.Event = .{ .key = .{ .cp = 'j', .text = "j" } };
+ // A key in the session's own view: its outcome goes, not theirs.
+ q.update(key);
+ try std.testing.expect(!saysOutcome(q, q.live));
+ for (kept) |k| try std.testing.expect(saysOutcome(q, k.index()));
+ // Nobody attached: the clock takes nothing a kept view waits for.
+ q.unattended = true;
+ q.update(.tick);
+ for (kept) |k| try std.testing.expect(saysOutcome(q, k.index()));
+ q.unattended = false;
+ // A client back for its view has it (its join's dump); the next key,
+ // anyone's, takes it.
+ try std.testing.expect(q.rejoinView(kept[0]));
+ try std.testing.expect(saysOutcome(q, kept[0].index()));
+ q.update(key);
+ try std.testing.expect(!saysOutcome(q, kept[0].index()));
+ try std.testing.expect(saysOutcome(q, kept[1].index()));
+ // One never back: once its view's kept time is up, as anyone's.
+ q.advance(q.views[kept[1].index()].?.away_ns + pardes.views.away_kept_ns);
+ q.update(key);
+ try std.testing.expect(!saysOutcome(q, kept[1].index()));
+}
+
+/// Whether view `k`'s keyboard pane says the Upgrade's outcome.
+fn saysOutcome(q: *const pardes.Pardes, k: usize) bool {
+ const pane = q.panes[q.views[k].?.active].?;
+ return std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes ");
+}
+
+/// `p` dumped and loaded as an Upgrade's new process loads it (`load`).
+fn upgradedForTest(gpa: std.mem.Allocator, p: *pardes.Pardes) !*pardes.Pardes {
const bytes = try pardes.dump.byteDump(p);
defer gpa.free(bytes);
var tmp = std.testing.tmpDir(.{});
@@ -507,16 +568,9 @@ test "an upgrade's outcome is said in every view, at the pane its keyboard is on
var text_buf: [4300]u8 = undefined;
var rec = try Record.decode(try std.fmt.bufPrint(&text_buf, "link -1\nstub -1\nold -1\nwindow 0\nexe /x/pardes\ndump {s}/pardes-upgrade-1.dump\n", .{dir}));
const q = try load(gpa, gpa, .{ .tty_only = true }, &rec);
- defer q.deinit();
+ errdefer q.deinit();
try std.testing.expect(!rec.fresh);
- var seen: usize = 0;
- for (q.views) |v| if (v) |view| {
- const pane = q.panes[view.active].?;
- try std.testing.expect(std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes "));
- seen += 1;
- };
- try std.testing.expectEqual(@as(usize, 2), seen);
- try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active);
+ return q;
}
test "an upgrade's record reads back as it was written, and refuses one cut short" {