diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 22:03:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 22:39:43 -0300 |
| commit | e8e612685e31989c22f2844cc55d9703d817d1df (patch) | |
| tree | 31e882a86107f07b06eace9afdca4d4417d6b702 /core/replica.zig | |
| parent | 1ce129e7415590a4979e71da683966c056fba532 (diff) | |
| download | pardes-e8e612685e31989c22f2844cc55d9703d817d1df.tar.gz pardes-e8e612685e31989c22f2844cc55d9703d817d1df.zip | |
replica: a client's kept list that reaches its bound (rebase_after, 32 units) while a key of its own is applied on top is let go free at the next unit that leaves nothing applied (the key's own unit, next in the stream), not put back with the 32 units replayed and the key applied again; with inputs on top all the while it is put back at twice the bound, so a rollback still replays a bounded list: before the session sends its pump's unit (it moved nothing, kept as neutral) ahead of every client key, so two units are kept a key and whether the 32nd is the pump's (the whole replay, about 50 to 100M instructions on the 3.2 MB file) or the key's own (free) is the parity the client's first units set, which made a near client's `edit` key 14.3 or 16.7 to 18.8M a block of 20 and `key-down` 3.8 or 8.8M by chance of the run, in either order of the send (`klmtkkpz` did not cause it: base against base with the order turned back, 6 runs each, edit medians 17.05 and 17.06M, 4 of 12 blocks over 1.05 in both); the kit (pardes-perf-sendfirst), base against this, 6 runs alternated, 12 blocks each, ReleaseFast, load 16 to 47: client edit 16.88M median (14.28 to 18.78, 5 blocks over 1.05) to 14.28M (14.26 to 14.30, none), key-down 3.83M (3.81 to 8.78, 2 over) to 3.84M (3.81 to 3.99, none), type 11.24M (11.00 to 12.88, 1 over) to 11.15M (11.01 to 11.29, none), rebases 1 to 5 a run to 0, the own path and the session unchanged; a test through the replica's surface (hand-ordered: a pump unit then the key's unit, 31 keys) fails before (one whole replay) and passes; tui core-test 849/992 (143 skipped), shell-test 1028/1031, pane-test 183/184, term-test 15/15, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275
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.zig | 81 |
1 files changed, 67 insertions, 14 deletions
diff --git a/core/replica.zig b/core/replica.zig index 3a36a06b..040c33ca 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -40,8 +40,10 @@ const checked = builtin.mode == .debug or builtin.mode == .safe; const head_len = 6; // origin or client: u16le, seq: u32le /// A `stamp` frame (wire.zig): its header and the two clocks. const stamp_len = wire.header_len + 16; -/// Confirmed units fast-pathed under one copy before it is taken afresh: -/// a rollback replays them all. +/// Confirmed units kept under one copy before it is let go, at the next +/// unit that leaves nothing applied on top (free: it is the confirmed +/// state); a rollback replays them all, so with inputs applied on top all +/// the while it is put back at twice as many. const rebase_after = 32; /// A client compares its core's digest with the session's at most once in /// this many confirmed units (a unit that carries one, its state the @@ -1037,22 +1039,23 @@ pub const Replica = struct { if (r.diverged == null) r.diverged = r.gpa.dupe(u8, why) catch return; } - /// A unit kept to replay when the copy is next put back; past - /// `rebase_after` of them, that is now (`toConfirmed`). + /// A unit kept to replay when the copy is next put back (`rebase_after`). fn keepSince(r: *Replica, unit: []const u8) void { const kept = r.gpa.dupe(u8, unit) catch return r.fail("out of memory"); r.since.append(r.gpa, kept) catch return r.fail("out of memory"); - if (r.since.items.len >= rebase_after) { - // Nothing on top: it is the confirmed state already. - if (r.applied == 0) { - r.copy.release(); - rollback.Epoch.select(null); - return r.clearSince(); - } - r.stats.rebases += 1; - r.toConfirmed(); - r.dirty = true; + if (r.since.items.len < rebase_after) return; + // Nothing on top: it is the confirmed state already. + if (r.applied == 0) { + r.copy.release(); + rollback.Epoch.select(null); + return r.clearSince(); } + // An input applied on top (the session's pump unit before its own + // unit, the next to come): let go then, not replayed whole now. + if (r.since.items.len < 2 * rebase_after) return; + r.stats.rebases += 1; + r.toConfirmed(); + r.dirty = true; } fn clearSince(r: *Replica) void { @@ -3680,6 +3683,56 @@ test "the copy taken for an input of its own stays once the input is confirmed: try std.testing.expectEqual(@as(u32, 1), r.stats.foreign); } +test "the session's pump units that moved nothing, kept under a key applied on top, reach the kept list's bound: it is let go at the confirm that leaves nothing applied, never replayed whole" { + // The live pair's order (core/replica.zig Peers.boundary): before it + // steps a client's key the session sends its pump's unit, which moved + // nothing; the client takes it with the key applied on top (`neutral`, + // kept), then the key's own unit (fast, kept). Two kept a key: which + // of them is the bound's is the arrivals' parity, and a pump's unit + // while idle turns it. + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + defer r.deinit(); + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + freshSecond(); + // A first key, confirmed: the copy held, one unit kept (the parity + // that puts the bound on a pump's unit). + try key(r, 'j', &sent); + r.confirm(try a.take(sent.items[0])); + for (1..rebase_after) |i| { + try key(r, if (i % 2 == 0) 'j' else 'k', &sent); + a.pump(); + r.confirm((try a.pending()).?); + r.confirm(try a.take(sent.items[i])); + r.settle(); + try std.testing.expect(r.since.items.len <= rebase_after); + } + try std.testing.expectEqual(@as(u32, rebase_after - 1), r.neutral); + try std.testing.expectEqual(@as(u32, 0), r.stats.rebases); + try agrees(a, r); + // Keys applied on top all the while (one ahead of the session): the + // list is put back and replayed at twice the bound, not let grow. + try key(r, 'j', &sent); + for (0..3 * rebase_after) |i| { + try key(r, 'k', &sent); + a.pump(); + r.confirm((try a.pending()).?); + r.confirm(try a.take(sent.items[rebase_after + i])); + r.settle(); + try std.testing.expect(r.since.items.len <= 2 * rebase_after); + } + try std.testing.expect(r.stats.rebases >= 1); + r.confirm(try a.take(sent.items[sent.items.len - 1])); + r.settle(); + try agrees(a, r); +} + test "a rollback over a Tab it applied measures tabs as its core has them again" { // A tab's width is the core's (settings.tab, handed to every width // function), which the copy holds: once the process's (config.tab_now), |
