Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 142 --json
JSON
/christopher/abso-core/versions/142?format=json

Avoid full-base membership copies during collision checks

of shared·codex-capacity-chair··Not checked

Version 141 · Files at version 142

3 files, 44 lines added, 6 removed.

--- a/worker/project/collisions.ts
+++ b/worker/project/collisions.ts
@@ -12,6 +12,7 @@
1212 parseKey,
1313 type View,
1414} from "../../src/engine/index.ts";
15+import { differenceSet, StableOverlaySet } from "../../src/engine/state-source.ts";
1516import { definedTwice } from "./definitions.ts";
1617import type { AgentState, Collision, CollisionSide } from "./project-types.ts";
1718import { SHARED, type Space } from "./spaces.ts";
@@ -235,7 +236,7 @@
235236 readonly spaces: ReadonlyMap<string, Space>;
236237 version(): number;
237238 spaceOf(agent: AgentState): Space;
238− agentSet(agent: AgentState): Set<AtomId>;
239+ agentSet(agent: AgentState): ReadonlySet<AtomId>;
239240 draft(agent: AgentState): AtomId[];
240241 agentView(agent: AgentState): View;
241242 at(space: Space, version: number): ReadonlySet<AtomId>;
@@ -305,11 +306,11 @@
305306export function openPairs(host: CollisionHost, agent: AgentState): Pair[] {
306307 const space = host.spaceOf(agent);
307308 const set = host.agentSet(agent);
308− const mine = new Set(agent.mine);
309+ const mine = new StableOverlaySet(agent.mine);
309310 const out: Pair[] = [];
310311 const draft = host.draft(agent);
311312 if (draft.length > 0) {
312− const seen = new Set([...host.at(space, agent.base)].filter((id) => !mine.has(id)));
313+ const seen = differenceSet(host.at(space, agent.base), mine);
313314 out.push(...pairsIn(host.graph, draft, seen, set));
314315 }
315316 if (space.name !== SHARED) {
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -22,6 +22,7 @@
2222 StableUnionSet,
2323 StoredMap,
2424 storedArray,
25+ unionOverlay,
2526} from "../../src/engine/state-source.ts";
2627import { type AddDraftHost, addDraft as hostedAddDraft } from "./add-draft.ts";
2728import { type AmendHost, amend as hostedAmend } from "./amend.ts";
@@ -1773,7 +1774,7 @@
17731774 spaces: this.#spaces,
17741775 version: () => this.version,
17751776 spaceOf: (agent) => this.#spaceOf(agent),
1776− agentSet: (agent) => this.#agentSet(agent),
1777+ agentSet: (agent) => unionOverlay(this.#at(this.#spaceOf(agent), agent.base), agent.mine),
17771778 draft: (agent) => this.#draft(agent),
17781779 agentView: (agent) => this.#agentView(agent),
17791780 at: (space, version) => this.#at(space, version),
--- a/worker/project/test/collision-streaming.test.ts
+++ b/worker/project/test/collision-streaming.test.ts
@@ -1,9 +1,11 @@
11import assert from "node:assert/strict";
22import { test } from "node:test";
33import { buildBase, Graph } from "../../../src/engine/index.ts";
4−import { CachedStateStorage } from "../../../src/engine/state-source.ts";
4+import { CachedStateStorage, StableOverlaySet, unionOverlay } from "../../../src/engine/state-source.ts";
55import { SqlState } from "../../../src/engine/test/storage-helper.ts";
6−import { pairsIn } from "../collisions.ts";
6+import { type CollisionHost, openPairs, pairsIn } from "../collisions.ts";
7+import type { AgentState } from "../project-types.ts";
8+import { newSpace } from "../spaces.ts";
79
810test("persistent conflict candidates and resolver intersections stream in exact canonical order", (t) => {
911 const source = new SqlState();
@@ -67,6 +69,40 @@
6769 );
6870 const selected = new Set(["a1", "a257", "a513"]);
6971 assert.deepEqual(pairsIn(reopened, [draft], selected, settled), []);
72+ const base = new StableOverlaySet(against);
73+ t.mock.method(base, "values", () => {
74+ throw Error("enumerating the complete base membership is forbidden");
75+ });
76+ const actor: AgentState = {
77+ name: "fixture",
78+ space: "",
79+ base: 0,
80+ synced: true,
81+ mine: ["a1", draft],
82+ news: [],
83+ newsAt: [],
84+ told: new Set(),
85+ parked: new Map(),
86+ marked: [],
87+ };
88+ const space = newSpace("");
89+ const host: CollisionHost = {
90+ graph: reopened,
91+ spaces: new Map([["", space]]),
92+ version: () => 0,
93+ spaceOf: () => space,
94+ agentSet: (agent) => unionOverlay(base, agent.mine),
95+ draft: () => [draft],
96+ at: () => base,
97+ shared: () => space,
98+ agentView: () => {
99+ throw Error("open pairs must not build a View");
100+ },
101+ };
102+ assert.deepEqual(
103+ openPairs(host, actor).map((pair) => pair.theirs),
104+ [...against].filter((id) => id !== "a1"),
105+ );
70106 } finally {
71107 source.db.close();
72108 }