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 134 --json
JSON
/christopher/abso-core/versions/134?format=json

Stream project conflict candidates and resolver intersections

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

Version 133 · Files at version 134

2 files, 130 lines added, 8 removed.

--- a/worker/project/collisions.ts
+++ b/worker/project/collisions.ts
@@ -46,25 +46,74 @@
4646 const out: Pair[] = [];
4747 for (const yours of draft) {
4848 const atom = g.atom(yours);
49− const candidates = new Set<AtomId>();
49+ const streams: IterableIterator<AtomId>[] = [];
5050 for (const key of atom.writes) {
51− for (const list of [g.writersOf(key), g.readersOf(key), g.holdersOf(key)]) {
52− for (const id of list) if (against.has(id)) candidates.add(id);
53− }
51+ streams.push(g.eachWriterOf(key), g.eachReaderOf(key), g.eachHolderOf(key));
5452 }
55− for (const key of claimsOf(atom)) for (const id of g.writersOf(key)) if (against.has(id)) candidates.add(id);
56− for (const theirs of [...candidates].sort((p, q) => g.atom(p).seq - g.atom(q).seq)) {
53+ for (const key of claimsOf(atom)) streams.push(g.eachWriterOf(key));
54+ for (const theirs of orderedClaimants(g, streams)) {
55+ if (!against.has(theirs)) continue;
5756 const [lo, hi] = g.atom(yours).seq < g.atom(theirs).seq ? [yours, theirs] : [theirs, yours];
5857 const keys = conflictKeys(g.atom(lo), g.atom(hi), g.dependsOn(hi, lo));
5958 if (keys.length === 0 || sideBySide(g, lo, hi, keys)) continue;
60− const fromHi = new Set(g.resolversOf(hi));
61− if (g.resolversOf(lo).some((r) => fromHi.has(r) && settled.has(r))) continue;
59+ if (hasCommonResolver(g, lo, hi, settled)) continue;
6260 out.push({ yours, theirs, keys });
6361 }
6462 }
6563 return out;
6664}
6765
66+/** Claim indexes append in canonical seq order. Merge one cursor per current
67+ * atom key, retaining no candidate set proportional to historical claims. */
68+function* orderedClaimants(g: Graph, streams: IterableIterator<AtomId>[]): IterableIterator<AtomId> {
69+ try {
70+ const heads = streams.map((stream) => stream.next());
71+ let previous = -1;
72+ for (;;) {
73+ let best = -1;
74+ let seq = Infinity;
75+ for (let i = 0; i < heads.length; i++) {
76+ const head = heads[i]!;
77+ if (head.done) continue;
78+ const current = g.atom(head.value).seq;
79+ if (current < seq) {
80+ best = i;
81+ seq = current;
82+ }
83+ }
84+ if (best < 0) return;
85+ const id = heads[best]!.value!;
86+ heads[best] = streams[best]!.next();
87+ if (seq === previous) continue;
88+ previous = seq;
89+ yield id;
90+ }
91+ } finally {
92+ for (const stream of streams) stream.return?.();
93+ }
94+}
96+/** Resolver indexes share the same append order, so intersection needs two cursors. */
97+function hasCommonResolver(g: Graph, lo: AtomId, hi: AtomId, settled: ReadonlySet<AtomId>): boolean {
98+ const left = g.eachResolverOf(lo);
99+ const right = g.eachResolverOf(hi);
100+ try {
101+ let a = left.next();
102+ let b = right.next();
103+ while (!a.done && !b.done) {
104+ const x = g.atom(a.value).seq;
105+ const y = g.atom(b.value).seq;
106+ if (x === y && settled.has(a.value)) return true;
107+ if (x <= y) a = left.next();
108+ if (y <= x) b = right.next();
109+ }
110+ return false;
111+ } finally {
112+ left.return?.();
113+ right.return?.();
114+ }
115+}
68117/**
69118 * Two pure insertions at the same point, and nothing else between them
70119 * (#37, the game trial): both only write the gap after one line. Neither
--- /dev/null
+++ b/worker/project/test/collision-streaming.test.ts
@@ -0,0 +1,73 @@
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { buildBase, Graph } from "../../../src/engine/index.ts";
4+import { CachedStateStorage } from "../../../src/engine/state-source.ts";
5+import { SqlState } from "../../../src/engine/test/storage-helper.ts";
6+import { pairsIn } from "../collisions.ts";
7+
8+test("persistent conflict candidates and resolver intersections stream in exact canonical order", (t) => {
9+ const source = new SqlState();
10+ try {
11+ const graph = new Graph({ storage: new CachedStateStorage(source, 8192, 32) });
12+ graph.add(buildBase({ "a.txt": "one\n" }, { author: "fixture", message: "base", time: 0 }));
13+ const count = 513;
14+ for (let seq = 1; seq <= count + 1; seq++)
15+ graph.add({
16+ id: `a${seq}`,
17+ seq,
18+ author: "fixture",
19+ message: "claim",
20+ time: seq,
21+ inserts: [],
22+ deletes: [],
23+ writes: ["L:a0.0"],
24+ reads: ["G:^a.txt"],
25+ holds: [],
26+ needs: [],
27+ resolves: [],
28+ reasons: [],
29+ deps: ["a0"],
30+ });
31+ const draft = `a${count + 1}`;
32+ const against = new Set(Array.from({ length: count }, (_, n) => `a${n + 1}`));
33+ const settled = new Set<string>();
34+ for (let n = 1; n <= count; n += 2) {
35+ const seq = graph.size;
36+ const id = `a${seq}`;
37+ graph.add({
38+ id,
39+ seq,
40+ author: "fixture",
41+ message: "resolve",
42+ time: seq,
43+ inserts: [],
44+ deletes: [],
45+ writes: [],
46+ reads: [],
47+ holds: [],
48+ needs: [],
49+ resolves: [`a${n}`, draft],
50+ reasons: [],
51+ deps: [`a${n}`, draft],
52+ });
53+ settled.add(id);
54+ }
55+ const reopened = new Graph({ storage: new CachedStateStorage(source, 8192, 32) });
56+ for (const method of ["writersOf", "readersOf", "holdersOf", "resolversOf"] as const)
57+ t.mock.method(reopened, method, () => {
58+ throw new Error(`materialized ${method} forbidden`);
59+ });
60+ assert.deepEqual(
61+ pairsIn(reopened, [draft], against, new Set()).map((pair) => pair.theirs),
62+ [...against],
63+ );
64+ assert.deepEqual(
65+ pairsIn(reopened, [draft], against, settled).map((pair) => pair.theirs),
66+ [...against].filter((id) => Number(id.slice(1)) % 2 === 0),
67+ );
68+ const selected = new Set(["a1", "a257", "a513"]);
69+ assert.deepEqual(pairsIn(reopened, [draft], selected, settled), []);
70+ } finally {
71+ source.db.close();
72+ }
73+});