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

Page disk-first numeric graph indexes under bounded storage cache

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

Version 112 · Files at version 113

3 files, 99 lines added, 16 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -15,7 +15,7 @@
1515 seqOf,
1616 startNode,
1717} from "./keys.ts";
18−import { type GraphStateStorage, type StateMap, storedArray, storedMap } from "./state-source.ts";
18+import { type GraphStateStorage, type StateMap, storedArray, storedMap, storedNumbers } from "./state-source.ts";
1919import {
2020 ATTR_NAMES,
2121 type Atom,
@@ -286,21 +286,7 @@
286286 this.#storage = options.storage;
287287 if (options.storage) {
288288 const storage = options.storage;
289− const numbers = (name: string): NumberIndex => {
290− const values = storedArray<number>(storage, name);
291− return {
292− get length() {
293− return values.length;
294− },
295− push: (value) => {
296− values.push(value);
297− },
298− at: (index) => values[index]!,
299− set: (index, value) => {
300− values[index] = value;
301− },
302− };
303− };
289+ const numbers = (name: string): NumberIndex => storedNumbers(storage, name);
304290 this.#atoms = storedArray<Atom>(storage, "atoms", (atom) =>
305291 freezeAtom(
306292 atom,
--- a/src/engine/state-source.ts
+++ b/src/engine/state-source.ts
@@ -160,6 +160,56 @@
160160const indexKey = (key: PropertyKey): key is string =>
161161 typeof key === "string" && /^(0|[1-9][0-9]*)$/.test(key) && Number.isSafeInteger(Number(key));
162162
163+/** Fixed-size numeric pages; callers retain no pages outside the bounded storage cache. */
164+export function storedNumbers(storage: GraphStateStorage, name: string) {
165+ const pageSize = 256;
166+ const meta = `${name}:meta`;
167+ const length = () => (storage.read(meta, "length") as number | undefined) ?? 0;
168+ // Older experimental writer indexes must be rebuilt from their canonical log.
169+ // Never interpret per-element rows as pages or silently lose existing history.
170+ const page = (index: number): number[] => {
171+ if (storage.read(meta, "format") !== 2)
172+ throw new Error(`writer numeric index ${name} requires canonical-log adoption`);
173+ const values = storage.read(`${name}:pages`, String(Math.floor(index / pageSize))) as number[] | undefined;
174+ if (!values) throw new Error(`missing writer numeric page in ${name}`);
175+ return values;
176+ };
177+ return {
178+ get length() {
179+ return length();
180+ },
181+ at(index: number): number {
182+ if (!Number.isSafeInteger(index) || index < 0 || index >= length())
183+ throw new Error(`writer numeric index out of bounds in ${name}`);
184+ const value = page(index)[index % pageSize];
185+ if (value === undefined) throw new Error(`incomplete writer numeric page in ${name}`);
186+ return value;
187+ },
188+ push(value: number): void {
189+ if (!Number.isSafeInteger(value)) throw new Error("writer numeric indexes require safe integers");
190+ const index = length();
191+ if (index > 0 && storage.read(meta, "format") !== 2)
192+ throw new Error(`writer numeric index ${name} requires canonical-log adoption`);
193+ const offset = index % pageSize;
194+ const values = offset === 0 ? [] : page(index);
195+ if (values.length !== offset) throw new Error(`invalid writer numeric page length in ${name}`);
196+ values.push(value);
197+ storage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);
198+ if (index === 0) storage.write(meta, "format", 2);
199+ storage.write(meta, "length", index + 1);
200+ },
201+ set(index: number, value: number): void {
202+ if (!Number.isSafeInteger(value)) throw new Error("writer numeric indexes require safe integers");
203+ if (!Number.isSafeInteger(index) || index < 0 || index >= length())
204+ throw new Error(`writer numeric index out of bounds in ${name}`);
205+ const values = page(index);
206+ if (index % pageSize >= values.length) throw new Error(`incomplete writer numeric page in ${name}`);
207+ values[index % pageSize] = value;
208+ storage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);
209+ },
210+ };
211+}
163213/** Array-shaped access without retaining its historical values in memory. */
164214export function storedArray<T>(storage: GraphStateStorage, name: string, decode?: (value: T) => T): T[] {
165215 const length = () => (storage.read(`${name}:meta`, "length") as number | undefined) ?? 0;
--- a/src/engine/test/state-source.test.ts
+++ b/src/engine/test/state-source.test.ts
@@ -1,9 +1,56 @@
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";
45import { lines, Repo } from "./helpers.ts";
56import { SqlState } from "./storage-helper.ts";
67
8+test("numeric pages cross boundaries, reopen, mutate and roll back without retaining history", () => {
9+ const source = new SqlState();
10+ const storage = new CachedStateStorage(source);
11+ const numbers = storedNumbers(storage, "numbers");
12+ storage.transaction(() => {
13+ for (let i = 0; i < 1025; i++) numbers.push(i - 1);
14+ });
15+ storage.clear();
16+ const reads = source.reads;
17+ for (let i = 0; i < 1025; i++) assert.equal(numbers.at(i), i - 1);
18+ assert.ok(source.reads - reads <= 7, "one backing read per page plus metadata");
19+ assert.equal([...source.entries("numbers:pages")].length, 5);
20+ assert.throws(
21+ () =>
22+ storage.transaction(() => {
23+ numbers.set(255, -99);
24+ numbers.set(256, -98);
25+ numbers.push(1025);
26+ throw new Error("rollback");
27+ }),
28+ /rollback/,
29+ );
30+ const reopened = storedNumbers(new CachedStateStorage(source), "numbers");
31+ assert.equal(reopened.length, 1025);
32+ assert.equal(reopened.at(255), 254);
33+ assert.equal(reopened.at(256), 255);
34+ assert.equal(numbers.at(255), 254);
35+ reopened.set(256, -42);
36+ assert.equal(reopened.at(256), -42);
37+ assert.throws(() => reopened.at(1025), /out of bounds/);
38+ assert.throws(() => reopened.set(-1, 2), /out of bounds/);
39+ assert.throws(() => reopened.push(NaN), /safe integers/);
40+});
42+test("numeric pages reject legacy or missing pages instead of fabricating values", () => {
43+ const storage = new SqlState();
44+ storage.write("legacy:meta", "length", 256);
45+ const legacy = storedNumbers(storage, "legacy");
46+ assert.throws(() => legacy.at(0), /canonical-log adoption/);
47+ assert.throws(() => legacy.push(1), /canonical-log adoption/);
48+ const numbers = storedNumbers(storage, "new");
49+ numbers.push(5);
50+ storage.remove("new:pages", "0");
51+ assert.throws(() => numbers.at(0), /missing writer numeric page/);
52+});
754test("stored graph reopens without replay and preserves moves, conflicts and new edits", () => {
855 const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
956 oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });