Old agent rows move their told lists into buckets a few at each write (abso Capacity, issue 664; Agent VCS's go). Version 262 of shared· capacity· Oct 15 (2026-10-15 19:54 UTC) · 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 @@
255 255 const WRITER_CACHE_ROWS = 16_384; 256 256 /** The biggest row the writer cache keeps (abso Capacity): an agent and all the news it was told can be 100 KB. */ 257 257 const 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; 258 260 export interface WriterSource { 259 261 readonly generation: number; 260 262 readonly logLength: number; @@ -1701,6 +1703,8 @@
1701 1703 const out = this.#pending; 1702 1704 this.#store.append(out); 1703 1705 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); 1704 1708 this.#pending = []; 1705 1709 this.#stored += out.length; 1706 1710 this.#writeCheckpoint(); --- a/worker/project/test/told-buckets.test.ts
+++ b/worker/project/test/told-buckets.test.ts
@@ -10,7 +10,7 @@
10 10 import { SqlState } from "../../../src/engine/test/storage-helper.ts"; 11 11 import { MemoryStore, Project } from "../project.ts"; 12 12 import 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"; 15 15 const TOLD = "project:agents:told"; 16 16 const AGENTS = "project:agents"; @@ -125,3 +125,97 @@
125 125 storage.db.close(); 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), 141 + for (const f of setup) { 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)); 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); 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), 167 + for (const f of writes) { 168 + assert.deepEqual(step(project, f), step(oracle, f)); 169 + left.push(oldRows().length); 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. 177 + storage.read("project:agents:told:meta", "cursor"), 178 + storedArray(storage, "project:agents:order").length, 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(); 188 + const agents = new WriterAgents(storage); 189 + const names = Array.from({ length: 10 }, (_, i) => `a${i}`); 190 + for (const name of names) { 198 + told: new Set([`k ${name}`]), 201 + agents.set(name, agent as unknown as Parameters<typeof agents.set>[1]); 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)); 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); --- 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"; 2 2 import type { AgentState } from "./project-types.ts"; 4 4 type StoredAgent = Omit<AgentState, "told" | "parked"> & { @@ -205,4 +205,36 @@
205 205 for (const [key, value] of this.#touched) super.set(key, value); 206 206 this.#touched.clear(); 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. 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; 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); 229 + this.#storage.write(TOLD_META, "cursor", at); 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"); 239 + /** Where the move of old told lists into buckets has got to (WriterAgents.moveOldTold). */ 240 + const TOLD_META = "project:agents:told:meta";