- MCP
- show on this site's /mcp
- CLI
- abso show 146 --json
- JSON
- /christopher/abso-core/versions/146?format=json
Page atom adoption and move reconciliation with restart-safe private state
of shared·codex-capacity-chair··Not checked
Version 145 · Files at version 146
7 files, 1312 lines added, 113 removed.
--- /dev/null
+++ b/src/engine/experimental/projection-atom-adoption.ts
@@ -0,0 +1,293 @@
5+
29+const digest = (value: unknown) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
44+ if (value.format !== 1 || typeof value.checksum !== "string" || value.checksum !== digest(value.cursor))
50+ if (cursor.state[key] !== null && (!Number.isSafeInteger(cursor.state[key]) || Number(cursor.state[key]) < 0))
69+
105+ if (digest(p.graph.atom(atom.id)) !== digest(atom)) throw Error("canonical adoption atom mismatch");
120+ ![cursor.index, cursor.run, cursor.line, cursor.k].every((n) => Number.isSafeInteger(n) && n >= 0)
124+ if (cursor.run > atom.inserts.length || cursor.line > (atom.inserts[cursor.run]?.lines.length ?? 0))
171+ if (!p.members.get(state.membership, p.graph.atom(id).seq)?.present) throw Error("missing dependency");
200+ state.sequence = p.sequence.update(state.sequence, { kind: "visibility", id: marker.enter, delta: 1 });
225+ if (!member?.present || (input.remove && member.dependents < 1)) throw Error("invalid dependency count");
265+ state.membership = p.members.set(state.membership, atom.seq, { present: !input.remove, dependents: 0 });
290+ return { done: cursor.phase === "done", state: structuredClone(state), steps, atomicMoveWork };
--- a/src/engine/experimental/projection-marker.ts
+++ b/src/engine/experimental/projection-marker.ts
@@ -119,50 +119,10 @@
122− const insert = (rank: number, text: string, hidden = false): number => {
123− const id = state.sequence.next;
124− state.sequence = sequence.update(state.sequence, { kind: "insert", rank, text });
125− if (hidden) state.sequence = sequence.update(state.sequence, { kind: "visibility", id, delta: 1 });
126− return id;
127− };
131− for (const run of atom.inserts)
132− for (const text of run.lines) {
133− const line = `${atom.id}.${k++}`,
134− n = this.graph.lineN(line),
135− parent = this.graph.parentCodeOf(n);
136− if (n + 1 >= 0x80000000) throw Error("prototype line identity limit");
137− const existing = this.markers.get(state.locator, n + 1);
138− if (existing) {
139− state.sequence = sequence.update(state.sequence, { kind: "visibility", id: existing.enter, delta: -1 });
140− continue;
141− }
142− const parentMarker = this.markers.get(state.locator, this.parentKey(parent));
143− if (!parentMarker) throw Error("missing parent marker");
144− const parentKey = this.parentKey(parent);
145− const index = this.priorities;
146− const root = this.childRoots.get(state.children, parentKey)?.root ?? null;
147− const seq = this.graph.writerSeqOf(n);
148− const key = orderedChildKey({
149− n,
150− replaces: this.graph.replacesN(n) ? 1 : 0,
151− lamport: this.graph.lamportOfSeq(seq),
152− seq,
153− k: this.graph.kOf(n),
154− });
155− const preceding = index.before(root, key);
156− const anchor =
157− preceding === undefined
158− ? parentMarker.enter
159− : required(this.markers.get(state.locator, preceding + 1)).exit;
160− state.children = this.childRoots.set(state.children, parentKey, { root: index.insert(root, key, n) });
161− const at = sequence.rank(state.sequence, anchor) + 1;
162− const enter = insert(at, line),
163− exit = insert(at + 1, `${line}:end`, true);
164− state.locator = this.markers.set(state.locator, n + 1, { kind: "line", enter, exit, parentKey, key });
165− }
125+ for (const run of atom.inserts) for (const _ of run.lines) this.insertLine(state, `${atom.id}.${k++}`);
@@ -179,6 +139,46 @@
149+ if (hidden) state.sequence = sequence.update(state.sequence, { kind: "visibility", id, delta: 1 });
157+ state.sequence = sequence.update(state.sequence, { kind: "visibility", id: existing.enter, delta: -1 });
175+ preceding === undefined ? parentMarker.enter : required(this.markers.get(state.locator, preceding + 1)).exit;
176+ state.children = this.childRoots.set(state.children, parentKey, { root: index.insert(root, key, n) });
180+ state.locator = this.markers.set(state.locator, n + 1, { kind: "line", enter, exit, parentKey, key });
--- /dev/null
+++ b/src/engine/experimental/projection-move-adoption.ts
@@ -0,0 +1,186 @@
7+
23+const collections = ["selected", "seen", "work", "ignored", "reached", "progress", "planned", "plans"];
24+const digest = (value: unknown) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
25+
37+
46+ if (!task || task.length > 128 || !/^[a-f0-9]{64}$/.test(identity)) throw Error("invalid move adoption identity");
60+ if (saved.format !== 1 || saved.checksum !== digest(saved.cursor)) throw Error("damaged move adoption cursor");
89+ const has = (id: string) => p.members.get(state.membership, p.graph.atom(id).seq)?.present ?? false;
120+ const parentKey = parent.startsWith("^") ? p.fileKey(parent.slice(1)) : p.graph.lineN(parent) + 1;
--- /dev/null
+++ b/src/engine/experimental/projection-move-resolution.ts
@@ -0,0 +1,234 @@
6+
23+const digest = (value: unknown) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
24+const integer = (value: unknown): value is number => Number.isSafeInteger(value) && Number(value) >= 0;
39+ if (value.format !== 1 || value.checksum !== digest(value.state)) throw Error("damaged move resolution cursor");
40+ shape(value.state, "identity phase mover move work item line slow fast meeting entry current weakest best");
46+ !["scan", "walk", "entry", "weakest", "repick", "mark", "done"].includes(String(state.phase)) ||
57+ if (state[key] !== null && (typeof state[key] !== "string" || !state[key] || String(state[key]).length > 4096))
70+ (["entry", "weakest", "repick", "mark"].includes(String(state.phase)) && state.line === null) ||
77+
87+ if (!identity || identity.length > 4096 || !Number.isSafeInteger(maxSteps) || maxSteps < 1 || maxSteps > 256)
108+ const selected = (line: string) => storage.read("selected", line) as RelocationInfo | undefined;
114+ const terminal = (node: NodeId | null) => node === null || isStartNode(node) || !!storage.read("reached", node);
116+ const stronger = (a: RelocationInfo, b: RelocationInfo) => graph.comparePriority(a.atom, b.atom) > 0;
--- /dev/null
+++ b/src/engine/test/projection-atom-adoption.test.ts
@@ -0,0 +1,327 @@
14+
23+ const previous = new ExperimentalMarkerProjection(db, new Graph({ storage: db }), "a.txt", "restart").empty();
27+ const adapter = new ExperimentalMarkerProjection(db, new Graph({ storage: db }), "a.txt", "restart");
57+
58+test("atom adoption resumes small pages and matches atomic additions and reverse removals", () => {
107+ db.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection LIKE ?").get("%move-adoption:%")!.n,
121+
122+test("source drift rolls back an atom page and a changed atom cannot resume its cursor", () => {
164+ assert.throws(() => job.page({ ...input, validateSource: () => Promise.resolve() }), /must be synchronous/);
168+ () => job.page({ ...input, validateSource: () => (++asyncChecks === 2 ? Promise.resolve() : undefined) }),
189+ assert.throws(() => job.page({ ...input, source: "c".repeat(64) }), /changed atom adoption cursor/);
196+
197+test("move adoption rolls back complete pages and resumes every phase after SQLite reopen", () => {
216+ const adapter = new ExperimentalMarkerProjection(db, new Graph({ storage: db }), "a.txt", "restart-moves");
218+ const input = { previous, atom: move, remove, source: "f".repeat(64), maxSteps: 1, validateSource: () => {} };
245+ const adapter = new ExperimentalMarkerProjection(db, new Graph({ storage: db }), "a.txt", "restart-moves");
254+ for (const path of ["a.txt", "b.txt"]) assert.deepEqual(adapter.lines(state, path), oracle.lines(expected, path));
256+ db.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection LIKE ?").get("%move-adoption:%")!.n,
260+ for (const phase of ["files", "resolve", "plans", "park", "place", "cleanup"]) assert.ok(phases.has(phase), phase);
267+
268+test("move application rejects damaged cursor envelopes and invalid positions without mutation", () => {
316+ if (index > 0) bad.checksum = createHash("sha256").update(JSON.stringify(bad.cursor)).digest("hex");
--- a/src/engine/test/projection-marker-cycle.test.ts
+++ b/src/engine/test/projection-marker-cycle.test.ts
@@ -1,83 +1,106 @@
34import { ExperimentalMarkerProjection as MarkerProjection } from "../experimental/projection-marker.ts";
810
9−test("typed marker projection matches competing cyclic moves and removals", () => {
10− const db = new SqlState();
11− try {
12− const repo = Repo.init({ "f.txt": Array.from({ length: 12 }, (_, n) => `${n}\n`).join("") }),
13− graph = new Graph({ storage: new CachedStateStorage(db) }),
14− rng = new Rng(45131);
15− graph.add(repo.graph.atom("a0"));
16− const p = new MarkerProjection(db, graph, "f.txt", "typed-" + "cycle");
17− let state = p.apply(p.empty(), repo.graph.atom("a0")),
18− checks = 0;
19− const atoms = [];
20− const check = () => {
21− const view = repo.view();
22− assert.deepEqual(
23− p.lines(state),
24− view.lines("f.txt").map((x) => x.id),
25− );
26− for (let n = 0; n < 12; n++) {
27− const parent = view.parentOf(`a0.${n}`);
28− assert.equal(
29− (p.markers.get(state.locator, n + 1) as { parentKey: number }).parentKey,
30− parent.startsWith("^") ? 0 : graph.lineN(parent) + 1,
12+ test(`typed marker projection matches competing cyclic moves and removals (paged=${paged})`, () => {
32− }
33− checks++;
34− };
35− for (let j = 0; j < 24; j++) {
36− const offset = rng.int(12),
37− moves = Array.from({ length: 3 }, (_, i) => {
38− const line = `a0.${(offset + i) % 12}`,
39− candidate = `a0.${rng.int(12)}`;
40− return { line, parent: candidate === line ? "^f.txt" : candidate };
41− });
42− const atom = {
43− id: repo.graph.nextId(),
44− seq: repo.graph.size,
45− author: "fixture",
46− message: "move",
47− time: j,
48− inserts: [],
49− deletes: [],
50− writes: moves.flatMap((m) => [`P:${m.line}`, `G:${m.parent}`]),
51− reads: [],
52− holds: [],
53− needs: [],
54− resolves: [],
55− reasons: [],
56− deps: ["a0"],
57− moves,
59− repo.graph.add(atom);
60− repo.shared.add(atom.id);
61− graph.add(atom);
62− atoms.push(atom);
63− state = p.apply(state, atom);
64− check();
97+ "SELECT count(*) AS n FROM state WHERE collection LIKE '%sequence-resolver:%' OR collection LIKE '%sequence-relocation-work:%' OR collection LIKE '%move-adoption:%'",
66− for (const atom of atoms.filter((_, i) => i % 2 === 0)) {
67− repo.shared.delete(atom.id);
68− state = p.removeAtom(state, atom);
69− check();
70− }
71− assert.equal(
72− db.db
73− .prepare(
74− "SELECT count(*) AS n FROM state WHERE collection LIKE '%sequence-resolver:%' OR collection LIKE '%sequence-relocation-work:%'",
75− )
76− .get()!.n,
77− 0,
78− );
79− assert.equal(checks, 36);
80− } finally {
81− db.db.close();
82− }
83−});
--- /dev/null
+++ b/src/engine/test/projection-move-resolution.test.ts
@@ -0,0 +1,136 @@
9+
10+test("one-step move pages preserve cycle resolution across competing and excluded moves", () => {
14+ const repo = Repo.init({ "f.txt": Array.from({ length: 12 }, (_, i) => `${i}\n`).join(""), "g.txt": "" });
55+ assert.deepEqual(actual.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
57+ const result = resolveMovesPage(repo.graph, (id) => repo.shared.has(id), actual, `trial-${trial}`, 1);
70+ assert.throws(() => resolveMovesPage(repo.graph, () => true, actual, "changed", 1), /identity changed/);
79+
80+test("damaged and structurally invalid move cursors refuse without changing stored state", () => {
125+ if (index > 0) damaged.checksum = createHash("sha256").update(JSON.stringify(damaged.state)).digest("hex");
128+ assert.throws(() => resolveMovesPage(repo.graph, () => true, storage, "source", 1), /invalid|damaged|incomplete/);
129+ assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);