Identify suppressed relocation cycles across persistent reads
of shared·codex-capacity-chair·
Version 125 · Files at version 126
2 files, 25 lines added, 4 removed.
--- a/src/engine/test/moves.test.ts
+++ b/src/engine/test/moves.test.ts
@@ -5,8 +5,10 @@
66import assert from "node:assert/strict"; 77import { describe, it } from "node:test"; 8−import { type Atom, type AtomId, conflicts } from "../index.ts";
8+import { type Atom, type AtomId, conflicts, Graph, View } from "../index.ts"; 9+import { StableOverlaySet } from "../state-source.ts"; 910import { lines, Repo, Rng } from "./helpers.ts"; 11+import { SqlState } from "./storage-helper.ts"; 1113const BASE_SEED = Number(process.env.PROP_SEED ?? 20261004); 1214const CASES = Number(process.env.PROP_CASES ?? 200); @@ -243,6 +245,22 @@
243245 accept(repo, mk("a0.2", "a0.0")); 244246 const text = repo.text("f.txt"); 245247 assert.deepEqual(text.split("\n").filter(Boolean).sort(), ["m", "n", "x", "y"]); 248+ class BoundedReads extends SqlState { 249+ override read(collection: string, key: string): unknown { 250+ if (this.reads > 10_000) throw new Error("relocation cycle did not terminate"); 251+ return super.read(collection, key); 254+ const storage = new BoundedReads(); 256+ const stored = new Graph({ storage }); 257+ for (let seq = 0; seq < repo.graph.size; seq++) stored.add(repo.graph.atom(repo.graph.idOfSeq(seq))); 258+ const reopened = new Graph({ storage }); 259+ assert.equal(new View(reopened, repo.shared).text("f.txt"), text); 260+ assert.equal(new View(reopened, new StableOverlaySet(repo.shared)).text("f.txt"), text); 248266 it("rejects a move onto itself or out of range", () => { --- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -198,11 +198,14 @@
198198 if (this.#relocs) return this.#relocs; 199199 const graph = this.graph; 200200 const stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0; 201− const ignored = new Set<RelocationInfo>();
201+ // Persistent reads decode new objects. Cycle suppression must identify the 202+ // logical move, not one particular decoded JavaScript object. 203+ const identity = (r: RelocationInfo): string => JSON.stringify([r.atom, r.k]); 204+ const ignored = new Set<string>(); 202205 const pick = (line: LineId): RelocationInfo | undefined => { 203206 let best: RelocationInfo | undefined; 204207 for (const r of graph.relocationsOf(line)) { 205− if (this.#has(graph.atom(r.atom).seq) && !ignored.has(r) && (!best || stronger(r, best))) best = r;
208+ if (this.#has(graph.atom(r.atom).seq) && !ignored.has(identity(r)) && (!best || stronger(r, best))) best = r; @@ -239,7 +242,7 @@
239242 const r = relocs.get(l); 240243 if (r && (!weakest || stronger(weakest, r))) weakest = r; 242− ignored.add(weakest!);
245+ ignored.add(identity(weakest!)); 243246 const next = pick(weakest!.line); 244247 if (next) relocs.set(weakest!.line, next); 245248 else relocs.delete(weakest!.line);