{"version":110,"agent":"codex-capacity-chair","message":"Keep current-file views and key scans from retaining historical state","time":1791826888785,"timeIso":"2026-10-12T17:41:28.785Z","changes":5,"change":1284,"files":["src/engine/state-source.ts","src/engine/test/view.test.ts","src/engine/view.ts","worker/project/test/stored-membership.test.ts"],"draft":null,"diff":[{"path":"src/engine/state-source.ts","added":5,"removed":1,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -220,7 +220,11 @@\n \t\t}\n \t}\n \toverride *keys(): MapIterator<K> {\n-\t\tfor (const [key] of this.entries()) yield key;\n+\t\tconst keys = storedArray<K>(this.#storage, `${this.#name}:order`);\n+\t\tfor (let slot = 0; slot < keys.length; slot++) {\n+\t\t\tconst key = keys[slot]!;\n+\t\t\tif (this.#row(key)?.slot === slot) yield key;\n+\t\t}\n \t}\n \toverride *values(): MapIterator<V> {\n \t\tfor (const [, value] of this.entries()) yield value;"},{"path":"src/engine/test/view.test.ts","added":6,"removed":0,"diff":"--- a/src/engine/test/view.test.ts\n+++ b/src/engine/test/view.test.ts\n@@ -32,6 +32,12 @@\n \t\tassert.equal(second.weight(), weight, \"membership resident size does not increase with historical atom count\");\n \t\tassert.equal(first.text(\"a.txt\"), \"40\\n\");\n \t\tassert.equal(second.text(\"a.txt\"), \"80\\n\");\n+\t\tassert.equal(second.weight(), first.weight(), \"current text retains visible lines, not historical tombstones\");\n+\t\tconst currentWeight = second.weight();\n+\t\tassert.equal(second.sequence(\"a.txt\").length, 81);\n+\t\tassert.equal(second.sequence(\"a.txt\").filter((line) => line.visible).length, 1);\n+\t\tassert.ok(second.weight() > currentWeight, \"explicit history reads may retain their requested sequence\");\n+\t\tassert.equal(second.text(\"a.txt\"), \"80\\n\");\n \t\tassert.equal(first.set.has(\"a80\"), false);\n \t\tassert.throws(() => new View(repo.graph, new StableOverlaySet<AtomId>([\"a1\"])), /not closed/);\n \t});"},{"path":"src/engine/view.ts","added":14,"removed":11,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -49,6 +49,8 @@\n \n interface FileState {\n \treadonly attrs: FileAttrs;\n+\t/** Full history is retained only when a sequence caller explicitly requests it. */\n+\treadonly complete: boolean;\n \t/** The file's sequence, tombstones included: each line's n. */\n \treadonly seq: Int32Array;\n \t/** Its visible lines' n, in order. */\n@@ -70,7 +72,7 @@\n }\n \n const EMPTY_INTS = new Int32Array(0);\n-const NO_FILE: FileState = { attrs: NO_ATTRS, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };\n+const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };\n \n // Approximate retained-container costs for View.weight(): reference slots,\n // object headers, and map/set entries. These are cache-budget units, not V8\n@@ -314,7 +316,7 @@\n \t}\n \n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n-\t#layout(path: string): FileState {\n+\t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n \t\t// For each attribute, the highest-priority setter in the set wins.\n \t\tconst setters = new Map<string, { id: AtomId; value: string | null }>();\n@@ -343,9 +345,10 @@\n \t\t\tconst n = stack.pop()!;\n \t\t\tconst deleters = graph.deleterSeqsOf(n);\n \t\t\tconst by = deleters.length === 0 ? NONE : deleters.filter((d) => this.#has(d));\n-\t\t\tif (by.length > 0) deletedBy.set(seq.length, by.length > 1 ? [...by].sort(priority) : by);\n-\t\t\telse vis.push(n);\n-\t\t\tseq.push(n);\n+\t\t\tif (by.length > 0) {\n+\t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? [...by].sort(priority) : by);\n+\t\t\t} else vis.push(n);\n+\t\t\tif (complete) seq.push(n);\n \t\t\tpushChildren(n);\n \t\t}\n \t\tconst attrs: FileAttrs = {\n@@ -354,7 +357,7 @@\n \t\t\tlink: setters.get(\"link\")?.value ?? null,\n \t\t\tblob: setters.get(\"blob\")?.value ?? null,\n \t\t};\n-\t\treturn { attrs, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };\n+\t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };\n \t}\n \n \tget #known(): string[] {\n@@ -431,7 +434,7 @@\n \tsequence(path: string): readonly SeqLine[] {\n \t\tif (this.#seqCache?.path === path) return this.#seqCache.seq;\n \t\tconst graph = this.graph;\n-\t\tconst f = this.#file(path);\n+\t\tconst f = this.#file(path, true);\n \t\tconst out: SeqLine[] = new Array(f.seq.length);\n \t\tfor (let i = 0; i < f.seq.length; i++) {\n \t\t\tconst n = f.seq[i]!;\n@@ -450,7 +453,7 @@\n \n \t/** Index of a line in `sequence(path)`, or -1. */\n \tsequenceIndex(path: string, line: LineId): number {\n-\t\tconst f = this.#file(path);\n+\t\tconst f = this.#file(path, true);\n \t\tif (!f.seqIndex) {\n \t\t\tf.seqIndex = new Map();\n \t\t\tfor (let i = 0; i < f.seq.length; i++) f.seqIndex.set(f.seq[i]!, i);\n@@ -528,10 +531,10 @@\n \t\treturn n;\n \t}\n \n-\t#file(path: string): FileState {\n+\t#file(path: string, complete = false): FileState {\n \t\tlet state = this.#files.get(path);\n-\t\tif (!state) {\n-\t\t\tstate = this.graph.atomsIn(path).length === 0 ? NO_FILE : this.#layout(path);\n+\t\tif (!state || (complete && !state.complete)) {\n+\t\t\tstate = this.graph.atomsIn(path).length === 0 ? NO_FILE : this.#layout(path, complete);\n \t\t\tthis.#files.set(path, state);\n \t\t}\n \t\treturn state;"},{"path":"worker/project/test/stored-membership.test.ts","added":23,"removed":0,"diff":"--- a/worker/project/test/stored-membership.test.ts\n+++ b/worker/project/test/stored-membership.test.ts\n@@ -5,6 +5,29 @@\n import { MemoryStore, Project } from \"../project.ts\";\n import { Membership } from \"../spaces.ts\";\n \n+test(\"key-only scans do not decode or retain values through overridden entry iterators\", () => {\n+\tconst storage = new SqlState();\n+\tconst seed = new StoredMap<string, number>(storage, \"keys-only\");\n+\tseed.set(\"old\", 1).set(\"kept\", 2);\n+\tseed.delete(\"old\");\n+\tseed.set(\"old\", 3);\n+\tclass ValuesForbidden extends StoredMap<string, number> {\n+\t\toverride entries(): MapIterator<[string, number]> {\n+\t\t\tthrow new Error(\"key scans must not invoke retaining value iterators\");\n+\t\t}\n+\t}\n+\tconst map = new ValuesForbidden(storage, \"keys-only\", {\n+\t\tencode: (value) => value,\n+\t\tdecode: () => {\n+\t\t\tthrow new Error(\"value decoding forbidden\");\n+\t\t},\n+\t});\n+\tassert.deepEqual([...map.keys()], [\"kept\", \"old\"]);\n+\tmap.clear();\n+\tassert.equal(map.size, 0);\n+\tstorage.db.close();\n+});\n+\n test(\"persistent collections preserve insertion order, deletion, reinsert and undefined values\", () => {\n \tconst storage = new SqlState();\n \tconst map = new StoredMap<string, number | undefined>(storage, \"map\");"}],"ci":null}