{"version":205,"agent":"capacity","message":"Disk-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.","time":1792030075730,"timeIso":"2026-10-15T02:07:55.730Z","changes":11,"change":3464,"files":["src/engine/graph.ts","src/engine/state-source.ts","src/engine/test/visible-neighbours.test.ts","src/engine/view.ts","worker/project/project.ts","worker/project/spaces.ts","worker/project/test/stored-closure.test.ts","worker/project/test/stored-membership.test.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":5,"removed":2,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -913,8 +913,11 @@\n \t\t\tthis.#lineParent.at(code + 1) === code\n \t\t)\n \t\t\tyield code + 1;\n-\t\tif (this.#runStartPages) yield* this.#runStartPages.values(String(code));\n-\t\telse yield* listOf(this.#runStarts.get(code));\n+\t\tif (this.#runStartPages) {\n+\t\t\t// The paged child counts say a line has no other children without a row read per line (abso Capacity).\n+\t\t\tif (code >= 0 && this.#childCounts && this.#childCounts.at(code, this.#lineTotal) === 0) return;\n+\t\t\tyield* this.#runStartPages.values(String(code));\n+\t\t} else yield* listOf(this.#runStarts.get(code));\n \t}\n \n \tget hasOrderedChildren(): boolean {"},{"path":"src/engine/state-source.ts","added":19,"removed":0,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -127,6 +127,19 @@\n \t}\n }\n \n+/**\n+ * Sets known to be closed under dependencies (abso Capacity): every atom's deps are in the set. A view or a project\n+ * given one skips proving it again, which read every atom and every dependency in the history.\n+ */\n+const closedSets = new WeakSet<object>();\n+export function markClosed<S extends ReadonlySet<unknown>>(set: S): S {\n+\tclosedSets.add(set);\n+\treturn set;\n+}\n+export function isClosedSet(set: unknown): boolean {\n+\treturn typeof set === \"object\" && set !== null && closedSets.has(set);\n+}\n+\n /** Immutable membership whose implementation does not retain its enumerated keys. */\n export abstract class StableSet<T> implements ReadonlySet<T> {\n \tabstract has(value: T): boolean;\n@@ -167,6 +180,12 @@\n \tget retainedBytes(): number {\n \t\treturn 32 + this.#left.retainedBytes + this.#right.retainedBytes;\n \t}\n+\tget left(): StableSet<T> {\n+\t\treturn this.#left;\n+\t}\n+\tget right(): StableSet<T> {\n+\t\treturn this.#right;\n+\t}\n \thas(value: T): boolean {\n \t\treturn this.#left.has(value) || this.#right.has(value);\n \t}"},{"path":"src/engine/test/visible-neighbours.test.ts","added":2,"removed":1,"diff":"--- a/src/engine/test/visible-neighbours.test.ts\n+++ b/src/engine/test/visible-neighbours.test.ts\n@@ -45,7 +45,8 @@\n \t\t\t\t\t);\n \t\t\t\t}\n \t\t\t}\n-\t\t\tassert.equal(actual.weight(), weight, \"neighbour lookup retains no file/history projection\");\n+\t\t\t// It may keep the moves it resolved, once per view and bounded (abso Capacity); never a file or its history.\n+\t\t\tassert.ok(actual.weight() - weight <= 4096, \"neighbour lookup retains no file/history projection\");\n \t\t\tassert.equal(source.db.prepare(\"SELECT count(*) AS n FROM state\").get()!.n, rows);\n \t\t}\n \t} finally {"},{"path":"src/engine/view.ts","added":46,"removed":10,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -12,7 +12,7 @@\n import type { Graph, RelocationInfo } from \"./graph.ts\";\n import { isStartNode } from \"./keys.ts\";\n import { resolveScratchMoves, scratchLayoutNodes } from \"./relocation-scratch.ts\";\n-import { StableSet } from \"./state-source.ts\";\n+import { isClosedSet, StableSet } from \"./state-source.ts\";\n import { joinLines } from \"./text.ts\";\n import { type AtomId, type AtomSet, EngineError, type LineId, type NodeId } from \"./types.ts\";\n \n@@ -91,6 +91,13 @@\n const SET_ENTRY_BYTES = 32;\n const REFERENCE_BYTES = 8;\n const FILE_LOCATION_MEMO_ENTRIES = 256;\n+/**\n+ * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on\n+ * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.\n+ */\n+export const MOVED_LINES_KEPT = 20_000;\n+class TooManyMoves extends Error {}\n+const NO_LINES: readonly number[] = Object.freeze([]);\n \n /**\n  * The projection of a closed set. Construct once, then ask for files, lines\n@@ -118,6 +125,10 @@\n \t#relocs: Map<LineId, RelocationInfo> | undefined;\n \t/** The same, by n, with the new parent's code. */\n \t#relocsN: Map<number, { readonly r: RelocationInfo; readonly parent: number }> | undefined;\n+\t/** The moved lines under each node, by its code, made from the relocations on first use. */\n+\t#movedInto: Map<number, number[]> | undefined;\n+\t/** Whether this view's moves are too many to keep, so they're resolved on disk per layout; undefined until asked. */\n+\t#movesOnDisk: boolean | undefined;\n \t/** Bounded memo: ancestry can span the entire history even for one visible line. */\n \t#fileOf = new Map<number, string>();\n \t/** The latest records asked for: one file's lines, one file's sequence, one file's text. */\n@@ -131,7 +142,8 @@\n \t\t\tthis.#stable = set;\n \t\t\tthis.#set = set;\n \t\t\tthis.#in = new Uint8Array(0);\n-\t\t\tfor (const id of set) {\n+\t\t\t// A set kept closed when it was written needs no proof here (abso Capacity).\n+\t\t\tfor (const id of isClosedSet(set) ? [] : set) {\n \t\t\t\tconst atom = graph.atom(id);\n \t\t\t\tfor (const dependency of atom.deps) {\n \t\t\t\t\tgraph.atom(dependency);\n@@ -220,6 +232,7 @@\n \t\tfor (const id of this.#eachMover()) {\n \t\t\tfor (const m of graph.atom(id).moves!) {\n \t\t\t\tif (!relocs.has(m.line)) relocs.set(m.line, pick(m.line)!);\n+\t\t\t\tif (graph.hasOrderedChildren && relocs.size > MOVED_LINES_KEPT) throw new TooManyMoves();\n \t\t\t}\n \t\t}\n \t\tconst parentOf = (line: LineId): NodeId => relocs.get(line)?.parent ?? graph.lineParent(line)!;\n@@ -259,6 +272,21 @@\n \t\treturn relocs;\n \t}\n \n+\t/** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */\n+\t#scratchMoves(): boolean {\n+\t\tif (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;\n+\t\tif (this.#movesOnDisk === undefined) {\n+\t\t\ttry {\n+\t\t\t\tthis.#relocations();\n+\t\t\t\tthis.#movesOnDisk = false;\n+\t\t\t} catch (error) {\n+\t\t\t\tif (!(error instanceof TooManyMoves)) throw error;\n+\t\t\t\tthis.#movesOnDisk = true;\n+\t\t\t}\n+\t\t}\n+\t\treturn this.#movesOnDisk;\n+\t}\n+\n \t/** The relocations by n, with each new parent's code. */\n \t#relocationsN(): Map<number, { readonly r: RelocationInfo; readonly parent: number }> {\n \t\tif (this.#relocsN) return this.#relocsN;\n@@ -272,7 +300,7 @@\n \t/** The node a line hangs off in this set: where it was written, or where a move put it. */\n \tparentOf(line: LineId): NodeId {\n \t\tif (this.graph.lineParent(line) === undefined) throw new EngineError(\"unknown-line\", `no line ${line}`);\n-\t\tif (this.#hasMoves && this.graph.hasOrderedChildren)\n+\t\tif (this.#scratchMoves())\n \t\t\treturn this.graph.withProjectionScratch((scratch) =>\n \t\t\t\tresolveScratchMoves(this.graph, (id) => this.#has(this.graph.atom(id).seq), scratch).parent(line),\n \t\t\t);\n@@ -302,7 +330,7 @@\n \t#fileOfN(n: number): string {\n \t\tconst graph = this.graph;\n \t\tif (!this.#hasMoves) return graph.writtenIn(n);\n-\t\tif (graph.hasOrderedChildren)\n+\t\tif (this.#scratchMoves())\n \t\t\treturn graph.withProjectionScratch((scratch) => {\n \t\t\t\tconst moves = resolveScratchMoves(graph, (id) => this.#has(graph.atom(id).seq), scratch);\n \t\t\t\tlet current = graph.nodeOf(n);\n@@ -345,10 +373,18 @@\n \t\t\tout.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });\n \t\t}\n \t\tif (relocs) {\n-\t\t\tfor (const r of graph.eachRelocatedToCode(code)) {\n-\t\t\t\tconst n = graph.lineN(r.line);\n-\t\t\t\tconst selected = relocs.get(n)?.r;\n-\t\t\t\tif (!selected || selected.atom !== r.atom || selected.k !== r.k) continue;\n+\t\t\t// The lines this set's moves put under each node, from the moves it already resolved: no row read per node\n+\t\t\t// (abso Capacity).\n+\t\t\tif (!this.#movedInto) {\n+\t\t\t\tthis.#movedInto = new Map();\n+\t\t\t\tfor (const [n, { parent }] of relocs) {\n+\t\t\t\t\tconst into = this.#movedInto.get(parent);\n+\t\t\t\t\tif (into) into.push(n);\n+\t\t\t\t\telse this.#movedInto.set(parent, [n]);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tfor (const n of this.#movedInto.get(code) ?? NO_LINES) {\n+\t\t\t\tconst r = relocs.get(n)!.r;\n \t\t\t\tconst seq = graph.atom(r.atom).seq;\n \t\t\t\tout.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });\n \t\t\t}\n@@ -415,7 +451,7 @@\n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n \t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n-\t\tif (this.#hasMoves && graph.hasOrderedChildren)\n+\t\tif (this.#scratchMoves())\n \t\t\treturn graph.withProjectionScratch((scratch) =>\n \t\t\t\tthis.#layoutResolved(\n \t\t\t\t\tpath,\n@@ -635,7 +671,7 @@\n \t\t\t}\n \t\t\treturn found && previous !== undefined ? [previous] : [];\n \t\t};\n-\t\tif (this.#hasMoves && graph.hasOrderedChildren)\n+\t\tif (this.#scratchMoves())\n \t\t\treturn graph.withProjectionScratch((scratch) =>\n \t\t\t\tscan(scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, graph.nodeOf(start))),\n \t\t\t);"},{"path":"worker/project/project.ts","added":13,"removed":4,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -17,6 +17,8 @@\n \tCachedStateStorage,\n \tdifferenceSet,\n \ttype GraphStateStorage,\n+\tisClosedSet,\n+\tmarkClosed,\n \tStableOverlaySet,\n \tStableSet,\n \tStableUnionSet,\n@@ -174,7 +176,7 @@\n import { recordFile as hostedRecordFile, type RecordFileHost } from \"./record-file.ts\";\n import { refusals as hostedRefusals, refuse as hostedRefuse, type RefuseHost } from \"./refuse.ts\";\n import { restore as hostedRestore, type RestoreHost } from \"./restore.ts\";\n-import { last, Membership, SHARED, SharedAdditions, type Space, sharedBaseOf } from \"./spaces.ts\";\n+import { indexClosure, last, Membership, SHARED, SharedAdditions, type Space, sharedBaseOf } from \"./spaces.ts\";\n import { starting as hostedStarting, type StartingHost } from \"./start.ts\";\n import { switchTo as hostedSwitchTo, type SwitchHost } from \"./switch-to.ts\";\n import { sync as hostedSync, type SyncHost } from \"./sync.ts\";\n@@ -1584,6 +1586,10 @@\n \t\tconst versionsBefore = this.#spaces.get(SHARED)?.versions.length ?? 0;\n \t\ttry {\n \t\t\tthis.#applyEntry(entry, at, keptTime);\n+\t\t\t// Shared's closure, kept per version on disk (abso Capacity): after the entry, since its atoms join the graph after\n+\t\t\t// its membership.\n+\t\t\tif (this.#writerStorage && (this.#spaces.get(SHARED)?.versions.length ?? 0) > versionsBefore)\n+\t\t\t\tindexClosure(this.#writerStorage, this.#spaces.get(SHARED)!, this.#graph);\n \t\t} finally {\n \t\t\t// Positions by version: where each version of shared was made.\n \t\t\tconst versionsAfter = this.#spaces.get(SHARED)?.versions.length ?? 0;\n@@ -2719,9 +2725,12 @@\n \t * (abso issue 80). A closed set is unchanged.\n \t */\n \t#closed(set: Iterable<AtomId>): ReadonlySet<AtomId> {\n+\t\tif (isClosedSet(set)) return set as ReadonlySet<AtomId>;\n \t\tif (set instanceof StableSet) {\n \t\t\t// Keep indexed membership external. Only dependencies absent from\n-\t\t\t// that snapshot belong in the operation's closure overlay.\n+\t\t\t// that snapshot belong in the operation's closure overlay. Over a stored closed base (abso Capacity),\n+\t\t\t// only the overlay's atoms can reach outside it.\n+\t\t\tconst walk = set instanceof StableUnionSet && isClosedSet(set.left) ? set.right : set;\n \t\t\tconst missing = new Set<AtomId>();\n \t\t\tconst visit = (id: AtomId) => {\n \t\t\t\tconst stack = [id];\n@@ -2734,8 +2743,8 @@\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t};\n-\t\t\tfor (const id of set) visit(id);\n-\t\t\treturn missing.size ? new StableUnionSet(set, new StableOverlaySet(missing)) : set;\n+\t\t\tfor (const id of walk) visit(id);\n+\t\t\treturn markClosed(missing.size ? new StableUnionSet(set, new StableOverlaySet(missing)) : set);\n \t\t}\n \t\treturn this.#graph.closureOf(set);\n \t}"},{"path":"worker/project/spaces.ts","added":113,"removed":8,"diff":"--- a/worker/project/spaces.ts\n+++ b/worker/project/spaces.ts\n@@ -6,6 +6,7 @@\n import type { AtomId } from \"../../src/engine/index.ts\";\n import {\n \ttype GraphStateStorage,\n+\tmarkClosed,\n \tStableSet,\n \tStableUnionSet,\n \tStoredMap,\n@@ -119,6 +120,111 @@\n \t}\n }\n \n+/**\n+ * Shared's closure on disk (abso Capacity): the atoms a version's views hold beyond what it published, because\n+ * something in it depends on them (a discarded atom a later publish still needs, abso issue 80). Kept per version as\n+ * events like membership's, so \"is a in shared's closure at v\" is two lookups, and no read proves closure again.\n+ * Indexed from the first version only: a writer adopted before this has none and is proved as before.\n+ */\n+const CLOSURE = 'closure:\"\"';\n+const OWN = `membership:${JSON.stringify(SHARED)}`;\n+\n+function extraEvent(storage: GraphStateStorage, atom: AtomId, version: number): MembershipEvent | undefined {\n+\treturn membershipEvent(storage, CLOSURE, atom, version);\n+}\n+\n+/** The newest shared version whose closure is indexed, or undefined when this writer has none. */\n+export function closureIndexed(storage: GraphStateStorage): number | undefined {\n+\treturn storage.read(`${CLOSURE}:meta`, \"indexed\") as number | undefined;\n+}\n+\n+export interface ClosureGraph {\n+\tatom(id: AtomId): { readonly deps: readonly AtomId[]; readonly seq: number };\n+\teachDependentOf(id: AtomId): Iterable<AtomId>;\n+}\n+\n+/** Index shared's closure for every version applied since the last call. */\n+export function indexClosure(storage: GraphStateStorage, shared: Space, graph: ClosureGraph): void {\n+\tconst indexed = closureIndexed(storage);\n+\tconst newest = last(shared);\n+\tif (indexed === undefined && newest > 0) return;\n+\tfor (let v = (indexed ?? -1) + 1; v <= newest; v++) indexClosureVersion(storage, shared.versions[v]!, graph);\n+\tif (newest >= 0) storage.write(`${CLOSURE}:meta`, \"indexed\", newest);\n+}\n+\n+function indexClosureVersion(storage: GraphStateStorage, version: Published, graph: ClosureGraph): void {\n+\tconst v = version.version;\n+\tconst own = (atom: AtomId) => membershipEvent(storage, OWN, atom, v)?.present ?? false;\n+\tconst extra = (atom: AtomId) => extraEvent(storage, atom, v)?.present ?? false;\n+\tconst present = (atom: AtomId) => own(atom) || extra(atom);\n+\tconst order = storedArray<MembershipEvent>(storage, `${CLOSURE}:events`);\n+\tconst set = (atom: AtomId, on: boolean) => {\n+\t\tif (extra(atom) === on) return;\n+\t\tconst event = { atom, version: v, present: on, slot: order.length };\n+\t\tstoredArray<MembershipEvent>(storage, `${CLOSURE}:events:${atom}`).push(event);\n+\t\torder.push(event);\n+\t};\n+\tfor (const added of version.atoms) {\n+\t\tconst stack = [added];\n+\t\twhile (stack.length)\n+\t\t\tfor (const dep of graph.atom(stack.pop()!).deps)\n+\t\t\t\tif (!present(dep)) {\n+\t\t\t\t\tset(dep, true);\n+\t\t\t\t\tstack.push(dep);\n+\t\t\t\t}\n+\t}\n+\t// A dropped atom stays while something in the set depends on it, and so on down its deps: newest first, so an atom\n+\t// is decided after everything that could depend on it.\n+\tconst candidates = new Map<AtomId, number>();\n+\tfor (const dropped of version.dropped ?? []) if (!own(dropped)) candidates.set(dropped, graph.atom(dropped).seq);\n+\twhile (candidates.size) {\n+\t\tlet atom: AtomId | undefined;\n+\t\tlet seq = -1;\n+\t\tfor (const [a, s] of candidates)\n+\t\t\tif (s > seq) {\n+\t\t\t\tatom = a;\n+\t\t\t\tseq = s;\n+\t\t\t}\n+\t\tcandidates.delete(atom!);\n+\t\tif (own(atom!)) continue;\n+\t\tlet needed = false;\n+\t\tfor (const dependent of graph.eachDependentOf(atom!))\n+\t\t\tif (present(dependent)) {\n+\t\t\t\tneeded = true;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\tset(atom!, needed);\n+\t\tif (!needed)\n+\t\t\tfor (const dep of graph.atom(atom!).deps)\n+\t\t\t\tif (!own(dep) && extra(dep) && !candidates.has(dep)) candidates.set(dep, graph.atom(dep).seq);\n+\t}\n+}\n+\n+/** Shared at a version with its closure: what it published, and what that depends on. Marked closed. */\n+class ClosedVersionSet extends StableSet<AtomId> {\n+\treadonly retainedBytes = 96;\n+\treadonly #storage: GraphStateStorage;\n+\treadonly #version: number;\n+\treadonly #own: StoredVersionSet;\n+\tconstructor(storage: GraphStateStorage, version: number) {\n+\t\tsuper();\n+\t\tthis.#storage = storage;\n+\t\tthis.#version = version;\n+\t\tthis.#own = new StoredVersionSet(storage, OWN, version);\n+\t}\n+\thas(atom: AtomId): boolean {\n+\t\treturn this.#own.has(atom) || (extraEvent(this.#storage, atom, this.#version)?.present ?? false);\n+\t}\n+\t*values(): SetIterator<AtomId> {\n+\t\tyield* this.#own;\n+\t\tfor (const event of storedArray<MembershipEvent>(this.#storage, `${CLOSURE}:events`)) {\n+\t\t\tif (event.version > this.#version) break;\n+\t\t\tif (!event.present || this.#own.has(event.atom)) continue;\n+\t\t\tif (extraEvent(this.#storage, event.atom, this.#version)?.slot === event.slot) yield event.atom;\n+\t\t}\n+\t}\n+}\n+\n /** Immutable historical shared membership; iteration reads one event at a time. */\n class StoredVersionSet extends StableSet<AtomId> {\n \treadonly retainedBytes = 64;\n@@ -356,16 +462,15 @@\n \t */\n \tat(space: Space, version: number): ReadonlySet<AtomId> {\n \t\tif (this.#storage) {\n-\t\t\tconst own = new StoredVersionSet(this.#storage, `membership:${JSON.stringify(space.name)}`, version);\n-\t\t\tif (space.name === SHARED) return own;\n+\t\t\tconst storage = this.#storage;\n+\t\t\tconst closed = (v: number) => (closureIndexed(storage) ?? -1) >= v;\n+\t\t\tconst sharedAt = (v: number): StableSet<AtomId> =>\n+\t\t\t\tclosed(v) ? markClosed(new ClosedVersionSet(storage, v)) : new StoredVersionSet(storage, OWN, v);\n+\t\t\tif (space.name === SHARED) return sharedAt(version);\n+\t\t\tconst own = new StoredVersionSet(storage, `membership:${JSON.stringify(space.name)}`, version);\n \t\t\t// Named drafts add local atoms over an immutable shared base; drop\n \t\t\t// entries target shared, never a named draft's local membership.\n-\t\t\tconst base = new StoredVersionSet(\n-\t\t\t\tthis.#storage,\n-\t\t\t\t`membership:${JSON.stringify(SHARED)}`,\n-\t\t\t\tspace.versions[version]!.sharedBase!,\n-\t\t\t);\n-\t\t\treturn new StableUnionSet(base, own);\n+\t\t\treturn new StableUnionSet(sharedAt(space.versions[version]!.sharedBase!), own);\n \t\t}\n \t\tif (space.name === SHARED && version === last(space)) return space.own;\n \t\tconst key = `${spaceId(space)}:${version}`;"},{"path":"worker/project/test/stored-closure.test.ts","added":88,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/stored-closure.test.ts\n@@ -0,0 +1,88 @@\n+// Shared's closure kept on disk (abso Capacity, spaces.ts indexClosure): a writer-backed project answers every\n+// version as the in-memory one does, through drops that leave atoms a later version still needs.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { isClosedSet, storedArray } from \"../../../src/engine/state-source.ts\";\n+import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n+import { MemoryStore, Project } from \"../project.ts\";\n+import type { Entry, ProjectStore } from \"../project-types.ts\";\n+import { addVersion, closureIndexed, indexClosure, Membership } from \"../spaces.ts\";\n+\n+function writer() {\n+\tconst storage = new SqlState();\n+\tconst entries = storedArray<Entry>(storage, \"canonical-log\");\n+\tconst store: ProjectStore = {\n+\t\tappend(batch) {\n+\t\t\tfor (const entry of batch) entries.push(entry);\n+\t\t},\n+\t};\n+\treturn { storage, project: new Project(store, { writerStorage: storage }) };\n+}\n+\n+/** The same history on both: edits on top of edits, then drops of the earlier ones, then more. */\n+function history(project: Project) {\n+\tproject.init({ \"a.txt\": \"one\\ntwo\\nthree\\n\", \"b.txt\": \"b\\n\" }, 0);\n+\tproject.record(\"ann\", { \"a.txt\": \"ONE\\ntwo\\nthree\\n\" }, 1);\n+\tassert.equal(project.publish(\"ann\", \"First\", 2).ok, true);\n+\tproject.record(\"ann\", { \"a.txt\": \"ONE\\nTWO\\nthree\\n\", \"b.txt\": \"b\\nmore\\n\" }, 3);\n+\tassert.equal(project.publish(\"ann\", \"Second\", 4).ok, true);\n+\tproject.record(\"bob\", { \"a.txt\": \"ONE!\\nTWO\\nthree\\n\" }, 5);\n+\tassert.equal(project.publish(\"bob\", \"Third, on the first\", 6).ok, true);\n+\tconst answers: unknown[] = [];\n+\tfor (const versions of [[1], [2]])\n+\t\ttry {\n+\t\t\tanswers.push(project.drop(\"ann\", versions, `Drop ${versions}`, 7 + versions[0]!));\n+\t\t} catch (error) {\n+\t\t\tanswers.push(String(error));\n+\t\t}\n+\tproject.record(\"cy\", { \"c.txt\": \"new\\n\" }, 10);\n+\tassert.equal(project.publish(\"cy\", \"Fourth\", 11).ok, true);\n+\treturn answers;\n+}\n+\n+test(\"every version reads the same from the stored closure as from memory\", () => {\n+\tconst oracle = new Project(new MemoryStore());\n+\tconst { storage, project } = writer();\n+\tassert.deepEqual(history(project), history(oracle));\n+\tassert.equal(closureIndexed(storage), oracle.version);\n+\tfor (let v = 0; v <= oracle.version; v++) {\n+\t\tconst want = oracle.viewAt(v);\n+\t\tconst got = project.viewAt(v);\n+\t\tassert.ok(isClosedSet(got.set), `version ${v}'s set is known closed`);\n+\t\tassert.deepEqual(got.files(), want.files(), `version ${v}`);\n+\t\tassert.deepEqual([...got.set].sort(), [...want.set].sort(), `version ${v}'s atoms`);\n+\t}\n+\tassert.deepEqual(project.files(), oracle.files());\n+});\n+\n+test(\"an atom only a published one needs is in the closure until nothing in shared needs it\", () => {\n+\tconst storage = new SqlState();\n+\tconst membership = new Membership(storage);\n+\tconst shared = membership.shared;\n+\t// a1 was never published (a discarded draft atom); a2, published, builds on it.\n+\tconst deps: Record<string, string[]> = { a0: [], a1: [\"a0\"], a2: [\"a1\"], a3: [\"a0\"] };\n+\tconst graph = {\n+\t\tatom: (id: string) => ({ deps: deps[id]!, seq: Number(id.slice(1)) }),\n+\t\t*eachDependentOf(id: string) {\n+\t\t\tfor (const [atom, list] of Object.entries(deps)) if (list.includes(id)) yield atom;\n+\t\t},\n+\t};\n+\tconst version = (v: number, atoms: string[], dropped?: string[]) => {\n+\t\taddVersion(shared, { version: v, agent: \"w\", message: `v${v}`, time: v, atoms, ...(dropped ? { dropped } : {}) });\n+\t\tindexClosure(storage, shared, graph);\n+\t};\n+\tconst at = (v: number) => [...membership.at(shared, v)].sort();\n+\tversion(0, [\"a0\"]);\n+\tversion(1, [\"a2\"]);\n+\tversion(2, [\"a3\"]);\n+\tversion(3, [], [\"a2\"]);\n+\tassert.deepEqual(at(0), [\"a0\"]);\n+\tassert.deepEqual(at(1), [\"a0\", \"a1\", \"a2\"], \"a1 is in because a2 needs it\");\n+\tassert.deepEqual(at(2), [\"a0\", \"a1\", \"a2\", \"a3\"]);\n+\tassert.deepEqual(at(3), [\"a0\", \"a3\"], \"dropping a2 takes a1 out too\");\n+\tassert.equal(membership.at(shared, 1).has(\"a1\"), true);\n+\tassert.equal(membership.at(shared, 3).has(\"a1\"), false);\n+\tfor (let v = 0; v <= 3; v++) assert.ok(isClosedSet(membership.at(shared, v)));\n+\tstorage.db.close();\n+});"},{"path":"worker/project/test/stored-membership.test.ts","added":2,"removed":1,"diff":"--- a/worker/project/test/stored-membership.test.ts\n+++ b/worker/project/test/stored-membership.test.ts\n@@ -143,7 +143,8 @@\n \tconst shared = reopened.shared;\n \tconst reads = storage.reads;\n \tconst old = reopened.at(shared, 20);\n-\tassert.equal(storage.reads - reads, 0, \"opening a historical membership does not read historical state\");\n+\t// One read: whether shared's closure is kept on disk (abso Capacity). Nothing of the history.\n+\tassert.equal(storage.reads - reads, 1, \"opening a historical membership does not read historical state\");\n \tassert.equal(old.size, 41);\n \tassert.equal(old.has(\"a0\"), true);\n \tassert.equal(old.has(\"a79\"), false);"}],"ci":null}