{"version":144,"agent":"codex-capacity-chair","message":"Allow transactional bulk cleanup of temporary projection pages (#16)","time":1791855586601,"timeIso":"2026-10-13T01:39:46.601Z","changes":2,"change":1284,"files":["src/engine/experimental/projection-overlay-storage.ts","src/engine/test/projection-overlay-storage.test.ts"],"draft":null,"diff":[{"path":"src/engine/experimental/projection-overlay-storage.ts","added":10,"removed":2,"diff":"--- a/src/engine/experimental/projection-overlay-storage.ts\n+++ b/src/engine/experimental/projection-overlay-storage.ts\n@@ -6,11 +6,13 @@\n export class ProjectionOverlayStorage implements GraphStateStorage {\n \treadonly #base: GraphStateStorage;\n \treadonly #collection: string;\n+\treadonly #clearCollection?: (collection: string) => void;\n \t#open = true;\n-\tconstructor(base: GraphStateStorage, namespace: string) {\n+\tconstructor(base: GraphStateStorage, namespace: string, clearCollection?: (collection: string) => void) {\n \t\tif (!namespace) throw Error(\"missing projection overlay namespace\");\n \t\tthis.#base = base;\n \t\tthis.#collection = `projection:temporary:${namespace}`;\n+\t\tthis.#clearCollection = clearCollection;\n \t\tfor (const _ of base.entries(this.#collection)) throw Error(\"projection overlay namespace is occupied\");\n \t}\n \t#check(): void {\n@@ -64,7 +66,13 @@\n \tclose(): void {\n \t\tif (!this.#open) return;\n \t\tthis.#base.transaction(() => {\n-\t\t\tfor (const [key] of this.#base.entries(this.#collection)) this.#base.remove(this.#collection, key);\n+\t\t\tif (this.#clearCollection) {\n+\t\t\t\tconst result: unknown = this.#clearCollection(this.#collection);\n+\t\t\t\tif (result && typeof result === \"object\" && \"then\" in result)\n+\t\t\t\t\tthrow Error(\"overlay cleanup must be synchronous\");\n+\t\t\t} else {\n+\t\t\t\tfor (const [key] of this.#base.entries(this.#collection)) this.#base.remove(this.#collection, key);\n+\t\t\t}\n \t\t});\n \t\tthis.#open = false;\n \t}"},{"path":"src/engine/test/projection-overlay-storage.test.ts","added":33,"removed":0,"diff":"--- a/src/engine/test/projection-overlay-storage.test.ts\n+++ b/src/engine/test/projection-overlay-storage.test.ts\n@@ -3,6 +3,39 @@\n import { ProjectionOverlayStorage } from \"../experimental/projection-overlay-storage.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"host cleanup deletes only its overlay and a failed deletion rolls back without scanning\", (t) => {\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tlet fail = true;\n+\t\tconst overlay = new ProjectionOverlayStorage(storage, \"bulk\", (collection) => {\n+\t\t\tassert.equal(collection, \"projection:temporary:bulk\");\n+\t\t\tstorage.db.prepare(\"DELETE FROM state WHERE collection = ?\").run(collection);\n+\t\t\tif (fail) throw Error(\"cleanup failed after deletion\");\n+\t\t});\n+\t\tstorage.write(\"pages\", \"durable\", 1);\n+\t\tstorage.write(\"projection:temporary:other\", \"other\", 2);\n+\t\tfor (let i = 0; i < 100; i++) overlay.write(\"pages\", String(i), i);\n+\t\tconst before = storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();\n+\t\tt.mock.method(storage, \"entries\", () => {\n+\t\t\tthrow Error(\"cleanup must not enumerate rows\");\n+\t\t});\n+\t\tassert.throws(() => overlay.close(), /cleanup failed/);\n+\t\tassert.deepEqual(storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all(), before);\n+\t\tassert.equal(overlay.read(\"pages\", \"99\"), 99);\n+\t\tfail = false;\n+\t\toverlay.close();\n+\t\tassert.equal(storage.read(\"pages\", \"durable\"), 1);\n+\t\tassert.equal(storage.read(\"projection:temporary:other\", \"other\"), 2);\n+\t\tassert.equal(\n+\t\t\tstorage.db.prepare(\"SELECT COUNT(*) AS n FROM state WHERE collection = ?\").get(\"projection:temporary:bulk\")!.n,\n+\t\t\t0,\n+\t\t);\n+\t\tassert.throws(() => overlay.read(\"pages\", \"99\"), /closed/);\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});\n+\n test(\"temporary projection pages shadow committed pages and cleanup preserves durable writes\", () => {\n \tconst storage = new SqlState();\n \ttry {"}],"ci":null}