{"version":221,"agent":"capacity","message":"Packed layout follows lines written in another file (disk-first 2; abso Capacity).\n\nwhere {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them.\n\n- Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up.\n- New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again.\n- packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project.\n\nNamed tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.","time":1792048744878,"timeIso":"2026-10-15T07:19:04.878Z","changes":3,"change":3599,"files":["src/engine/graph.ts","src/engine/view.ts","worker/project/test/packed-crossings.test.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":39,"removed":7,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -262,6 +262,8 @@\n export type PackedDelete = [number, number];\n /** An attribute set on a file: [seq, name, value]. */\n export type PackedAttr = [number, string, string | null];\n+/** A run written in another file under one of a file's lines: [the parent's n, the run's file index]. */\n+export type PackedCrossing = [number, number];\n const EMPTY_NUMBERS: readonly number[] = Object.freeze([]);\n /** Lines longer than this aren't packed with their file; their text is read on its own. */\n const PACKED_TEXT = 4096;\n@@ -599,13 +601,16 @@\n \t\t\tthis.#fileTexts = storedLists<string | null>(storage, \"file-texts\");\n \t\t\tthis.#fileDeletes = storedLists<PackedDelete>(storage, \"file-deletes\");\n \t\t\tthis.#fileAttrs = storedLists<PackedAttr>(storage, \"file-attrs\");\n+\t\t\tthis.#fileCrossings = storedLists<PackedCrossing>(storage, \"file-crossings\");\n \t\t\tthis.#packFiles = options.packFiles ?? true;\n \t\t}\n \t}\n \n \t// Each file's line history packed, in pages (abso Capacity) ---------------------------------------------------\n \t// For each file, by its path index: every line written in it ([n, parent code, writer seq, k, replaces]) and its\n-\t// text, every delete of one of those lines ([n, deleter seq]), and every attribute set on it ([seq, name, value]).\n+\t// text, every delete of one of those lines ([n, deleter seq]), every attribute set on it ([seq, name, value]), and\n+\t// every run written in another file under one of its lines ([parent n, the run's file]): a line follows its parent,\n+\t// so a run written while its parent was moved elsewhere lays out wherever the parent is.\n \t// Appended as atoms are added, so a view lays a file out from a few pages instead of a row read per line. Kept from\n \t// a fresh adoption on; a graph adopted before has none, and views lay out as before.\n \n@@ -613,19 +618,39 @@\n \t#fileTexts: ReturnType<typeof storedLists<string | null>> | undefined;\n \t#fileDeletes: ReturnType<typeof storedLists<PackedDelete>> | undefined;\n \t#fileAttrs: ReturnType<typeof storedLists<PackedAttr>> | undefined;\n+\t#fileCrossings: ReturnType<typeof storedLists<PackedCrossing>> | undefined;\n \t/** Whether a new stored graph starts packing (GraphOptions.packFiles). */\n \t#packFiles = true;\n-\t/** Whether this graph's files are packed: read once, when first asked, so opening reads nothing. */\n-\t#packedKnown: boolean | undefined;\n+\t/**\n+\t * How this graph's files are packed, read once when first asked so opening reads nothing: 0 not at all, 1 lines,\n+\t * deletes and attributes, 2 the runs written across files as well.\n+\t */\n+\t#formatKnown: number | undefined;\n+\tget #format(): number {\n+\t\tif (this.#formatKnown === undefined) {\n+\t\t\tconst format = this.#storage?.read(\"file-lines:meta\", \"format\");\n+\t\t\tthis.#formatKnown = format === 1 || format === 2 ? format : 0;\n+\t\t}\n+\t\treturn this.#formatKnown;\n+\t}\n \tget #packed(): boolean {\n-\t\tthis.#packedKnown ??= !!this.#storage && this.#storage.read(\"file-lines:meta\", \"format\") === 1;\n-\t\treturn this.#packedKnown;\n+\t\treturn this.#format >= 1;\n \t}\n+\tget #crossings(): boolean {\n+\t\treturn this.#format >= 2;\n+\t}\n \n \t/** Whether this graph keeps each file's line history packed. */\n \tget packedFiles(): boolean {\n \t\treturn this.#packed;\n \t}\n+\t/**\n+\t * Whether a file can be laid out from packed history alone: it also keeps the runs written across files. A graph\n+\t * packed before those were kept lays files out line by line.\n+\t */\n+\tget packedLayout(): boolean {\n+\t\treturn this.#crossings;\n+\t}\n \t/** A path's index, or undefined when nothing was ever written or set in it. */\n \tpathIndexOf(path: string): number | undefined {\n \t\treturn this.#pathIndex.get(path);\n@@ -646,6 +671,9 @@\n \t*packedAttrs(file: number): IterableIterator<PackedAttr> {\n \t\tyield* this.#fileAttrs!.values(String(file));\n \t}\n+\t*packedCrossings(file: number): IterableIterator<PackedCrossing> {\n+\t\tyield* this.#fileCrossings!.values(String(file));\n+\t}\n \n \t/** Where an atom's key and delete lists are when the graph doesn't keep them (#46): the stored atom. */\n \t#lists: ((seq: number) => AtomLists) | undefined;\n@@ -1449,8 +1477,8 @@\n \t\t\tthis.#storage.write(\"ordered-children\", \"format\", 2);\n \t\t}\n \t\tif (this.#storage && this.#atoms.length === 0 && this.#packFiles) {\n-\t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 1);\n-\t\t\tthis.#packedKnown = true;\n+\t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 2);\n+\t\t\tthis.#formatKnown = 2;\n \t\t}\n \n \t\tif (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));\n@@ -1535,6 +1563,10 @@\n \t\t\telse pushOne(this.#runStarts, parent, first);\n \t\t\tconst replacesParent = deletes(run.parent) ? 1 : 0;\n \t\t\tif (this.#packed) {\n+\t\t\t\tif (this.#crossings && parent >= 0) {\n+\t\t\t\t\tconst from = this.#lineFile.at(parent);\n+\t\t\t\t\tif (from !== file) this.#fileCrossings!.append(String(from), [parent, file]);\n+\t\t\t\t}\n \t\t\t\tconst base = this.#lineBase[seq]!;\n \t\t\t\tthis.#fileLines!.appendAll(\n \t\t\t\t\tString(file),"},{"path":"src/engine/view.ts","added":6,"removed":4,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -597,7 +597,7 @@\n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n \t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n-\t\tif (graph.packedFiles && !this.#scratchMoves()) return this.#layoutPacked(path, complete);\n+\t\tif (graph.packedLayout && !this.#scratchMoves()) return this.#layoutPacked(path, complete);\n \t\tif (this.#scratchMoves())\n \t\t\treturn graph.withProjectionScratch((scratch) =>\n \t\t\t\tthis.#layoutResolved(\n@@ -632,9 +632,9 @@\n \t}\n \n \t/**\n-\t * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, and in the\n-\t * files its moved-in lines came from, read a page at a time; the same tree and order as #layoutResolved, built in\n-\t * memory with no read per line.\n+\t * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, in the files\n+\t * its moved-in lines came from, and in the files runs under any of those lines were written in, read a page at a\n+\t * time; the same tree and order as #layoutResolved, built in memory with no read per line.\n \t */\n \t#layoutPacked(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n@@ -670,6 +670,8 @@\n \t\t\t\tif (by) by.push(deleter);\n \t\t\t\telse deleters.set(n, [deleter]);\n \t\t\t}\n+\t\t\t// Runs written elsewhere under this file's lines follow them; the loop reads their files too.\n+\t\t\tfor (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);\n \t\t}\n \t\tconst order = (a: Child, b: Child) =>\n \t\t\tb.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;"},{"path":"worker/project/test/packed-crossings.test.ts","added":58,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/packed-crossings.test.ts\n@@ -0,0 +1,58 @@\n+// Packed file layout and lines written across files (abso Capacity). A line can be written in one file under a\n+// parent written in another: the parent was moved there. When a later move takes the parent on, the line follows\n+// it without a move of its own. Laid out from packed history, the file must still hold those lines, as the\n+// in-memory project's does.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { storedArray } from \"../../../src/engine/state-source.ts\";\n+import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n+import { MemoryStore, Project } from \"../project.ts\";\n+import type { Entry, ProjectStore } from \"../project-types.ts\";\n+import { where } from \"../where.ts\";\n+\n+function writer() {\n+\tconst storage = new SqlState();\n+\tconst entries = storedArray<Entry>(storage, \"canonical-log\");\n+\tconst store: ProjectStore = {\n+\t\tappend(batch) {\n+\t\t\tfor (const entry of batch) entries.push(entry);\n+\t\t},\n+\t};\n+\treturn new Project(store, { writerStorage: storage });\n+}\n+\n+const C = \"const x = 1;\\nconst y = 2;\\n\";\n+\n+function history(project: Project) {\n+\tlet t = 0;\n+\tproject.init({ \"c.ts\": C, \"other.ts\": \"other\\n\" }, t);\n+\tproject.sync(\"cy\");\n+\tproject.move(\"ann\", \"c.ts\", \"d.ts\", ++t);\n+\tassert.equal(project.publish(\"ann\", \"Move c to d\", ++t).ok, true);\n+\t// bob adds a line at the end of d.ts: written in d.ts, under a line written in c.ts.\n+\tproject.sync(\"bob\");\n+\tproject.record(\"bob\", { \"d.ts\": `${C}const z = 3;\\n` }, ++t);\n+\tassert.equal(project.publish(\"bob\", \"Add z\", ++t).ok, true);\n+\t// dee moves d.ts on to e.ts. bob's line follows its parent there with no move of its own.\n+\tproject.sync(\"dee\");\n+\tproject.move(\"dee\", \"d.ts\", \"e.ts\", ++t);\n+\tproject.record(\"dee\", { \"other.ts\": \"other\\nmore\\n\" }, ++t);\n+\tproject.sync(\"idle\");\n+}\n+\n+const text = (project: Project, agent: string, file: string) =>\n+\t(project.draftOf(agent)?.view ?? project.sharedView()).text(file);\n+\n+test(\"a file laid out from packed history keeps lines written in another file under its own lines\", () => {\n+\tconst oracle = new Project(new MemoryStore());\n+\tconst project = writer();\n+\thistory(oracle);\n+\thistory(project);\n+\tassert.equal(text(oracle, \"dee\", \"e.ts\"), `${C}const z = 3;\\n`);\n+\tassert.deepEqual(project.files(), oracle.files());\n+\tassert.deepEqual(where(project), where(oracle));\n+\tfor (const agent of [\"ann\", \"bob\", \"cy\", \"dee\", \"idle\"])\n+\t\tfor (const file of [\"c.ts\", \"d.ts\", \"e.ts\"])\n+\t\t\tassert.equal(text(project, agent, file), text(oracle, agent, file), `${agent} ${file}`);\n+});"}],"ci":null}