summaryrefslogtreecommitdiff
path: root/core/term
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 22:06:32 -0300
committerGabriel Schneider <[email protected]>2026-11-20 00:38:51 -0300
commit2662a45ac245e574987bf6876f4470aed89da09c (patch)
treec582032cde0cb742a67e2dd548022f7b83f8d1fd /core/term
parentba10cc4ff30d08d27ad35576df04a03282b6521b (diff)
downloadpardes-2662a45ac245e574987bf6876f4470aed89da09c.tar.gz
pardes-2662a45ac245e574987bf6876f4470aed89da09c.zip
replica: the bytes kind of replica made right and joinable (P29, P32; the brief's step 2: 2a, 2b, 2c and 2d in one change): the one rule in place of two, the faults shown first (a session's output kept over a copy held ahead was fed again by a rollback: the digests apart; the pages an emulator gained while a copy was held were the epoch's and freed with it: a crash in PageList.increaseCapacity in the rollback's replay): every replica's emulators on the C heap (panes.emulatorGpa), Term.writes counting the writes into emulators, a unit whose replay wrote one never kept over a copy taken ahead, never taken as moving nothing (tape.feedsTerminal), a client's input that owed a reflow always replayed when confirmed; a speculation moves a terminal's view under bytes as under screen state; tape.unit_max (1 MiB) and Tape.cut, which the session's Peers sets, so a pump's reads are cut into units under it; the join: whole terminals in a joiner's dump, every replica the session included reloading each live terminal in the step that opens or reopens a view (panes.reloadTerminals), the session's hash taped (Site.reload) and compared, kitty records left out of it, the cell pixels set first as a feed does; .positions and .prompt compared with the replica's own emulator on replay; replicas load kitty images by direct data only (Term.direct); Peers.bytes for the soak; six tests (core/replica.zig, bytes:); tui core-test 848/997 (149 skipped), shell-test 1033/1036, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 0, process-test 2 of 144 (the base's), image- and kitty-harness pass, unit-test bytes: 22/22; gui unit-test 1633/1637 (the perf check's BaselineHarnessMismatch); the soaks in klrvlrly's
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/term')
-rw-r--r--core/term/term.zig1
-rw-r--r--core/term/terminal.zig45
2 files changed, 41 insertions, 5 deletions
diff --git a/core/term/term.zig b/core/term/term.zig
index 4bb60079..b18f5875 100644
--- a/core/term/term.zig
+++ b/core/term/term.zig
@@ -32,6 +32,7 @@ pub const ops: iface.Ops = .{
.snapshot = cast(iface.Ops, "snapshot", terminal_.snapshot),
.load = cast(iface.Ops, "load", terminal_.load),
.reload = cast(iface.Ops, "reload", terminal_.reload),
+ .direct = cast(iface.Ops, "direct", terminal_.direct),
.feed = cast(iface.Ops, "feed", terminal_.feed),
.grid = cast(iface.Ops, "grid", terminal_.grid),
.viewTo = cast(iface.Ops, "viewTo", terminal_.viewTo),
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index 4de389bd..055c8981 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -195,6 +195,11 @@ pub const State = struct {
/// the step reads the grid it had, as its replicas' replays do, and the
/// rows sent them for it (Screens.fill) are of that grid's numbering.
resize_to: ?struct { cols: u16, rows: u16 } = null,
+ /// Its program's kitty images by direct data alone (`direct`): a
+ /// replica's emulator, which is not the session's. A file, a temporary
+ /// file or shared memory is the session's machine's (and a temporary
+ /// one is deleted by its first reader): its image is absent here.
+ direct: bool = false,
/// The stream over the emulator, its answers to the program and its
/// size reports routed here, PNG decoded: what `create` and a dump's
@@ -338,15 +343,35 @@ pub fn reload(s: *State) !u64 {
var reply: [@typeInfo(@FieldType(State, "reply")).array.len]u8 = undefined;
@memcpy(reply[0..saved.reply.len], saved.reply);
saved.reply = reply[0..saved.reply.len];
- const kept = .{ s.changes, s.read, s.resize_to };
+ const kept = .{ s.changes, s.read, s.resize_to, s.direct };
if (comptime images_enabled) s.images.deinit(gpa);
s.stream.deinit();
s.vt.deinit(gpa);
- s.* = .{ .gpa = gpa, .vt = decoded.toOwned(), .stream = undefined, .changes = kept[0] +% 1, .read = kept[1], .resize_to = kept[2] };
+ s.* = .{ .gpa = gpa, .vt = decoded.toOwned(), .stream = undefined, .changes = kept[0] +% 1, .read = kept[1], .resize_to = kept[2], .direct = kept[3] };
// Short of room for its sequence in flight it goes on without it (lost
// at the next cut), as ghostty's stream does: not worth a terminal.
_ = install(s, decoded.continuation, &saved);
- return std.hash.Wyhash.hash(0, bytes.written());
+ return joinHash(bytes.written());
+}
+
+/// What a join compares of a snapshot (`reload`): every record of it but
+/// its kitty images' (tags 8 to 10, which ghostty's framing makes optional:
+/// snapshot/record.zig, a u16 tag, a u32 length, a u32 CRC and the payload,
+/// after a 10-byte envelope): an image by file or shared memory is the
+/// session's alone (P32, `direct`), and no digest reads an image.
+fn joinHash(bytes: []const u8) u64 {
+ const envelope = 10;
+ const head = 10;
+ var h: std.hash.Wyhash = .init(0);
+ h.update(bytes[0..@min(bytes.len, envelope)]);
+ var at: usize = envelope;
+ while (at + head <= bytes.len) {
+ const tag = std.mem.readInt(u16, bytes[at..][0..2], .little);
+ const end = @min(bytes.len, at + head + std.mem.readInt(u32, bytes[at + 2 ..][0..4], .little));
+ if (tag < 8 or tag > 10) h.update(bytes[at..end]);
+ at = end;
+ }
+ return h.final();
}
/// A decoded emulator at its address made a terminal: its stream wired,
@@ -354,7 +379,7 @@ pub fn reload(s: *State) !u64 {
/// whether its stream had all the room it wanted (`wire`).
fn install(out: *State, continuation: ghostty_vt.snapshot.Continuation, saved: *const Term.Parts) bool {
if (comptime images_enabled) inline for (.{ .primary, .alternate }) |which| {
- if (out.vt.screens.get(which)) |screen| screen.kitty_images.image_limits = .allWithTempDir(tempDir());
+ if (out.vt.screens.get(which)) |screen| screen.kitty_images.image_limits = if (out.direct) .direct else .allWithTempDir(tempDir());
};
const whole = out.wire();
switch (continuation) {
@@ -384,6 +409,16 @@ fn install(out: *State, continuation: ghostty_vt.snapshot.Continuation, saved: *
return whole;
}
+/// Its program's kitty images by direct data alone from now on: the
+/// emulator of a replica that is not the session (P32).
+pub fn direct(s: *State) void {
+ if (comptime !images_enabled) return;
+ s.direct = true;
+ inline for (.{ .primary, .alternate }) |which| {
+ if (s.vt.screens.get(which)) |screen| screen.kitty_images.image_limits = .direct;
+ }
+}
+
/// The allocator it was opened with, its own from then on.
pub fn gpaOf(s: *const State) std.mem.Allocator {
return s.gpa;
@@ -1748,7 +1783,7 @@ test "a join at a cut: every side reloaded from its own snapshot holds the same
// the session's snapshot taken after (the join's dump).
const hash = try reload(session);
try std.testing.expectEqual(hash, try reload(there));
- try std.testing.expectEqual(hash, std.hash.Wyhash.hash(0, before));
+ try std.testing.expectEqual(hash, joinHash(before));
const after = try snapshotOf(gpa, session);
defer gpa.free(after);
const joiner = try load(gpa, after, &parts(session));