From 544d41b77eea27447b329a06f0fa2b852479674c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 10:21:51 -0300 Subject: pty: what a run's command printed taped (tape .prompt), as a step's read of its terminal after output is: a screen-state replica's emulator is its deltas', which a lagging client's are states behind, and a run's end replayed there read pins into pages it never had (ghostty's leftWrap overflowed: a window client stopped while a shell flooded the session aborted 3 runs in 8; none in 6 since) Co-Authored-By: Claude Opus 5.5 --- src/ninep/pty.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/ninep') diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index d80f7175..e68ad84f 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -378,9 +378,11 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { /// Answers a run whose command ended with `status`: the header and the /// output it printed. fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void { - const printed = pardes.panes.terminal.commandOutput(pane, p.gpa, output_rows) catch + // As the authority's emulator has it (taped): a screen-state replica's + // is its deltas', which a lagging client's can be states behind, its + // pins in pages it never had (ghostty's leftWrap overflowed on one). + const printed = pardes.tape.value(.prompt, printedBy, .{ pane, p.scratch.allocator() }) orelse return answer(p, slot, "error out of memory", .{}); - defer p.gpa.free(printed.text); // Keep the tail, cut at a line start so the first line kept is whole. var keep: []const u8 = printed.text; if (keep.len > output_cap) { @@ -409,6 +411,14 @@ fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void { answer(p, slot, "exit {s}", .{status}); } +const Printed = struct { text: []const u8, whole: bool }; + +/// What pane `pane`'s command printed (terminal.commandOutput), in `arena`. +fn printedBy(pane: *Pane, arena: std.mem.Allocator) ?Printed { + const out = pardes.panes.terminal.commandOutput(pane, arena, output_rows) catch return null; + return .{ .text = out.text, .whole = out.whole }; +} + /// The shell itself exited (a run's `exit 3`, or one typed): a run waiting /// on the command it ran answers with the shell's status and what it /// printed, and the log says `exit` before the pane's `del`. Unknown, the -- cgit v1.3