Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 139 --json
JSON
/christopher/abso-core/versions/139?format=json

Bound persistent dependency reachability with rollback scratch

of shared·codex-capacity-chair··Not checked

Version 138 · Files at version 139

2 files, 105 lines added, 0 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -947,6 +947,32 @@
947947 */
948948 #reaches(from: Iterable<AtomId>, target: AtomId): boolean {
949949 const floor = this.#lamport[this.#seq(target)]!;
950+ if (this.#storage) {
951+ // Roots belong to the current atom's dependency list, not its history.
952+ const roots = [...from];
953+ if (roots.includes(target)) return true;
954+ if (roots.every((id) => this.#lamport[this.#seq(id)]! <= floor)) return false;
955+ return this.withProjectionScratch((scratch) => {
956+ let length = 0;
957+ const push = (id: AtomId): void => {
958+ if (scratch.read("seen", id)) return;
959+ scratch.write("seen", id, true);
960+ scratch.write("stack", String(length++), id);
961+ };
962+ for (const id of roots) push(id);
963+ while (length > 0) {
964+ const key = String(--length);
965+ const current = scratch.read("stack", key) as AtomId;
966+ scratch.remove("stack", key);
967+ if (this.#lamport[this.#seq(current)]! <= floor) continue;
968+ for (const dependency of this.atom(current).deps) {
969+ if (dependency === target) return true;
970+ push(dependency);
971+ }
972+ }
973+ return false;
974+ });
975+ }
950976 const seen = new Set<AtomId>();
951977 const stack = [...from];
952978 while (stack.length > 0) {
--- /dev/null
+++ b/src/engine/test/reachability-scratch.test.ts
@@ -0,0 +1,79 @@
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { buildBase, Graph } from "../index.ts";
4+import { CachedStateStorage } from "../state-source.ts";
5+import type { Atom } from "../types.ts";
6+import { SqlState } from "./storage-helper.ts";
7+
8+test("persistent reachability uses rollback scratch across deep shared ancestry and graph append", () => {
9+ const source = new SqlState();
10+ try {
11+ const storage = new CachedStateStorage(source, 8192, 32);
12+ const graph = new Graph({ storage });
13+ const oracle = new Graph();
14+ const add = (atom: Atom) => {
15+ graph.add(atom);
16+ oracle.add(atom);
17+ };
18+ add(buildBase({ "a.txt": "base\n" }, { author: "fixture", message: "base", time: 0 }));
19+ for (let seq = 1; seq <= 513; seq++)
20+ add({
21+ id: `a${seq}`,
22+ seq,
23+ author: "fixture",
24+ message: "branch",
25+ time: seq,
26+ inserts: seq === 1 ? [{ file: "b.txt", parent: "^b.txt", lines: ["other"] }] : [],
27+ deletes: [],
28+ writes: [],
29+ reads: [],
30+ holds: [],
31+ needs: [],
32+ resolves: [],
33+ reasons: [],
34+ deps: seq === 1 ? [] : seq === 2 ? ["a1"] : [`a${seq - 1}`, `a${seq - 2}`],
35+ });
36+ const before = source.db.prepare("SELECT * FROM state ORDER BY collection, key").all();
37+ for (const target of ["a0", "a1", "a127", "a512", "a513"]) {
38+ assert.equal(graph.dependsOn("a513", target), oracle.dependsOn("a513", target));
39+ assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
40+ }
41+ const atom: Atom = {
42+ id: "a514",
43+ seq: 514,
44+ author: "fixture",
45+ message: "append through ancestor",
46+ time: 514,
47+ inserts: [{ file: "b.txt", parent: "a1.0", lines: ["next"] }],
48+ deletes: [],
49+ writes: [],
50+ reads: [],
51+ holds: [],
52+ needs: [],
53+ resolves: [],
54+ reasons: [],
55+ deps: ["a513"],
56+ };
57+ source.failWrite = source.writes + 3;
58+ assert.throws(() => graph.add(atom), /injected storage failure/);
59+ assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
60+ source.failWrite = Infinity;
61+ const reopened = new Graph({ storage: new CachedStateStorage(source) });
62+ assert.throws(
63+ () => reopened.add({ ...atom, inserts: [{ file: "a.txt", parent: "a0.0", lines: ["invalid"] }] }),
64+ /not in its closure/,
65+ );
66+ assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
67+ reopened.add(atom);
68+ oracle.add(atom);
69+ assert.equal(reopened.lineCount, oracle.lineCount);
70+ assert.equal(reopened.size, oracle.size);
71+ assert.equal(reopened.dependsOn("a514", "a1"), true);
72+ assert.equal(
73+ source.db.prepare("SELECT count(*) AS n FROM state WHERE collection LIKE 'projection-scratch:%'").get()!.n,
74+ 0,
75+ );
76+ } finally {
77+ source.db.close();
78+ }
79+});