{"version":262,"agent":"capacity","message":"Old agent rows move their told lists into buckets a few at each write (abso Capacity, issue 664; Agent VCS's go).\n\nA 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.\n\nTests (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.","time":1792094049264,"timeIso":"2026-10-15T19:54:09.264Z","changes":7,"change":4028,"files":["worker/project/project.ts","worker/project/test/told-buckets.test.ts","worker/project/writer-agents.ts"],"draft":null,"diff":[{"path":"worker/project/project.ts","added":4,"removed":0,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -255,6 +255,8 @@\n const WRITER_CACHE_ROWS = 16_384;\n /** The biggest row the writer cache keeps (abso Capacity): an agent and all the news it was told can be 100 KB. */\n const WRITER_CACHE_ROW_BYTES = 16_384;\n+/** Old-form agent rows moved to told buckets at each write (abso Capacity): abso's 109 take about 28 writes. */\n+const OLD_TOLD_PER_WRITE = 4;\n export interface WriterSource {\n \treadonly generation: number;\n \treadonly logLength: number;\n@@ -1701,6 +1703,8 @@\n \t\tconst out = this.#pending;\n \t\tthis.#store.append(out);\n \t\tthis.#persistMutable();\n+\t\t// A few more agents' old told lists into their buckets at each write, until every row has moved (writer-agents.ts).\n+\t\tif (this.#agents instanceof WriterAgents) this.#agents.moveOldTold(OLD_TOLD_PER_WRITE);\n \t\tthis.#pending = [];\n \t\tthis.#stored += out.length;\n \t\tthis.#writeCheckpoint();"},{"path":"worker/project/test/told-buckets.test.ts","added":95,"removed":1,"diff":"--- a/worker/project/test/told-buckets.test.ts\n+++ b/worker/project/test/told-buckets.test.ts\n@@ -10,7 +10,7 @@\n import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n import { MemoryStore, Project } from \"../project.ts\";\n import type { Entry, ProjectStore } from \"../project-types.ts\";\n-import { StoredTold, TOLD_BUCKETS } from \"../writer-agents.ts\";\n+import { StoredTold, TOLD_BUCKETS, WriterAgents } from \"../writer-agents.ts\";\n \n const TOLD = \"project:agents:told\";\n const AGENTS = \"project:agents\";\n@@ -125,3 +125,97 @@\n \t\tstorage.db.close();\n \t}\n });\n+\n+test(\"a project written before the buckets moves every agent's told list over a few writes, news unchanged\", () => {\n+\tconst oracle = new Project(new MemoryStore());\n+\tconst { storage, entries, store, project: first } = writer();\n+\tconst names = Array.from({ length: 9 }, (_, i) => `agent${i}`);\n+\tconst setup: ((p: Project) => unknown)[] = [\n+\t\t(p) => p.init({ \"a.ts\": \"one\\n\" }, 0),\n+\t\t...names.map((name, i) => (p: Project) => p.record(name, { [`${name}.ts`]: `${i}\\n` }, i + 1)),\n+\t\t(p) => p.record(\"boss\", { \"boss.ts\": \"b\\n\" }, 19),\n+\t\t// An announcer isn't told its own announcement: someone else announces to the nine.\n+\t\t(p) => p.announce(\"boss\", \"To everyone\", names, 20),\n+\t];\n+\ttry {\n+\t\tfor (const f of setup) {\n+\t\t\tf(first);\n+\t\t\tf(oracle);\n+\t\t}\n+\t\t// Every agent's row back to the old form: its told keys in the row's list, none in buckets.\n+\t\tconst told = new Map<string, string[]>();\n+\t\tfor (const name of names) {\n+\t\t\tconst keys = bucketKeys(storage, name);\n+\t\t\tassert.ok(keys.length > 0, `${name} was told something`);\n+\t\t\ttold.set(name, keys);\n+\t\t\tconst row = storage.read(AGENTS, agentKey(name)) as { slot: number; value: Record<string, unknown> };\n+\t\t\tstorage.write(AGENTS, agentKey(name), { ...row, value: { ...row.value, told: keys } });\n+\t\t\tfor (let b = 0; b < TOLD_BUCKETS; b++) storage.remove(TOLD, toldRow(name, b));\n+\t\t}\n+\t\t// As a project adopted before the buckets: no move started.\n+\t\tstorage.remove(\"project:agents:told:meta\", \"cursor\");\n+\t\tconst oldRows = () =>\n+\t\t\tnames.filter((n) => (storage.read(AGENTS, agentKey(n)) as { value: { told?: unknown } }).value.told);\n+\t\tassert.equal(oldRows().length, 9);\n+\t\tconst project = Project.openWriter(store, storage, entries.length);\n+\t\tconst writes = [\n+\t\t\t(p: Project) => p.record(\"agent8\", { \"agent8.ts\": \"8\\nmore\\n\" }, 30),\n+\t\t\t(p: Project) => p.record(\"agent8\", { \"agent8.ts\": \"8\\nmore\\nagain\\n\" }, 31),\n+\t\t\t(p: Project) => p.announce(\"boss\", \"Once more\", names, 32),\n+\t\t];\n+\t\tconst left = [];\n+\t\tfor (const f of writes) {\n+\t\t\tassert.deepEqual(step(project, f), step(oracle, f));\n+\t\t\tleft.push(oldRows().length);\n+\t\t}\n+\t\t// Every row moved within the writes (each write rewrites the agents it touches, and the cursor the rest).\n+\t\tassert.equal(left.at(-1), 0);\n+\t\tfor (const name of names)\n+\t\t\tfor (const key of told.get(name)!) assert.ok(bucketKeys(storage, name).includes(key), key);\n+\t\t// Past every agent in the order they joined.\n+\t\tassert.equal(\n+\t\t\tstorage.read(\"project:agents:told:meta\", \"cursor\"),\n+\t\t\tstoredArray(storage, \"project:agents:order\").length,\n+\t\t);\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});\n+\n+test(\"the move takes a few untouched agents' old rows at a time, in the order they joined, once\", () => {\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst agents = new WriterAgents(storage);\n+\t\tconst names = Array.from({ length: 10 }, (_, i) => `a${i}`);\n+\t\tfor (const name of names) {\n+\t\t\tconst agent = {\n+\t\t\t\tname,\n+\t\t\t\tspace: \"\",\n+\t\t\t\tbase: 0,\n+\t\t\t\tmine: [],\n+\t\t\t\tnews: [],\n+\t\t\t\tnewsAt: [],\n+\t\t\t\ttold: new Set([`k ${name}`]),\n+\t\t\t\tparked: new Map(),\n+\t\t\t};\n+\t\t\tagents.set(name, agent as unknown as Parameters<typeof agents.set>[1]);\n+\t\t}\n+\t\tagents.flush();\n+\t\t// Back to old rows, with no move started.\n+\t\tfor (const name of names) {\n+\t\t\tconst row = storage.read(AGENTS, agentKey(name)) as { slot: number; value: Record<string, unknown> };\n+\t\t\tstorage.write(AGENTS, agentKey(name), { ...row, value: { ...row.value, told: [`k ${name}`] } });\n+\t\t\tfor (let b = 0; b < TOLD_BUCKETS; b++) storage.remove(TOLD, toldRow(name, b));\n+\t\t}\n+\t\tconst fresh = new WriterAgents(storage);\n+\t\tconst moves = [fresh.moveOldTold(4), fresh.moveOldTold(4), fresh.moveOldTold(4), fresh.moveOldTold(4)];\n+\t\tassert.deepEqual(moves, [4, 4, 2, 0]);\n+\t\tfor (const name of names) {\n+\t\t\tassert.deepEqual(bucketKeys(storage, name), [`k ${name}`]);\n+\t\t\tassert.equal((storage.read(AGENTS, agentKey(name)) as { value: { told?: unknown } }).value.told, undefined);\n+\t\t\tassert.equal(new WriterAgents(storage).get(name)!.told.has(`k ${name}`), true);\n+\t\t}\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"},{"path":"worker/project/writer-agents.ts","added":33,"removed":1,"diff":"--- a/worker/project/writer-agents.ts\n+++ b/worker/project/writer-agents.ts\n@@ -1,4 +1,4 @@\n-import { type GraphStateStorage, StoredMap } from \"../../src/engine/state-source.ts\";\n+import { type GraphStateStorage, StoredMap, storedArray } from \"../../src/engine/state-source.ts\";\n import type { AgentState } from \"./project-types.ts\";\n \n type StoredAgent = Omit<AgentState, \"told\" | \"parked\"> & {\n@@ -205,4 +205,36 @@\n \t\tfor (const [key, value] of this.#touched) super.set(key, value);\n \t\tthis.#touched.clear();\n \t}\n+\n+\t/**\n+\t * Move up to `limit` more agents' old told lists into their buckets (abso Capacity, issue 664; Agent VCS's go): a\n+\t * cursor walks the agents in the order they joined, once, a few rows at each write, so a project adopted before the\n+\t * buckets moves every row over without a separate step. Rows written since are in the new form already, and an\n+\t * agent read in between answers the same (StoredTold.listed). Returns how many rows it rewrote.\n+\t */\n+\tmoveOldTold(limit: number): number {\n+\t\tconst done = (this.#storage.read(TOLD_META, \"cursor\") as number | undefined) ?? 0;\n+\t\tconst order = this.#order();\n+\t\tif (done >= order.length) return 0;\n+\t\tlet at = done;\n+\t\tlet moved = 0;\n+\t\tfor (; at < order.length && at < done + limit; at++) {\n+\t\t\tconst key = order[at]!;\n+\t\t\tif (this.#touched.has(key)) continue; // written with this operation: its row is new already\n+\t\t\tconst agent = super.get(key);\n+\t\t\tif (!(agent?.told instanceof StoredTold) || agent.told.listed.size === 0) continue;\n+\t\t\tsuper.set(key, agent);\n+\t\t\tmoved++;\n+\t\t}\n+\t\tthis.#storage.write(TOLD_META, \"cursor\", at);\n+\t\treturn moved;\n+\t}\n+\n+\t/** The agents' keys in the order they joined (StoredMap's slots, a removed agent's included: it reads as absent). */\n+\t#order(): readonly string[] {\n+\t\treturn storedArray<string>(this.#storage, \"project:agents:order\");\n+\t}\n }\n+\n+/** Where the move of old told lists into buckets has got to (WriterAgents.moveOldTold). */\n+const TOLD_META = \"project:agents:told:meta\";"}],"ci":null}