summaryrefslogtreecommitdiff
path: root/src/tape.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:19:25 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:03:40 -0300
commitf2ede98aee0265e3506f5afd6039c70be7812767 (patch)
tree284a64fc9fcf7ba777a20fad75cc6295d70695fb /src/tape.zig
parent08c9415dde1a1d5da2c20124c4fcd4c92783b290 (diff)
downloadpardes-f2ede98aee0265e3506f5afd6039c70be7812767.tar.gz
pardes-f2ede98aee0265e3506f5afd6039c70be7812767.zip
remote clients: a pointer's hit carries the place it was made on (Layer.Place, on the wire, version 17) and a step resolves it from that, never from this process's frame (`surface`, `.local`), which a session never draws for a client: a window's pointer over a tag diverged it at once (the user's `tape byte 119`, 15 rejoins in 25 s) and a click there aborted it; a replay that meets a site its tape lacks, or makes a syscall that is none, is a divergence that goes on harmless (poisonOf), not a panic, and a speculation that makes one waits (Tty's shell lookup, untaped, is a value site now, as Shell's was); a copy over a queue is refused, not asserted; a session's last client, while no one else watches it, leaves it its layout (leaveView, settled as closeView is), which its rejoin copies; a redial waits only after an Upgrade's `refused` (a divergence's redialled a gone session 20 s); a dying session shuts its clients' links before its trace, and an --attach client ends its ssh and socket whatever way it exits; a far join's hashing stops at a blob once its client is let go (its leave waits for it in the step); a confirmed speculation's state is checked against its unit's digest, and the trace gives a key's and a pointer's words; test/daemon.py: 200 far joins level, a window's pointer swept over tags and body, ssh stand-in clients refused and detached, a client of a killed session ending in 2 s; in-process tests for each
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tape.zig')
-rw-r--r--src/tape.zig83
1 files changed, 78 insertions, 5 deletions
diff --git a/src/tape.zig b/src/tape.zig
index b16f39f9..12e3bdec 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -62,6 +62,7 @@ pub const Input = union(enum) {
file_deleted: u8,
open_view,
close_view: u8,
+ leave_view: u8,
to_view: u8,
/// What a window says of its font and its opacity (gui.zig).
take_font_request,
@@ -605,6 +606,7 @@ pub const Tape = struct {
.file_deleted => |id| pardes.panes.File.deleted(p, id),
.open_view => _ = p.openView(),
.close_view => |k| p.closeView(k),
+ .leave_view => |k| p.leaveView(k),
.to_view => |k| p.toView(k),
.take_font_request => _ = p.takeFontRequest(),
.observe_font => |f| _ = p.observeFont(f.name, f.size, f.unit),
@@ -845,12 +847,14 @@ fn call(comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anyt
const t = on orelse return if (yields) out(f, args) else @call(.auto, f, args);
const id: u16 = @as(u16, host_fns.len) + @backingInt(s);
if (t.replay) {
- if (!t.expectHost(id, @tagName(s))) {
- std.debug.print("replay: {s}\n", .{t.diverged orelse "?"});
- @panic("tape: the replay diverged at a host call of the core's own");
- }
+ // Diverged (said in `diverged`): what a speculation gets, harmless,
+ // for the rest of the input. A replica joins again; a replay says so.
+ if (!t.expectHost(id, @tagName(s))) return poisonOf(R);
var ret = t.last_ret;
- return walk.decode(R, &ret, a orelse t.arena.allocator()) catch @panic("tape: a short result");
+ return walk.decode(R, &ret, a orelse t.arena.allocator()) catch {
+ t.diverge("the tape's answer to {t} is short", .{s});
+ return poisonOf(R);
+ };
}
// The host's own (a shell's spawn asking the shell), or one inside a
// site's syscall: the outer call is the record.
@@ -906,6 +910,13 @@ pub fn recordDigest(t: *Tape) void {
t.record(.digest, []const u64, &d);
}
+/// The core's digest against a digest record's payload (a unit's last): a
+/// difference is `diverged`, its fields named when the record has them.
+pub fn checkDigest(t: *Tape, payload: []const u8) void {
+ var r: walk.Reader = .{ .bytes = payload };
+ t.check(&r);
+}
+
/// A core made outside the tape (a replica client's, from a dump) is the
/// one it replays into.
pub fn adoptCore(t: *Tape, p: *Pardes) void {
@@ -945,6 +956,14 @@ pub fn replaying() bool {
return if (on) |t| t.replay or t.speculating else false;
}
+/// A syscall of the core's that is no site, made by a replica: what it
+/// returns is the authority's to say. A speculation waits for it, and a
+/// replay has diverged.
+pub fn stray() void {
+ const t = on orelse return;
+ if (t.speculating) t.poisoned = true else t.diverge("a syscall that is no tape site, made replaying", .{});
+}
+
/// A replica speculating (src/replica.zig): state only the authority
/// changes (a terminal's emulator) is left alone, and the input waits.
pub fn speculating() bool {
@@ -1115,6 +1134,16 @@ pub fn describe(bytes: []const u8, w: *std.Io.Writer) void {
const tag = std.mem.bytesToValue(std.meta.Tag(Input), payload[0..@sizeOf(std.meta.Tag(Input))]);
w.print("input {t}", .{tag}) catch {};
if (tag == .update) w.print(" {t}", .{std.mem.bytesToValue(std.meta.Tag(pardes.Event), payload[@sizeOf(std.meta.Tag(Input))..][0..@sizeOf(std.meta.Tag(pardes.Event))])}) catch {};
+ // A key's or a pointer's own words: which one a divergence
+ // starts at.
+ var room: [4096]u8 = undefined;
+ var fixed: std.heap.FixedBufferAllocator = .init(&room);
+ var in: walk.Reader = .{ .bytes = payload };
+ if (tag == .update) if (walk.decode(Input, &in, fixed.allocator())) |input| switch (input.update) {
+ .key => |k| w.print(" {any}", .{k}) catch {},
+ .mouse => |m| w.print(" {t} {t} {d},{d} body {any} tag {any}", .{ m.button, m.kind, m.col, m.row, m.body_hit != null, m.tag_hit != null }) catch {},
+ else => {},
+ } else |_| {};
},
.host => {
const id = std.mem.bytesToValue(u16, payload[0..2]);
@@ -1201,3 +1230,47 @@ pub fn replayMain(io: std.Io, path: []const u8) u8 {
}
return if (failed) 1 else 0;
}
+
+test "a syscall that is no site, made replaying, diverges the replay and poisons a speculation" {
+ if (comptime !pardes.hosted) return;
+ const gpa = std.testing.allocator;
+ var t: Tape = .{ .gpa = gpa, .replay = true, .scratch = .init(gpa), .arena = .init(gpa) };
+ defer t.scratch.deinit();
+ defer t.arena.deinit();
+ defer if (t.diverged) |why| gpa.free(why);
+ on = &t;
+ defer on = null;
+ pardes.turn.yield();
+ pardes.turn.back();
+ try std.testing.expect(t.diverged != null);
+ t.replay = false;
+ t.speculating = true;
+ pardes.turn.yield();
+ pardes.turn.back();
+ try std.testing.expect(t.poisoned);
+}
+
+test "a replay that finds no answer where its core reads one diverges, and the read goes on harmless" {
+ if (comptime !pardes.hosted) return;
+ const gpa = std.testing.allocator;
+ var t: Tape = .{ .gpa = gpa, .replay = true, .scratch = .init(gpa), .arena = .init(gpa) };
+ defer t.scratch.deinit();
+ defer t.arena.deinit();
+ defer if (t.diverged) |why| gpa.free(why);
+ // The input's end where the core reads a value of the host's (a
+ // window client's step that took a turn the session's had not, H9 of
+ // 2026-10-30: it aborted the client).
+ const bytes = [5]u8{ @backingInt(Kind.done), 0, 0, 0, 0 };
+ t.in = .{ .bytes = &bytes };
+ t.host_side = false;
+ on = &t;
+ defer on = null;
+ const read = struct {
+ fn f() bool {
+ return true;
+ }
+ }.f;
+ try std.testing.expect(!value(.denied, read, .{}));
+ try std.testing.expect(t.diverged != null);
+ try std.testing.expect(!value(.denied, read, .{}));
+}