summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 06:35:16 -0300
committerGabriel Schneider <[email protected]>2026-11-20 09:14:33 -0300
commitff183922e78f04eee85043d29f1bd5e5ba43a6cd (patch)
tree62fd4aa1fa53235507da94a6bc36fe65066afbde /core
parent89f4b611e4e6e1732595d070184daf167b53bfb3 (diff)
downloadpardes-ff183922e78f04eee85043d29f1bd5e5ba43a6cd.tar.gz
pardes-ff183922e78f04eee85043d29f1bd5e5ba43a6cd.zip
tape: the turn's check is a count, step 9a (reports/pardes-handle-69-design.md section 3.2): Turn.yield no longer asks the global tape whether a replica steps, it counts (Turn.yields, and Turn.zig no longer imports the tape); a speculation's tape notes the count at beginSpeculation and endSpeculation compares it, and apply compares it around each replayed input (the divergence still names the input; not around a session's end, whose dump check reads through no tape), with the same verdicts as before (a speculation poisoned, a replay diverged: Tape.stray, which now takes the count it started from); the free stray goes, the free replaying stays (the terminal's emulatorGpa reads it); the stray test drives a yield through both; the tape's bytes do not move (semantics df1f0502317ed362, cross_replay both ways against step 7: 29 and 27 digests agree x3); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed at a load of 37 (tagalign, exec-bigdrag) and both pass alone, the bytes soak as the base (diverged 0, unequal 0, corpus 22 of 22, the base's one now stop), the plain soak cut short after rtt 80 (diverged 0, unequal 0, corpus 22 of 22; its 207 is the next change's gate); gui unit-test 1645/1649 (the perf check's BaselineHarnessMismatch)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/Turn.zig10
-rw-r--r--core/tape.zig32
2 files changed, 25 insertions, 17 deletions
diff --git a/core/Turn.zig b/core/Turn.zig
index 687e287f..249c6795 100644
--- a/core/Turn.zig
+++ b/core/Turn.zig
@@ -17,7 +17,6 @@
//! come from a shell performing a save between steps -- so a parked request
//! is never the syscall's own.
const std = @import("std");
-const tape = @import("tape.zig");
const Turn = @This();
@@ -46,6 +45,10 @@ restores: u64 = 0,
lsp_answers: u64 = 0,
/// All of the above, and `out` reaching zero.
settled: std.Io.Condition = .init,
+/// Every `yield`, ever: a replica's step makes none (each syscall of its
+/// core is a tape site), which its tape checks by this count across a
+/// speculation and a replayed input (core/tape.zig `stray`).
+yields: u64 = 0,
/// The editor's thread takes the turn for good; it has it until `stop`.
pub fn start(t: *Turn, io: std.Io) void {
@@ -79,10 +82,7 @@ pub fn wake(t: *Turn) void {
/// a step. Nests: a directory listing that resolves each entry yields
/// inside a yield, and only the outermost one lets go.
pub fn yield(t: *Turn) void {
- // A replica makes no syscall: each is a site of the tape's. One that
- // is none stops a speculation and diverges a replay (it joins
- // again), never the process (a window client's `Term fish`, H17).
- if (tape.replaying()) tape.stray();
+ t.yields +%= 1;
const io = t.io orelse return;
yield_depth += 1;
if (yield_depth != 1) return;
diff --git a/core/tape.zig b/core/tape.zig
index 934bc499..c32c4453 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -280,6 +280,8 @@ pub const Tape = struct {
/// checks.
speculating: bool = false,
poisoned: bool = false,
+ /// The turn's yields when the speculation began (`stray`).
+ yields: u64 = 0,
/// What stopped it: a host function's or a site's name, or a poison's
/// reason (PARDES_REPLICA_STATS counts them).
poisoned_by: []const u8 = "",
@@ -664,6 +666,9 @@ pub const Tape = struct {
defer t.applying = outer;
t.host_side = true;
defer t.host_side = true;
+ // Not at the end: the dump checked there reads through no tape.
+ const yields = pardes.turn.yields;
+ defer if (input != .deinit) t.stray(yields);
switch (input) {
.init, .init_from_dump => {
var opts = switch (input) {
@@ -858,11 +863,13 @@ pub const Tape = struct {
return t.replay or t.speculating;
}
- /// 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(t: *Tape) void {
- if (t.through) return;
+ /// A syscall of the core's that is no site, made by a replica since the
+ /// turn's count of yields was `since`: what it returned is the
+ /// authority's to say. A speculation waits for it, and a replay has
+ /// diverged (it joins again), never the process (a window client's
+ /// `Term fish`, H17).
+ fn stray(t: *Tape, since: u64) void {
+ if (pardes.turn.yields == since) return;
if (t.speculating) t.poisoned = true else t.diverge("a syscall that is no tape site, made replaying", .{});
}
@@ -1328,10 +1335,6 @@ pub fn replaying() bool {
return (on orelse &none).replaying();
}
-pub fn stray() void {
- (on orelse &none).stray();
-}
-
/// A replica speculating (core/replica.zig): state only the authority
/// changes (a terminal's emulator) is left alone, and the input waits.
pub fn speculating() bool {
@@ -1462,12 +1465,14 @@ pub fn beginSpeculation(t: *Tape) void {
t.poisoned_by = "";
t.touched = false;
t.no_digest = true;
+ t.yields = pardes.turn.yields;
t.buf.clearRetainingCapacity();
t.seeFields();
}
/// Whether it stayed clean (no host call, no syscall, no authority state).
pub fn endSpeculation(t: *Tape) bool {
+ t.stray(t.yields);
t.speculating = false;
t.no_digest = false;
return !t.poisoned;
@@ -1642,16 +1647,19 @@ test "a syscall that is no site, made replaying, diverges the replay and poisons
defer t.scratch.deinit();
defer t.arena.deinit();
defer if (t.diverged) |why| gpa.free(why);
- on = &t;
- defer on = null;
+ const since = pardes.turn.yields;
+ t.stray(since);
+ try std.testing.expect(t.diverged == null);
pardes.turn.yield();
pardes.turn.back();
+ t.stray(since);
try std.testing.expect(t.diverged != null);
t.replay = false;
t.speculating = true;
+ t.yields = pardes.turn.yields;
pardes.turn.yield();
pardes.turn.back();
- try std.testing.expect(t.poisoned);
+ try std.testing.expect(!endSpeculation(&t));
}
test "a replay that finds no answer where its core reads one diverges, and the read goes on harmless" {