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

Versions 293 to 318

Compare

+53 −52 in 2 places
Lines 1524–1562 at 318 (were 1524–1566 at 293)
15241524 * the search never descends below the target's lamport.
15251525 */
15261526 #reaches(from: Iterable<AtomId>, target: AtomId): boolean {
1527− const floor = this.#lamportAt(this.#seq(target));
1528− if (this.#storage) {
1529− return this.withProjectionScratch((scratch) => {
1530− let length = 0;
1531− const push = (id: AtomId): void => {
1532− if (scratch.read("seen", id)) return;
1533− scratch.write("seen", id, true);
1534− scratch.write("stack", String(length++), id);
1535− };
1536− for (const id of from) {
1537− if (id === target) return true;
1538− if (this.#lamportAt(this.#seq(id)) > floor) push(id);
1539− }
1540− while (length > 0) {
1541− const key = String(--length);
1542− const current = scratch.read("stack", key) as AtomId;
1543− scratch.remove("stack", key);
1544− if (this.#lamportAt(this.#seq(current)) <= floor) continue;
1545− for (const dependency of this.atom(current).deps) {
1546− if (dependency === target) return true;
1547− push(dependency);
1548− }
1549− }
1550− return false;
1551− });
1527+ return this.#reachable(from, new Set([target])).has(target);
1528+ }
1530+ /**
1531+ * Which of `targets` are reachable along deps from any of `from` (themselves included), in one walk: it never
1532+ * descends below the lowest target's lamport, and stops once every target is found (abso 714, piece 4: record
1533+ * walked once per line writer).
1534+ * The walk's seen marks and stack are in memory, by atom number: one byte and four bytes an atom at most, so about
1535+ * 62 KB on abso's 12,454 atoms and 50 MB at 10 million, under a Worker's 128 MB. They were scratch rows in storage
1536+ * (abso-core 139, bounding memory with the graph), which cost a read and a write per atom visited: on abso's Oct 14
1537+ * tables, 41,000 of a 1470-shaped record's 77,767 statements.
1538+ */
1539+ #reachable(from: Iterable<AtomId>, targets: ReadonlySet<AtomId>): Set<AtomId> {
1540+ const found = new Set<AtomId>();
1541+ let floor = Number.POSITIVE_INFINITY;
1542+ for (const target of targets) floor = Math.min(floor, this.#lamportAt(this.#seq(target)));
1543+ const seen = new Uint8Array(this.#atoms.length);
1544+ const stack = new Int32Array(this.#atoms.length);
1545+ let length = 0;
1546+ const visit = (id: AtomId): void => {
1547+ if (targets.has(id)) found.add(id);
1548+ const seq = this.#seq(id);
1549+ if (seen[seq]) return;
1550+ seen[seq] = 1;
1551+ stack[length++] = seq;
1552+ };
1553+ for (const id of from) visit(id);
1554+ while (length > 0 && found.size < targets.size) {
1555+ const seq = stack[--length]!;
1556+ if (this.#lamportAt(seq) <= floor) continue;
1557+ for (const dependency of this.atom(atomId(seq)).deps) visit(dependency);
15521558 }
1553− const seen = new Set<AtomId>();
1554− const stack = [...from];
1555− while (stack.length > 0) {
1556− const cur = stack.pop()!;
1557− if (cur === target) return true;
1558− if (seen.has(cur)) continue;
1559− seen.add(cur);
1560− if (this.#lamportAt(this.#seq(cur)) <= floor) continue;
1561− for (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);
1562− }
1563− return false;
1559+ return found;
15641560 }
15651561
15661562 /**
Lines 1606–1633 at 318 (were 1610–1632 at 293)
16101606 for (const r of atom.reasons) if (!this.has(r.to)) bad(`reason points at unknown atom ${r.to}`);
16111607
16121608 // Everything it touches must come from its closure. Derived deps name the
1613− // writers directly, so this is usually one lookup per writer.
1614− const memoryBelow = scratch ? undefined : new Map<AtomId, boolean>();
1615− const below = {
1616− get: (key: AtomId) => (scratch ? (scratch.read("below", key) as boolean | undefined) : memoryBelow!.get(key)),
1617− set: (key: AtomId, value: boolean) => {
1618− if (scratch) scratch.write("below", key, value);
1619− else memoryBelow!.set(key, value);
1620− },
1621− };
1622− const inClosure = (writer: AtomId): boolean => {
1623− let hit = below.get(writer);
1624− if (hit === undefined) {
1625− hit = deps.has(writer) || this.#reaches(atom.deps, writer);
1626− below.set(writer, hit);
1609+ // writers directly, so this is usually one lookup per writer. The writers
1610+ // that aren't deps are walked for together, once (abso 714, piece 4).
1611+ const touched: LineId[] = [];
1612+ for (const run of atom.inserts) if (!isStartNode(run.parent)) touched.push(run.parent);
1613+ for (const m of atom.moves ?? []) {
1614+ touched.push(m.line);
1615+ if (!isStartNode(m.parent)) touched.push(m.parent);
1616+ }
1617+ touched.push(...atom.deletes);
1618+ for (const list of [atom.writes, atom.reads, atom.holds])
1619+ for (const key of list) {
1620+ const parsed = parseKey(key);
1621+ if (parsed.kind === "line" || ((parsed.kind === "gap" || parsed.kind === "pos") && !isStartNode(parsed.node)))
1622+ touched.push(parsed.node);
16271623 }
1628− return hit;
1629− };
1624+ const beyond = new Set<AtomId>();
1625+ for (const line of touched) {
1626+ const writer = this.lineAtom(line);
1627+ if (writer !== undefined && !deps.has(writer)) beyond.add(writer);
1628+ }
1629+ const reached = beyond.size > 0 ? this.#reachable(atom.deps, beyond) : beyond;
1630+ const inClosure = (writer: AtomId): boolean => deps.has(writer) || reached.has(writer);
16301631 const checkLine = (line: LineId, what: string): void => {
16311632 const writer = this.lineAtom(line);
16321633 if (writer === undefined) return bad(`${what} names unknown line ${line}`);
MCP
compare on this site's /mcp
CLI
abso diff 293 318 src/engine/graph.ts --json
JSON
/christopher/abso-core/compare/293..318?file=src%2Fengine%2Fgraph.ts&format=json