{"version":166,"agent":"codex-capacity-chair","message":"Read long insertion text lazily and stream files through Git commit construction","time":1791954093327,"timeIso":"2026-10-14T05:01:33.327Z","changes":6,"change":2473,"files":["server/src/push.ts","server/test/push.test.ts","src/engine/experimental/projection-reader.ts","src/engine/graph.ts","src/engine/test/graph-long-text.test.ts","src/engine/test/projection-reader.test.ts"],"draft":null,"diff":[{"path":"server/src/push.ts","added":2,"removed":2,"diff":"--- a/server/src/push.ts\n+++ b/server/src/push.ts\n@@ -170,10 +170,10 @@\n \t// Each file goes into the tree as a blob with its mode (#27): 100755 for exec, 120000 for a link, whose blob is\n \t// its target.\n \tconst enc = new TextEncoder();\n-\tfor (const [path, text] of Object.entries(shared.files)) {\n+\tfor (const path of Object.keys(shared.files)) {\n \t\tconst mode = shared.modes?.[path];\n \t\tconst link = typeof mode?.link === \"string\" ? mode.link : null;\n-\t\tconst bytes = enc.encode(link ?? text);\n+\t\tconst bytes = enc.encode(link ?? shared.files[path]!);\n \t\tawait put(path, bytes, link !== null ? \"120000\" : mode?.exec ? \"100755\" : \"100644\", await blobOid(bytes));\n \t}\n \tconst agent = shared.last?.agent ?? \"abso\";"},{"path":"server/test/push.test.ts","added":27,"removed":0,"diff":"--- a/server/test/push.test.ts\n+++ b/server/test/push.test.ts\n@@ -22,6 +22,33 @@\n });\n \n describe(\"commitShared\", () => {\n+\tit(\"reads one lazy file at a time and does not read symlink placeholder text\", async (t) => {\n+\t\tconst fs = new MemoryFS();\n+\t\tconst dir = \"/repo\";\n+\t\tawait git.init({ fs, dir, defaultBranch: \"main\" });\n+\t\tlet writes = 0;\n+\t\tconst writeBlob = git.writeBlob;\n+\t\tt.mock.method(git, \"writeBlob\", async (options: Parameters<typeof writeBlob>[0]) => {\n+\t\t\tconst result = await writeBlob(options);\n+\t\t\twrites++;\n+\t\t\treturn result;\n+\t\t});\n+\t\tconst files = {\n+\t\t\tget a() {\n+\t\t\t\tassert.equal(writes, 0);\n+\t\t\t\treturn \"first\";\n+\t\t\t},\n+\t\t\tget b() {\n+\t\t\t\tassert.equal(writes, 1);\n+\t\t\t\treturn \"second\";\n+\t\t\t},\n+\t\t\tget link(): string {\n+\t\t\t\tthrow Error(\"symlink placeholder text must not be read\");\n+\t\t\t},\n+\t\t};\n+\t\tawait commitShared(fs, dir, null, { version: 0, files, modes: { link: { link: \"a\" } } }, () => null);\n+\t\tassert.equal(writes, 3);\n+\t});\n \tit(\"writes shared as a commit with its modes, then only what changed\", async () => {\n \t\tconst fs = new MemoryFS();\n \t\tconst dir = \"/repo\";"},{"path":"src/engine/experimental/projection-reader.ts","added":18,"removed":3,"diff":"--- a/src/engine/experimental/projection-reader.ts\n+++ b/src/engine/experimental/projection-reader.ts\n@@ -1,6 +1,5 @@\n import { startNode } from \"../keys.ts\";\n import { StableSet } from \"../state-source.ts\";\n-import { joinLines } from \"../text.ts\";\n import type { FileAttrs, ReadView, SeqLine, VisibleLine } from \"../view.ts\";\n import type { ExperimentalMarkerProjection, MarkerState } from \"./projection-marker.ts\";\n \n@@ -74,7 +73,14 @@\n \t}\n \tlineNumber(path: string, line: string): number {\n \t\tthis.#assertLive();\n-\t\treturn this.lines(path).findIndex((item) => item.id === line);\n+\t\tlet index = 0;\n+\t\tfor (const id of this.#adapter.lineIds(this.#state, path)) {\n+\t\t\tthis.#assertLive();\n+\t\t\tif (id === line) return index;\n+\t\t\tindex++;\n+\t\t}\n+\t\tthis.#assertLive();\n+\t\treturn -1;\n \t}\n \tsameText(path: string, other: ReadView): boolean {\n \t\tthis.#assertLive();\n@@ -193,7 +199,16 @@\n \t}\n \ttext(path: string): string {\n \t\tthis.#assertLive();\n-\t\treturn joinLines([...this.visibleLines(path)].map((line) => line.text));\n+\t\tlet text = \"\",\n+\t\t\tpart = \"\";\n+\t\tfor (const line of this.visibleLines(path)) {\n+\t\t\tpart += `${line.text}\\n`;\n+\t\t\tif (part.length >= 16384) {\n+\t\t\t\ttext += part;\n+\t\t\t\tpart = \"\";\n+\t\t\t}\n+\t\t}\n+\t\treturn text + part;\n \t}\n \thasFile(path: string): boolean {\n \t\tthis.#assertLive();"},{"path":"src/engine/graph.ts","added":6,"removed":1,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -429,7 +429,12 @@\n \t\t\t\t\t}\n \t\t\t\t\tconst listCount = Object.keys(lists).length;\n \t\t\t\t\tconst hasLists = listCount > 0;\n-\t\t\t\t\tif (atom.inserts.length > 256 || atom.inserts.some((run) => run.lines.length > 256)) {\n+\t\t\t\t\tlet insertionCharacters = 0;\n+\t\t\t\t\tif (\n+\t\t\t\t\t\tatom.inserts.length > 256 ||\n+\t\t\t\t\t\tatom.inserts.some((run) => run.lines.length > 256) ||\n+\t\t\t\t\t\tatom.inserts.some((run) => run.lines.some((line) => (insertionCharacters += line.length) > 65536))\n+\t\t\t\t\t) {\n \t\t\t\t\t\tconst collection = `atom-inserts:${input.seq}`;\n \t\t\t\t\t\tconst runs = storedArray<unknown>(storage, collection);\n \t\t\t\t\t\tlet runIndex = 0;"},{"path":"src/engine/test/graph-long-text.test.ts","added":22,"removed":0,"diff":"--- a/src/engine/test/graph-long-text.test.ts\n+++ b/src/engine/test/graph-long-text.test.ts\n@@ -4,6 +4,28 @@\n import { Graph } from \"../graph.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"large insertion text stays lazy even when the run has few lines\", (t) => {\n+\tconst storage = new SqlState();\n+\tt.after(() => storage.db.close());\n+\tconst memory = new MemoryStore();\n+\tconst line = \"x\".repeat(100000);\n+\tnew Project(memory).init({ \"a.txt\": `${line}\\n${line}\\n${line}\\n` }, 0);\n+\tconst entry = memory.entries[0]!;\n+\tif (entry.type !== \"init\") throw Error(\"expected init\");\n+\tnew Graph({ storage }).add(entry.atom);\n+\tconst read = storage.read.bind(storage);\n+\tlet textReads = 0;\n+\tt.mock.method(storage, \"read\", (collection: string, key: string) => {\n+\t\tif (collection === \"atom-text:long:chunks\") textReads++;\n+\t\treturn read(collection, key);\n+\t});\n+\tconst atom = new Graph({ storage }).atom(\"a0\");\n+\tassert.equal(atom.inserts[0]!.lines.length, 3);\n+\tassert.equal(textReads, 0, \"reading line count must not decode the complete run\");\n+\tassert.equal(atom.inserts[0]!.lines[1], line);\n+\tassert.equal(textReads, Math.ceil(line.length / 16384), \"an indexed read decodes only the selected line\");\n+});\n+\n test(\"persistent graph stores long lines in chunks and reopens exact text\", () => {\n \tconst storage = new SqlState();\n \ttry {"},{"path":"src/engine/test/projection-reader.test.ts","added":24,"removed":0,"diff":"--- a/src/engine/test/projection-reader.test.ts\n+++ b/src/engine/test/projection-reader.test.ts\n@@ -10,6 +10,30 @@\n import { Repo } from \"./helpers.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"projected text streams lines and line lookup does not read file text\", (t) => {\n+\tconst storage = new SqlState();\n+\tt.after(() => storage.db.close());\n+\tconst text = `${\"x\".repeat(40000)}\\nsecond\\nthird\\n`;\n+\tconst repo = Repo.init({ \"f.txt\": text, \"empty.txt\": \"\" });\n+\tconst graph = new Graph({ storage: new CachedStateStorage(storage) });\n+\tgraph.add(repo.graph.atom(\"a0\"));\n+\tconst adapter = new ExperimentalMarkerProjection(storage, graph, \"f.txt\", \"streamed-text\");\n+\tconst state = adapter.apply(adapter.empty(), graph.atom(\"a0\"));\n+\tconst reader = new ProjectionReader(adapter, state, () => {});\n+\tt.mock.method(reader, \"lines\", () => {\n+\t\tthrow Error(\"full line array forbidden\");\n+\t});\n+\tassert.equal(reader.text(\"f.txt\"), text);\n+\tassert.equal(reader.text(\"empty.txt\"), \"\");\n+\tassert.equal(reader.text(\"missing.txt\"), \"\");\n+\tconst ids = [...adapter.lineIds(state, \"f.txt\")];\n+\tt.mock.method(graph, \"textOf\", () => {\n+\t\tthrow Error(\"line lookup must not read text\");\n+\t});\n+\tfor (let i = 0; i < ids.length; i++) assert.equal(reader.lineNumber(\"f.txt\", ids[i]!), i);\n+\tassert.equal(reader.lineNumber(\"f.txt\", \"missing\"), -1);\n+});\n+\n test(\"unchanged atom builder consumes the private reader for replacement and insertion edits\", () => {\n \tconst storage = new SqlState();\n \ttry {"}],"ci":null}