summaryrefslogtreecommitdiff
path: root/runtime/client.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 04:05:02 -0300
committerGabriel Schneider <[email protected]>2026-11-23 04:20:58 -0300
commit3a0acb503613a672c3d84f685031ab5e65c10ff6 (patch)
tree907c7ccdb4fc3b8dbe6471991ed1c63fce8a6542 /runtime/client.zig
parent4faf94b72b60ecb0656e7e90ca693b63b1fde71c (diff)
parenta3d98f0e465ed9634d0534e0a6c71767b2a709b9 (diff)
downloadpardes-3a0acb503613a672c3d84f685031ab5e65c10ff6.tar.gz
pardes-3a0acb503613a672c3d84f685031ab5e65c10ff6.zip
merge: round 1 of a link's lifecycle (pardes-link-1, `nlqrtuns`: a client whose link is up comes back over it) onto the dump and the digest (pardes-m63-base, `xxvnuywy`: the installed tree + the one decision + a join's digest taken with its dump, a refused load naming its field), the two implementations of "a refused load names its field" made one: the dump line's naming kept (every join's dump ends with the session's digest a field at a time, `dump.joinParts`, read by `loadDiffers`), round 1's deleted (the wire's `ServerTag.parts` 0x0d and `ServerMsg.parts`, a bye's byte 3 and `ClientMsg.bye.parts`, `Peer.fields`, `Peer.parts`, `Peers.partsOf`, `Peer.writeParts`, the `Parts` read in `loadAgain`, `comeBack`'s `parts` argument, `fromDump`'s second naming from that message); round 1's road kept (`fromDump` asks once more over the same connection, `loadAgain`, `joinOn` reading on to a welcome); the conflicts: abi/wire.zig's 31 line (both sides' sentences, round 1's without `parts`), `Peers.join` (the dump line took `dumpJoin`'s `.{ bytes, digest }` inline where round 1 had split the dump and the welcome out, `Peers.dumped` and `Peers.welcome`: `dumped` now returns the bytes WITH the digest `dumpJoin` took at the dump's moment and `welcome` takes that digest, so a join again over the link (`dumpAgain`) has the dump line's guarantee too, where round 1's `welcome` read `tape.digestOf(core)` after the dump), `fromDump` (the dump line's named refusal and round 1's loop: now the first refusal names its fields in the log and asks once more, a second, or a link that cannot ask (its words kept, `j` and its dump the caller's), gives up naming them in its words: "the session's dump loaded as another session twice: fs differs"); `loadAgain` asks before it lets the dump go (the dump line's test hands `fromDump` a dump of its own and no link: it was freed); semantic conflicts looked for: the one decision's `Replica.confirm` and core/tape.zig (`feedsTerminal`, `touchTerminal`, `Pending.terminal`, `shell_rows` gone): nothing of round 1's used them; the rollback copy's walk: `Peer`'s and `Link`'s new state (`gen`, `written`, `back`) is outside the core it walks (Peers and Link are the engines', not `Pardes`'s fields), nothing to declare; tests: round 1's "refused twice" made from the dump's own parts (its first field's word changed in the dump, no message), the dump line's "says which field" given the session's name argument; root.zig's machine_lines for replica.zig 90 -> 89 (`loadAgain`'s close gone); core-test 930/1094 (164 skipped: the base's 924/1088 and round 1's six), shell-test 1136/1139 (3 skipped: the base's 1130/1133 and round 1's six)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'runtime/client.zig')
-rw-r--r--runtime/client.zig45
1 files changed, 33 insertions, 12 deletions
diff --git a/runtime/client.zig b/runtime/client.zig
index 43fdf98d..2fbc75c8 100644
--- a/runtime/client.zig
+++ b/runtime/client.zig
@@ -95,7 +95,7 @@ pub const Start = struct {
s.o.frames = &s.frames;
// Exec'd at an Upgrade (`execAgain`): for the view it had.
if (init.environ_map.get("PARDES_JOIN_VIEW")) |v| s.o.join_view = std.fmt.parseInt(u8, v, 10) catch null;
- s.r = replica.join(s.gpa, &s.joined, dial.path, dial.session, s.o, s.have, &s.why, null) orelse return false;
+ s.r = replica.join(s.gpa, &s.joined, dial.path, dial.session, s.o, s.have, &s.why, null, false) orelse return false;
return true;
}
@@ -209,11 +209,23 @@ pub fn Loop(comptime Frontend: type) type {
l.after();
}
if (s.env.get("PARDES_REPLICA_STATS")) |file| link.writeStats(file);
- if (!link.gone) replica.bye(s.joined.fd, .{ .again = s.r.diverged != null or link.lagged != 0, .close = link.close });
- // The link's reader ends with the link, posting as it goes:
- // what it posted is let go until it has (a terminal's queue
- // is bounded: a reader blocked on it would never end).
- _ = libc.shutdown(s.joined.fd, 2);
+ // Its link up and the session's state to take again: its
+ // goodbye and its hello said on it, the session's dump comes
+ // there (`replica.comeBack`); its reader reads on to the welcome,
+ // letting the stream it leaves go. Only a link that is gone
+ // is dialled again.
+ const here = link.backHere() and s.joined.rest.overlong() == null and back: {
+ link.back.store(true, .release);
+ break :back replica.comeBack(s.joined.fd, s.dial.session, s.r.view);
+ };
+ if (!here) {
+ if (!link.gone) replica.bye(s.joined.fd, .{ .again = s.r.diverged != null or link.lagged != 0, .close = link.close });
+ _ = libc.shutdown(s.joined.fd, 2);
+ }
+ // The link's reader ends with the link (or at the welcome),
+ // posting as it goes: what it posted is let go until it has
+ // (a terminal's queue is bounded: a reader blocked on it
+ // would never end).
while (true) {
const ended = done.load(.acquire);
l.fe.drop();
@@ -221,14 +233,23 @@ pub fn Loop(comptime Frontend: type) type {
std.Thread.yield() catch {};
}
reader.join();
- _ = libc.close(s.joined.fd);
- s.joined.rest.deinit(s.gpa);
+ if (!here) {
+ _ = libc.close(s.joined.fd);
+ s.joined.rest.deinit(s.gpa);
+ }
// Its link cut with no word by a session that is there still
// (an Upgrade's exec): joined again, as when told so.
if (link.gone and link.refused == null and link.ended == null and !link.left and replica.cutListed("the session hung up", s.dial.session, s.have != null))
link.refused = std.heap.c_allocator.dupe(u8, replica.upgrading) catch null;
- // Why it joins again is in its notice until a key.
- if (!link.rejoins()) {
+ // A last word goes first, one read after it said it comes
+ // back too (a Detach in it, the session's end). Why it joins
+ // again is in its notice until a key.
+ const goes = link.ended != null or link.left;
+ if (here and goes) {
+ _ = libc.close(s.joined.fd);
+ s.joined.rest.deinit(s.gpa);
+ }
+ if (goes or !link.rejoins()) {
// What it made since it joined, kept for its next start.
if (s.have) |h| h.keep(s.r.core());
s.r.deinit();
@@ -238,7 +259,7 @@ pub fn Loop(comptime Frontend: type) type {
}
// The session again, the core it leaves held meanwhile: its
// blobs are not sent again.
- s.r = replica.join(s.gpa, &s.joined, s.dial.path, s.dial.session, s.o, s.have, &s.why, s.r) orelse {
+ s.r = replica.join(s.gpa, &s.joined, s.dial.path, s.dial.session, s.o, s.have, &s.why, s.r, here) orelse {
if (replica.ended(&s.why)) return .gone;
if (replica.otherBuild(&s.why) and upgrade.replaced()) return .{ .upgrade = s.joined.view };
return .failed;
@@ -272,7 +293,7 @@ pub fn Loop(comptime Frontend: type) type {
/// and its end.
fn read(l: *L, s: *Start, done: *std.atomic.Value(bool)) void {
defer done.store(true, .release);
- replica.readLink(s.gpa, s.joined.fd, &s.joined.rest, l.fe, Frontend.said);
+ replica.readLink(s.gpa, s.joined.fd, &s.joined.rest, &l.link, l.fe, Frontend.said);
l.fe.ended();
}