From 494aeadc46212766b3d7869a2ed8b811ac490ffa Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 17:54:43 -0300 Subject: replica: an input's time is its client's: it is sent stamped with the client's guess of the session's clocks (wire 18's `stamp`), the guess its speculation records, and the authority's step reads that, not its own clocks (within a second of them, else its own), so a step's clock read never mispredicts: an edit's second across a turn, a message's millisecond (Ctrl-W's, a jump's) were each a rollback (fixer 1: 4 seen in 2 minutes), and every reapply of one now reads the same time Co-Authored-By: Claude Opus 5.5 --- src/tape.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/tape.zig') diff --git a/src/tape.zig b/src/tape.zig index 12f7fe3d..4759d598 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -257,6 +257,11 @@ pub const Tape = struct { /// (src/replica.zig): its clock reads (a message's stamp, a file's /// mtime) answer this instead of the clocks here. guess: ?Guess = null, + /// The same guess, as the client sent it with its input, while the + /// authority steps that input: the step's clock reads are the input's + /// time, so the guess a speculation recorded is what the authority + /// records (a message's millisecond, an edit's second never miss). + stamp: ?Guess = null, fn record(t: *Tape, kind: Kind, comptime T: type, v: *const T) void { t.scratch.clearRetainingCapacity(); @@ -914,7 +919,7 @@ fn call(comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anyt t.poisoned_by = @tagName(s); return poisonOf(R); } - if (comptime s == .clock or s == .mtime) if (t.speculating) if (t.guess) |g| { + if (comptime s == .clock or s == .mtime) if (if (t.speculating) t.guess else t.stamp) |g| { const r = guessed(R, g); t.record(.host, u16, &id); t.record(.ret, R, &r); -- cgit v1.3