summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 03:03:25 -0300
committerGabriel Schneider <[email protected]>2026-11-22 03:03:55 -0300
commit70c9e3fbf9cdc7139b4da0142f3a44741a7e1491 (patch)
tree966bee71386ad820cb8b23a96ac0c09e5a0f0c1d /core/replica.zig
parentd56973aa92d0de6d84446dff73eba9d5654fe6f4 (diff)
downloadpardes-70c9e3fbf9cdc7139b4da0142f3a44741a7e1491.tar.gz
pardes-70c9e3fbf9cdc7139b4da0142f3a44741a7e1491.zip
replica: no road to choose, and the wire at 30 (the old road's deletion, piece 4 of 8; the coordinator's decision: the welcome's road byte goes, no dead field stays on the wire): `Peers.bytes` (set by runtime/session.zig unless PARDES_TERM_SCREEN), the welcome's `bytes` byte (abi/wire.zig: its encode, its decode, the round-trip test's byte), `Joined.bytes` and `joinOn`'s copy of it, `road` (fromDump's, ownBoot's, confirmBoot's, a test's: a replica's `made` arms its echo already, and no replica starts on screen state since piece 3), and ownBoot's read of PARDES_TERM_SCREEN; so PARDES_TERM_SCREEN and PARDES_TERM_BYTES name nothing in the tree; abi/wire.zig's version is 30, its history line saying both of this line's wire changes (the screen messages retired as gaps in piece 3, the welcome's byte here); test/daemon.py's `WIRE` 30; firstOnPair's argument is now what it chose, `by_dump` (a client joined by the session's dump, or one that makes its own core); core/root.zig `machine_lines` for replica.zig 74 -> 73; core-test 911/1068 (157 skipped), shell-test 1110/1113
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig53
1 files changed, 14 insertions, 39 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 3f897044..55e7a1f7 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -1789,11 +1789,6 @@ pub const Peers = struct {
/// writer would write (its join, then `out`) and its reader read
/// (`Peer.take`, then `.gone` posted) are its driver's to do.
threads: bool = true,
- /// Its clients' terminals cross as the pty's bytes in its units, each
- /// client's emulator its own (P29, P32), not as screen state: every
- /// session's (runtime/session.zig) but under PARDES_TERM_SCREEN, the
- /// soak's `--bytes`; its welcome says so to each client.
- bytes: bool = false,
pub const Note = union(enum) { join: Joining, input: Msg, gone: *Peer, check: *Peer, joined: *Peer };
/// A connection to join, and the view it joins again for, if it does.
@@ -1992,7 +1987,7 @@ pub const Peers = struct {
// (a pair's client, its own boot: `writeJoin`).
const digest = tape.digestOf(core);
peer.digest = digest;
- peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = peer.view, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len), .bytes = ps.bytes } }) catch unreachable).len;
+ peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = peer.view, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
if (ps.threads and (peer.writer == null or peer.reader == null)) {
@@ -2316,9 +2311,6 @@ pub const Joined = struct {
/// Its replica is its own boot, the welcome not read yet (`ownBoot`,
/// `confirmBoot`).
booted: bool = false,
- /// Its session's terminals come as the pty's bytes, not screen state
- /// (the welcome's word, Peers.bytes).
- bytes: bool = false,
};
/// A blob a far join was sent: where it is in the dump, and its hash.
@@ -2399,7 +2391,6 @@ fn joinOn(gpa: Allocator, fd: c_int, session: ?[]const u8, why: []u8, have: ?*Ha
r.j.gmtoff = w.gmtoff;
r.j.digest = w.digest;
r.j.semantics = w.semantics;
- r.j.bytes = w.bytes;
if (r.boot == w.digest) {
r.done = true;
return false;
@@ -2803,16 +2794,14 @@ pub fn join(gpa: Allocator, j: *Joined, path: []const u8, session: []const u8, o
return fromDump(gpa, j, o, have, why, t0);
}
-/// The replica of the dump `j` brought, on the road its welcome says, its
-/// load checked by the session's digest, and what it takes of `j`; null,
-/// and why in `why`, when it does not load as the session.
+/// The replica of the dump `j` brought, its load checked by the session's
+/// digest (its emulators' among it), and what it takes of `j`; null, and
+/// why in `why`, when it does not load as the session.
fn fromDump(gpa: Allocator, j: *Joined, o: pardes.Options, have: ?*Have, why: []u8, t0: u64) ?*Replica {
const r = Replica.initDump(gpa, j.client, j.view, j.dump, o) catch |err| {
_ = std.fmt.bufPrint(why, "the session's dump would not load: {t}\x00", .{err}) catch {};
return null;
};
- // Before the check: on the bytes road the digest covers its emulators.
- road(r, j.bytes);
if (!r.loaded(j.digest)) {
r.deinit();
_ = std.fmt.bufPrint(why, "the session's dump loaded as another session (a build's dump is not complete)\x00", .{}) catch {};
@@ -2822,14 +2811,6 @@ fn fromDump(gpa: Allocator, j: *Joined, o: pardes.Options, have: ?*Have, why: []
return r;
}
-/// Its terminals its own emulators, fed the pty's bytes its units carry
-/// (`bytes`, its session's Peers.bytes), or the session's screen state;
-/// its echo predicted on either (core/echo.zig).
-fn road(r: *Replica, bytes: bool) void {
- r.t.screen_state = !bytes;
- r.core().echo = &r.echo;
-}
-
/// What a replica joined by `j` takes of it, and of the environment.
fn takeJoined(r: *Replica, j: *Joined, have: ?*Have, t0: u64) void {
// PARDES_NO_ECHO: no predicted echo (the gates' baseline).
@@ -2867,10 +2848,7 @@ fn ownBoot(gpa: Allocator, j: *Joined, fd: c_int, o: pardes.Options, why: *[600]
_ = std.fmt.bufPrint(why, "the session hung up\x00", .{}) catch {};
return null;
}
- // Its session is this process's child, on the road this environment
- // says (runtime/session.zig): the welcome says it again.
- j.* = .{ .fd = fd, .pid = 0, .client = r.id, .view = r.view, .gmtoff = gmtoff(), .dump = &.{}, .digest = digest, .semantics = wire.semantics, .booted = true, .bytes = std.c.getenv("PARDES_TERM_SCREEN") == null };
- road(r, j.bytes);
+ j.* = .{ .fd = fd, .pid = 0, .client = r.id, .view = r.view, .gmtoff = gmtoff(), .dump = &.{}, .digest = digest, .semantics = wire.semantics, .booted = true };
takeJoined(r, j, null, t0);
return r;
}
@@ -2889,7 +2867,6 @@ pub fn confirmBoot(gpa: Allocator, j: *Joined, r: *Replica, o: pardes.Options, w
if (j.dump.len == 0) {
r.id = j.client;
r.view = j.view;
- road(r, j.bytes);
return r;
}
defer {
@@ -4230,9 +4207,10 @@ fn ownBootAgainst(edited: bool) !void {
/// A session's first client on a socket pair (runtime/session.zig's, then
/// the client's first join on its end), the session's first effects after:
/// its boot shell spawned, its first bytes output; the client quiet and
-/// checked. Bytes: the client loaded as the soak's bytes clients are
-/// (`replica.join` loads the screen-state kind until the switch).
-fn firstOnPair(bytes: bool) !void {
+/// checked. `by_dump`: the client joined by the session's dump, as any
+/// client loads one (`fromDump`); else it makes its own core (Options.pair,
+/// `confirmBoot`).
+fn firstOnPair(by_dump: bool) !void {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
const Spawns = struct {
@@ -4249,7 +4227,7 @@ fn firstOnPair(bytes: bool) !void {
const core = try Pardes.init(gpa, opts);
defer core.deinit();
core.host = .{ .ctx = &spawns, .vtable = &Spawns.vtable };
- var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "pair", .bytes = true, .detached = true };
+ var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "pair", .detached = true };
defer ps.deinit();
defer live_peers = null;
defer ps.dropAll(core);
@@ -4257,12 +4235,10 @@ fn firstOnPair(bytes: bool) !void {
ps.join(core, .{ .fd = fds[0], .own = true });
var j: Joined = undefined;
var why: [600]u8 = @splat(0);
- const r = if (bytes) r: {
- // Joined by its dump as any client loads one (`fromDump`): the
- // welcome says the road, and its load is checked on it.
+ const r = if (by_dump) r: {
+ // Joined by its dump as any client loads one (`fromDump`).
j = joinOn(gpa, fds[1], null, &why, null, null, null) orelse return error.JoinFailed;
defer gpa.free(j.dump);
- try std.testing.expect(j.bytes);
break :r fromDump(gpa, &j, opts, null, &why, nowNs()) orelse {
std.debug.print("the join: {s}\n", .{std.mem.sliceTo(&why, 0)});
return error.JoinFailed;
@@ -4333,7 +4309,7 @@ fn firstOnPair(bytes: bool) !void {
defer arena.deinit();
const rows = try pardes.Term.viewport(r.core().panes[shell].?.terminal.?, arena.allocator(), false);
try std.testing.expect(std.mem.indexOf(u8, rows[0], "first$") != null);
- if (!bytes) return;
+ if (!by_dump) return;
// One that comes after the shell's bytes: every side reloads.
var late: [2]c_int = undefined;
if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &late) != 0) return error.NoSocket;
@@ -5767,7 +5743,7 @@ test "a step of the session's own that reads a terminal right after its output,
core.view().active = shell;
// The session as runtime/session.zig runs it; the client's link in
// memory.
- var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .threads = false, .bytes = true };
+ var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .threads = false };
defer ps.deinit();
defer ps.dropAll(core);
var fds: [2]c_int = undefined;
@@ -5795,7 +5771,6 @@ test "a step of the session's own that reads a terminal right after its output,
try whole.appendSlice(gpa, peer.dump[pos..]);
const r = try Replica.initDump(gpa, w.client, w.view.index(), whole.items, .{ .cols = 80, .rows = 24, .boot = .tty });
defer r.deinit();
- road(r, w.bytes);
try std.testing.expect(r.loaded(w.digest));
var link: Link = .{ .r = r, .fd = fds[1] };
defer link.deinit(gpa);