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 119 --json
JSON
/christopher/abso-core/versions/119?format=json

Page per-file atom indexes and stream current-view attribute scans

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

Version 118 · Files at version 119

4 files, 109 lines added, 7 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -15,8 +15,15 @@
1515 seqOf,
1616 startNode,
1717} from "./keys.ts";
18−import { type GraphStateStorage, type StateMap, storedArray, storedMap, storedNumbers } from "./state-source.ts";
1918import {
19+ type GraphStateStorage,
20+ type StateMap,
21+ storedArray,
22+ storedLists,
23+ storedMap,
24+ storedNumbers,
25+} from "./state-source.ts";
26+import {
2027 ATTR_NAMES,
2128 type Atom,
2229 type AtomId,
@@ -314,7 +321,7 @@
314321 this.#dependents = storedMap(storage, "dependents");
315322 this.#resolvers = storedMap(storage, "resolvers");
316323 this.#together = storedMap(storage, "together");
317− this.#fileAtoms = storedMap(storage, "file-atoms");
324+ this.#fileAtomPages = storedLists<AtomId>(storage, "file-atoms");
318325 this.#runStarts = storedMap(storage, "run-starts");
319326 this.#relocations = storedMap(storage, "relocations");
320327 this.#relocatedTo = storedMap(storage, "relocated-to");
@@ -420,6 +427,7 @@
420427 #resolvers: StateMap<AtomId, AtomId | AtomId[]> = new Map();
421428 #together: StateMap<AtomId, TogetherLink[]> = new Map();
422429 #fileAtoms: StateMap<string, AtomId[]> = new Map();
430+ #fileAtomPages: ReturnType<typeof storedLists<AtomId>> | undefined;
423431 /** First lines of runs (their n), by the node they were written after: a line's n, or -1 - a path's index. */
424432 #runStarts: StateMap<number, number | number[]> = new Map();
425433 /** 1 for the first line of a run whose atom deleted the line it hangs off: the run replaces it. */
@@ -702,12 +710,20 @@
702710
703711 /** Every atom that inserts or deletes a line of the file, in seq order. */
704712 atomsIn(file: string): readonly AtomId[] {
713+ if (this.#fileAtomPages) return [...this.#fileAtomPages.values(file)];
705714 return this.#fileAtoms.get(file) ?? EMPTY;
706715 }
716+ *eachAtomIn(file: string): IterableIterator<AtomId> {
717+ if (this.#fileAtomPages) yield* this.#fileAtomPages.values(file);
718+ else yield* this.#fileAtoms.get(file) ?? EMPTY;
719+ }
720+ hasAtomsIn(file: string): boolean {
721+ return this.#fileAtomPages ? this.#fileAtomPages.length(file) > 0 : this.#fileAtoms.has(file);
722+ }
707723
708724 /** Unique historical file paths, streamed without collecting their names. */
709725 *knownFiles(): IterableIterator<string> {
710− yield* this.#fileAtoms.keys();
726+ yield* this.#fileAtomPages ? this.#fileAtomPages.keys() : this.#fileAtoms.keys();
711727 }
712728
713729 /**
@@ -981,7 +997,10 @@
981997 files.add(isStartNode(m.parent) ? m.parent.slice(1) : this.lineFile(m.parent)!);
982998 }
983999 this.#atomFiles.push(Object.freeze([...files].sort()));
984− for (const file of files) pushIndex(this.#fileAtoms, file, frozen.id);
1000+ for (const file of files) {
1001+ if (this.#fileAtomPages) this.#fileAtomPages.append(file, frozen.id);
1002+ else pushIndex(this.#fileAtoms, file, frozen.id);
1003+ }
9851004 for (const r of frozen.reasons) {
9861005 if (r.kind !== "together" || r.to === frozen.id) continue;
9871006 pushIndex(this.#together, frozen.id, { other: r.to, text: r.text, from: frozen.id });
--- a/src/engine/state-source.ts
+++ b/src/engine/state-source.ts
@@ -259,6 +259,56 @@
259259 values(): IterableIterator<V>;
260260}
261261
262+/** Append-only per-key lists, retaining at most one fixed-size page per iterator. */
263+export function storedLists<V>(storage: GraphStateStorage, name: string) {
264+ const pageSize = 256;
265+ // The previous experimental layout stored one whole historical list per key.
266+ const length = (key: string) => {
267+ const stored = storage.read(`${name}:lengths`, key) as number | undefined;
268+ if (stored === undefined && storage.read(name, JSON.stringify(["string", key])) !== undefined)
269+ throw new Error(`writer list index ${name} requires canonical-log adoption`);
270+ const count = stored ?? 0;
271+ if (!Number.isSafeInteger(count) || count < 0) throw new Error(`invalid writer list count in ${name}`);
272+ return count;
273+ };
274+ const pageKey = (key: string, page: number) => JSON.stringify([key, page]);
275+ const page = (key: string, index: number): V[] => {
276+ const values = storage.read(`${name}:pages`, pageKey(key, index)) as V[] | undefined;
277+ if (!Array.isArray(values) || values.length < 1 || values.length > pageSize)
278+ throw new Error(`missing or invalid writer list page in ${name}`);
279+ return values;
280+ };
281+ return {
282+ length,
283+ *keys(): IterableIterator<string> {
284+ for (const entry of storage.entries(name)) {
285+ void entry;
286+ throw new Error(`writer list index ${name} requires canonical-log adoption`);
287+ }
288+ for (const [key] of storage.entries(`${name}:lengths`)) yield key;
289+ },
290+ *values(key: string): IterableIterator<V> {
291+ const count = length(key);
292+ for (let start = 0; start < count; start += pageSize) {
293+ const values = page(key, start / pageSize);
294+ if (values.length !== Math.min(pageSize, count - start))
295+ throw new Error(`incomplete writer list page in ${name}`);
296+ yield* values;
297+ }
298+ },
299+ append(key: string, value: V): void {
300+ const count = length(key);
301+ const offset = count % pageSize;
302+ const index = Math.floor(count / pageSize);
303+ const values = offset === 0 ? [] : page(key, index);
304+ if (values.length !== offset) throw new Error(`invalid writer list length in ${name}`);
305+ values.push(value);
306+ storage.write(`${name}:pages`, pageKey(key, index), values);
307+ storage.write(`${name}:lengths`, key, count + 1);
308+ },
309+ };
310+}
262312/** Keys are tagged so numeric graph codes cannot collide with string keys. */
263313export function storedMap<K extends string | number, V>(storage: GraphStateStorage, name: string): StateMap<K, V> {
264314 const keyOf = (key: K) => JSON.stringify([typeof key, key]);
--- a/src/engine/test/state-source.test.ts
+++ b/src/engine/test/state-source.test.ts
@@ -1,10 +1,43 @@
11import assert from "node:assert/strict";
22import { test } from "node:test";
33import { checkDraft, Graph, View } from "../index.ts";
4−import { CachedStateStorage, storedNumbers } from "../state-source.ts";
4+import { CachedStateStorage, storedLists, storedNumbers } from "../state-source.ts";
55import { lines, Repo } from "./helpers.ts";
66import { SqlState } from "./storage-helper.ts";
77
8+test("per-file list pages append and reopen without reading the full historical list", () => {
9+ const source = new SqlState();
10+ try {
11+ const storage = new CachedStateStorage(source);
12+ const lists = storedLists<string>(storage, "files");
13+ for (let i = 0; i < 1025; i++) storage.transaction(() => lists.append("a.txt", `a${i}`));
14+ assert.equal(lists.length("a.txt"), 1025);
15+ assert.deepEqual([...lists.keys()], ["a.txt"]);
16+ storage.clear();
17+ const before = source.reads;
18+ storage.transaction(() => lists.append("a.txt", "a1025"));
19+ assert.ok(source.reads - before <= 2, "append reads only one page and its length");
20+ assert.throws(
21+ () =>
22+ storage.transaction(() => {
23+ lists.append("a.txt", "rolled-back");
24+ throw new Error("rollback");
25+ }),
26+ /rollback/,
27+ );
28+ const reopened = storedLists<string>(new CachedStateStorage(source), "files");
29+ assert.deepEqual(
30+ [...reopened.values("a.txt")],
31+ Array.from({ length: 1026 }, (_, i) => `a${i}`),
32+ );
33+ for (const [, page] of source.entries("files:pages")) assert.ok((page as string[]).length <= 256);
34+ source.write("legacy", "a.txt", ["a0"]);
35+ assert.throws(() => [...storedLists(source, "legacy").keys()], /canonical-log adoption/);
36+ } finally {
37+ source.db.close();
38+ }
39+});
841test("numeric pages cross boundaries, reopen, mutate and roll back without retaining history", () => {
942 const source = new SqlState();
1043 const storage = new CachedStateStorage(source);
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -330,7 +330,7 @@
330330 const graph = this.graph;
331331 // For each attribute, the highest-priority setter in the set wins.
332332 const setters = new Map<string, { id: AtomId; value: string | null }>();
333− for (const id of graph.atomsIn(path)) {
333+ for (const id of graph.eachAtomIn(path)) {
334334 if (!this.#has(graph.atom(id).seq)) continue;
335335 for (const a of graph.atom(id).attrs ?? []) {
336336 if (a.file !== path) continue;
@@ -553,7 +553,7 @@
553553 #file(path: string, complete = false): FileState {
554554 let state = this.#files.get(path);
555555 if (!state || (complete && !state.complete)) {
556− state = this.graph.atomsIn(path).length === 0 ? NO_FILE : this.#layout(path, complete);
556+ state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
557557 this.#files.set(path, state);
558558 }
559559 return state;