{"version":125,"agent":"codex-capacity-chair","message":"Bound file-location ancestry scratch and memo","time":1791836675099,"timeIso":"2026-10-12T20:24:35.099Z","changes":2,"change":1284,"files":["src/engine/test/view.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/test/view.test.ts","added":17,"removed":0,"diff":"--- a/src/engine/test/view.test.ts\n+++ b/src/engine/test/view.test.ts\n@@ -8,6 +8,23 @@\n import { lines, Repo } from \"./helpers.ts\";\n \n describe(\"View\", () => {\n+\tit(\"bounds file-location memo growth across long ancestry walks with moves\", () => {\n+\t\tconst retained = (count: number) => {\n+\t\t\tconst repo = Repo.init({ \"long.txt\": \"line\\n\".repeat(count), \"a.txt\": \"move\\n\", \"b.txt\": \"base\\n\" });\n+\t\t\trepo.edit({ move: { file: \"a.txt\", start: 0, end: 1, to: \"b.txt\", at: 1 } });\n+\t\t\tconst view = new View(repo.graph, new StableOverlaySet<AtomId>([\"a0\", \"a1\"]));\n+\t\t\tconst oracle = repo.view();\n+\t\t\t// Resolve the deepest ancestry first, then force repeated cache eviction.\n+\t\t\tconst sequence = oracle.sequence(\"long.txt\");\n+\t\t\tassert.equal(sequence.length, count);\n+\t\t\tassert.equal(view.fileOf(sequence[count - 1]!.id), \"long.txt\");\n+\t\t\tfor (const line of sequence) assert.equal(view.fileOf(line.id), \"long.txt\");\n+\t\t\tfor (const line of oracle.lines(\"b.txt\")) assert.equal(view.fileOf(line.id), \"b.txt\");\n+\t\t\tassert.equal(view.fileOf(sequence[count - 1]!.id), \"long.txt\");\n+\t\t\treturn view.weight();\n+\t\t};\n+\t\tassert.equal(retained(2048), retained(512), \"file-location retained state must not grow with ancestry depth\");\n+\t});\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\" };"},{"path":"src/engine/view.ts","added":11,"removed":2,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -83,6 +83,7 @@\n const MAP_ENTRY_BYTES = 40;\n const SET_ENTRY_BYTES = 32;\n const REFERENCE_BYTES = 8;\n+const FILE_LOCATION_MEMO_ENTRIES = 256;\n \n /**\n  * The projection of a closed set. Construct once, then ask for files, lines\n@@ -110,6 +111,7 @@\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/** 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 \t#linesCache: { path: string; lines: readonly VisibleLine[] } | undefined;\n@@ -286,7 +288,10 @@\n \t\tconst graph = this.graph;\n \t\tif (!this.#hasMoves) return graph.writtenIn(n);\n \t\tconst relocs = this.#relocationsN();\n+\t\t// Keep only a fixed tail of the walk for path compression. The selected\n+\t\t// relocation graph is acyclic, so traversal needs no history-sized stack.\n \t\tconst path: number[] = [];\n+\t\tlet visited = 0;\n \t\tlet cur = n;\n \t\tlet file: string | undefined;\n \t\twhile (file === undefined) {\n@@ -294,12 +299,16 @@\n \t\t\telse {\n \t\t\t\tfile = this.#fileOf.get(cur);\n \t\t\t\tif (file === undefined) {\n-\t\t\t\t\tpath.push(cur);\n+\t\t\t\t\tpath[visited++ % FILE_LOCATION_MEMO_ENTRIES] = cur;\n \t\t\t\t\tcur = relocs.get(cur)?.parent ?? graph.parentCodeOf(cur);\n \t\t\t\t}\n \t\t\t}\n \t\t}\n-\t\tfor (const l of path) this.#fileOf.set(l, file);\n+\t\tfor (const l of path) {\n+\t\t\tif (!this.#fileOf.has(l) && this.#fileOf.size >= FILE_LOCATION_MEMO_ENTRIES)\n+\t\t\t\tthis.#fileOf.delete(this.#fileOf.keys().next().value!);\n+\t\t\tthis.#fileOf.set(l, file);\n+\t\t}\n \t\treturn file;\n \t}\n "}],"ci":null}