{"version":129,"agent":"codex-capacity-chair","message":"Page together relationship history for bounded traversal","time":1791839961178,"timeIso":"2026-10-12T21:19:21.178Z","changes":3,"change":1284,"files":["src/engine/conflicts.ts","src/engine/graph.ts","src/engine/test/state-source.test.ts"],"draft":null,"diff":[{"path":"src/engine/conflicts.ts","added":1,"removed":1,"diff":"--- a/src/engine/conflicts.ts\n+++ b/src/engine/conflicts.ts\n@@ -261,7 +261,7 @@\n \tconst seen = new Set<string>();\n \tfor (const a of [...changed].sort(bySeq(graph))) {\n \t\tif (a === atom.id) continue;\n-\t\tfor (const link of graph.togetherLinks(a)) {\n+\t\tfor (const link of graph.eachTogetherLink(a)) {\n \t\t\tconst b = link.other;\n \t\t\tif (b === atom.id || !set.has(b) || acknowledged.has(b)) continue;\n \t\t\tconst tag = `${a} ${b}`;"},{"path":"src/engine/graph.ts","added":17,"removed":4,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -322,7 +322,7 @@\n \t\t\tthis.#holdersPages = storedLists<AtomId>(storage, \"holders\", (key) => key);\n \t\t\tthis.#dependentsPages = storedLists<AtomId>(storage, \"dependents\");\n \t\t\tthis.#resolversPages = storedLists<AtomId>(storage, \"resolvers\");\n-\t\t\tthis.#together = storedMap(storage, \"together\");\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.#relocationPages = storedLists<RelocationInfo>(storage, \"relocations\");\n@@ -436,6 +436,7 @@\n \t#resolvers: StateMap<AtomId, AtomId | AtomId[]> = new Map();\n \t#resolversPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t#together: StateMap<AtomId, TogetherLink[]> = new Map();\n+\t#togetherPages: ReturnType<typeof storedLists<TogetherLink>> | undefined;\n \t#fileAtoms: StateMap<string, AtomId[]> = new Map();\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@@ -833,8 +834,12 @@\n \n \t/** `together` reasons touching this atom, in either direction. */\n \ttogetherLinks(id: AtomId): readonly TogetherLink[] {\n-\t\treturn this.#together.get(id) ?? EMPTY;\n+\t\treturn [...this.eachTogetherLink(id)];\n \t}\n+\t*eachTogetherLink(id: AtomId): IterableIterator<TogetherLink> {\n+\t\tif (this.#togetherPages) yield* this.#togetherPages.values(id);\n+\t\telse yield* this.#together.get(id) ?? EMPTY;\n+\t}\n \n \t/**\n \t * The atom plus everything it depends on, transitively. Computed on demand\n@@ -1068,8 +1073,16 @@\n \t\t}\n \t\tfor (const r of frozen.reasons) {\n \t\t\tif (r.kind !== \"together\" || r.to === frozen.id) continue;\n-\t\t\tpushIndex(this.#together, frozen.id, { other: r.to, text: r.text, from: frozen.id });\n-\t\t\tpushIndex(this.#together, r.to, { other: frozen.id, text: r.text, from: frozen.id });\n+\n+\t\t\tconst forward = { other: r.to, text: r.text, from: frozen.id };\n+\t\t\tconst reverse = { other: frozen.id, text: r.text, from: frozen.id };\n+\t\t\tif (this.#togetherPages) {\n+\t\t\t\tthis.#togetherPages.append(frozen.id, forward);\n+\t\t\t\tthis.#togetherPages.append(r.to, reverse);\n+\t\t\t} else {\n+\t\t\t\tpushIndex(this.#together, frozen.id, forward);\n+\t\t\t\tpushIndex(this.#together, r.to, reverse);\n+\t\t\t}\n \t\t}\n \t}\n "},{"path":"src/engine/test/state-source.test.ts","added":47,"removed":0,"diff":"--- a/src/engine/test/state-source.test.ts\n+++ b/src/engine/test/state-source.test.ts\n@@ -315,3 +315,50 @@\n \tassert.equal(new Graph({ storage }).label(\"child\")?.base, \"a0\");\n \tstorage.db.close();\n });\n+\n+test(\"together links stream bounded pages in both directions after storage reopen\", () => {\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 === \"together: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 === \"together: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\\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 = {\n+\t\t\t\t...draft,\n+\t\t\t\tid: `a${seq}`,\n+\t\t\t\tseq,\n+\t\t\t\treasons: [{ to: \"a0\", kind: \"together\" as const, text: `reason ${seq}` }],\n+\t\t\t};\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\tstorage.pageReads = 0;\n+\t\tconst iterator = reopened.eachTogetherLink(\"a0\");\n+\t\tassert.deepEqual(iterator.next().value, oracle.graph.togetherLinks(\"a0\")[0]);\n+\t\tassert.equal(storage.pageReads, 1);\n+\t\tstorage.pageReads = 0;\n+\t\tassert.deepEqual(reopened.togetherLinks(\"a0\"), oracle.graph.togetherLinks(\"a0\"));\n+\t\tassert.equal(storage.pageReads, 3);\n+\t\tassert.deepEqual(reopened.togetherLinks(\"a513\"), oracle.graph.togetherLinks(\"a513\"));\n+\t\tassert.equal(storage.largestPage, 256);\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"}],"ci":null}