{"version":164,"agent":"codex-capacity-chair","message":"Fix disk-backed historical paths, empty queues and canonical frame integrity","time":1791952865078,"timeIso":"2026-10-14T04:41:05.078Z","changes":11,"change":2447,"files":["server/src/decoded-frames.ts","server/src/json-events.ts","server/src/small-frame-json.ts","server/src/stored-json.ts","server/test/canonical-frame-numbers.test.ts","server/test/projected-path-history.test.ts","server/test/projected-queue.test.ts","server/test/small-frame-integrity.test.ts","src/engine/test/projection-reader-integrity.test.ts","worker/project/pathindex.ts","worker/project/queue.ts"],"draft":null,"diff":[{"path":"server/src/decoded-frames.ts","added":1,"removed":1,"diff":"--- a/server/src/decoded-frames.ts\n+++ b/server/src/decoded-frames.ts\n@@ -49,7 +49,7 @@\n \t\t\t\tif (size <= 4096) {\n \t\t\t\t\tyield { seq, bytes: size, entry: smallFrameJson(log.frameChunks(seq)) as Entry };\n \t\t\t\t} else {\n-\t\t\t\t\tstoreJson(state, String(seq), log.frameChunks(seq));\n+\t\t\t\t\tstoreJson(state, String(seq), log.frameChunks(seq), { finiteNumbers: true });\n \t\t\t\t\tyield { seq, bytes: size, entry: storedJsonView(new StoredJson(reads, String(seq))) as Entry };\n \t\t\t\t}\n \t\t\t}"},{"path":"server/src/json-events.ts","added":7,"removed":2,"diff":"--- a/server/src/json-events.ts\n+++ b/server/src/json-events.ts\n@@ -6,7 +6,10 @@\n \t| { kind: \"value\"; value: number | boolean | null };\n \n /** Structural JSON decoding. Retains nesting and one bounded string fragment, not a decoded tree. */\n-export function* jsonEvents(chunks: Iterable<string>): IterableIterator<JsonEvent> {\n+export function* jsonEvents(\n+\tchunks: Iterable<string>,\n+\toptions: { finiteNumbers?: boolean } = {},\n+): IterableIterator<JsonEvent> {\n \tconst cursor = new JsonChunkCursor(chunks);\n \tconst whitespace = () => {\n \t\twhile (cursor.peek() !== undefined && /[ \\t\\n\\r]/.test(cursor.peek()!)) cursor.take();\n@@ -61,7 +64,9 @@\n \t\t\tyield { kind: \"value\", value: token === \"null\" ? null : token === \"true\" };\n \t\t} else {\n \t\t\tif (!/^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/.test(token)) throw Error(\"invalid JSON scalar\");\n-\t\t\tyield { kind: \"value\", value: Number(token) };\n+\t\t\tconst number = Number(token);\n+\t\t\tif (options.finiteNumbers && !Number.isFinite(number)) throw Error(\"non-finite JSON number\");\n+\t\t\tyield { kind: \"value\", value: number };\n \t\t}\n \t}\n \ttry {"},{"path":"server/src/small-frame-json.ts","added":9,"removed":2,"diff":"--- a/server/src/small-frame-json.ts\n+++ b/server/src/small-frame-json.ts\n@@ -10,6 +10,13 @@\n \t// Count UTF-8 after joining so a surrogate pair split across chunks counts once.\n \tif (new TextEncoder().encode(text).byteLength > 4096) throw Error(\"small canonical frame exceeds bound\");\n \t// Preserve depth, key and scalar limits; the fast path must not change acceptance.\n-\tfor (const event of jsonEvents([text])) void event;\n-\treturn JSON.parse(text);\n+\tfor (const event of jsonEvents([text], { finiteNumbers: true })) void event;\n+\tconst freeze = (value: unknown): unknown => {\n+\t\tif (value !== null && typeof value === \"object\") {\n+\t\t\tfor (const child of Object.values(value)) freeze(child);\n+\t\t\tObject.freeze(value);\n+\t\t}\n+\t\treturn value;\n+\t};\n+\treturn freeze(JSON.parse(text));\n }"},{"path":"server/src/stored-json.ts","added":7,"removed":2,"diff":"--- a/server/src/stored-json.ts\n+++ b/server/src/stored-json.ts\n@@ -3,10 +3,15 @@\n import { type JsonEvent, jsonEvents } from \"./json-events.ts\";\n \n /** Temporary decoded JSON on disk. A root is published only after complete parsing. */\n-export function storeJson(storage: GraphStateStorage, namespace: string, chunks: Iterable<string>): number {\n+export function storeJson(\n+\tstorage: GraphStateStorage,\n+\tnamespace: string,\n+\tchunks: Iterable<string>,\n+\toptions: { finiteNumbers?: boolean } = {},\n+): number {\n \treturn storage.transaction(() => {\n \t\tif (storage.read(namespace, \"root\") !== undefined) throw Error(\"decoded JSON already exists\");\n-\t\tconst events = jsonEvents(chunks);\n+\t\tconst events = jsonEvents(chunks, options);\n \t\tlet nextId = 0;\n \t\tconst take = (): JsonEvent => {\n \t\t\tconst event = events.next();"},{"path":"server/test/canonical-frame-numbers.test.ts","added":32,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/canonical-frame-numbers.test.ts\n@@ -0,0 +1,32 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { withDecodedFrames } from \"../src/decoded-frames.ts\";\n+import { SqliteLog } from \"../src/engine-project.ts\";\n+import { SqliteWriterState } from \"../src/writer-host.ts\";\n+import { memoryStorage } from \"./helpers.ts\";\n+\n+for (const padding of [0, 5000]) {\n+\ttest(`canonical frames reject numeric overflow with ${padding} padding bytes and clean scratch`, (t) => {\n+\t\tconst storage = memoryStorage();\n+\t\tt.after(() => storage.db.close());\n+\t\tconst log = new SqliteLog(storage);\n+\t\tconst json = `{\"type\":\"join\",\"agent\":\"${\"a\".repeat(padding)}\",\"version\":1e400}`;\n+\t\tstorage.sql.exec(\"INSERT INTO log(seq,part,text) VALUES(?,?,?)\", 0, 0, json);\n+\t\tSqliteWriterState.initialize(storage);\n+\t\tconst rows = () => storage.db.prepare(\"SELECT * FROM writer_state ORDER BY namespace,collection,key,part\").all();\n+\t\tconst before = rows();\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\twithDecodedFrames(\n+\t\t\t\t\tstorage,\n+\t\t\t\t\t\"number-frame\",\n+\t\t\t\t\tlog,\n+\t\t\t\t\t{ from: 0, to: 1, maxEntries: 1, maxBytes: 10000, digest: \"\" },\n+\t\t\t\t\t(frames) => [...frames],\n+\t\t\t\t),\n+\t\t\t/non-finite JSON number/,\n+\t\t);\n+\t\tassert.deepEqual(rows(), before);\n+\t\tassert.equal(storage.db.prepare(\"SELECT text FROM log WHERE seq=0 AND part=0\").get()!.text, json);\n+\t});\n+}"},{"path":"server/test/projected-path-history.test.ts","added":42,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/projected-path-history.test.ts\n@@ -0,0 +1,42 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { answer } from \"../../worker/project/http.ts\";\n+import { Project } from \"../../worker/project/project.ts\";\n+import { DiskFirstRuntime } from \"../src/disk-first-runtime.ts\";\n+import { EngineProject } from \"../src/engine-project.ts\";\n+import { memoryStorage } from \"./helpers.ts\";\n+\n+test(\"tree and path history after a move match memory without persistent read writes\", (t) => {\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tconst memory = EngineProject.open(storage);\n+\tassert.equal(answer(memory, \"init\", undefined, { files: { \"a.txt\": \"one\\ntwo\\n\" } }).status, 200);\n+\tassert.equal(answer(memory, \"move\", \"alice\", { from: \"a.txt\", to: \"b.txt\" }).status, 200);\n+\tassert.equal(answer(memory, \"publish\", \"alice\", { message: \"Move\" }).status, 200);\n+\tconst requests = [\n+\t\t[\"tree\", {}],\n+\t\t[\"tree\", { version: 0 }],\n+\t\t[\"path\", { path: \"a.txt\" }],\n+\t\t[\"path\", { path: \"b.txt\" }],\n+\t] as const;\n+\tconst expected = requests.map(([op, body]) => answer(memory, op, \"alice\", body));\n+\tfor (const result of expected) assert.equal(result.status, 200, JSON.stringify(result));\n+\tt.mock.method(Project, \"load\", () => {\n+\t\tthrow Error(\"full-history replay forbidden\");\n+\t});\n+\tconst runtime = () => new DiskFirstRuntime(storage, \"path-history\", \"path-history\");\n+\twhile (!runtime().preparePage(() => {}).ready) {}\n+\tconst rows = () => storage.db.prepare(\"SELECT * FROM writer_state ORDER BY namespace,collection,key,part\").all();\n+\tconst before = rows();\n+\tfor (let i = 0; i < requests.length; i++) {\n+\t\tconst [op, body] = requests[i]!;\n+\t\tassert.deepEqual(\n+\t\t\truntime().read(\n+\t\t\t\t(calls) => answer(calls, op, \"alice\", body),\n+\t\t\t\t() => {},\n+\t\t\t),\n+\t\t\texpected[i],\n+\t\t);\n+\t}\n+\tassert.deepEqual(rows(), before);\n+});"},{"path":"server/test/projected-queue.test.ts","added":7,"removed":0,"diff":"--- a/server/test/projected-queue.test.ts\n+++ b/server/test/projected-queue.test.ts\n@@ -76,6 +76,13 @@\n \t\t() => {},\n \t);\n \tassert.deepEqual(landed.versions, [{ id: 1, version: 1 }]);\n+\tconst empty = runtime().read(\n+\t\t(c) => (c as unknown as { project: Project }).project.queueCandidate(4),\n+\t\t() => {},\n+\t);\n+\tassert.deepEqual(empty.ids, []);\n+\tassert.deepEqual(empty.files, candidate.files);\n+\tassert.equal(empty.tree, candidate.tree);\n \tassert.equal(\n \t\truntime().read(\n \t\t\t(c) => c.shared().files[\"a.txt\"],"},{"path":"server/test/small-frame-integrity.test.ts","added":24,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/small-frame-integrity.test.ts\n@@ -0,0 +1,24 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { jsonEvents } from \"../src/json-events.ts\";\n+import { smallFrameJson } from \"../src/small-frame-json.ts\";\n+\n+test(\"small decoded frames freeze nested objects and arrays\", () => {\n+\tconst value = smallFrameJson(['{\"items\":[{\"value\":1}]}']) as { items: { value: number }[] };\n+\tassert.equal(Object.isFrozen(value), true);\n+\tassert.equal(Object.isFrozen(value.items), true);\n+\tassert.equal(Object.isFrozen(value.items[0]), true);\n+\tassert.throws(() => value.items.push({ value: 2 }), TypeError);\n+\tassert.throws(() => {\n+\t\tvalue.items[0]!.value = 3;\n+\t}, TypeError);\n+\tassert.deepEqual(value, { items: [{ value: 1 }] });\n+});\n+\n+test(\"both JSON paths refuse non-finite numeric values\", () => {\n+\tfor (const input of [\"1e400\", \"-1e400\", '{\"n\":1e400}', \"[1e400]\"]) {\n+\t\tassert.throws(() => smallFrameJson([input]), /non-finite/);\n+\t\tassert.throws(() => [...jsonEvents([input], { finiteNumbers: true })], /non-finite/);\n+\t}\n+\tassert.equal(smallFrameJson([\"1e308\"]), 1e308);\n+});"},{"path":"src/engine/test/projection-reader-integrity.test.ts","added":29,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/projection-reader-integrity.test.ts\n@@ -0,0 +1,29 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { ExperimentalMarkerProjection } from \"../experimental/projection-marker.ts\";\n+import { ProjectionReader } from \"../experimental/projection-reader.ts\";\n+import { Graph } from \"../graph.ts\";\n+import { Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"file lookup rejects a missing marker for an included writer instead of following ancestry\", (t) => {\n+\tconst storage = new SqlState();\n+\tt.after(() => storage.db.close());\n+\tconst repo = Repo.init({ \"f.txt\": \"one\\ntwo\\n\" });\n+\tconst graph = new Graph({ storage });\n+\tgraph.add(repo.graph.atom(\"a0\"));\n+\tconst adapter = new ExperimentalMarkerProjection(storage, graph, \"f.txt\", \"included-marker\");\n+\tconst state = adapter.apply(adapter.empty(), graph.atom(\"a0\"));\n+\tconst reader = new ProjectionReader(adapter, state, () => {});\n+\tconst line = [...adapter.lineIds(state, \"f.txt\")][0]!;\n+\tassert.equal(reader.fileOf(line), \"f.txt\");\n+\tconst markerKey = graph.lineN(line) + 1;\n+\tconst get = adapter.markers.get.bind(adapter.markers);\n+\tt.mock.method(adapter.markers, \"get\", (root: Parameters<typeof get>[0], key: number) =>\n+\t\tkey === markerKey ? undefined : get(root, key),\n+\t);\n+\tt.mock.method(graph, \"lineParent\", () => {\n+\t\tthrow Error(\"included writer must not use ancestry fallback\");\n+\t});\n+\tassert.throws(() => reader.fileOf(line), /missing projected line/);\n+});"},{"path":"worker/project/pathindex.ts","added":3,"removed":1,"diff":"--- a/worker/project/pathindex.ts\n+++ b/worker/project/pathindex.ts\n@@ -141,7 +141,9 @@\n \t\t\treturn running;\n \t\t};\n \t\tfor (let v = index.upTo + 1; v <= last(space); v++) {\n-\t\t\tif (space.name === SHARED && !this.#keptFiles(space, v)) {\n+\t\t\t// Persistent graphs use the indexed version reader; a raw View would\n+\t\t\t// rebuild move scratch state and copy historical membership during a read.\n+\t\t\tif (space.name === SHARED && !this.#deps.graph.hasOrderedChildren && !this.#keptFiles(space, v)) {\n \t\t\t\tif (v > 0 && !views.has(v - 1)) views.set(v - 1, new View(this.#deps.graph, new Set(setAt(v - 1))));\n \t\t\t\tviews.set(v, new View(this.#deps.graph, new Set(setAt(v))));\n \t\t\t}"},{"path":"worker/project/queue.ts","added":6,"removed":3,"diff":"--- a/worker/project/queue.ts\n+++ b/worker/project/queue.ts\n@@ -237,9 +237,12 @@\n \thost.needInit();\n \tconst items = host.queued().slice(0, Math.max(0, n));\n \tconst changes = items.flatMap((q) => q.changes);\n-\tconst view = host.sharedOverlay\n-\t\t? host.sharedOverlay(changes)\n-\t\t: host.view(unionOverlay(host.setOf(host.shared()), changes));\n+\tconst view =\n+\t\tchanges.length === 0\n+\t\t\t? host.sharedView()\n+\t\t\t: host.sharedOverlay\n+\t\t\t\t? host.sharedOverlay(changes)\n+\t\t\t\t: host.view(unionOverlay(host.setOf(host.shared()), changes));\n \tconst files = view.files();\n \tconst modes = modesOf(view);\n \tconst blobs = view.blobs();"}],"ci":null}