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
blame on this site's /mcp
CLI
abso blame worker/project/spaces.ts --version 307 --json
JSON
/christopher/abso-core/blame/worker/project/spaces.ts?version=307&format=json
616 linescapacity 46% · First import 27% · codex-capacity-chair 27%Last change capacity in version 307,

616 lines from 11 changes in 10 versions.

init0Start the project1// Version membership (#46, disk-first 1): which atoms are in which space at which version. Shared ('') and
2// named drafts, their versions, what each version added and dropped, and the shared version a draft builds
3// on. Project and the derived tables (tables/, issue 47) both keep it from the same entries, so the rules
4// live here once.
5
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare6import { type AtomId, seqOf } from "../../src/engine/index.ts";
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare7import {
8 type GraphStateStorage,
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare9 markClosed,
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare10 StableSet,
11 StableUnionSet,
12 StoredMap,
13 StoredSet,
14 storedArray,
15} from "../../src/engine/state-source.ts";
init0Start the project16import type { Entry } from "./project.ts";
18export const SHARED = "";
20export interface Published {
21 readonly version: number;
22 readonly agent: string;
23 /** The message now (an amend can correct it). */
24 message: string;
25 /** The message it was published with, once amended. */
26 originalMessage?: string;
27 readonly time: number;
28 /** Everything this version added to its space (changes and tie). */
29 readonly atoms: readonly AtomId[];
30 /** For a named draft: the version of shared this version builds on. */
31 readonly sharedBase?: number;
32 /** For a drop: the atoms it took out, and the versions they came from. */
33 readonly dropped?: readonly AtomId[];
34 readonly droppedVersions?: readonly number[];
37export /** Shared ('') or a named draft. */
38interface Space {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare39 /** Storage-backed spaces append the historical membership index here. */
40 indexVersion?: (version: Published) => void;
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare41 /** Version of the selected membership event, independent of later publishes. */
42 membershipVersion?: (atom: AtomId, version: number) => number | undefined;
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare43 /**
44 * membershipVersion reading the membership pages first, each page once (abso - Performance, 714): for a walk over
45 * many atoms, such as SharedAdditions. Most atoms have one event, and the page says its version.
46 */
47 membershipVersions?: () => (atom: AtomId, version: number) => number | undefined;
init0Start the project48 readonly name: string;
49 readonly versions: Published[];
50 /** Every atom published into this space (for shared, everything in it). */
51 readonly own: Set<AtomId>;
52 readonly publishedIn: Map<AtomId, number>;
53 /** Atoms a drop took out, and the version of the drop. */
54 readonly droppedIn: Map<AtomId, number>;
55 /** For a named draft, the log position of the entry that made it: the change its work belongs to (#44). */
56 startedAt?: number;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare59export function newSpace(name: string, storage?: GraphStateStorage): Space {
60 if (storage) {
61 const prefix = `membership:${JSON.stringify(name)}`;
62 return {
63 name,
64 indexVersion: (version) => indexMembership(storage, prefix, version),
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare65 membershipVersion: (atom, version) => membershipEvent(storage, prefix, atom, version)?.version,
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare66 membershipVersions: () => {
67 const pages = new PageReader(storage, prefix);
68 return (atom, version) => {
69 const known = pages.versionAt(atom, version);
70 return known === null ? membershipEvent(storage, prefix, atom, version)?.version : known;
71 };
72 },
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare73 versions: storedArray(storage, `${prefix}:versions`),
74 own: new StoredSet(storage, `${prefix}:own`),
75 publishedIn: new StoredMap(storage, `${prefix}:published`),
76 droppedIn: new StoredMap(storage, `${prefix}:dropped`),
77 };
78 }
capacity200Project 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.Compare79 return { name, versions: [], own: new Set(), publishedIn: new Map(), droppedIn: new Map() };
init0Start the project80}
82export function addVersion(space: Space, version: Published): void {
83 space.versions.push(version);
84 for (const id of version.atoms) {
85 space.own.add(id);
86 space.publishedIn.set(id, version.version);
87 }
88 for (const id of version.dropped ?? []) {
89 space.own.delete(id);
90 space.droppedIn.set(id, version.version);
91 }
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare92 space.indexVersion?.(version);
init0Start the project93}
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare95interface MembershipEvent {
96 version: number;
97 present: boolean;
98 slot: number;
99 atom: AtomId;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare102/**
103 * Membership by atom number (abso Capacity): for each 256 atoms one page of numbers, one per atom. NONE when the atom
104 * has no event, the version of its only event when that adds it, or MIXED when it has more (a drop, a return), which
105 * reads its events as before. "Is a in the space at v" is then one page for most atoms, against two or three rows.
106 * Kept from a space's first event on; a space indexed before has none, and reads its events.
107 */
108const PAGE = 256;
109const NONE = -1;
110const MIXED = -2;
112function startPages(storage: GraphStateStorage, prefix: string): void {
113 if (storage.read(`${prefix}:pages:meta`, "kept") === undefined) storage.write(`${prefix}:pages:meta`, "kept", 1);
116function notePage(storage: GraphStateStorage, prefix: string, atom: AtomId, code: number): void {
117 if (storage.read(`${prefix}:pages:meta`, "kept") !== 1) return;
118 const seq = seqOf(atom);
119 if (seq < 0) return;
120 const key = String(Math.floor(seq / PAGE));
121 const page = (storage.read(`${prefix}:pages`, key) as number[] | undefined) ?? [];
122 while (page.length <= seq % PAGE) page.push(NONE);
123 page[seq % PAGE] = code;
124 storage.write(`${prefix}:pages`, key, page);
127/** Pages read once per set: a later version only adds events after this set's version, which can't change its answers. */
128class PageReader {
129 readonly #storage: GraphStateStorage;
130 readonly #prefix: string;
131 #kept: boolean | undefined;
132 readonly #pages = new Map<number, readonly number[]>();
133 constructor(storage: GraphStateStorage, prefix: string) {
134 this.#storage = storage;
135 this.#prefix = prefix;
136 }
137 /** Whether atom is present at version, or undefined when its events must be read. */
138 presentAt(atom: AtomId, version: number): boolean | undefined {
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare139 const code = this.#code(atom);
140 if (code === undefined || code === MIXED) return undefined;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare141 if (code === NONE) return false;
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare142 return version >= code;
143 }
144 /** membershipVersion from the page: the version of its only event, or undefined; null when its events must be read. */
145 versionAt(atom: AtomId, version: number): number | undefined | null {
146 const code = this.#code(atom);
147 if (code === undefined || code === MIXED) return null;
148 if (code === NONE) return undefined;
149 return version >= code ? code : undefined;
150 }
151 #code(atom: AtomId): number | undefined {
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare152 this.#kept ??= this.#storage.read(`${this.#prefix}:pages:meta`, "kept") === 1;
153 if (!this.#kept) return undefined;
154 const seq = seqOf(atom);
155 if (seq < 0) return undefined;
156 const index = Math.floor(seq / PAGE);
157 let page = this.#pages.get(index);
158 if (!page) {
159 page = (this.#storage.read(`${this.#prefix}:pages`, String(index)) as number[] | undefined) ?? [];
160 if (this.#pages.size >= 64) this.#pages.delete(this.#pages.keys().next().value!);
161 this.#pages.set(index, page);
162 }
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare163 return page[seq % PAGE] ?? NONE;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare164 }
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare167function membershipEvent(
168 storage: GraphStateStorage,
169 prefix: string,
170 atom: AtomId,
171 version: number,
172): MembershipEvent | undefined {
173 const events = storedArray<MembershipEvent>(storage, `${prefix}:events:${atom}`);
174 let lo = 0;
175 let hi = events.length;
176 while (lo < hi) {
177 const mid = lo + Math.floor((hi - lo) / 2);
178 if (events[mid]!.version <= version) lo = mid + 1;
179 else hi = mid;
180 }
181 return lo === 0 ? undefined : events[lo - 1];
184function indexMembership(storage: GraphStateStorage, prefix: string, version: Published): void {
185 const order = storedArray<MembershipEvent>(storage, `${prefix}:events`);
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare186 if (order.length === 0) startPages(storage, prefix);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare187 for (const [ids, present] of [
188 [version.atoms, true],
189 [version.dropped ?? [], false],
190 ] as const) {
191 for (const atom of ids) {
192 const previous = membershipEvent(storage, prefix, atom, version.version);
193 if ((previous?.present ?? false) === present) continue;
194 const event = { atom, version: version.version, present, slot: order.length };
195 storedArray<MembershipEvent>(storage, `${prefix}:events:${atom}`).push(event);
196 order.push(event);
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare197 notePage(storage, prefix, atom, previous === undefined && present ? version.version : MIXED);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare198 }
199 }
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare202/**
203 * Shared's closure on disk (abso Capacity): the atoms a version's views hold beyond what it published, because
204 * something in it depends on them (a discarded atom a later publish still needs, abso issue 80). Kept per version as
205 * events like membership's, so "is a in shared's closure at v" is two lookups, and no read proves closure again.
206 * Indexed from the first version only: a writer adopted before this has none and is proved as before.
207 */
208const CLOSURE = 'closure:""';
209const OWN = `membership:${JSON.stringify(SHARED)}`;
211function extraEvent(storage: GraphStateStorage, atom: AtomId, version: number): MembershipEvent | undefined {
212 return membershipEvent(storage, CLOSURE, atom, version);
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare215/** Whether shared's closure changed at this version: its newest closure event is from it. */
216export function closureChangedAt(storage: GraphStateStorage, version: number): boolean {
217 const order = storedArray<MembershipEvent>(storage, `${CLOSURE}:events`);
218 const length = order.length;
219 return length > 0 && order[length - 1]!.version === version;
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare222/** The newest shared version whose closure is indexed, or undefined when this writer has none. */
223export function closureIndexed(storage: GraphStateStorage): number | undefined {
224 return storage.read(`${CLOSURE}:meta`, "indexed") as number | undefined;
227export interface ClosureGraph {
228 atom(id: AtomId): { readonly deps: readonly AtomId[]; readonly seq: number };
229 eachDependentOf(id: AtomId): Iterable<AtomId>;
232/** Index shared's closure for every version applied since the last call. */
233export function indexClosure(storage: GraphStateStorage, shared: Space, graph: ClosureGraph): void {
234 const indexed = closureIndexed(storage);
235 const newest = last(shared);
236 if (indexed === undefined && newest > 0) return;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare237 if (indexed === undefined) startPages(storage, CLOSURE);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare238 for (let v = (indexed ?? -1) + 1; v <= newest; v++) indexClosureVersion(storage, shared.versions[v]!, graph);
239 if (newest >= 0) storage.write(`${CLOSURE}:meta`, "indexed", newest);
242function indexClosureVersion(storage: GraphStateStorage, version: Published, graph: ClosureGraph): void {
243 const v = version.version;
244 const own = (atom: AtomId) => membershipEvent(storage, OWN, atom, v)?.present ?? false;
245 const extra = (atom: AtomId) => extraEvent(storage, atom, v)?.present ?? false;
246 const present = (atom: AtomId) => own(atom) || extra(atom);
247 const order = storedArray<MembershipEvent>(storage, `${CLOSURE}:events`);
248 const set = (atom: AtomId, on: boolean) => {
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare249 const previous = extraEvent(storage, atom, v);
250 if ((previous?.present ?? false) === on) return;
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare251 const event = { atom, version: v, present: on, slot: order.length };
252 storedArray<MembershipEvent>(storage, `${CLOSURE}:events:${atom}`).push(event);
253 order.push(event);
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare254 notePage(storage, CLOSURE, atom, previous === undefined && on ? v : MIXED);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare255 };
256 for (const added of version.atoms) {
257 const stack = [added];
258 while (stack.length)
259 for (const dep of graph.atom(stack.pop()!).deps)
260 if (!present(dep)) {
261 set(dep, true);
262 stack.push(dep);
263 }
264 }
265 // A dropped atom stays while something in the set depends on it, and so on down its deps: newest first, so an atom
266 // is decided after everything that could depend on it.
267 const candidates = new Map<AtomId, number>();
268 for (const dropped of version.dropped ?? []) if (!own(dropped)) candidates.set(dropped, graph.atom(dropped).seq);
269 while (candidates.size) {
270 let atom: AtomId | undefined;
271 let seq = -1;
272 for (const [a, s] of candidates)
273 if (s > seq) {
274 atom = a;
275 seq = s;
276 }
277 candidates.delete(atom!);
278 if (own(atom!)) continue;
279 let needed = false;
280 for (const dependent of graph.eachDependentOf(atom!))
281 if (present(dependent)) {
282 needed = true;
283 break;
284 }
285 set(atom!, needed);
286 if (!needed)
287 for (const dep of graph.atom(atom!).deps)
288 if (!own(dep) && extra(dep) && !candidates.has(dep)) candidates.set(dep, graph.atom(dep).seq);
289 }
292/** Shared at a version with its closure: what it published, and what that depends on. Marked closed. */
293class ClosedVersionSet extends StableSet<AtomId> {
294 readonly retainedBytes = 96;
295 readonly #storage: GraphStateStorage;
296 readonly #version: number;
297 readonly #own: StoredVersionSet;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare298 readonly #pages: PageReader;
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare299 constructor(storage: GraphStateStorage, version: number) {
300 super();
301 this.#storage = storage;
302 this.#version = version;
303 this.#own = new StoredVersionSet(storage, OWN, version);
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare304 this.#pages = new PageReader(storage, CLOSURE);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare305 }
306 has(atom: AtomId): boolean {
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare307 if (this.#own.has(atom)) return true;
308 return (
309 this.#pages.presentAt(atom, this.#version) ?? extraEvent(this.#storage, atom, this.#version)?.present ?? false
310 );
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare311 }
312 *values(): SetIterator<AtomId> {
313 yield* this.#own;
314 for (const event of storedArray<MembershipEvent>(this.#storage, `${CLOSURE}:events`)) {
315 if (event.version > this.#version) break;
316 if (!event.present || this.#own.has(event.atom)) continue;
317 if (extraEvent(this.#storage, event.atom, this.#version)?.slot === event.slot) yield event.atom;
318 }
319 }
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare322/** Immutable historical shared membership; iteration reads one event at a time. */
323class StoredVersionSet extends StableSet<AtomId> {
324 readonly retainedBytes = 64;
325 readonly #storage: GraphStateStorage;
326 readonly #prefix: string;
327 readonly #version: number;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare328 readonly #pages: PageReader;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare329 constructor(storage: GraphStateStorage, prefix: string, version: number) {
330 super();
331 this.#storage = storage;
332 this.#prefix = prefix;
333 this.#version = version;
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare334 this.#pages = new PageReader(storage, prefix);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare335 }
336 get [Symbol.toStringTag](): string {
337 return "Set";
338 }
339 has(atom: AtomId): boolean {
capacity226Membership by atom number, a page per 256 atoms (disk-first 2; abso Capacity). Asking whether an atom is in shared (or shared's closure) at a version read the atom's event list: its length, then the event, and closure's length after that. where asks it for every line of every file a draft touches, for every agent with a draft. On typescript-rs that came to about 100,000 of where's 180,000 row reads, and to most of an agent's diff. - Each space now also keeps, per 256 atoms, a page of numbers, one per atom: none, the version of its only event when that event adds it, or mixed when it has more (dropped, or back again). A set reads a page once and answers from it; a mixed atom reads its events as before. Shared's closure keeps the same pages. - Kept from a space's first event on, so only fresh adoptions have them. A space indexed before reads its events as before. On typescript-rs adopted fresh, with one opened writer, cold: - where: 180,000 reads to 59,000; 36 s to 4.9 s - diff for cloud-ts-06: 59,000 reads to 4,500; 592 ms - show: about 5,000 reads to about 3,000; about 300 ms 26 of 27 answers match replay; collisions still runs past 60 s. New test membership-pages: every atom at every version, through drops, answers as the in-memory project. It fails when the page comparison is off by one. Named tests: membership-pages, stored-membership, stored-closure, membership-cache, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, drop, named-drafts (42 of 42); tsc and biome clean.Compare340 return (
341 this.#pages.presentAt(atom, this.#version) ??
342 membershipEvent(this.#storage, this.#prefix, atom, this.#version)?.present ??
343 false
344 );
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare345 }
346 get size(): number {
347 let count = 0;
348 for (const _ of this) count++;
349 return count;
350 }
351 *values(): SetIterator<AtomId> {
352 const events = storedArray<MembershipEvent>(this.#storage, `${this.#prefix}:events`);
353 for (const event of events) {
354 if (event.version > this.#version) break;
355 if (!event.present) continue;
356 const selected = membershipEvent(this.#storage, this.#prefix, event.atom, this.#version);
357 if (selected?.slot === event.slot) yield event.atom;
358 }
359 }
360 keys(): SetIterator<AtomId> {
361 return this.values();
362 }
363 *entries(): SetIterator<[AtomId, AtomId]> {
364 for (const atom of this) yield [atom, atom];
365 }
366 [Symbol.iterator](): SetIterator<AtomId> {
367 return this.values();
368 }
369 forEach(callback: (value: AtomId, key: AtomId, set: ReadonlySet<AtomId>) => void, thisArg?: unknown): void {
370 for (const atom of this) callback.call(thisArg, atom, atom, this);
371 }
init0Start the project374export function last(space: Space): number {
375 return space.versions.length - 1;
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare376}
378/** Shared-version difference enumerates only versions newer than the base. */
379export class SharedAdditions extends StableSet<AtomId> {
380 readonly retainedBytes = 96;
381 readonly endVersion: number;
382 readonly space: Space;
383 readonly baseVersion: number;
384 readonly base: ReadonlySet<AtomId>;
385 readonly current: ReadonlySet<AtomId>;
capacity295Owed news: a publish can leave its definition news for other agents for after its write (abso Capacity; prod abso's publishes reset its object, 2026-10-15) - With Project.owesDefinitionNews set, newsForOthers still tells same-lines and move news in the publish, but leaves the definition rule over other agents' drafts out. It records an OwedDefinitionNews {version, space, publisher, names} instead; takeOwedDefinitionNews hands it to the host once. - definitionNewsOwed(owed) works that news out later, as it would have been told at the publish: the rule runs against the space at that version, with the work published up to that version only (#newerFor and SharedAdditions take an end version). It reads only. An agent that has synced past the version since is left out. - deliverOwedNews(found) tells it through queueNews, so a key an agent was already told adds nothing. - Default off: the replay engine and every existing caller behave as before. abso's disk route turns it on, keeps the marker in the publish's own transaction, and delivers from the alarm. - Why: on abso's stored tables, the definition rule over ~40 drafts was 5.5 of a 1437-shaped publish's 7.3 s in the lab, about 45 s of one storage transaction in prod. That reset abso's object at 11:08 PM CT. With the rule owed, the publish's write is 18,622 statements instead of 105,252. - On prod since 11:35 PM CT as a patch (abso 2341e805), with Agent VCS's yes. This brings core level with it; abso's pin follows. - Keeps Observability's publishNews log lines (abso 702), and adds owed: 1 or 0 to the end line. Checks: tsc clean. node --test in worker/project/test, 41 of 41 pass: changed-definition, collision-streaming, collisions-kept-views, news-cap, news-lazy, news-lines, news-times, news-written, owed-definition-news (new: the same news, against the publish's version even after a later publish removes the name, synced agents left out, the replay engine unchanged), project-writer-storage, writer-adoption.Compare386 /** `endVersion`: the version `current` is (the newest by default; an earlier one for owed news, news.ts). */
387 constructor(
388 space: Space,
389 baseVersion: number,
390 base: ReadonlySet<AtomId>,
391 current: ReadonlySet<AtomId>,
392 endVersion = last(space),
393 ) {
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare394 super();
395 if (space.name !== SHARED || !space.membershipVersion) throw Error("shared additions require indexed shared space");
capacity295Owed news: a publish can leave its definition news for other agents for after its write (abso Capacity; prod abso's publishes reset its object, 2026-10-15) - With Project.owesDefinitionNews set, newsForOthers still tells same-lines and move news in the publish, but leaves the definition rule over other agents' drafts out. It records an OwedDefinitionNews {version, space, publisher, names} instead; takeOwedDefinitionNews hands it to the host once. - definitionNewsOwed(owed) works that news out later, as it would have been told at the publish: the rule runs against the space at that version, with the work published up to that version only (#newerFor and SharedAdditions take an end version). It reads only. An agent that has synced past the version since is left out. - deliverOwedNews(found) tells it through queueNews, so a key an agent was already told adds nothing. - Default off: the replay engine and every existing caller behave as before. abso's disk route turns it on, keeps the marker in the publish's own transaction, and delivers from the alarm. - Why: on abso's stored tables, the definition rule over ~40 drafts was 5.5 of a 1437-shaped publish's 7.3 s in the lab, about 45 s of one storage transaction in prod. That reset abso's object at 11:08 PM CT. With the rule owed, the publish's write is 18,622 statements instead of 105,252. - On prod since 11:35 PM CT as a patch (abso 2341e805), with Agent VCS's yes. This brings core level with it; abso's pin follows. - Keeps Observability's publishNews log lines (abso 702), and adds owed: 1 or 0 to the end line. Checks: tsc clean. node --test in worker/project/test, 41 of 41 pass: changed-definition, collision-streaming, collisions-kept-views, news-cap, news-lazy, news-lines, news-times, news-written, owed-definition-news (new: the same news, against the publish's version even after a later publish removes the name, synced agents left out, the replay engine unchanged), project-writer-storage, writer-adoption.Compare396 this.endVersion = endVersion;
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare397 this.space = space;
398 this.baseVersion = baseVersion;
399 this.base = base;
400 this.current = current;
401 }
402 has(id: AtomId): boolean {
403 return this.current.has(id) && !this.base.has(id);
404 }
405 *values(): SetIterator<AtomId> {
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare406 const versionOf = this.space.membershipVersions?.() ?? this.space.membershipVersion!;
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare407 for (let version = this.baseVersion + 1; version <= this.endVersion; version++) {
408 for (const id of this.space.versions[version]!.atoms) {
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it) - After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object. - Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it. - Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different. Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare409 if (versionOf(id, this.endVersion) === version && this.has(id)) yield id;
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare410 }
411 }
412 }
init0Start the project413}
415export function sharedBaseOf(space: Space): number {
416 return space.versions[space.versions.length - 1]!.sharedBase ?? 0;
capacity200Project 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.Compare419/**
420 * How many built membership sets the in-memory path keeps, across every space (abso Capacity). Each named draft's set
421 * 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:
422 * on prod project abso, 106 drafts kept 37 MB of them. One least-recently-used cache holds at most this many; a set
423 * that fell out is built again when asked for, in milliseconds at that size. Measured on abso's prod export (81,855
424 * 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.
425 */
426export const MEMBERSHIP_SETS_KEPT = 16;
428/** A number per space object, so a space replaced under the same name (tables/build.ts) never gets the old one's sets. */
429const spaceIds = new WeakMap<Space, number>();
430let nextSpaceId = 0;
431function spaceId(space: Space): number {
432 let id = spaceIds.get(space);
433 if (id === undefined) spaceIds.set(space, (id = nextSpaceId++));
434 return id;
init0Start the project437/** Every space, and each one's contents at any of its versions. */
438export class Membership {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare439 readonly spaces: Map<string, Space>;
440 readonly #storage?: GraphStateStorage;
capacity200Project 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.Compare441 /** Built sets by space and version, oldest use first (MEMBERSHIP_SETS_KEPT). */
442 readonly #sets = new Map<string, ReadonlySet<AtomId>>();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare443 constructor(storage?: GraphStateStorage) {
444 this.#storage = storage;
445 if (!storage) {
446 this.spaces = new Map([[SHARED, newSpace(SHARED)]]);
447 return;
448 }
capacity252Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). - Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. - An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. - View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. - PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. - Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB. Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).Compare449 // The same space for the same stored row (abso Capacity): a space reads everything else through to storage, and
450 // each read decoding a new one emptied every cache kept by space (a path index, a version's files, its file list)
451 // on every call, so an agent's tree read all 1,225 of abso's kept version rows each time.
452 const decoded = new Map<string, Space>();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare453 this.spaces = new StoredMap(storage, "membership:spaces", {
454 encode: (space) => ({ name: space.name, startedAt: space.startedAt }),
455 decode: (value) => {
capacity252Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). - Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. - An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. - View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. - PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. - Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB. Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).Compare456 const raw = JSON.stringify(value);
457 let space = decoded.get(raw);
458 if (!space) {
459 const meta = value as { name: string; startedAt?: number };
460 space = {
461 ...newSpace(meta.name, storage),
462 ...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }),
463 };
464 decoded.set(raw, space);
465 }
466 return space;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare467 },
468 });
469 if (!this.spaces.has(SHARED)) storage.transaction(() => this.spaces.set(SHARED, newSpace(SHARED, storage)));
470 }
init0Start the project471
472 get shared(): Space {
473 return this.spaces.get(SHARED)!;
474 }
476 /** What an entry (at log position `at`) does to membership; other kinds change none. */
477 apply(entry: Entry, at: number): void {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare478 if (this.#storage) this.#storage.transaction(() => this.#apply(entry, at));
479 else this.#apply(entry, at);
480 }
482 #apply(entry: Entry, at: number): void {
init0Start the project483 switch (entry.type) {
484 case "init":
485 addVersion(this.shared, {
486 version: 0,
487 agent: "init",
488 message: entry.atom.message,
489 time: entry.time,
490 atoms: [entry.atom.id],
491 });
492 break;
493 case "publish": {
494 const space = this.spaces.get(entry.space ?? SHARED)!;
495 const atoms = [...entry.changes, entry.tie.id];
496 addVersion(space, {
497 version: entry.version,
498 agent: entry.agent,
499 message: entry.message,
500 time: entry.time,
501 atoms,
502 ...(space.name !== SHARED ? { sharedBase: sharedBaseOf(space) } : {}),
503 });
504 break;
505 }
506 case "drop":
507 addVersion(this.shared, {
508 version: entry.version,
509 agent: entry.agent,
510 message: entry.message,
511 time: entry.time,
512 atoms: [],
513 dropped: entry.atoms,
514 droppedVersions: entry.versions,
515 });
516 break;
517 case "amend": {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare518 const space = this.spaces.get(entry.space ?? SHARED)!;
519 const p = space.versions[entry.version]!;
init0Start the project520 p.originalMessage ??= p.message;
521 p.message = entry.message;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare522 space.versions[entry.version] = p;
init0Start the project523 break;
524 }
525 case "space": {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare526 const space = newSpace(entry.name, this.#storage);
init0Start the project527 space.startedAt = at;
528 this.spaces.set(entry.name, space);
529 addVersion(space, {
530 version: 0,
531 agent: entry.agent,
532 message: `Start draft ${entry.name}`,
533 time: entry.time,
534 atoms: [],
535 sharedBase: entry.sharedBase,
536 });
537 break;
538 }
539 case "space-sync": {
540 const space = this.spaces.get(entry.space)!;
541 addVersion(space, {
542 version: entry.version,
543 agent: entry.agent,
544 message: `Move draft ${entry.space} onto shared version ${entry.sharedBase}`,
545 time: entry.time,
546 atoms: [],
547 sharedBase: entry.sharedBase,
548 });
549 break;
550 }
551 case "land": {
552 const atoms = [...entry.changes, entry.tie.id];
553 addVersion(this.shared, {
554 version: entry.version,
555 agent: entry.agent,
556 message: entry.message,
557 time: entry.time,
558 atoms,
559 });
560 if (entry.rebase) {
561 const space = this.spaces.get(entry.space)!;
562 addVersion(space, {
563 version: last(space) + 1,
564 agent: entry.agent,
565 message: `Landed in shared version ${entry.version}`,
566 time: entry.time,
567 atoms: [],
568 sharedBase: entry.version,
569 });
570 }
571 break;
572 }
573 }
574 }
576 /**
577 * A space's contents at one of its versions. For shared's latest version this is `shared.own` itself, not a
578 * copy (it is read on every publish and sync, and copying it would cost a set per call): it changes when the
579 * next version is applied. A caller that keeps it across an apply copies it first.
580 */
581 at(space: Space, version: number): ReadonlySet<AtomId> {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare582 if (this.#storage) {
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare583 const storage = this.#storage;
584 const closed = (v: number) => (closureIndexed(storage) ?? -1) >= v;
585 const sharedAt = (v: number): StableSet<AtomId> =>
586 closed(v) ? markClosed(new ClosedVersionSet(storage, v)) : new StoredVersionSet(storage, OWN, v);
587 if (space.name === SHARED) return sharedAt(version);
588 const own = new StoredVersionSet(storage, `membership:${JSON.stringify(space.name)}`, version);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare589 // Named drafts add local atoms over an immutable shared base; drop
590 // entries target shared, never a named draft's local membership.
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare591 return new StableUnionSet(sharedAt(space.versions[version]!.sharedBase!), own);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare592 }
init0Start the project593 if (space.name === SHARED && version === last(space)) return space.own;
capacity200Project 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.Compare594 const key = `${spaceId(space)}:${version}`;
595 const kept = this.#sets.get(key);
596 if (kept) {
597 this.#sets.delete(key);
598 this.#sets.set(key, kept);
599 return kept;
600 }
601 const s = new Set<AtomId>();
602 if (space.name !== SHARED) for (const id of this.at(this.shared, space.versions[version]!.sharedBase!)) s.add(id);
603 for (let v = 0; v <= version; v++) {
604 for (const id of space.versions[v]!.atoms) s.add(id);
605 for (const id of space.versions[v]!.dropped ?? []) s.delete(id);
init0Start the project606 }
capacity200Project 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.Compare607 this.#sets.set(key, s);
608 if (this.#sets.size > MEMBERSHIP_SETS_KEPT) this.#sets.delete(this.#sets.keys().next().value!);
609 return s;
610 }
612 /** How many built sets the in-memory cache holds now (for tests). */
613 get setsKept(): number {
614 return this.#sets.size;
init0Start the project615 }