{"version":200,"agent":"capacity","message":"Project abso's memory, cut by a third (abso Capacity, prod abso hit its isolate memory limit at 7:20 and 7:25 PM CT). (1) The in-memory membership cache is one least-recently-used cache of 16 sets across every space, not up to 17 per space: each named draft cached whole copies of shared's set, 37 MB on prod abso with 106 drafts. Keyed by the space object, so a space rebuilt under the same name never gets old sets. (2) An agent keeps at most 200 unheard news lines (trimmed in batches of 50), the oldest dropped behind one line counting them: stopped agents kept every line, 7 MB. Measured on Engine's prod export of abso (81,855 entries) with measure-memory.ts --disk --reads: 96.6 MB after load before, 61.1 MB after; 105.3 MB after the heaviest reads before, 66.3 MB after. New tests membership-cache.test.ts and news-cap.test.ts.","time":1792024401295,"timeIso":"2026-10-15T00:33:21.295Z","changes":6,"change":3399,"files":["worker/project/apply-entry.ts","worker/project/news.ts","worker/project/spaces.ts","worker/project/test/membership-cache.test.ts","worker/project/test/news-cap.test.ts","worker/project/test/stored-membership.test.ts"],"draft":null,"diff":[{"path":"worker/project/apply-entry.ts","added":2,"removed":1,"diff":"--- a/worker/project/apply-entry.ts\n+++ b/worker/project/apply-entry.ts\n@@ -3,7 +3,7 @@\n // which space) is applied first, in spaces.ts.\n \n import type { AtomId, Graph } from \"../../src/engine/index.ts\";\n-import { outlastsSync } from \"./news.ts\";\n+import { capNews, outlastsSync } from \"./news.ts\";\n import { ProjectError } from \"./project-error.ts\";\n import type {\n \tAgentState,\n@@ -201,6 +201,7 @@\n \t\t\t\thost.setAnnounced(Math.max(host.announced(), id));\n \t\t\t\ttellSent(host.tells, id, entry.text[i] ?? entry.text[0] ?? \"\", agent.name, time);\n \t\t\t});\n+\t\t\tcapNews(agent);\n \t\t\tbreak;\n \t\t}\n \t\tcase \"discard\": {"},{"path":"worker/project/news.ts","added":32,"removed":0,"diff":"--- a/worker/project/news.ts\n+++ b/worker/project/news.ts\n@@ -123,6 +123,38 @@\n }\n \n /**\n+ * How many unheard news lines an agent keeps (abso Capacity). An agent that never hears its news, most often one that\n+ * stopped, kept every line: 7 MB of prod project abso's memory. Past this many (and NEWS_TRIM more), the oldest go,\n+ * and one line in front says how many.\n+ */\n+export const NEWS_KEPT = 200;\n+/** How far past NEWS_KEPT the news grows before the oldest are trimmed off. */\n+export const NEWS_TRIM = 50;\n+\n+const DROPPED_NEWS = /^(\\d+) older news items? went unheard and (?:was|were) dropped: an agent keeps its newest \\d+\\.$/;\n+\n+/** The line in front of an agent's news that counts what was dropped. */\n+export function droppedNewsLine(count: number): string {\n+\treturn `${count} older news ${count === 1 ? \"item\" : \"items\"} went unheard and ${count === 1 ? \"was\" : \"were\"} dropped: an agent keeps its newest ${NEWS_KEPT}.`;\n+}\n+\n+/**\n+ * Keeps an agent's unheard news to at most NEWS_KEPT + NEWS_TRIM lines (and their times, in step): the oldest go, and the dropped-count\n+ * line in front adds them up. Deterministic, so a replay of the log keeps the same lines.\n+ */\n+export function capNews(agent: { news: string[]; newsAt: (number | undefined)[] }): void {\n+\tconst counted = DROPPED_NEWS.exec(agent.news[0] ?? \"\");\n+\tconst before = counted ? Number(counted[1]) : 0;\n+\tconst from = counted ? 1 : 0;\n+\t// Trimmed in batches of NEWS_TRIM, so a busy agent isn't copied on every line of news.\n+\tif (agent.news.length - from <= NEWS_KEPT + NEWS_TRIM) return;\n+\tconst over = agent.news.length - from - NEWS_KEPT;\n+\tconst at = agent.newsAt[from + over];\n+\tagent.news = [droppedNewsLine(before + over), ...agent.news.slice(from + over)];\n+\tagent.newsAt = [at, ...agent.newsAt.slice(from + over)];\n+}\n+\n+/**\n  * News a sync doesn't make moot, so it is kept through one: announcements,\n  * and what a settle kept (the pull brings the file, not whose side survived).\n  */"},{"path":"worker/project/spaces.ts","added":41,"removed":15,"diff":"--- a/worker/project/spaces.ts\n+++ b/worker/project/spaces.ts\n@@ -46,7 +46,6 @@\n \treadonly publishedIn: Map<AtomId, number>;\n \t/** Atoms a drop took out, and the version of the drop. */\n \treadonly droppedIn: Map<AtomId, number>;\n-\treadonly atCache: Map<number, ReadonlySet<AtomId>>;\n \t/** For a named draft, the log position of the entry that made it: the change its work belongs to (#44). */\n \tstartedAt?: number;\n }\n@@ -62,10 +61,9 @@\n \t\t\town: new StoredSet(storage, `${prefix}:own`),\n \t\t\tpublishedIn: new StoredMap(storage, `${prefix}:published`),\n \t\t\tdroppedIn: new StoredMap(storage, `${prefix}:dropped`),\n-\t\t\tatCache: new Map(),\n \t\t};\n \t}\n-\treturn { name, versions: [], own: new Set(), publishedIn: new Map(), droppedIn: new Map(), atCache: new Map() };\n+\treturn { name, versions: [], own: new Set(), publishedIn: new Map(), droppedIn: new Map() };\n }\n \n export function addVersion(space: Space, version: Published): void {\n@@ -204,10 +202,30 @@\n \treturn space.versions[space.versions.length - 1]!.sharedBase ?? 0;\n }\n \n+/**\n+ * How many built membership sets the in-memory path keeps, across every space (abso Capacity). Each named draft's set\n+ * is a whole copy of shared's at its base plus its own atoms, so a cache per space held one copy of shared per draft:\n+ * on prod project abso, 106 drafts kept 37 MB of them. One least-recently-used cache holds at most this many; a set\n+ * that fell out is built again when asked for, in milliseconds at that size. Measured on abso's prod export (81,855\n+ * entries): 96.6 MB after load before, 64.6 MB with 16 kept, 62.0 MB with 8; 16 keeps the load as fast as before.\n+ */\n+export const MEMBERSHIP_SETS_KEPT = 16;\n+\n+/** A number per space object, so a space replaced under the same name (tables/build.ts) never gets the old one's sets. */\n+const spaceIds = new WeakMap<Space, number>();\n+let nextSpaceId = 0;\n+function spaceId(space: Space): number {\n+\tlet id = spaceIds.get(space);\n+\tif (id === undefined) spaceIds.set(space, (id = nextSpaceId++));\n+\treturn id;\n+}\n+\n /** Every space, and each one's contents at any of its versions. */\n export class Membership {\n \treadonly spaces: Map<string, Space>;\n \treadonly #storage?: GraphStateStorage;\n+\t/** Built sets by space and version, oldest use first (MEMBERSHIP_SETS_KEPT). */\n+\treadonly #sets = new Map<string, ReadonlySet<AtomId>>();\n \tconstructor(storage?: GraphStateStorage) {\n \t\tthis.#storage = storage;\n \t\tif (!storage) {\n@@ -350,18 +368,26 @@\n \t\t\treturn new StableUnionSet(base, own);\n \t\t}\n \t\tif (space.name === SHARED && version === last(space)) return space.own;\n-\t\tlet set = space.atCache.get(version);\n-\t\tif (!set) {\n-\t\t\tconst s = new Set<AtomId>();\n-\t\t\tif (space.name !== SHARED) for (const id of this.at(this.shared, space.versions[version]!.sharedBase!)) s.add(id);\n-\t\t\tfor (let v = 0; v <= version; v++) {\n-\t\t\t\tfor (const id of space.versions[v]!.atoms) s.add(id);\n-\t\t\t\tfor (const id of space.versions[v]!.dropped ?? []) s.delete(id);\n-\t\t\t}\n-\t\t\tset = s;\n-\t\t\tif (space.atCache.size > 16) space.atCache.clear();\n-\t\t\tspace.atCache.set(version, set);\n+\t\tconst key = `${spaceId(space)}:${version}`;\n+\t\tconst kept = this.#sets.get(key);\n+\t\tif (kept) {\n+\t\t\tthis.#sets.delete(key);\n+\t\t\tthis.#sets.set(key, kept);\n+\t\t\treturn kept;\n \t\t}\n-\t\treturn set;\n+\t\tconst s = new Set<AtomId>();\n+\t\tif (space.name !== SHARED) for (const id of this.at(this.shared, space.versions[version]!.sharedBase!)) s.add(id);\n+\t\tfor (let v = 0; v <= version; v++) {\n+\t\t\tfor (const id of space.versions[v]!.atoms) s.add(id);\n+\t\t\tfor (const id of space.versions[v]!.dropped ?? []) s.delete(id);\n+\t\t}\n+\t\tthis.#sets.set(key, s);\n+\t\tif (this.#sets.size > MEMBERSHIP_SETS_KEPT) this.#sets.delete(this.#sets.keys().next().value!);\n+\t\treturn s;\n \t}\n+\n+\t/** How many built sets the in-memory cache holds now (for tests). */\n+\tget setsKept(): number {\n+\t\treturn this.#sets.size;\n+\t}\n }"},{"path":"worker/project/test/membership-cache.test.ts","added":56,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/membership-cache.test.ts\n@@ -0,0 +1,56 @@\n+// The in-memory membership cache is bounded across every space (abso Capacity): 106 drafts on prod project abso\n+// each kept whole copies of shared's set, 37 MB in all. One least-recently-used cache now holds MEMBERSHIP_SETS_KEPT.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { addVersion, MEMBERSHIP_SETS_KEPT, Membership, newSpace } from \"../spaces.ts\";\n+\n+const SHARED = \"\";\n+\n+/** Shared with `versions` versions, version v adding atom s<v>; then `drafts` drafts, each on shared's version 3. */\n+function membership(versions: number, drafts: number): Membership {\n+\tconst m = new Membership();\n+\tfor (let v = 0; v < versions; v++)\n+\t\taddVersion(m.shared, { version: v, agent: \"a\", message: `v${v}`, time: 0, atoms: [`s${v}`] });\n+\tfor (let d = 0; d < drafts; d++) {\n+\t\tconst space = newSpace(`d${d}`);\n+\t\tm.spaces.set(space.name, space);\n+\t\taddVersion(space, { version: 0, agent: \"a\", message: \"start\", time: 0, atoms: [], sharedBase: 3 });\n+\t\taddVersion(space, { version: 1, agent: \"a\", message: \"work\", time: 0, atoms: [`d${d}-x`], sharedBase: 3 });\n+\t}\n+\treturn m;\n+}\n+\n+test(\"the cache never holds more than MEMBERSHIP_SETS_KEPT sets, however many drafts are read\", () => {\n+\tconst m = membership(10, MEMBERSHIP_SETS_KEPT * 3);\n+\tfor (let d = 0; d < MEMBERSHIP_SETS_KEPT * 3; d++) m.at(m.spaces.get(`d${d}`)!, 1);\n+\tassert.ok(m.setsKept <= MEMBERSHIP_SETS_KEPT, `kept ${m.setsKept}`);\n+});\n+\n+test(\"a set that fell out of the cache is built again the same, and a kept one is the same object\", () => {\n+\tconst m = membership(10, MEMBERSHIP_SETS_KEPT * 2);\n+\tconst first = m.spaces.get(\"d0\")!;\n+\tconst before = [...m.at(first, 1)].sort();\n+\tassert.deepEqual(before, [\"d0-x\", \"s0\", \"s1\", \"s2\", \"s3\"], \"shared at its base, plus its own\");\n+\tfor (let d = 1; d < MEMBERSHIP_SETS_KEPT * 2; d++) m.at(m.spaces.get(`d${d}`)!, 1);\n+\tassert.deepEqual([...m.at(first, 1)].sort(), before, \"rebuilt after eviction, same contents\");\n+\tconst again = m.at(first, 1);\n+\tassert.equal(m.at(first, 1), again, \"while kept, the same set\");\n+\t// Shared's history and its newest version answer as before.\n+\tassert.deepEqual([...m.at(m.shared, 2)].sort(), [\"s0\", \"s1\", \"s2\"]);\n+\tassert.equal(m.at(m.shared, 9), m.shared.own, \"shared's newest version is its live set, never cached\");\n+});\n+\n+test(\"a draft replaced under the same name never gets the old one's set\", () => {\n+\tconst m = membership(10, 1);\n+\tconst old = m.spaces.get(\"d0\")!;\n+\tassert.ok(m.at(old, 1).has(\"d0-x\"));\n+\tconst replaced = newSpace(\"d0\");\n+\tm.spaces.set(\"d0\", replaced);\n+\taddVersion(replaced, { version: 0, agent: \"a\", message: \"start\", time: 0, atoms: [], sharedBase: 5 });\n+\taddVersion(replaced, { version: 1, agent: \"a\", message: \"work\", time: 0, atoms: [\"new\"], sharedBase: 5 });\n+\tconst now = m.at(replaced, 1);\n+\tassert.equal(now.has(\"d0-x\"), false);\n+\tassert.deepEqual([...now].sort(), [\"new\", \"s0\", \"s1\", \"s2\", \"s3\", \"s4\", \"s5\"]);\n+\tassert.equal(SHARED, m.shared.name);\n+});"},{"path":"worker/project/test/news-cap.test.ts","added":47,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/news-cap.test.ts\n@@ -0,0 +1,47 @@\n+// An agent's unheard news is capped (abso Capacity): stopped agents kept every line, 7 MB of prod project abso.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { capNews, droppedNewsLine, NEWS_KEPT, NEWS_TRIM } from \"../news.ts\";\n+\n+const agentWith = (n: number) => ({\n+\tnews: Array.from({ length: n }, (_, i) => `news ${i}`),\n+\tnewsAt: Array.from({ length: n }, (_, i) => i),\n+});\n+\n+test(\"news up to NEWS_KEPT plus NEWS_TRIM lines is kept as it is\", () => {\n+\tconst agent = agentWith(NEWS_KEPT + NEWS_TRIM);\n+\tcapNews(agent);\n+\tassert.equal(agent.news.length, NEWS_KEPT + NEWS_TRIM);\n+\tassert.equal(agent.news[0], \"news 0\");\n+});\n+\n+test(\"past that, the oldest go: the newest NEWS_KEPT stay, behind one line counting the dropped, times in step\", () => {\n+\tconst n = NEWS_KEPT + NEWS_TRIM + 1;\n+\tconst agent = agentWith(n);\n+\tcapNews(agent);\n+\tassert.equal(agent.news.length, NEWS_KEPT + 1);\n+\tassert.equal(agent.news[0], droppedNewsLine(n - NEWS_KEPT));\n+\tassert.equal(agent.news[1], `news ${n - NEWS_KEPT}`);\n+\tassert.equal(agent.news.at(-1), `news ${n - 1}`);\n+\tassert.equal(agent.newsAt.length, agent.news.length);\n+\tassert.equal(agent.newsAt[1], n - NEWS_KEPT);\n+});\n+\n+test(\"the dropped count adds up across trims\", () => {\n+\tconst agent = agentWith(NEWS_KEPT + NEWS_TRIM + 1);\n+\tcapNews(agent);\n+\tconst first = NEWS_TRIM + 1;\n+\tfor (let i = 0; i < NEWS_TRIM + 1; i++) {\n+\t\tagent.news.push(`more ${i}`);\n+\t\tagent.newsAt.push(1000 + i);\n+\t}\n+\tcapNews(agent);\n+\tassert.equal(agent.news[0], droppedNewsLine(first + NEWS_TRIM + 1));\n+\tassert.equal(agent.news.length, NEWS_KEPT + 1);\n+\tassert.equal(agent.news.at(-1), `more ${NEWS_TRIM}`);\n+\tassert.equal(\n+\t\tdroppedNewsLine(1),\n+\t\t`1 older news item went unheard and was dropped: an agent keeps its newest ${NEWS_KEPT}.`,\n+\t);\n+});"},{"path":"worker/project/test/stored-membership.test.ts","added":1,"removed":1,"diff":"--- a/worker/project/test/stored-membership.test.ts\n+++ b/worker/project/test/stored-membership.test.ts\n@@ -147,6 +147,6 @@\n \tassert.equal(old.size, 41);\n \tassert.equal(old.has(\"a0\"), true);\n \tassert.equal(old.has(\"a79\"), false);\n-\tassert.equal(shared.atCache.size, 0, \"storage-backed shared history never fills the in-memory set cache\");\n+\tassert.equal(reopened.setsKept, 0, \"storage-backed shared history never fills the in-memory set cache\");\n \tstorage.db.close();\n });"}],"ci":null}