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 252 to 253

Compare

+39 −6 in 4 places
Lines 30–60 at 253 (were 30–41 at 252)
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;
Lines 108–121 at 253 (were 89–100 at 252)
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);
Lines 125–131 at 253 (were 104–109 at 252)
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.
Lines 133–160 at 253 (were 111–127 at 252)
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 }
MCP
compare on this site's /mcp
CLI
abso diff 252 253 src/engine/state-source.ts --json
JSON
/christopher/abso-core/compare/252..253?file=src%2Fengine%2Fstate-source.ts&format=json