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

An atom's long lists kept 256 values to a row (list format 2; disk-first 2; abso Capacity).

of shared·capacity··Not checked

Collisions reads every key each draft atom writes. An atom's lists over 256 values were stored a row per value (readonlyStoredArray). On website, collisions read 75,000 of those rows (a draft deleting a big file has thousands of keys).

  • New atoms store such lists 256 values to a row (writePagedArray) and mark it listFormat 2. readonlyPagedArray reads them a page at a time, in order or by index.
  • An atom stored before keeps listFormat 1 and its row per value, and reads as before. The format is per atom record, so old and new atoms sit side by side. Only atoms stored from this version on, or a fresh adoption, get pages.

On website adopted fresh, cold, one opened writer: collisions 9.6 s to 4.7 s (79,000 reads to 3,900), matching replay (0.4 s). Adoption took 87 s instead of 119 s.

Tests: graph-atom-list-pages (new: a new atom's list is paged and reads whole; an atom rewritten as list format 1 reads whole). graph-atom-list-rollback now injects its failure on the list's second page. Every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.

Version 238 · Files at version 239

4 files, 158 lines added, 12 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -21,12 +21,14 @@
2121import { withProjectionScratch } from "./projection-scratch.ts";
2222import {
2323 type GraphStateStorage,
24+ readonlyPagedArray,
2425 readonlyStoredArray,
2526 type StateMap,
2627 storedArray,
2728 storedLists,
2829 storedMap,
2930 storedNumbers,
31+ writePagedArray,
3032} from "./state-source.ts";
3133import { StoredText } from "./stored-text.ts";
3234import {
@@ -353,7 +355,7 @@
353355 insertionFormat?: 1;
354356 insertionRuns?: string;
355357 textFormat?: 1;
356− listFormat?: 1;
358+ listFormat?: 1 | 2;
357359 listCount?: number;
358360 lists?: Partial<Record<(typeof listFields)[number], string>>;
359361 atom: Atom;
@@ -365,9 +367,9 @@
365367 const encoded = value as unknown as Partial<EncodedAtom>;
366368 if (encoded.textFormat !== undefined && encoded.textFormat !== 1)
367369 throw Error("invalid stored atom text format");
368− if (encoded.listFormat !== undefined && encoded.listFormat !== 1)
370+ if (encoded.listFormat !== undefined && encoded.listFormat !== 1 && encoded.listFormat !== 2)
369371 throw Error("invalid stored atom list format");
370− if (encoded.listFormat === 1) {
372+ if (encoded.listFormat === 1 || encoded.listFormat === 2) {
371373 if (
372374 !encoded.lists ||
373375 typeof encoded.lists !== "object" ||
@@ -382,7 +384,10 @@
382384 if (encoded.insertionFormat !== undefined && encoded.insertionFormat !== 1)
383385 throw Error("invalid stored insertion format");
384386 const atom =
385− encoded.textFormat === 1 || encoded.listFormat === 1 || encoded.insertionFormat === 1
387+ encoded.textFormat === 1 ||
388+ encoded.listFormat === 1 ||
389+ encoded.listFormat === 2 ||
390+ encoded.insertionFormat === 1
386391 ? encoded.atom!
387392 : value;
388393 if (encoded.insertionFormat === 1 && (!Array.isArray(atom.inserts) || atom.inserts.length !== 0))
@@ -462,7 +467,8 @@
462467 (author) => author,
463468 text,
464469 );
465− if (encoded.listFormat !== 1 && encoded.insertionFormat !== 1) return streamed(frozen);
470+ if (encoded.listFormat !== 1 && encoded.listFormat !== 2 && encoded.insertionFormat !== 1)
471+ return streamed(frozen);
466472 const result = { ...frozen };
467473 if (encoded.insertionFormat === 1) {
468474 const collection = `atom-inserts:${atom.seq}`;
@@ -492,7 +498,11 @@
492498 if (collection === undefined) continue;
493499 if (typeof collection !== "string" || collection !== `atom-list:${atom.seq}:${field}`)
494500 throw Error("invalid stored atom list reference");
495− Object.defineProperty(result, field, { value: readonlyStoredArray(storage, collection), enumerable: true });
501+ const list =
502+ encoded.listFormat === 2
503+ ? readonlyPagedArray(storage, collection)
504+ : readonlyStoredArray(storage, collection);
505+ Object.defineProperty(result, field, { value: list, enumerable: true });
496506 }
497507 return streamed(Object.freeze(result));
498508 },
@@ -502,9 +512,9 @@
502512 for (const field of listFields) {
503513 const values = input[field];
504514 if (!values || values.length <= 256) continue;
515+ // 256 to a row from list format 2 on (abso Capacity); an atom stored before keeps a row per value.
505516 const collection = `atom-list:${input.seq}:${field}`;
506− const saved = storedArray<unknown>(storage, collection);
507− for (const value of values) saved.push(value);
517+ writePagedArray(storage, collection, values);
508518 lists[field] = collection;
509519 Object.defineProperty(atom, field, { value: [], enumerable: true });
510520 }
@@ -535,12 +545,12 @@
535545 return {
536546 insertionFormat: 1,
537547 insertionRuns: collection,
538− ...(hasLists ? { listFormat: 1, listCount, lists } : {}),
548+ ...(hasLists ? { listFormat: 2, listCount, lists } : {}),
539549 atom: { ...atom, inserts: [] },
540550 };
541551 }
542552 if (!atom.inserts.some((run) => run.lines.some((line) => line.length > StoredText.chunkCharacters)))
543− return hasLists ? { listFormat: 1, listCount, lists, atom } : atom;
553+ return hasLists ? { listFormat: 2, listCount, lists, atom } : atom;
544554 let index = 0;
545555 const inserts = atom.inserts.map((run) => ({
546556 ...run,
@@ -553,7 +563,7 @@
553563 }));
554564 return {
555565 textFormat: 1,
556− ...(hasLists ? { listFormat: 1, listCount, lists } : {}),
566+ ...(hasLists ? { listFormat: 2, listCount, lists } : {}),
557567 atom: { ...atom, inserts },
558568 };
559569 },
--- a/src/engine/state-source.ts
+++ b/src/engine/state-source.ts
@@ -583,6 +583,70 @@
583583}
584584
585585/** Read-only array access to individually stored values, without copying the list. */
586+/** How many values an atom's long list keeps to a row (readonlyPagedArray). */
587+export const LIST_PAGE = 256;
589+/** Write a list as readonlyPagedArray reads it: its values LIST_PAGE to a row, and its length. */
590+export function writePagedArray(storage: GraphStateStorage, name: string, values: readonly unknown[]): void {
591+ for (let start = 0; start < values.length; start += LIST_PAGE)
592+ storage.write(`${name}:pages`, String(start / LIST_PAGE), values.slice(start, start + LIST_PAGE));
593+ storage.write(`${name}:meta`, "length", values.length);
594+}
596+/**
597+ * A stored list read a page of LIST_PAGE values at a time (abso Capacity): an atom's long lists, which
598+ * readonlyStoredArray reads a row per value. Collisions read every key a draft's atoms write; a draft deleting a big
599+ * file has thousands, and that was a row each.
600+ */
601+export function readonlyPagedArray<T>(storage: GraphStateStorage, name: string): readonly T[] {
602+ const length = () => {
603+ const count = storage.read(`${name}:meta`, "length");
604+ if (!Number.isSafeInteger(count) || (count as number) < 0) throw Error("invalid stored list length");
605+ return count as number;
606+ };
607+ length();
608+ let held = -1;
609+ let page: readonly unknown[] = [];
610+ const at = (index: number): T => {
611+ const p = Math.floor(index / LIST_PAGE);
612+ if (p !== held) {
613+ const raw = storage.read(`${name}:pages`, String(p));
614+ if (!Array.isArray(raw)) throw Error("missing stored list page");
615+ page = raw;
616+ held = p;
617+ }
618+ const value = page[index % LIST_PAGE];
619+ if (value === undefined) throw Error("missing stored list element");
620+ return (value && typeof value === "object" ? Object.freeze(value) : value) as T;
621+ };
622+ function* inOrder(): IterableIterator<T> {
623+ const count = length();
624+ for (let index = 0; index < count; index++) yield at(index);
625+ }
626+ return new Proxy([] as T[], {
627+ get(target, key, receiver) {
628+ if (key === "length") return length();
629+ if (key === Symbol.iterator || key === "values") return inOrder;
630+ if (indexKey(key)) return Number(key) >= length() ? undefined : at(Number(key));
631+ return Reflect.get(target, key, receiver);
632+ },
633+ has(target, key) {
634+ return indexKey(key) ? Number(key) < length() : Reflect.has(target, key);
635+ },
636+ ownKeys() {
637+ return [...Array.from({ length: length() }, (_, index) => String(index)), "length"];
638+ },
639+ getOwnPropertyDescriptor(target, key) {
640+ if (indexKey(key) && Number(key) < length())
641+ return { configurable: true, enumerable: true, writable: false, value: at(Number(key)) };
642+ return Reflect.getOwnPropertyDescriptor(target, key);
643+ },
644+ set() {
645+ throw Error("stored lists are read-only");
646+ },
647+ });
648+}
586650export function readonlyStoredArray<T>(
587651 storage: GraphStateStorage,
588652 name: string,
--- /dev/null
+++ b/src/engine/test/graph-atom-list-pages.test.ts
@@ -0,0 +1,71 @@
1+// An atom's long lists (abso Capacity, readonlyPagedArray): a new atom keeps them 256 values to a row (list format 2),
2+// and an atom stored before keeps a row per value (list format 1). Both read back whole, in order and by index.
3+
4+import assert from "node:assert/strict";
5+import { test } from "node:test";
6+import { buildBase, Graph } from "../index.ts";
7+import { lineKey } from "../keys.ts";
8+import { storedArray } from "../state-source.ts";
9+import type { Atom } from "../types.ts";
10+import { SqlState } from "./storage-helper.ts";
12+function listAtom(keys: string[]): Atom {
13+ return {
14+ id: "a1",
15+ seq: 1,
16+ author: "fixture",
17+ message: "lists",
18+ time: 1,
19+ inserts: [],
20+ deletes: [],
21+ writes: keys,
22+ reads: [],
23+ holds: [],
24+ needs: [],
25+ resolves: [],
26+ reasons: [],
27+ deps: ["a0"],
28+ };
29+}
31+const keys = Array.from({ length: 600 }, () => lineKey("a0.0"));
33+test("a new atom's long list is kept 256 values to a row and reads back whole", () => {
34+ const storage = new SqlState();
35+ try {
36+ const graph = new Graph({ storage });
37+ graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
38+ graph.add(listAtom(keys));
39+ assert.equal((storage.read("atoms", "1") as { listFormat?: number }).listFormat, 2);
40+ assert.equal((storage.read("atom-list:1:writes:pages", "2") as unknown[]).length, 600 - 512);
41+ assert.equal(storage.read("atom-list:1:writes", "0"), undefined, "no row per value");
42+ const writes = new Graph({ storage }).atom("a1").writes;
43+ assert.deepEqual([...writes], keys);
44+ assert.equal(writes.length, 600);
45+ assert.equal(writes[300], keys[300]);
46+ assert.equal(writes[600], undefined);
47+ } finally {
48+ storage.db.close();
49+ }
50+});
52+test("an atom stored before pages, a row per value, still reads back whole", () => {
53+ const storage = new SqlState();
54+ try {
55+ const graph = new Graph({ storage });
56+ graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
57+ graph.add(listAtom(keys));
58+ // Rewrite it as list format 1 kept it: a row per value and no pages.
59+ const record = storage.read("atoms", "1") as Record<string, unknown>;
60+ for (let page = 0; page < 3; page++) storage.remove("atom-list:1:writes:pages", String(page));
61+ storage.remove("atom-list:1:writes:meta", "length");
62+ const rows = storedArray<string>(storage, "atom-list:1:writes");
63+ for (const key of keys) rows.push(key);
64+ storage.write("atoms", "1", { ...record, listFormat: 1 });
65+ const writes = new Graph({ storage }).atom("a1").writes;
66+ assert.deepEqual([...writes], keys);
67+ assert.equal(writes[599], keys[599]);
68+ } finally {
69+ storage.db.close();
70+ }
71+});
--- a/src/engine/test/graph-atom-list-rollback.test.ts
+++ b/src/engine/test/graph-atom-list-rollback.test.ts
@@ -31,7 +31,8 @@
3131 const write = storage.write.bind(storage);
3232 storage.write = (collection, key, value) => {
3333 write(collection, key, value);
34− if (collection === "atom-list:1:writes" && key === "128") throw Error("injected list persistence failure");
34+ // Partway through: the second of the list's two pages (256 values to a page).
35+ if (collection === "atom-list:1:writes:pages" && key === "1") throw Error("injected list persistence failure");
3536 };
3637 assert.throws(() => graph.add(atom), /injected list persistence failure/);
3738 assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);