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

The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).

of shared·capacity··Not checked

  • CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.
  • A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.

On a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.

Tests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.

codex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.

Version 252 · Files at version 253

4 files, 103 lines added, 8 removed.

--- a/src/engine/state-source.ts
+++ b/src/engine/state-source.ts
@@ -30,12 +30,31 @@
3030 readonly #maxBytes: number;
3131 readonly #maxEntries: number;
3232 #bytes = 0;
33− constructor(source: GraphStateStorage, maxBytes = 1_048_576, maxEntries = 4096) {
34− if (!Number.isSafeInteger(maxBytes) || maxBytes < 0 || !Number.isSafeInteger(maxEntries) || maxEntries < 0)
33+ /**
34+ * The keys written or removed in each open transaction, innermost last (abso Capacity). A rollback drops only those:
35+ * every projection scratch scope ends in a rollback, and dropping the whole cache there read the same rows from
36+ * storage again within a call and on every call of a kept reader.
37+ */
38+ readonly #touched: Set<string>[] = [];
39+ /**
40+ * The biggest one row may be and still be kept (abso Capacity). A few big rows read on every call (each agent with
41+ * all the news it was told: 4.3 MB for abso's 109 agents) otherwise push every small page out of the cache.
42+ */
43+ readonly #maxEntryBytes: number;
44+ constructor(source: GraphStateStorage, maxBytes = 1_048_576, maxEntries = 4096, maxEntryBytes = maxBytes) {
45+ if (
46+ !Number.isSafeInteger(maxBytes) ||
47+ maxBytes < 0 ||
48+ !Number.isSafeInteger(maxEntries) ||
49+ maxEntries < 0 ||
50+ !Number.isSafeInteger(maxEntryBytes) ||
51+ maxEntryBytes < 0
52+ )
3553 throw new Error("invalid writer cache limits");
3654 this.#source = source;
3755 this.#maxBytes = maxBytes;
3856 this.#maxEntries = maxEntries;
57+ this.#maxEntryBytes = Math.min(maxEntryBytes, maxBytes);
3958 }
4059 get retainedBytes(): number {
4160 return this.#bytes;
@@ -89,12 +108,14 @@
89108 entry = { kind: "json", json, bytes: overhead + 2 * json.length };
90109 }
91110 this.#remember(cacheKey, entry);
111+ // A projection scope's own rows are never read again once it ends in its rollback: forget them with it.
112+ if (collection.startsWith("projection-scratch:")) this.#touched.at(-1)?.add(cacheKey);
92113 return value;
93114 }
94115 #remember(cacheKey: string, entry: CachedValue): void {
95116 this.#drop(cacheKey);
96117 // Payload accounting is bounded, not a measurement of actual isolate heap.
97− if (entry.bytes <= this.#maxBytes && this.#maxEntries > 0) {
118+ if (entry.bytes <= this.#maxEntryBytes && this.#maxEntries > 0) {
98119 while (this.#bytes + entry.bytes > this.#maxBytes || this.#cache.size >= this.#maxEntries)
99120 this.#drop(this.#cache.keys().next().value!);
100121 this.#cache.set(cacheKey, entry);
@@ -104,6 +125,7 @@
104125 write(collection: string, key: string, value: unknown): void {
105126 const cacheKey = JSON.stringify([collection, key]);
106127 this.#drop(cacheKey);
128+ this.#touched.at(-1)?.add(cacheKey);
107129 this.#source.write(collection, key, value);
108130 // Allocation counters are immutable scalars. Keep successful writes within
109131 // the existing cache budget instead of immediately reading them back.
@@ -111,17 +133,28 @@
111133 this.#remember(cacheKey, { kind: "scalar", value, bytes: 2 * cacheKey.length + 176 });
112134 }
113135 remove(collection: string, key: string): void {
114− this.#drop(JSON.stringify([collection, key]));
136+ const cacheKey = JSON.stringify([collection, key]);
137+ this.#drop(cacheKey);
138+ this.#touched.at(-1)?.add(cacheKey);
115139 this.#source.remove(collection, key);
116140 }
117141 entries(collection: string): Iterable<readonly [string, unknown]> {
118142 return this.#source.entries(collection);
119143 }
120144 transaction<T>(body: () => T): T {
145+ const touched = new Set<string>();
146+ this.#touched.push(touched);
121147 try {
122− return this.#source.transaction(body);
148+ const result = this.#source.transaction(body);
149+ this.#touched.pop();
150+ // Committed into the outer transaction, which may still roll back.
151+ const outer = this.#touched.at(-1);
152+ if (outer) for (const key of touched) outer.add(key);
153+ return result;
123154 } catch (error) {
124− this.clear();
155+ this.#touched.pop();
156+ // What the transaction wrote, and anything read back after it wrote it, is gone with the rollback.
157+ for (const key of touched) this.#drop(key);
125158 throw error;
126159 }
127160 }
--- a/src/engine/test/projection-scratch.test.ts
+++ b/src/engine/test/projection-scratch.test.ts
@@ -32,7 +32,9 @@
3232 );
3333 assert.deepEqual(result, { value: 99, data: new Int32Array([1, 2]) });
3434 assert.throws(() => escaped!.write("x", "y", true), /ended/);
35− assert.equal(storage.retainedEntries, 0, "scratch rollback invalidates every cached value");
35+ // A scratch rollback drops only what the scratch wrote (abso Capacity): the canonical value written before it, in
36+ // the outer transaction, stays cached and is still right.
37+ assert.equal(storage.retainedEntries, 1, "only the canonical value written before the scratch remains");
3638 assert.equal(storage.read("canonical", "before"), 1);
3739 storage.write("canonical", "after", 2);
3840 });
--- a/src/engine/test/state-cache.test.ts
+++ b/src/engine/test/state-cache.test.ts
@@ -105,3 +105,61 @@
105105 assert.equal(cache.retainedBytes, 0);
106106 source.db.close();
107107});
109+test("a rollback drops only what its transaction wrote; a nested commit's writes go with an outer rollback (abso Capacity)", () => {
110+ const source = new SqlState();
111+ try {
112+ const cache = new CachedStateStorage(source, 8192, 16);
113+ source.write("rows", "kept", "k");
114+ source.write("rows", "inner", "i0");
115+ source.write("rows", "outer", "o0");
116+ for (const key of ["kept", "inner", "outer"]) cache.read("rows", key);
117+ const reads = source.reads;
118+ // A projection scratch scope: rolled back on purpose, and the rows read around it stay cached.
119+ assert.throws(
120+ () =>
121+ cache.transaction(() => {
122+ cache.write("scratch", "x", "temporary");
123+ throw new Error("scratch rollback");
124+ }),
125+ /scratch rollback/,
126+ );
127+ assert.equal(cache.read("rows", "kept"), "k");
128+ assert.equal(source.reads, reads, "the rows read before were not read again");
129+ assert.equal(cache.read("scratch", "x"), undefined);
130+ // A nested transaction commits, then the outer one rolls back: both writes are undone, and the cache forgets both.
131+ assert.throws(
132+ () =>
133+ cache.transaction(() => {
134+ cache.write("rows", "outer", "o1");
135+ cache.transaction(() => cache.write("rows", "inner", "i1"));
136+ assert.equal(cache.read("rows", "inner"), "i1");
137+ throw new Error("outer rollback");
138+ }),
139+ /outer rollback/,
140+ );
141+ assert.equal(cache.read("rows", "inner"), "i0");
142+ assert.equal(cache.read("rows", "outer"), "o0");
143+ assert.equal(cache.read("rows", "kept"), "k");
144+ } finally {
145+ source.db.close();
146+ }
147+});
149+test("a row over the per-row limit is read but not kept, and pushes nothing out (abso Capacity)", () => {
150+ const source = new SqlState();
151+ try {
152+ const cache = new CachedStateStorage(source, 8192, 64, 1024);
153+ source.write("rows", "small", "s");
154+ source.write("rows", "big", "x".repeat(2000));
155+ cache.read("rows", "small");
156+ const reads = source.reads;
157+ assert.equal((cache.read("rows", "big") as string).length, 2000);
158+ assert.equal(cache.read("rows", "small"), "s");
159+ assert.equal(source.reads, reads + 1, "the big row was read from storage once and the small one stayed cached");
160+ assert.equal((cache.read("rows", "big") as string).length, 2000);
161+ assert.equal(source.reads, reads + 2, "the big row isn't kept");
162+ } finally {
163+ source.db.close();
164+ }
165+});
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -253,6 +253,8 @@
253253 */
254254const WRITER_CACHE_BYTES = 4 * 1_048_576;
255255const WRITER_CACHE_ROWS = 16_384;
256+/** The biggest row the writer cache keeps (abso Capacity): an agent and all the news it was told can be 100 KB. */
257+const WRITER_CACHE_ROW_BYTES = 16_384;
256258export interface WriterSource {
257259 readonly generation: number;
258260 readonly logLength: number;
@@ -403,7 +405,7 @@
403405 throw Error("accepted atom indexing requires writer storage");
404406 this.#store = store;
405407 this.#writerStorage = options.writerStorage
406− ? new CachedStateStorage(options.writerStorage, WRITER_CACHE_BYTES, WRITER_CACHE_ROWS)
408+ ? new CachedStateStorage(options.writerStorage, WRITER_CACHE_BYTES, WRITER_CACHE_ROWS, WRITER_CACHE_ROW_BYTES)
407409 : undefined;
408410 if (this.#writerStorage) {
409411 const storage = this.#writerStorage;