{"version":118,"agent":"codex-capacity-chair","message":"Avoid retaining deleted historical paths in indexed current views","time":1791831208035,"timeIso":"2026-10-12T18:53:28.035Z","changes":4,"change":1284,"files":["src/engine/graph.ts","src/engine/state-source.ts","src/engine/test/view.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":5,"removed":0,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -705,6 +705,11 @@\n \t\treturn this.#fileAtoms.get(file) ?? EMPTY;\n \t}\n \n+\t/** Unique historical file paths, streamed without collecting their names. */\n+\t*knownFiles(): IterableIterator<string> {\n+\t\tyield* this.#fileAtoms.keys();\n+\t}\n+\n \t/**\n \t * The files an atom inserts, deletes or moves lines in, or sets attributes\n \t * of, sorted. For lines, the file each was written in (or, for a move to a"},{"path":"src/engine/state-source.ts","added":4,"removed":0,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -251,6 +251,7 @@\n }\n \n export interface StateMap<K, V> {\n+\tkeys(): IterableIterator<K>;\n \tget(key: K): V | undefined;\n \tset(key: K, value: V): StateMap<K, V>;\n \thas(key: K): boolean;\n@@ -262,6 +263,9 @@\n export function storedMap<K extends string | number, V>(storage: GraphStateStorage, name: string): StateMap<K, V> {\n \tconst keyOf = (key: K) => JSON.stringify([typeof key, key]);\n \tconst map: StateMap<K, V> = {\n+\t\t*keys() {\n+\t\t\tfor (const [key] of storage.entries(name)) yield (JSON.parse(key) as [string, K])[1];\n+\t\t},\n \t\tget: (key) => storage.read(name, keyOf(key)) as V | undefined,\n \t\thas: (key) => storage.read(name, keyOf(key)) !== undefined,\n \t\tset(key, value) {"},{"path":"src/engine/test/view.test.ts","added":14,"removed":0,"diff":"--- a/src/engine/test/view.test.ts\n+++ b/src/engine/test/view.test.ts\n@@ -8,6 +8,20 @@\n import { lines, Repo } from \"./helpers.ts\";\n \n describe(\"View\", () => {\n+\tit(\"current indexed paths do not retain deleted historical file layouts\", () => {\n+\t\tconst retained = (count: number) => {\n+\t\t\tconst files: Record<string, string> = { \"live.txt\": \"live\\n\" };\n+\t\t\tfor (let i = 0; i < count; i++) files[`old-${i}.txt`] = \"gone\\n\";\n+\t\t\tconst repo = Repo.init(files);\n+\t\t\trepo.edit({ edits: Array.from({ length: count }, (_, i) => ({ file: `old-${i}.txt`, old: \"gone\\n\", new: \"\" })) });\n+\t\t\tconst view = new View(repo.graph, new StableOverlaySet<AtomId>([\"a0\", \"a1\"]));\n+\t\t\tassert.deepEqual(view.files(), { \"live.txt\": \"live\\n\" });\n+\t\t\tconst weight = view.weight();\n+\t\t\tassert.equal(view.knownPaths().length, count + 1, \"explicit historical enumeration is preserved\");\n+\t\t\treturn weight;\n+\t\t};\n+\t\tassert.equal(retained(200), retained(20), \"deleted path count must not grow current-view retained state\");\n+\t});\n \tit(\"reuses indexed membership across a long run of lines without a history-sized memo\", () => {\n \t\tconst repo = Repo.init({ \"long.txt\": \"line\\n\".repeat(1000) });\n \t\tclass CountingSet extends StableOverlaySet<AtomId> {"},{"path":"src/engine/view.ts","added":8,"removed":0,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -386,6 +386,14 @@\n \n \t/** Files with at least one visible line, sorted. */\n \tpaths(): string[] {\n+\t\tif (this.#stable) {\n+\t\t\tconst paths: string[] = [];\n+\t\t\tfor (const path of this.graph.knownFiles()) {\n+\t\t\t\tif (this.hasFile(path)) paths.push(path);\n+\t\t\t\telse this.#files.delete(path);\n+\t\t\t}\n+\t\t\treturn paths.sort();\n+\t\t}\n \t\treturn this.#known.filter((p) => this.hasFile(p));\n \t}\n "}],"ci":null}