summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 23:10:56 -0300
committerGabriel Schneider <[email protected]>2026-11-22 23:10:56 -0300
commit6270f531cd89130a26ee3d5423a740db707f8888 (patch)
tree4b44449bb78bbd60ac2e2cedb6cabd9f98ba7565 /core/replica.zig
parent9acf9f558de00f4588b51dee2cd56b9150c7fb35 (diff)
parentbb60e9cb3d0559ee9cdb1faa972726de097a51b0 (diff)
downloadpardes-6270f531cd89130a26ee3d5423a740db707f8888.tar.gz
pardes-6270f531cd89130a26ee3d5423a740db707f8888.zip
integration (a base for the next rounds, not yet the gathered line): a client's way back at an Upgrade on the viewport's line: pardes-viewport (`llpwyqul`, on pardes-tj11-base: where a view stands in a terminal's history is the view's, the wire at 31; in its whole gate as merge59) and pardes-upgrade-back (`krqkqlyo` on `kryvuotu` on `vlmyrllp` on `qltlrpvu`, on pardes-raw-tty: a client no longer gives up while its session says it is upgrading; an old build's client that comes back early says bye with `again`, the view kept for it not closed; test/daemon.py keeps the evidence of a failed upgrade and reads a far client's environment once its new image runs); no conflict; core-test 917/1077 (160 skipped), shell-test 1119/1122 (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig28
1 files changed, 19 insertions, 9 deletions
diff --git a/core/replica.zig b/core/replica.zig
index f4a3284c..9067a12a 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -2815,7 +2815,7 @@ pub fn join(gpa: Allocator, j: *Joined, path: []const u8, session: []const u8, o
sameBuild(gpa, (dial(gpa, path, session, why, have, null) orelse
// Handed to the session as it upgraded, or cut by its exec with
// its dump on the way: it is there again soon.
- if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading) or cutListed(why, session, have != null)) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why)) orelse return null;
+ if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading) or cutListed(why, session, have != null)) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why, false)) orelse return null;
defer {
if (have) |h| h.store(gpa, j) else gpa.free(j.dump);
j.dump = &.{};
@@ -2892,7 +2892,7 @@ fn ownBoot(gpa: Allocator, j: *Joined, fd: c_int, o: pardes.Options, why: *[600]
pub fn confirmBoot(gpa: Allocator, j: *Joined, r: *Replica, o: pardes.Options, why: *[600]u8) ?*Replica {
const t0 = nowNs();
const digest = j.digest;
- j.* = sameBuild(gpa, joinOn(gpa, j.fd, null, why, null, null, digest) orelse return null, why) orelse return null;
+ j.* = sameBuild(gpa, joinOn(gpa, j.fd, null, why, null, null, digest) orelse return null, why, false) orelse return null;
if (j.dump.len == 0) {
r.id = j.client;
r.view = j.view;
@@ -2909,10 +2909,14 @@ pub fn confirmBoot(gpa: Allocator, j: *Joined, r: *Replica, o: pardes.Options, w
/// `j`, when its session runs this build; else its link let go, and why in
/// `why`: the daemon judged the hello by what the session last said, which
-/// an upgrade under way may not have said yet.
-fn sameBuild(gpa: Allocator, j: Joined, why: []u8) ?Joined {
+/// an upgrade under way may not have said yet. `again`: it was a rejoin for
+/// the view the session kept, which the welcome gave it: kept again for it
+/// (its bye's `again`), for the build at its start path, exec'd, to come
+/// back to (client.zig `execAgain`); closed, it came back in a new view,
+/// its own lost (1 in 4 Upgrades on one CPU, 2026-11-22).
+fn sameBuild(gpa: Allocator, j: Joined, why: []u8, again: bool) ?Joined {
if (j.semantics == wire.semantics) return j;
- bye(j.fd, .{});
+ bye(j.fd, .{ .again = again });
_ = libc.close(j.fd);
var jj = j;
jj.rest.deinit(gpa);
@@ -2923,7 +2927,10 @@ fn sameBuild(gpa: Allocator, j: Joined, why: []u8) ?Joined {
/// The session again, after a divergence or an upgrade: an upgrade's
/// takes the time its exec and load take, and its daemon's, so it is
-/// dialled every 100 ms for 20 s. Null, and why in `why`.
+/// dialled every 100 ms for 20 s. Null, and why in `why`. The session's
+/// own word that it is upgrading (`Peers.refuseAll`, until its exec) is
+/// not a try: it is there, writing its dump for as long as that takes (a
+/// 24 s write let every client go for good, 2026-11-22).
/// `patient`: after an Upgrade's `refused` alone, while the session is
/// away a moment; after a divergence a session that will not answer is
/// gone, and the client says so at once (it froze 20 s, 2026-10-30).
@@ -2931,9 +2938,9 @@ fn sameBuild(gpa: Allocator, j: Joined, why: []u8) ?Joined {
/// none for a first join that met an Upgrade.
fn redial(gpa: Allocator, path: []const u8, session: []const u8, why: *[600]u8, have: ?*Have, patient: bool, view: ?u8) ?Joined {
var tries: u32 = 0;
- while (true) : (tries += 1) {
+ while (true) {
why.* = @splat(0);
- if (dial(gpa, path, session, why, have, view)) |j| return sameBuild(gpa, j, why);
+ if (dial(gpa, path, session, why, have, view)) |j| return sameBuild(gpa, j, why, view != null);
// Another build, or another protocol (the daemon moved with its
// session): no dial again will do.
const words = std.mem.sliceTo(why, 0);
@@ -2944,7 +2951,10 @@ fn redial(gpa: Allocator, path: []const u8, session: []const u8, why: *[600]u8,
// Its daemon lists no such session: it is gone, not away a moment
// (an Upgrade keeps it listed throughout).
if (std.mem.startsWith(u8, words, "no session called ")) return null;
- if (!patient or tries > 200) return null;
+ if (!std.mem.eql(u8, words, upgrading)) {
+ if (!patient or tries > 200) return null;
+ tries += 1;
+ }
const ts: libc.timespec = .{ .sec = 0, .nsec = 100 * std.time.ns_per_ms };
_ = libc.nanosleep(&ts, null);
}