{"version":148,"agent":"codex-capacity-chair","message":"Read graph identities and metadata without decoding atom payloads","time":1791859187606,"timeIso":"2026-10-13T02:39:47.606Z","changes":2,"change":1284,"files":["src/engine/graph.ts","src/engine/test/graph-metadata-indexed.test.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":9,"removed":7,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -495,7 +495,7 @@\n \n \t/** lamport(a) = 1 + max lamport of its deps; 0 for an atom with no deps (such as a0). */\n \tlamport(id: AtomId): number {\n-\t\tthis.atom(id);\n+\t\tif (!this.has(id)) throw new EngineError(\"unknown-atom\", `no atom ${id}`);\n \t\treturn this.#lamport[this.#seq(id)]!;\n \t}\n \n@@ -510,7 +510,7 @@\n \t\tconst seq = this.#lineAtom.at(n);\n \t\treturn {\n \t\t\tid,\n-\t\t\tatom: this.#atoms[seq]!.id,\n+\t\t\tatom: this.idOfSeq(seq),\n \t\t\tk: n - this.#lineBase[seq]!,\n \t\t\tfile: this.#paths[this.#lineFile.at(n)]!,\n \t\t\tparent: this.#nodeName(this.#lineParent.at(n)),\n@@ -527,7 +527,7 @@\n \t/** The atom that wrote a line, or undefined: line(id).atom without making the record. */\n \tlineAtom(id: LineId): AtomId | undefined {\n \t\tconst n = this.#lineN(id);\n-\t\treturn n < 0 ? undefined : this.#atoms[this.#lineAtom.at(n)]!.id;\n+\t\treturn n < 0 ? undefined : this.idOfSeq(this.#lineAtom.at(n));\n \t}\n \n \t/** The file a line was written in, or undefined: line(id).file without making the record. */\n@@ -586,7 +586,9 @@\n \n \t/** The atom id with this seq, as the graph keeps it. */\n \tidOfSeq(seq: number): AtomId {\n-\t\treturn this.#atoms[seq]!.id;\n+\t\tif (!Number.isSafeInteger(seq) || seq < 0 || seq >= this.#atoms.length)\n+\t\t\tthrow new EngineError(\"unknown-atom\", `no atom at sequence ${seq}`);\n+\t\treturn atomId(seq);\n \t}\n \n \tlamportOfSeq(seq: number): number {\n@@ -741,7 +743,7 @@\n \t/** A line's id from its n. */\n \t#lineName(n: number): LineId {\n \t\tconst seq = this.#lineAtom.at(n);\n-\t\treturn `${this.#atoms[seq]!.id}.${n - this.#lineBase[seq]!}`;\n+\t\treturn `${this.idOfSeq(seq)}.${n - this.#lineBase[seq]!}`;\n \t}\n \n \t/** A node's code: a line's n, or -1 - a path's index for a start node; undefined when unknown. */\n@@ -781,7 +783,7 @@\n \tdeletersOf(line: LineId): readonly AtomId[] {\n \t\tconst n = this.#lineN(line);\n \t\tif (n < 0) return EMPTY;\n-\t\treturn [...this.eachDeleterSeqOf(n)].map((seq) => this.#atoms[seq]!.id);\n+\t\treturn [...this.eachDeleterSeqOf(n)].map((seq) => this.idOfSeq(seq));\n \t}\n \n \twritersOf(key: Key): readonly AtomId[] {\n@@ -837,7 +839,7 @@\n \t * start node, that file): a set's moves can have taken them elsewhere.\n \t */\n \tfilesOf(id: AtomId): readonly string[] {\n-\t\tthis.atom(id);\n+\t\tif (!this.has(id)) throw new EngineError(\"unknown-atom\", `no atom ${id}`);\n \t\treturn this.#atomFiles[this.#seq(id)]!;\n \t}\n "},{"path":"src/engine/test/graph-metadata-indexed.test.ts","added":33,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/graph-metadata-indexed.test.ts\n@@ -0,0 +1,33 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph } from \"../graph.ts\";\n+import { Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"indexed identities and metadata do not decode atom payloads\", () => {\n+\tconst db = new SqlState();\n+\ttry {\n+\t\tconst repo = Repo.init({ \"a.txt\": \"one\\ntwo\\n\" });\n+\t\tconst graph = new Graph({ storage: db });\n+\t\tgraph.add(repo.graph.atom(\"a0\"));\n+\t\tconst read = db.read.bind(db);\n+\t\tdb.read = (collection, key) => {\n+\t\t\tif (collection === \"atoms\") throw Error(\"atom payload read forbidden\");\n+\t\t\treturn read(collection, key);\n+\t\t};\n+\t\tassert.equal(graph.idOfSeq(0), \"a0\");\n+\t\tassert.equal(graph.lamport(\"a0\"), 0);\n+\t\tassert.deepEqual(graph.filesOf(\"a0\"), [\"a.txt\"]);\n+\t\tassert.equal(graph.line(\"a0.0\")?.atom, \"a0\");\n+\t\tassert.equal(graph.lineIdOf(0), \"a0.0\");\n+\t\tfor (const seq of [-1, 1, 0.5, NaN, Infinity]) assert.throws(() => graph.idOfSeq(seq), /no atom/);\n+\t\tfor (const id of [\"a1\", \"a00\", \"a-1\", \"invalid\"]) {\n+\t\t\tassert.throws(() => graph.lamport(id), /no atom/);\n+\t\t\tassert.throws(() => graph.filesOf(id), /no atom/);\n+\t\t}\n+\t\tassert.equal(graph.line(\"a1.0\"), undefined);\n+\t\tassert.throws(() => graph.atom(\"a0\"), /payload read forbidden/);\n+\t} finally {\n+\t\tdb.db.close();\n+\t}\n+});"}],"ci":null}