{"version":120,"agent":"codex-capacity-chair","message":"Page persistent claim indexes and stream dependency queries","time":1791834716611,"timeIso":"2026-10-12T19:51:56.611Z","changes":5,"change":1284,"files":["src/engine/build.ts","src/engine/conflicts.ts","src/engine/graph.ts","src/engine/state-source.ts","src/engine/test/state-source.test.ts"],"draft":null,"diff":[{"path":"src/engine/build.ts","added":2,"removed":2,"diff":"--- a/src/engine/build.ts\n+++ b/src/engine/build.ts\n@@ -353,10 +353,10 @@\n \t\t// An attribute builds on whoever set it last in the view, the way an insertion builds on a gap's writers;\n \t\t// a move builds on the earlier moves of its lines.\n \t\tif (kind !== \"attr\" && !isStartNode(node)) deps.add(writerOf(node));\n-\t\tif (kind !== \"line\") for (const writer of graph.writersOf(key)) if (view.set.has(writer)) deps.add(writer);\n+\t\tif (kind !== \"line\") for (const writer of graph.eachWriterOf(key)) if (view.set.has(writer)) deps.add(writer);\n \t}\n \tfor (const key of parts.writes) {\n-\t\tfor (const reader of graph.readersOf(key)) if (view.set.has(reader)) deps.add(reader);\n+\t\tfor (const reader of graph.eachReaderOf(key)) if (view.set.has(reader)) deps.add(reader);\n \t}\n \tfor (const id of parts.needs) deps.add(id);\n \tfor (const id of parts.resolves) deps.add(id);"},{"path":"src/engine/conflicts.ts","added":2,"removed":2,"diff":"--- a/src/engine/conflicts.ts\n+++ b/src/engine/conflicts.ts\n@@ -138,7 +138,7 @@\n /** Atoms in the set that claim (write, read or hold) a key. */\n function claimersIn(graph: Graph, set: AtomSet, key: Key): AtomId[] {\n \tconst out: AtomId[] = [];\n-\tfor (const list of [graph.writersOf(key), graph.readersOf(key), graph.holdersOf(key)]) {\n+\tfor (const list of [graph.eachWriterOf(key), graph.eachReaderOf(key), graph.eachHolderOf(key)]) {\n \t\tfor (const id of list) if (set.has(id)) out.push(id);\n \t}\n \treturn out;\n@@ -302,7 +302,7 @@\n \tconst below = graph.closureOf(draft.deps);\n \tconst candidates = new Set<AtomId>();\n \tfor (const key of draft.writes) for (const id of claimersIn(graph, set, key)) candidates.add(id);\n-\tfor (const key of claimsOf(draft)) for (const id of graph.writersOf(key)) if (set.has(id)) candidates.add(id);\n+\tfor (const key of claimsOf(draft)) for (const id of graph.eachWriterOf(key)) if (set.has(id)) candidates.add(id);\n \tconst found: Conflict[] = [];\n \tfor (const id of [...candidates].sort(bySeq(graph))) {\n \t\tconst other = graph.atom(id);"},{"path":"src/engine/graph.ts","added":39,"removed":9,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -315,9 +315,9 @@\n \t\t\tthis.#lineText = storedArray(storage, \"line-text\");\n \t\t\tthis.#pathIndex = storedMap(storage, \"path-index\");\n \t\t\tthis.#moreDeleters = storedMap(storage, \"more-deleters\");\n-\t\t\tthis.#writers = storedMap(storage, \"writers\");\n-\t\t\tthis.#readers = storedMap(storage, \"readers\");\n-\t\t\tthis.#holders = storedMap(storage, \"holders\");\n+\t\t\tthis.#writersPages = storedLists<AtomId>(storage, \"writers\", (key) => key);\n+\t\t\tthis.#readersPages = storedLists<AtomId>(storage, \"readers\", (key) => key);\n+\t\t\tthis.#holdersPages = storedLists<AtomId>(storage, \"holders\", (key) => key);\n \t\t\tthis.#dependents = storedMap(storage, \"dependents\");\n \t\t\tthis.#resolvers = storedMap(storage, \"resolvers\");\n \t\t\tthis.#together = storedMap(storage, \"together\");\n@@ -421,8 +421,11 @@\n \t#deleter: NumberIndex = new Ints();\n \t#moreDeleters: StateMap<number, number[]> = new Map();\n \t#writers: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#writersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t#readers: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#readersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t#holders: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#holdersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t#dependents: StateMap<AtomId, AtomId | AtomId[]> = new Map();\n \t#resolvers: StateMap<AtomId, AtomId | AtomId[]> = new Map();\n \t#together: StateMap<AtomId, TogetherLink[]> = new Map();\n@@ -695,18 +698,33 @@\n \t}\n \n \twritersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#writers.get(this.#code(key)));\n+\t\treturn [...this.eachWriterOf(key)];\n \t}\n+\t*eachWriterOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#writersPages) yield* this.#writersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#writers.get(code));\n+\t}\n \n \t/** Atoms whose implicit reads include the key. */\n \treadersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#readers.get(this.#code(key)));\n+\t\treturn [...this.eachReaderOf(key)];\n \t}\n+\t*eachReaderOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#readersPages) yield* this.#readersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#readers.get(code));\n+\t}\n \n \t/** Atoms whose explicit holds include the key. */\n \tholdersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#holders.get(this.#code(key)));\n+\t\treturn [...this.eachHolderOf(key)];\n \t}\n+\t*eachHolderOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#holdersPages) yield* this.#holdersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#holders.get(code));\n+\t}\n \n \t/** Every atom that inserts or deletes a line of the file, in seq order. */\n \tatomsIn(file: string): readonly AtomId[] {\n@@ -983,9 +1001,21 @@\n \t\t\tif (this.#deleter.at(n) < 0) this.#deleter.set(n, seq);\n \t\t\telse pushIndex(this.#moreDeleters, n, seq);\n \t\t}\n-\t\tfor (const key of new Set(atom.writes)) pushOne(this.#writers, this.#code(key), frozen.id);\n-\t\tfor (const key of new Set(atom.reads)) pushOne(this.#readers, this.#code(key), frozen.id);\n-\t\tfor (const key of new Set(atom.holds)) pushOne(this.#holders, this.#code(key), frozen.id);\n+\t\tfor (const key of new Set(atom.writes)) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#writersPages) this.#writersPages.append(JSON.stringify([typeof code, code]), frozen.id);\n+\t\t\telse pushOne(this.#writers, code, frozen.id);\n+\t\t}\n+\t\tfor (const key of new Set(atom.reads)) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#readersPages) this.#readersPages.append(JSON.stringify([typeof code, code]), frozen.id);\n+\t\t\telse pushOne(this.#readers, code, frozen.id);\n+\t\t}\n+\t\tfor (const key of new Set(atom.holds)) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#holdersPages) this.#holdersPages.append(JSON.stringify([typeof code, code]), frozen.id);\n+\t\t\telse pushOne(this.#holders, code, frozen.id);\n+\t\t}\n \t\tfor (const d of deps) pushOne(this.#dependents, d, frozen.id);\n \t\tfor (const r of new Set(frozen.resolves)) pushOne(this.#resolvers, r, frozen.id);\n \t\tconst files = new Set<string>();"},{"path":"src/engine/state-source.ts","added":6,"removed":2,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -260,12 +260,16 @@\n }\n \n /** Append-only per-key lists, retaining at most one fixed-size page per iterator. */\n-export function storedLists<V>(storage: GraphStateStorage, name: string) {\n+export function storedLists<V>(\n+\tstorage: GraphStateStorage,\n+\tname: string,\n+\tlegacyKey = (key: string) => JSON.stringify([\"string\", key]),\n+) {\n \tconst pageSize = 256;\n \t// The previous experimental layout stored one whole historical list per key.\n \tconst length = (key: string) => {\n \t\tconst stored = storage.read(`${name}:lengths`, key) as number | undefined;\n-\t\tif (stored === undefined && storage.read(name, JSON.stringify([\"string\", key])) !== undefined)\n+\t\tif (stored === undefined && storage.read(name, legacyKey(key)) !== undefined)\n \t\t\tthrow new Error(`writer list index ${name} requires canonical-log adoption`);\n \t\tconst count = stored ?? 0;\n \t\tif (!Number.isSafeInteger(count) || count < 0) throw new Error(`invalid writer list count in ${name}`);"},{"path":"src/engine/test/state-source.test.ts","added":38,"removed":0,"diff":"--- a/src/engine/test/state-source.test.ts\n+++ b/src/engine/test/state-source.test.ts\n@@ -5,6 +5,44 @@\n import { lines, Repo } from \"./helpers.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"hot claim indexes stream bounded pages after reopening\", (t) => {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\", \"two\") });\n+\tconst draft = oracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"ONE\" }] });\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage: source });\n+\t\tgraph.add(oracle.graph.atom(\"a0\"));\n+\t\tfor (let i = 0; i < 513; i++) {\n+\t\t\tconst atom = { ...draft, id: `a${i + 1}`, seq: i + 1 };\n+\t\t\tgraph.add(atom);\n+\t\t\toracle.graph.add(atom);\n+\t\t}\n+\t\tconst reopened = new Graph({ storage: source });\n+\t\tconst read = source.read.bind(source);\n+\t\tlet pagesRead = 0;\n+\t\tt.mock.method(source, \"read\", (collection: string, key: string) => {\n+\t\t\tif (collection === \"writers:pages\") pagesRead++;\n+\t\t\treturn read(collection, key);\n+\t\t});\n+\t\tconst iterator = reopened.eachWriterOf(\"L:a0.0\");\n+\t\tassert.equal(iterator.next().value, \"a1\");\n+\t\tassert.equal(pagesRead, 1, \"first claimant reads one claim page, not the entire hot-key history\");\n+\t\tassert.deepEqual(reopened.writersOf(\"L:a0.0\"), oracle.graph.writersOf(\"L:a0.0\"));\n+\t\tfor (const name of [\"writers\", \"readers\", \"holders\"]) {\n+\t\t\tassert.equal([...source.entries(name)].length, 0, \"no whole-list claim rows remain\");\n+\t\t\tfor (const [, page] of source.entries(`${name}:pages`)) assert.ok((page as string[]).length <= 256);\n+\t\t}\n+\t\tconst key = JSON.stringify([\"number\", 0]);\n+\t\tsource.write(\"legacy-claims\", key, [\"old\"]);\n+\t\tassert.throws(\n+\t\t\t() => [...storedLists(source, \"legacy-claims\", (value) => value).values(key)],\n+\t\t\t/canonical-log adoption/,\n+\t\t);\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});\n+\n test(\"per-file list pages append and reopen without reading the full historical list\", () => {\n \tconst source = new SqlState();\n \ttry {"}],"ci":null}