From d92ea9dfdd9198b69bff420c3b594f0ffed1e1bb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 16:50:58 -0300 Subject: Messages: a detached session's messages go on the clock in the pump, after its wait, not in the host's wait: the host's call (tty waitInput, gui waitDetached) was no input, its clock read untaped, so a replay (and every replica of a session nobody attached) kept a message its session had let go; with MessageLinger 0 (test/daemon.py's sessions) a tape whose session said a failure never replayed, on main too (pane 0's msg, digest 6, 7 of 7 runs; 0 of 6 after); test/cross_replay.py's session says MessageLinger 0 again Co-Authored-By: Claude Opus 5.5 --- src/Messages.zig | 12 +++++++----- src/gui/gui.zig | 3 +-- src/pardes.zig | 5 +++++ src/tty/tty.zig | 4 ++-- test/cross_replay.py | 7 +++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Messages.zig b/src/Messages.zig index e1d18849..371ed168 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -216,9 +216,10 @@ fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { /// With no frontend attached no input dismisses a message, and a detached /// session's /screen and messages kept what was said an hour ago: each /// pane's lines go once its newest has been up `message_linger_ms`, on the -/// clock, checked as the core is stepped and by the detached session's loop -/// between steps -- not as a 9P request is served, since a read is answered -/// while a step is out and must change nothing. +/// clock, checked as the core is stepped (each event, and each pump after +/// its wait, which a message wakes) -- not as a 9P request is served, since +/// a read is answered while a step is out and must change nothing, nor by +/// the host, whose call is no input a replay makes. /// ponytail: a pane's older lines go with its newest, not each on its own /// clock; the render pipeline's clock will give every line its own. fn nowMs() i64 { @@ -742,10 +743,11 @@ test "with no frontend attached a message goes once it has lingered, on the cloc // Detached with nobody attached: past its linger it is gone, and the // line above it with it. p.unattended = true; - // A read served meanwhile changes nothing; the session's loop expires. + // A read served meanwhile changes nothing; the session's step after its + // wait expires, not the host (whose call no replay makes). _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 }); try std.testing.expect(pane.msg_len > 0); - expireUnattended(p); + try p.pump(.{}); try std.testing.expectEqual(@as(u16, 0), pane.msg_len); try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); // A fresh one stays until its linger is up. diff --git a/src/gui/gui.zig b/src/gui/gui.zig index c3fdd63a..ead89a8a 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4941,9 +4941,8 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { /// Detached: no window, asleep until the queue's wake (an SDL user event: /// a pty's output, the daemon's window request), the core's next wake, or a /// quit (SDL makes SIGTERM and SIGINT one). With nobody to dismiss them, -/// messages go on the clock. +/// messages go on the clock (the pump's, after this wait), which wakes it. fn waitDetached(core: *pardes.Pardes, timeout_ms: u32) void { - pardes.Messages.expireUnattended(core); var ms: c_int = if (timeout_ms != 0) @intCast(@min(timeout_ms, std.math.maxInt(c_int))) else -1; for (core.panes) |slot| if (slot) |pane| if (pane.msg_len > 0) { ms = if (ms < 0) 100 else @min(ms, 100); diff --git a/src/pardes.zig b/src/pardes.zig index 189a5b02..a4fcb2d3 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -6175,6 +6175,11 @@ pub const Pardes = struct { } else 0; f(h.ctx, timeout); } + // Detached, nobody's key dismisses a message: they go on the clock, + // here in the step, where the clock read is taped (the host's wait + // did it, untaped, and a replay kept a message its session had let + // go). + Messages.expireUnattended(p); p.frames.mark_start = FrameStats.nowNs(); if (v.now) |clock| p.advance(clock(h.ctx)); p.settle(); diff --git a/src/tty/tty.zig b/src/tty/tty.zig index 39c287f7..03b7a7e2 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -2432,9 +2432,9 @@ const Shell = struct { // ends the wait at once and its frame is drawn then; the ticks after // it run from it. var wait = timeout_ms; - // Detached, nobody's key dismisses a message: they go on the clock. + // Detached, nobody's key dismisses a message: they go on the clock + // (the pump's, after this wait), which wakes it. if (!s.attached()) { - pardes.Messages.expireUnattended(s.core); for (s.core.panes) |slot| if (slot) |pane| if (pane.msg_len > 0) { wait = if (wait == 0) 100 else @min(wait, 100); break; diff --git a/test/cross_replay.py b/test/cross_replay.py index 2a4a7ae7..26304d9a 100644 --- a/test/cross_replay.py +++ b/test/cross_replay.py @@ -47,10 +47,9 @@ def record(binary, out): (root / 'dir').mkdir() (root / 'dir' / 'b.txt').write_text('in a directory\n') os.mkfifo(root / 'fifo') - # No `MessageLinger 0` (test/daemon.py's sessions have it): with it, now - # and then, a tape does not replay even by its own build, on main too - # (pane 0's message differs a step after a failure is said). - (root / 'config' / 'pardes' / 'init').write_text('') + # As test/daemon.py's sessions are: a detached session's message goes at + # once, on the clock (Messages.expireUnattended). + (root / 'config' / 'pardes' / 'init').write_text('MessageLinger 0\n') stem = Path(binary).name env['PARDES_RECORD'] = str(out / f'{stem}-') window = 'gui' in stem -- cgit v1.3