{"version":124,"agent":"codex-capacity-chair","message":"Reduce implicit dependencies to their maximal frontier","time":1791836238914,"timeIso":"2026-10-12T20:17:18.914Z","changes":7,"change":1284,"files":["src/engine/build.ts","src/engine/test/build.test.ts","src/engine/test/concurrent.test.ts","src/engine/test/record-query-contract.test.ts","src/engine/test/view.test.ts"],"draft":null,"diff":[{"path":"src/engine/build.ts","added":24,"removed":5,"diff":"--- a/src/engine/build.ts\n+++ b/src/engine/build.ts\n@@ -333,7 +333,12 @@\n  * - creating a file over a deleted one: the atoms that deleted its lines;\n  * - needs and resolves.\n  * Nothing else from the view: not the line below an insertion, not the\n- * tombstones around it.\n+ * tombstones around it. New atoms encode implicit dependencies as maximal\n+ * tips: ancestors reachable through another tip are omitted from direct deps.\n+ * Explicit needs/resolves always remain direct. Existing atoms are not rewritten.\n+ * Direct-edge diagnostics (including why/Deps trailers and missingDeps) therefore\n+ * show fewer redundant edges; transitive closure and dependency ordering remain\n+ * the semantic contract. A missing tip still implies its required ancestors.\n  */\n function deriveDeps(\n \tview: View,\n@@ -347,16 +352,30 @@\n \t},\n ): AtomId[] {\n \tconst graph = view.graph;\n-\tconst deps = new Set<AtomId>(parts.emptiedBy);\n+\t// New atoms retain maximal implicit dependencies. Their transitive closure is\n+\t// unchanged; explicit needs/resolves remain direct edges below.\n+\tconst deps = new Set<AtomId>();\n+\tconst addImplicit = (candidate: AtomId): void => {\n+\t\tif (deps.has(candidate)) return;\n+\t\tconst candidateClock = graph.lamport(candidate);\n+\t\tfor (const previous of deps) {\n+\t\t\tconst previousClock = graph.lamport(previous);\n+\t\t\t// Equal Lamport clocks cannot reach each other; check only the possible direction.\n+\t\t\tif (previousClock > candidateClock && graph.dependsOn(previous, candidate)) return;\n+\t\t\tif (candidateClock > previousClock && graph.dependsOn(candidate, previous)) deps.delete(previous);\n+\t\t}\n+\t\tdeps.add(candidate);\n+\t};\n+\tfor (const id of parts.emptiedBy) addImplicit(id);\n \tfor (const key of [...parts.writes, ...parts.reads, ...parts.holds]) {\n \t\tconst { kind, node } = parseKey(key);\n \t\t// An attribute builds on whoever set it last in the view, the way an insertion builds on a gap's writers;\n \t\t// a move builds on the earlier moves of its lines.\n-\t\tif (kind !== \"attr\" && !isStartNode(node)) deps.add(writerOf(node));\n-\t\tif (kind !== \"line\") for (const writer of graph.eachWriterOf(key)) if (view.set.has(writer)) deps.add(writer);\n+\t\tif (kind !== \"attr\" && !isStartNode(node)) addImplicit(writerOf(node));\n+\t\tif (kind !== \"line\") for (const writer of graph.eachWriterOf(key)) if (view.set.has(writer)) addImplicit(writer);\n \t}\n \tfor (const key of parts.writes) {\n-\t\tfor (const reader of graph.eachReaderOf(key)) if (view.set.has(reader)) deps.add(reader);\n+\t\tfor (const reader of graph.eachReaderOf(key)) if (view.set.has(reader)) addImplicit(reader);\n \t}\n \tfor (const id of parts.needs) deps.add(id);\n \tfor (const id of parts.resolves) deps.add(id);"},{"path":"src/engine/test/build.test.ts","added":12,"removed":6,"diff":"--- a/src/engine/test/build.test.ts\n+++ b/src/engine/test/build.test.ts\n@@ -335,7 +335,8 @@\n \t\tassert.equal(repo.text(\"g.txt\"), \"g1\\ng2\\n\");\n \t\tconst edited = repo.edit({ edits: [{ file: \"g.txt\", old: \"g2\", new: \"G2\" }] });\n \t\tconst removed = repo.edit({ edits: [{ file: \"g.txt\", old: \"g1\\nG2\\n\", new: \"\" }] });\n-\t\tassert.deepEqual(removed.deps, [created.id, edited.id]);\n+\t\tassert.deepEqual(removed.deps, [edited.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(removed.deps), repo.graph.closureOf([created.id, edited.id]));\n \t\tassert.equal(repo.view().hasFile(\"g.txt\"), false);\n \t\tassert.deepEqual(Object.keys(repo.files()), [\"f.txt\"]);\n \t\tassert.deepEqual(repo.view().knownPaths(), [\"f.txt\", \"g.txt\"]);\n@@ -343,7 +344,8 @@\n \t\t// lines hang off the start (gap rule) and on the deletions: it relies on\n \t\t// the file being empty, so its closure shows only the new text.\n \t\tconst again = repo.edit({ edits: [{ file: \"g.txt\", old: \"\", new: \"fresh\\n\" }] });\n-\t\tassert.deepEqual(again.deps, [created.id, edited.id, removed.id]);\n+\t\tassert.deepEqual(again.deps, [removed.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(again.deps), repo.graph.closureOf([created.id, edited.id, removed.id]));\n \t\tassert.equal(repo.text(\"g.txt\"), \"fresh\\n\");\n \t\tassert.equal(repo.text(\"g.txt\", repo.graph.closure(again.id)), \"fresh\\n\");\n \t});\n@@ -395,7 +397,8 @@\n \t\t\treliesOn: [{ file: \"g.txt\", start: 0, end: 1 }],\n \t\t});\n \t\tassert.deepEqual(atom.holds, [lineKey(`${g2.id}.0`)]);\n-\t\tassert.deepEqual(atom.deps, [\"a0\", g2.id]);\n+\t\tassert.deepEqual(atom.deps, [g2.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", g2.id]));\n \t});\n \n \tit(\"reliesOn a range of lines also holds the gaps between them\", () => {\n@@ -436,7 +439,8 @@\n \t\tconst three = repo.edit({ edits: [{ file: \"f.txt\", old: \"three\", new: \"THREE\" }] });\n \t\t// Inserting after \"two\": the gap holds mid (a tombstone hanging off \"two\") and then THREE.\n \t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two\\nnew\\n\", mode: \"after\" }] });\n-\t\tassert.deepEqual(atom.deps, [\"a0\", added.id]);\n+\t\tassert.deepEqual(atom.deps, [added.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", added.id]));\n \t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"new\", \"THREE\", \"four\", \"five\"));\n \t\t// It outranks mid, so it sits directly after \"two\" in any set; in its own\n \t\t// closure mid is back (the deletion isn't in it) and stays below it.\n@@ -481,7 +485,8 @@\n \t\tconst draft = repo.draft({ message: \"N after X\", edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"N\"] }] });\n \t\tassert.deepEqual(repo.check(draft).conflicts, []);\n \t\tconst N = repo.edit({ message: \"N after X\", edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"N\"] }] });\n-\t\tassert.deepEqual(N.deps, [\"a0\", A.id, B.id]);\n+\t\tassert.deepEqual(N.deps, [A.id, B.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(N.deps), repo.graph.closureOf([\"a0\", A.id, B.id]));\n \t\tassert.equal(repo.text(\"f.txt\"), lines(\"X\", \"N\", \"B\", \"A\", \"Y\"));\n \t\tassert.deepEqual(\n \t\t\tconflicts(repo.graph, repo.shared).map((c) => c.atoms),\n@@ -504,7 +509,8 @@\n \t\t// Deleting \"three\" (the line below the insert) touches nothing the insert wrote,\n \t\t// but it changes a line the insert read: a sequential edit, so a dependency.\n \t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"three\\n\", new: \"\" }] });\n-\t\tassert.deepEqual(atom.deps, [\"a0\", between.id]);\n+\t\tassert.deepEqual(atom.deps, [between.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", between.id]));\n \t\tassert.deepEqual(\n \t\t\tcheckDraft(repo.graph, repo.shared, repo.draft({ edits: [{ file: \"f.txt\", old: \"four\\n\", new: \"\" }] })).conflicts,\n \t\t\t[],"},{"path":"src/engine/test/concurrent.test.ts","added":10,"removed":2,"diff":"--- a/src/engine/test/concurrent.test.ts\n+++ b/src/engine/test/concurrent.test.ts\n@@ -453,10 +453,18 @@\n \t\t\t\t[before, \"before\"],\n \t\t\t] as const) {\n \t\t\t\tsubset(claimsOf(narrow), claimsOf(both), `claims ${name} ⊆ both`);\n-\t\t\t\tsubset(narrow.deps, both.deps, `deps ${name} ⊆ both`);\n+\t\t\t\tsubset(\n+\t\t\t\t\t[...repo.graph.closureOf(narrow.deps)],\n+\t\t\t\t\t[...repo.graph.closureOf(both.deps)],\n+\t\t\t\t\t`dependency closure ${name} ⊆ both`,\n+\t\t\t\t);\n \t\t\t}\n \t\t\tsubset(claimsOf(both), claimsOf(wide), \"claims both ⊆ wide\");\n-\t\t\tsubset(both.deps, wide.deps, \"deps both ⊆ wide\");\n+\t\t\tsubset(\n+\t\t\t\t[...repo.graph.closureOf(both.deps)],\n+\t\t\t\t[...repo.graph.closureOf(wide.deps)],\n+\t\t\t\t\"dependency closure both ⊆ wide\",\n+\t\t\t);\n \t\t\tfor (const other of pool) {\n \t\t\t\tconst [hitAfter, hitBefore, hitBoth, hitWide] = [after, before, both, wide].map(\n \t\t\t\t\t(v) => keyOverlap(v, other).length > 0,"},{"path":"src/engine/test/record-query-contract.test.ts","added":5,"removed":3,"diff":"--- a/src/engine/test/record-query-contract.test.ts\n+++ b/src/engine/test/record-query-contract.test.ts\n@@ -24,7 +24,8 @@\n \t\t// Nine existing atoms make a finite, repeatable history. The last query\n \t\t// both replaces a line and inserts at the repeatedly written gap.\n \t\tassert.equal(repo.graph.size, 9);\n-\t\tassert.deepEqual(recreation.deps, [\"a0\", deletion.id]);\n+\t\tassert.deepEqual(recreation.deps, [deletion.id]);\n+\t\tassert.deepEqual(repo.graph.closureOf(recreation.deps), repo.graph.closureOf([\"a0\", deletion.id]));\n \t\tassert.deepEqual(repo.view().attrs(\"src.txt\"), {\n \t\t\texists: false,\n \t\t\texec: false,\n@@ -43,9 +44,10 @@\n \t\t\tattrs: [{ file: \"src.txt\", name: \"exec\" as const, value: \"1\" }],\n \t\t};\n \t\tconst liveAtom = buildAtom(repo.view(), input);\n-\t\tconst expectedDeps = [\"a0\", writerOne.id, writerTwo.id, readerOne.id, readerTwo.id, attrOne.id, attrTwo.id];\n+\t\tconst expectedDeps = [writerOne.id, writerTwo.id, readerOne.id, readerTwo.id, attrOne.id, attrTwo.id];\n \t\tassert.deepEqual(liveAtom.deps, expectedDeps);\n-\t\tassert.equal(liveAtom.deps.length, 7);\n+\t\tassert.deepEqual(repo.graph.closureOf(liveAtom.deps), repo.graph.closureOf([\"a0\", ...expectedDeps]));\n+\t\tassert.equal(liveAtom.deps.length, 6);\n \t\tassert.equal(liveAtom.writes.length, 3);\n \t\tassert.equal(liveAtom.reads.length, 2);\n \t\tassert.equal(liveAtom.holds.length, 0);"},{"path":"src/engine/test/view.test.ts","added":2,"removed":1,"diff":"--- a/src/engine/test/view.test.ts\n+++ b/src/engine/test/view.test.ts\n@@ -117,8 +117,9 @@\n \t\tassert.equal(repo.text(\"f.txt\"), lines(\"top\", \"r\", \"q\", \"p\", \"bottom\"));\n \t\tassert.deepEqual(\n \t\t\tr.deps,\n-\t\t\t[\"a0\", p.id, q.id].sort((a, b) => Number(a.slice(1)) - Number(b.slice(1))),\n+\t\t\t[p.id, q.id].sort((a, b) => Number(a.slice(1)) - Number(b.slice(1))),\n \t\t);\n+\t\tassert.deepEqual(repo.graph.closureOf(r.deps), repo.graph.closureOf([\"a0\", p.id, q.id]));\n \t});\n \n \tit(\"puts a line's replacements ahead of the lines inserted after it, whatever their priority\", () => {"}],"ci":null}