{"version":142,"agent":"codex-capacity-chair","message":"Avoid full-base membership copies during collision checks","time":1791851427559,"timeIso":"2026-10-13T00:30:27.559Z","changes":3,"change":1284,"files":["worker/project/collisions.ts","worker/project/project.ts","worker/project/test/collision-streaming.test.ts"],"draft":null,"diff":[{"path":"worker/project/collisions.ts","added":4,"removed":3,"diff":"--- a/worker/project/collisions.ts\n+++ b/worker/project/collisions.ts\n@@ -12,6 +12,7 @@\n \tparseKey,\n \ttype View,\n } from \"../../src/engine/index.ts\";\n+import { differenceSet, StableOverlaySet } from \"../../src/engine/state-source.ts\";\n import { definedTwice } from \"./definitions.ts\";\n import type { AgentState, Collision, CollisionSide } from \"./project-types.ts\";\n import { SHARED, type Space } from \"./spaces.ts\";\n@@ -235,7 +236,7 @@\n \treadonly spaces: ReadonlyMap<string, Space>;\n \tversion(): number;\n \tspaceOf(agent: AgentState): Space;\n-\tagentSet(agent: AgentState): Set<AtomId>;\n+\tagentSet(agent: AgentState): ReadonlySet<AtomId>;\n \tdraft(agent: AgentState): AtomId[];\n \tagentView(agent: AgentState): View;\n \tat(space: Space, version: number): ReadonlySet<AtomId>;\n@@ -305,11 +306,11 @@\n export function openPairs(host: CollisionHost, agent: AgentState): Pair[] {\n \tconst space = host.spaceOf(agent);\n \tconst set = host.agentSet(agent);\n-\tconst mine = new Set(agent.mine);\n+\tconst mine = new StableOverlaySet(agent.mine);\n \tconst out: Pair[] = [];\n \tconst draft = host.draft(agent);\n \tif (draft.length > 0) {\n-\t\tconst seen = new Set([...host.at(space, agent.base)].filter((id) => !mine.has(id)));\n+\t\tconst seen = differenceSet(host.at(space, agent.base), mine);\n \t\tout.push(...pairsIn(host.graph, draft, seen, set));\n \t}\n \tif (space.name !== SHARED) {"},{"path":"worker/project/project.ts","added":2,"removed":1,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -22,6 +22,7 @@\n \tStableUnionSet,\n \tStoredMap,\n \tstoredArray,\n+\tunionOverlay,\n } from \"../../src/engine/state-source.ts\";\n import { type AddDraftHost, addDraft as hostedAddDraft } from \"./add-draft.ts\";\n import { type AmendHost, amend as hostedAmend } from \"./amend.ts\";\n@@ -1773,7 +1774,7 @@\n \t\t\tspaces: this.#spaces,\n \t\t\tversion: () => this.version,\n \t\t\tspaceOf: (agent) => this.#spaceOf(agent),\n-\t\t\tagentSet: (agent) => this.#agentSet(agent),\n+\t\t\tagentSet: (agent) => unionOverlay(this.#at(this.#spaceOf(agent), agent.base), agent.mine),\n \t\t\tdraft: (agent) => this.#draft(agent),\n \t\t\tagentView: (agent) => this.#agentView(agent),\n \t\t\tat: (space, version) => this.#at(space, version),"},{"path":"worker/project/test/collision-streaming.test.ts","added":38,"removed":2,"diff":"--- a/worker/project/test/collision-streaming.test.ts\n+++ b/worker/project/test/collision-streaming.test.ts\n@@ -1,9 +1,11 @@\n import assert from \"node:assert/strict\";\n import { test } from \"node:test\";\n import { buildBase, Graph } from \"../../../src/engine/index.ts\";\n-import { CachedStateStorage } from \"../../../src/engine/state-source.ts\";\n+import { CachedStateStorage, StableOverlaySet, unionOverlay } from \"../../../src/engine/state-source.ts\";\n import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n-import { pairsIn } from \"../collisions.ts\";\n+import { type CollisionHost, openPairs, pairsIn } from \"../collisions.ts\";\n+import type { AgentState } from \"../project-types.ts\";\n+import { newSpace } from \"../spaces.ts\";\n \n test(\"persistent conflict candidates and resolver intersections stream in exact canonical order\", (t) => {\n \tconst source = new SqlState();\n@@ -67,6 +69,40 @@\n \t\t);\n \t\tconst selected = new Set([\"a1\", \"a257\", \"a513\"]);\n \t\tassert.deepEqual(pairsIn(reopened, [draft], selected, settled), []);\n+\t\tconst base = new StableOverlaySet(against);\n+\t\tt.mock.method(base, \"values\", () => {\n+\t\t\tthrow Error(\"enumerating the complete base membership is forbidden\");\n+\t\t});\n+\t\tconst actor: AgentState = {\n+\t\t\tname: \"fixture\",\n+\t\t\tspace: \"\",\n+\t\t\tbase: 0,\n+\t\t\tsynced: true,\n+\t\t\tmine: [\"a1\", draft],\n+\t\t\tnews: [],\n+\t\t\tnewsAt: [],\n+\t\t\ttold: new Set(),\n+\t\t\tparked: new Map(),\n+\t\t\tmarked: [],\n+\t\t};\n+\t\tconst space = newSpace(\"\");\n+\t\tconst host: CollisionHost = {\n+\t\t\tgraph: reopened,\n+\t\t\tspaces: new Map([[\"\", space]]),\n+\t\t\tversion: () => 0,\n+\t\t\tspaceOf: () => space,\n+\t\t\tagentSet: (agent) => unionOverlay(base, agent.mine),\n+\t\t\tdraft: () => [draft],\n+\t\t\tat: () => base,\n+\t\t\tshared: () => space,\n+\t\t\tagentView: () => {\n+\t\t\t\tthrow Error(\"open pairs must not build a View\");\n+\t\t\t},\n+\t\t};\n+\t\tassert.deepEqual(\n+\t\t\topenPairs(host, actor).map((pair) => pair.theirs),\n+\t\t\t[...against].filter((id) => id !== \"a1\"),\n+\t\t);\n \t} finally {\n \t\tsource.db.close();\n \t}"}],"ci":null}