{"version":130,"agent":"codex-capacity-chair","message":"Stream paged child history into layout filtering","time":1791840531495,"timeIso":"2026-10-12T21:28:51.495Z","changes":3,"change":1284,"files":["src/engine/graph.ts","src/engine/test/state-source.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":15,"removed":20,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -324,7 +324,9 @@\n \t\t\tthis.#resolversPages = storedLists<AtomId>(storage, \"resolvers\");\n \t\t\tthis.#togetherPages = storedLists<TogetherLink>(storage, \"together\");\n \t\t\tthis.#fileAtomPages = storedLists<AtomId>(storage, \"file-atoms\");\n-\t\t\tthis.#runStarts = storedMap(storage, \"run-starts\");\n+\t\t\tthis.#runStartPages = storedLists<number>(storage, \"run-starts\", (key) =>\n+\t\t\t\tJSON.stringify([\"number\", Number(key)]),\n+\t\t\t);\n \t\t\tthis.#relocationPages = storedLists<RelocationInfo>(storage, \"relocations\");\n \t\t\tthis.#relocatedToPages = storedLists<RelocationInfo>(storage, \"relocated-to\");\n \t\t\tthis.#relocatedToCodePages = storedLists<RelocationInfo>(storage, \"relocated-to-code\", (key) =>\n@@ -441,6 +443,7 @@\n \t#fileAtomPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t/** First lines of runs (their n), by the node they were written after: a line's n, or -1 - a path's index. */\n \t#runStarts: StateMap<number, number | number[]> = new Map();\n+\t#runStartPages: ReturnType<typeof storedLists<number>> | undefined;\n \t/** 1 for the first line of a run whose atom deleted the line it hangs off: the run replaces it. */\n \t#replacing: NumberIndex = new Ints(true);\n \t#relocations: StateMap<LineId, RelocationInfo[]> = new Map();\n@@ -612,18 +615,20 @@\n \t}\n \n \t/** The lines (their n) written right after a node, as childrenOf, into `out`. */\n+\n \tchildrenN(code: number, out: number[]): void {\n+\t\tfor (const n of this.eachChildN(code)) out.push(n);\n+\t}\n+\t*eachChildN(code: number): IterableIterator<number> {\n \t\tif (\n \t\t\tcode >= 0 &&\n \t\t\tcode + 1 < this.#lineTotal &&\n \t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n \t\t\tthis.#lineParent.at(code + 1) === code\n \t\t)\n-\t\t\tout.push(code + 1);\n-\t\tconst starts = this.#runStarts.get(code);\n-\t\tif (starts === undefined) return;\n-\t\tif (Array.isArray(starts)) out.push(...starts);\n-\t\telse out.push(starts);\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}\n \n \treplacesN(n: number): boolean {\n@@ -770,21 +775,10 @@\n \t}\n \n \t/** Lines written right after a node (not counting moves), in seq order. */\n+\n \tchildrenOf(node: NodeId): LineId[] {\n-\t\tconst out: LineId[] = [];\n \t\tconst code = this.#nodeCode(node);\n-\t\tif (code === undefined) return out;\n-\t\t// The next line of the same run hangs off this one.\n-\t\tif (\n-\t\t\tcode >= 0 &&\n-\t\t\tcode + 1 < this.#lineTotal &&\n-\t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n-\t\t\tthis.#lineParent.at(code + 1) === code\n-\t\t) {\n-\t\t\tout.push(this.#lineName(code + 1));\n-\t\t}\n-\t\tfor (const n of listOf(this.#runStarts.get(code))) out.push(this.#lineName(n));\n-\t\treturn out;\n+\t\treturn code === undefined ? [] : [...this.eachChildN(code)].map((n) => this.#lineName(n));\n \t}\n \n \t/** Whether a line starts a run whose atom deleted the line it hangs off. */\n@@ -1007,7 +1001,8 @@\n \t\t\tconst file = this.#pathOf(run.file);\n \t\t\tlet parent = isStartNode(run.parent) ? -1 - file : this.#lineN(run.parent);\n \t\t\tconst first = this.#lineTotal;\n-\t\t\tpushOne(this.#runStarts, parent, first);\n+\t\t\tif (this.#runStartPages) this.#runStartPages.append(String(parent), first);\n+\t\t\telse pushOne(this.#runStarts, parent, first);\n \t\t\tfor (let i = 0; i < run.lines.length; i++) {\n \t\t\t\tconst n = this.#lineTotal;\n \t\t\t\tthis.#lineAtom.push(seq);"},{"path":"src/engine/test/state-source.test.ts","added":57,"removed":0,"diff":"--- a/src/engine/test/state-source.test.ts\n+++ b/src/engine/test/state-source.test.ts\n@@ -362,3 +362,60 @@\n \t\tstorage.db.close();\n \t}\n });\n+\n+test(\"child indexes stream bounded pages before filtering historical siblings\", () => {\n+\tclass ObservedStorage extends SqlState {\n+\t\tpageReads = 0;\n+\t\tlargestPage = 0;\n+\t\toverride read(collection: string, key: string): unknown {\n+\t\t\tif (collection === \"run-starts:pages\") this.pageReads++;\n+\t\t\treturn super.read(collection, key);\n+\t\t}\n+\t\toverride write(collection: string, key: string, value: unknown): void {\n+\t\t\tif (collection === \"run-starts:pages\") {\n+\t\t\t\tassert.ok(Array.isArray(value));\n+\t\t\t\tthis.largestPage = Math.max(this.largestPage, value.length);\n+\t\t\t}\n+\t\t\tsuper.write(collection, key, value);\n+\t\t}\n+\t}\n+\tconst storage = new ObservedStorage();\n+\ttry {\n+\t\tconst oracle = Repo.init({ \"a.txt\": \"one\\ntwo\\n\" });\n+\t\tconst draft = oracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"ONE\" }] });\n+\t\tconst graph = new Graph({ storage });\n+\t\tgraph.add(oracle.graph.atom(\"a0\"));\n+\t\tfor (let seq = 1; seq <= 513; seq++) {\n+\t\t\tconst atom = { ...draft, id: `a${seq}`, seq };\n+\t\t\tgraph.add(atom);\n+\t\t\toracle.graph.add(atom);\n+\t\t}\n+\t\tconst reopened = new Graph({ storage });\n+\t\tconst parent = draft.inserts[0]!.parent;\n+\t\tconst code = reopened.codeOf(parent)!;\n+\t\tstorage.pageReads = 0;\n+\t\tconst iterator = reopened.eachChildN(code);\n+\t\tconst first = iterator.next().value!;\n+\t\tassert.equal(first, reopened.lineN(oracle.graph.childrenOf(parent)[0]!));\n+\t\tassert.ok(storage.pageReads <= 1);\n+\t\tif (storage.pageReads === 0) {\n+\t\t\titerator.next();\n+\t\t\tassert.equal(storage.pageReads, 1, \"the implicit child needs no page; the next sibling needs one\");\n+\t\t}\n+\t\tassert.deepEqual(reopened.childrenOf(parent), oracle.graph.childrenOf(parent));\n+\t\tassert.deepEqual(\n+\t\t\treopened.childrenOf(\"a0.0\"),\n+\t\t\toracle.graph.childrenOf(\"a0.0\"),\n+\t\t\t\"implicit same-run child order is retained\",\n+\t\t);\n+\t\tassert.equal(storage.largestPage, 256);\n+\t\tconst membership = new StableOverlaySet([\"a0\"]);\n+\t\tassert.equal(new View(reopened, membership).text(\"a.txt\"), \"one\\ntwo\\n\");\n+\t\tassert.deepEqual(\n+\t\t\tnew View(reopened, membership).sequence(\"a.txt\"),\n+\t\t\tnew View(oracle.graph, membership).sequence(\"a.txt\"),\n+\t\t);\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"},{"path":"src/engine/view.ts","added":1,"removed":3,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -319,10 +319,8 @@\n \t#children(code: number): Child[] {\n \t\tconst graph = this.graph;\n \t\tconst relocs = this.#hasMoves ? this.#relocationsN() : undefined;\n-\t\tconst ns: number[] = [];\n-\t\tgraph.childrenN(code, ns);\n \t\tconst out: Child[] = [];\n-\t\tfor (const n of ns) {\n+\t\tfor (const n of graph.eachChildN(code)) {\n \t\t\tconst seq = graph.writerSeqOf(n);\n \t\t\tif (!this.#has(seq) || relocs?.has(n)) continue;\n \t\t\tout.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });"}],"ci":null}