From e1a47cef599070e3ea268255ef4c1164e4a3169b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:21:37 -0300 Subject: ninep: a client attached while a script's pty/run runs in a shell replays it as its session does: the open's handle is the session's 9P server's answer (tape.authority), not the client's first free open record, which a client joined since (holding none of the opens made before its join) chose otherwise, so its write named no record and its run never went (the base, the attach agent's probe: 6 of 6 runs a client diverged, "the core called prompt where the tape has a done"); and a run's step reads the shell's marks through the tape's prompt site (pty.marksOf, as the greeting and the run's answer did), not the emulator here, which on a client of screen-state terminals is the last delta's and comes a frame after the unit that replays the output (with the handle alone 3 of 6 still diverged: sent_command's count and the busy check read marks behind the session's); Pane.noteCommand takes the count from its caller; a client whose rejoin lands as its session ends goes as at a hang-up, in the same words ("let this client go"), never "could not join again: the session hung up before the dump was whole" (replica.ended: hung up, nothing answers, no such session); tests: a client joined from a dump with a listing open held across the join takes a run as the session does (failed on the base: its digest), the same with screen-state terminals and their deltas after each unit (failed with the handle fix alone: "the core did not make the host call the tape has, in output"), and the rejoin test says a session gone and one hung up mid-dump are its end; the tape's results list Term.Prompt, so the semantics word moves: 7a610621b2f37456 -> 92963bab2e4436fb; probe (exitclient.py, 6 runs): 0 of 6 diverge, 0 of 3 with a digest every unit (PARDES_REPLICA_TRACE); a pty/data-only variant diverged 0 of 2 on this build too; tui core-test 856/1009 (153 skipped: the two new tests need a shell), shell-test 1049/1052 (load 15-20) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/panes.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/panes.zig') diff --git a/core/panes.zig b/core/panes.zig index fd152e1e..d8e1bbcb 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1026,11 +1026,11 @@ pub const Pane = struct { /// started, for Kill: it runs from the shell's next C mark to its D. /// ponytail: of several lines queued for a shell not up yet, only the /// last is remembered, as the first of them. - pub fn noteCommand(pane: *Pane, line: []const u8) void { - const state = pane.terminal orelse return; + pub fn noteCommand(pane: *Pane, line: []const u8, started: u32) void { + if (pane.terminal == null) return; const said = std.mem.trim(u8, line, " \t"); const word = said[0 .. std.mem.indexOfAny(u8, said, " \t") orelse said.len]; - var sent: @typeInfo(@FieldType(Pane, "sent_command")).optional.child = .{ .seq = Term.prompt(state).started +% 1 }; + var sent: @typeInfo(@FieldType(Pane, "sent_command")).optional.child = .{ .seq = started +% 1 }; sent.len = @intCast(@min(word.len, sent.word.len)); @memcpy(sent.word[0..sent.len], word[0..sent.len]); pane.sent_command = sent; -- cgit v1.3 From 0165bc532446e61a74af604c493d6b354abf798a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:37:04 -0300 Subject: builtins: a far client's Del with a pane above and below is instant: the step that asks which way the space goes reads no clock (it asked the host's `now`, an answering entry a speculation stops at: the bytes soak's one stop off may_wait, a client's key d), its question's time is `Pane.question_asked` until the next advance, which counts the delay from its own time (Core.advance, the host's clock in its pump, right after the key's step; a client has the session's advance in its unit), so the question still shows 400 ms after it was asked in an idle session whose core time is seconds old; not a guessed clock: the core's clock is its host's (SDL's ticks on the window) where a guess is the session's CLOCK_MONOTONIC, so a guessed due time would be in another base than the clock it is compared with; nextWake skips a question not timed yet; a host with no clock (macOS's) never advances, and its question waited for ever before as now; test: a far client's Del with panes above and below applies both keys at once (failed on the base: 1 applied of 2, stopped at `d`), confirms with nothing mispredicted, and after the session's next pump its question's time is the session's clock plus the delay on both; the keys test of the delay times it with an advance; no layout moves (the field keeps its type), the semantics word stays 92963bab2e4436fb; exec.clockNow keeps its two REPL callers (a paste's Enter: a pty write that stops a far client anyway, and the session's own output steps); tui core-test 857/1010 (153 skipped), shell-test 1050/1053 (load 10-15) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 6 +++++- core/builtins.zig | 2 +- core/keys.zig | 3 +++ core/panes.zig | 8 +++++++- core/replica.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) (limited to 'core/panes.zig') diff --git a/core/Core.zig b/core/Core.zig index 9a542940..c8880a6a 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2073,7 +2073,7 @@ pub fn nextWake(p: *const Pardes) ?u64 { }; // Del's question goes up at the end of its delay: a frame then, and // none after (stepped time has reached it). - for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns) { + for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns and pane.question_due_ns != Pane.question_asked) { const wait = @max(1, (pane.question_due_ns - p.clock.stepped_ns + frame_ns - 1) / frame_ns); frames = if (frames) |soonest| @min(soonest, wait) else wait; }; @@ -2114,6 +2114,10 @@ fn advanceInner(p: *Pardes, now_ns: u64) void { p.clock.started = true; p.clock.now_ns = now_ns; if (!started) p.clock.stepped_ns = now_ns; + // Del's question asked since the last advance: its delay from now. + for (p.panes) |slot| if (slot) |pane| if (pane.question_due_ns == Pane.question_asked) { + pane.question_due_ns = now_ns + config.del_question_delay_ns; + }; const frame = frame_ns; var moving: u32 = 0; // The session's ticks are the recording session's: a picture still diff --git a/core/builtins.zig b/core/builtins.zig index 2740e05a..bee7e198 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1044,7 +1044,7 @@ pub const Del = struct { !c.pane.collapsed and c.pane.prompt == .none) { c.pane.prompt = .del_side; - c.pane.question_due_ns = exec.clockNow(c.p) + config.del_question_delay_ns; + c.pane.question_due_ns = Pane.question_asked; c.p.view().active = c.id; var rec: [32]u8 = undefined; pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch unreachable); // a u32 fits 32 diff --git a/core/keys.zig b/core/keys.zig index 72e3bb3b..8bfe8315 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -717,6 +717,9 @@ test "the Del question shows only once its delay is up: a quick SPC d j never se p.update(.{ .key = .{ .cp = 'd' } }); const pane = p.panes[mid].?; try std.testing.expectEqual(Pane.Prompt.del_side, pane.prompt); + // Its time is the next advance's (the host's clock, in its pump). + try std.testing.expectEqual(Pane.question_asked, pane.question_due_ns); + p.advance(asked_at); try std.testing.expectEqual(asked_at + config.del_question_delay_ns, pane.question_due_ns); // Asked, and nothing on the band yet. _ = try p.render(frame.allocator()); diff --git a/core/panes.zig b/core/panes.zig index d8e1bbcb..23fa3bba 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -53,6 +53,10 @@ pub const Pane = struct { return @backingInt(id); } }; + /// Del's question asked, its time not had yet: the step that asks + /// reads no clock (a far client's would wait on the session's), and + /// core time is the last frame's, seconds old in an idle session. + pub const question_asked: u64 = std.math.maxInt(u64); /// The words that throw unsaved text away (builtins.zig warnModified). pub const Discarding = enum { Exit, Restore, get, Del, Delcol }; @@ -218,7 +222,9 @@ pub const Pane = struct { repl_enter: u8 = 0, repl_enter_due_ns: u64 = 0, /// When Del's question (`del_side`) goes up on the notice band, on the - /// shell's clock (config.del_question_delay_ns after it was asked). + /// shell's clock (config.del_question_delay_ns after it was asked): + /// `question_asked` until the next advance, which counts the delay + /// from its own time (Core.advance). question_due_ns: u64 = 0, /// A question with its answers in it (`repl_choice`). question: [96]u8 = undefined, diff --git a/core/replica.zig b/core/replica.zig index 818e375a..5bf306fa 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6878,3 +6878,51 @@ test "a client of screen-state terminals takes a 9P pty/run in a shell as the se try agrees(a, r); try agrees(a, late); } + +// Del with a pane above and below asks which way the space goes, its +// question shown once a delay is up (builtins.zig): its time was the +// host's clock read in the step, an answering entry a speculation stops at. +test "a far client's Del with panes above and below is applied at once, and its question's time is the session's" { + const gpa = std.testing.allocator; + const Clocked = struct { + var now_ns: u64 = 7 * std.time.ns_per_s; + fn now(_: ?*anyopaque) u64 { + return now_ns; + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .now = now }; + }; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 30, .file = "mise.toml" }, .{ .vtable = &Clocked.vtable }, false); + defer a.deinit(); + _ = try a.local(.{ .command = "New" }); + const mid = a.core.view().active; + _ = try a.local(.{ .command = "New" }); + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + a.core.view().active = mid; + } + const r = try joinedFresh(a); + defer r.deinit(); + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + Clocked.now_ns += std.time.ns_per_s; + try key(r, ' ', &sent); + try key(r, 'd', &sent); + try std.testing.expectEqual(@as(usize, 2), r.applied); + try std.testing.expect(r.core().panes[mid].?.prompt == .del_side); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try agrees(a, r); + // The question shows a delay after it was asked, on the session's clock. + a.pump(); + r.confirm((try a.pending()).?); + r.settle(); + try agrees(a, r); + try std.testing.expectEqual(Clocked.now_ns + pardes.config.del_question_delay_ns, r.core().panes[mid].?.question_due_ns); +} -- cgit v1.3