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

Old agent rows move their told lists into buckets a few at each write (abso Capacity, issue 664; Agent VCS's go).

of shared·capacity··Not checked

A project adopted before the told buckets (260) keeps each old agent row's list until that agent's row is next written; idle agents' big rows would stay. WriterAgents.moveOldTold walks the agents in the order they joined, from a cursor in the writer state, and rewrites up to 4 old rows at each write (Project's flush of a committed write, never a read or an adoption page), until the cursor passes them all; then it costs one read.

Rows written since are in the new form, and an agent read in between answers the same. In practice a write also rewrites every agent it touches, so most rows move with the first writes.

Tests (told-buckets): nine agents' rows made old, with no move started, all move within three writes on a reopened writer while news matches the in-memory project, and the cursor ends past every agent; moveOldTold alone moves 4, 4, 2 then 0 of ten untouched old rows, each keeping its keys. All of src/engine/test and worker/project/test pass.

Version 261 · Files at version 262

3 files, 132 lines added, 2 removed.

--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -255,6 +255,8 @@
255255const WRITER_CACHE_ROWS = 16_384;
256256/** The biggest row the writer cache keeps (abso Capacity): an agent and all the news it was told can be 100 KB. */
257257const WRITER_CACHE_ROW_BYTES = 16_384;
258+/** Old-form agent rows moved to told buckets at each write (abso Capacity): abso's 109 take about 28 writes. */
259+const OLD_TOLD_PER_WRITE = 4;
258260export interface WriterSource {
259261 readonly generation: number;
260262 readonly logLength: number;
@@ -1701,6 +1703,8 @@
17011703 const out = this.#pending;
17021704 this.#store.append(out);
17031705 this.#persistMutable();
1706+ // A few more agents' old told lists into their buckets at each write, until every row has moved (writer-agents.ts).
1707+ if (this.#agents instanceof WriterAgents) this.#agents.moveOldTold(OLD_TOLD_PER_WRITE);
17041708 this.#pending = [];
17051709 this.#stored += out.length;
17061710 this.#writeCheckpoint();
--- a/worker/project/test/told-buckets.test.ts
+++ b/worker/project/test/told-buckets.test.ts
@@ -10,7 +10,7 @@
1010import { SqlState } from "../../../src/engine/test/storage-helper.ts";
1111import { MemoryStore, Project } from "../project.ts";
1212import type { Entry, ProjectStore } from "../project-types.ts";
13−import { StoredTold, TOLD_BUCKETS } from "../writer-agents.ts";
13+import { StoredTold, TOLD_BUCKETS, WriterAgents } from "../writer-agents.ts";
1414
1515const TOLD = "project:agents:told";
1616const AGENTS = "project:agents";
@@ -125,3 +125,97 @@
125125 storage.db.close();
126126 }
127127});
129+test("a project written before the buckets moves every agent's told list over a few writes, news unchanged", () => {
130+ const oracle = new Project(new MemoryStore());
131+ const { storage, entries, store, project: first } = writer();
132+ const names = Array.from({ length: 9 }, (_, i) => `agent${i}`);
133+ const setup: ((p: Project) => unknown)[] = [
134+ (p) => p.init({ "a.ts": "one\n" }, 0),
135+ ...names.map((name, i) => (p: Project) => p.record(name, { [`${name}.ts`]: `${i}\n` }, i + 1)),
136+ (p) => p.record("boss", { "boss.ts": "b\n" }, 19),
137+ // An announcer isn't told its own announcement: someone else announces to the nine.
138+ (p) => p.announce("boss", "To everyone", names, 20),
139+ ];
140+ try {
141+ for (const f of setup) {
142+ f(first);
143+ f(oracle);
144+ }
145+ // Every agent's row back to the old form: its told keys in the row's list, none in buckets.
146+ const told = new Map<string, string[]>();
147+ for (const name of names) {
148+ const keys = bucketKeys(storage, name);
149+ assert.ok(keys.length > 0, `${name} was told something`);
150+ told.set(name, keys);
151+ const row = storage.read(AGENTS, agentKey(name)) as { slot: number; value: Record<string, unknown> };
152+ storage.write(AGENTS, agentKey(name), { ...row, value: { ...row.value, told: keys } });
153+ for (let b = 0; b < TOLD_BUCKETS; b++) storage.remove(TOLD, toldRow(name, b));
154+ }
155+ // As a project adopted before the buckets: no move started.
156+ storage.remove("project:agents:told:meta", "cursor");
157+ const oldRows = () =>
158+ names.filter((n) => (storage.read(AGENTS, agentKey(n)) as { value: { told?: unknown } }).value.told);
159+ assert.equal(oldRows().length, 9);
160+ const project = Project.openWriter(store, storage, entries.length);
161+ const writes = [
162+ (p: Project) => p.record("agent8", { "agent8.ts": "8\nmore\n" }, 30),
163+ (p: Project) => p.record("agent8", { "agent8.ts": "8\nmore\nagain\n" }, 31),
164+ (p: Project) => p.announce("boss", "Once more", names, 32),
165+ ];
166+ const left = [];
167+ for (const f of writes) {
168+ assert.deepEqual(step(project, f), step(oracle, f));
169+ left.push(oldRows().length);
170+ }
171+ // Every row moved within the writes (each write rewrites the agents it touches, and the cursor the rest).
172+ assert.equal(left.at(-1), 0);
173+ for (const name of names)
174+ for (const key of told.get(name)!) assert.ok(bucketKeys(storage, name).includes(key), key);
175+ // Past every agent in the order they joined.
176+ assert.equal(
177+ storage.read("project:agents:told:meta", "cursor"),
178+ storedArray(storage, "project:agents:order").length,
179+ );
180+ } finally {
181+ storage.db.close();
182+ }
183+});
185+test("the move takes a few untouched agents' old rows at a time, in the order they joined, once", () => {
186+ const storage = new SqlState();
187+ try {
188+ const agents = new WriterAgents(storage);
189+ const names = Array.from({ length: 10 }, (_, i) => `a${i}`);
190+ for (const name of names) {
191+ const agent = {
192+ name,
193+ space: "",
194+ base: 0,
195+ mine: [],
196+ news: [],
197+ newsAt: [],
198+ told: new Set([`k ${name}`]),
199+ parked: new Map(),
200+ };
201+ agents.set(name, agent as unknown as Parameters<typeof agents.set>[1]);
202+ }
203+ agents.flush();
204+ // Back to old rows, with no move started.
205+ for (const name of names) {
206+ const row = storage.read(AGENTS, agentKey(name)) as { slot: number; value: Record<string, unknown> };
207+ storage.write(AGENTS, agentKey(name), { ...row, value: { ...row.value, told: [`k ${name}`] } });
208+ for (let b = 0; b < TOLD_BUCKETS; b++) storage.remove(TOLD, toldRow(name, b));
209+ }
210+ const fresh = new WriterAgents(storage);
211+ const moves = [fresh.moveOldTold(4), fresh.moveOldTold(4), fresh.moveOldTold(4), fresh.moveOldTold(4)];
212+ assert.deepEqual(moves, [4, 4, 2, 0]);
213+ for (const name of names) {
214+ assert.deepEqual(bucketKeys(storage, name), [`k ${name}`]);
215+ assert.equal((storage.read(AGENTS, agentKey(name)) as { value: { told?: unknown } }).value.told, undefined);
216+ assert.equal(new WriterAgents(storage).get(name)!.told.has(`k ${name}`), true);
217+ }
218+ } finally {
219+ storage.db.close();
220+ }
221+});
--- a/worker/project/writer-agents.ts
+++ b/worker/project/writer-agents.ts
@@ -1,4 +1,4 @@
1−import { type GraphStateStorage, StoredMap } from "../../src/engine/state-source.ts";
1+import { type GraphStateStorage, StoredMap, storedArray } from "../../src/engine/state-source.ts";
22import type { AgentState } from "./project-types.ts";
33
44type StoredAgent = Omit<AgentState, "told" | "parked"> & {
@@ -205,4 +205,36 @@
205205 for (const [key, value] of this.#touched) super.set(key, value);
206206 this.#touched.clear();
207207 }
209+ /**
210+ * Move up to `limit` more agents' old told lists into their buckets (abso Capacity, issue 664; Agent VCS's go): a
211+ * cursor walks the agents in the order they joined, once, a few rows at each write, so a project adopted before the
212+ * buckets moves every row over without a separate step. Rows written since are in the new form already, and an
213+ * agent read in between answers the same (StoredTold.listed). Returns how many rows it rewrote.
214+ */
215+ moveOldTold(limit: number): number {
216+ const done = (this.#storage.read(TOLD_META, "cursor") as number | undefined) ?? 0;
217+ const order = this.#order();
218+ if (done >= order.length) return 0;
219+ let at = done;
220+ let moved = 0;
221+ for (; at < order.length && at < done + limit; at++) {
222+ const key = order[at]!;
223+ if (this.#touched.has(key)) continue; // written with this operation: its row is new already
224+ const agent = super.get(key);
225+ if (!(agent?.told instanceof StoredTold) || agent.told.listed.size === 0) continue;
226+ super.set(key, agent);
227+ moved++;
228+ }
229+ this.#storage.write(TOLD_META, "cursor", at);
230+ return moved;
231+ }
233+ /** The agents' keys in the order they joined (StoredMap's slots, a removed agent's included: it reads as absent). */
234+ #order(): readonly string[] {
235+ return storedArray<string>(this.#storage, "project:agents:order");
236+ }
208237}
239+/** Where the move of old told lists into buckets has got to (WriterAgents.moveOldTold). */
240+const TOLD_META = "project:agents:told:meta";