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

Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.

of shared·engine··Not checked

  • markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
  • draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
  • New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.

Version 54 · Files at version 55

4 files, 107 lines added, 9 removed.

--- a/worker/project/markers.ts
+++ b/worker/project/markers.ts
@@ -287,9 +287,12 @@
287287
288288/** The blocks of markers still in the agent's files, as collisions (#11): listed by sync and status. */
289289export function markedCollisions(host: MarkerHost, agent: AgentState): Collision[] {
290+ const files = markedFiles(agent);
291+ // No marked files, no view to build (abso-core issue 6): most agents have none.
292+ if (files.length === 0) return [];
290293 const view = host.agentView(agent);
291294 const out: Collision[] = [];
292− for (const file of markedFiles(agent)) {
295+ for (const file of files) {
293296 if (!view.hasFile(file)) continue;
294297 for (const b of blocksIn(view.lines(file).map((l) => l.text))) out.push(blockCollision(file, b));
295298 }
--- a/worker/project/overlaps.ts
+++ b/worker/project/overlaps.ts
@@ -24,6 +24,8 @@
2424 readonly agents: ReadonlyMap<string, AgentState>;
2525 agentView(agent: AgentState): View;
2626 draft(agent: AgentState): readonly AtomId[];
27+ /** draftFiles below, kept per agent by the host. */
28+ draftFiles(agent: AgentState): Set<string>;
2729 liveNote(agent: AgentState): Starting | undefined;
2830 queueNews(agent: AgentState, items: readonly NewsItem[], entries: Entry[]): void;
2931}
@@ -64,8 +66,11 @@
6466/** The files the agent's unpublished changes touch, in its own view. */
6567export function draftFiles(host: OverlapHost, agent: AgentState): Set<string> {
6668 const files = new Set<string>();
69+ const draft = host.draft(agent);
70+ // No draft, no view to build: most agents in a big project have nothing unpublished.
71+ if (draft.length === 0) return files;
6772 const view = host.agentView(agent);
68− for (const id of host.draft(agent)) {
73+ for (const id of draft) {
6974 const atom = host.graph.atom(id);
7075 for (const run of atom.inserts) files.add(isStartNode(run.parent) ? run.file : view.fileOf(run.parent));
7176 for (const line of atom.deletes) files.add(view.fileOf(line));
@@ -81,7 +86,7 @@
8186 .filter((other) => other !== agent && other.space === agent.space)
8287 .map((other) => ({
8388 name: other.name,
84− files: draftFiles(host, other),
89+ files: host.draftFiles(other),
8590 changesIn: (file: string) => host.draft(other).filter((id) => host.graph.filesOf(id).includes(file)).length,
8691 note: host.liveNote(other),
8792 }));
@@ -94,7 +99,7 @@
9499 * the edit.
95100 */
96101export function overlapNews(host: OverlapHost, agent: AgentState, before: ReadonlySet<string>, entries: Entry[]): void {
97− const now = draftFiles(host, agent);
102+ const now = host.draftFiles(agent);
98103 const fresh = [...now].filter((f) => !before.has(f)).toSorted();
99104 if (fresh.length === 0) return;
100105 host.queueNews(agent, overlapItems(host.draft(agent)[0] ?? "", overlaps(host, agent, fresh)), entries);
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -225,6 +225,8 @@
225225 readonly #graph: Graph;
226226 /** Views laid out from atom sets, cached under a byte budget (views.ts). */
227227 readonly #views: ViewCache;
228+ /** Each agent's draft files, under the key they were worked out for (#draftFiles). */
229+ readonly #draftFilesKept = new Map<string, { key: string; files: Set<string> }>();
228230 /** Each version's files and each path's history (pathindex.ts). */
229231 readonly #paths: PathIndex;
230232 /** For each atom (by seq) that wrote lines, the log position of the entry that recorded it (#46). */
@@ -992,9 +994,20 @@
992994 }
993995 }
994996
995− /** The files the agent's unpublished changes touch, in its own view. */
996− #draftFiles(...args: Tail<Parameters<typeof hostedDraftFiles>>): ReturnType<typeof hostedDraftFiles> {
997− return hostedDraftFiles(this.#overlapHost, ...args);
997+ /**
998+ * The files the agent's unpublished changes touch, in its own view. Kept per agent under what they're
999+ * made of (abso-core issue 6): its view's key and its draft. Most agents haven't moved since the last
1000+ * status, and the view cache holds fewer views than a big project has agents, so working them out again
1001+ * on every call cost about 0.5 s on abso. A copy goes out, so no caller can change what's kept.
1002+ */
1003+ #draftFiles(agent: AgentState): Set<string> {
1004+ const key = `${this.#agentViewKey(agent)}|${this.#draft(agent).join(",")}`;
1005+ let kept = this.#draftFilesKept.get(agent.name);
1006+ if (kept?.key !== key) {
1007+ kept = { key, files: hostedDraftFiles(this.#overlapHost, agent) };
1008+ this.#draftFilesKept.set(agent.name, kept);
1009+ }
1010+ return new Set(kept.files);
9981011 }
9991012
10001013 /** Other agents in the agent's space whose unpublished changes or starting note meet `patterns`. */
@@ -2028,6 +2041,7 @@
20282041 agents: this.#agents,
20292042 agentView: (agent) => this.#agentView(agent),
20302043 draft: (agent) => this.#draft(agent),
2044+ draftFiles: (agent) => this.#draftFiles(agent),
20312045 liveNote: (agent) => this.#liveNote(agent),
20322046 queueNews: (agent, items, entries) => this.#queueNews(agent, items, entries),
20332047 };
@@ -2217,10 +2231,14 @@
22172231 }
22182232
22192233 #agentView(agent: AgentState): View {
2220− // Keyed by what the set is made of, not by sorting every atom in it (#46): that cost more than the work.
2221− return this.#viewKeyed(`a ${agent.space}@${agent.base}+${agent.mine.join(",")}`, () => this.#agentSet(agent));
2234+ return this.#viewKeyed(this.#agentViewKey(agent), () => this.#agentSet(agent));
22222235 }
22232236
2237+ /** An agent's view, keyed by what the set is made of, not by sorting every atom in it (#46): that cost more than the work. */
2238+ #agentViewKey(agent: AgentState): string {
2239+ return `a ${agent.space}@${agent.base}+${agent.mine.join(",")}`;
2240+ }
22242242 /** A space at a version: published versions never change, so the key is just their names (#46). */
22252243 #viewAt(space: Space, version: number): View {
22262244 return this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
--- /dev/null
+++ b/worker/project/test/draft-files-kept.test.ts
@@ -0,0 +1,72 @@
1+// Each agent's draft files are kept between calls (abso-core issue 6). Status
2+// must answer as a project that works them out cold does, after every kind of
3+// step, in shared and in a named draft.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { MemoryStore, Project } from "../project.ts";
8+
9+const START = {
10+ "core.ts": "export function step(x: number) {\n return x + 1;\n}\n\nexport const version = 1;\n",
11+ "notes.md": "one\ntwo\nthree\n",
12+};
14+function setup() {
15+ const store = new MemoryStore();
16+ const project = new Project(store);
17+ project.init(START, 0);
18+ for (const a of ["ann", "bob", "cat"]) project.sync(a);
19+ // Warm: every agent's draft files are kept from here on.
20+ project.status();
21+ return { project, store };
22+}
24+/** Status from the warm project, checked against the same log loaded cold. */
25+function same(project: Project, store: MemoryStore, step: string) {
26+ const warm = project.status();
27+ assert.deepEqual(warm, Project.load(store.entries, new MemoryStore()).status(), `after ${step}`);
28+ return warm;
29+}
31+const filesOf = (status: ReturnType<Project["status"]>, agent: string) =>
32+ status.agents.find((a) => a.agent === agent)!.files;
34+test("status answers the same warm and cold through records, publishes and syncs in shared", () => {
35+ const { project, store } = setup();
36+ project.edit("ann", { file: "core.ts", old: " return x + 1;", new: " return x + 2;" }, 1);
37+ assert.deepEqual(filesOf(same(project, store, "ann's edit"), "ann"), ["core.ts"]);
38+ project.edit("ann", { file: "notes.md", old: "two\n", new: "two!\n" }, 2);
39+ assert.deepEqual(filesOf(same(project, store, "ann's second edit"), "ann"), ["core.ts", "notes.md"]);
40+ project.edit("bob", { file: "notes.md", old: "three\n", new: "three!\n" }, 3);
41+ same(project, store, "bob's edit");
42+ project.publish("ann", "Ann's two", 4);
43+ assert.deepEqual(filesOf(same(project, store, "ann's publish"), "ann"), []);
44+ project.sync("bob");
45+ assert.deepEqual(filesOf(same(project, store, "bob's sync"), "bob"), ["notes.md"]);
46+ project.record("cat", { "new.ts": "export {};\n" }, 5);
47+ assert.deepEqual(filesOf(same(project, store, "cat's new file"), "cat"), ["new.ts"]);
48+ project.publish("cat", "Cat's file", 6);
49+ same(project, store, "cat's publish");
50+});
52+test("two agents in one named draft: one publishes, and the other's status still matches a cold load", () => {
53+ const { project, store } = setup();
54+ project.switchTo("ann", "rw", 1);
55+ project.switchTo("bob", "rw", 2);
56+ same(project, store, "both switch");
57+ project.edit("ann", { file: "core.ts", old: " return x + 1;", new: " return x * 2;" }, 3);
58+ project.edit("bob", { file: "notes.md", old: "one\n", new: "one (rw)\n" }, 4);
59+ const before = same(project, store, "both edit in rw");
60+ assert.deepEqual(filesOf(before, "bob"), ["notes.md"]);
61+ project.publish("ann", "Double", 5);
62+ const after = same(project, store, "ann publishes into rw");
63+ assert.deepEqual(filesOf(after, "ann"), []);
64+ project.sync("bob");
65+ assert.deepEqual(filesOf(same(project, store, "bob syncs in rw"), "bob"), ["notes.md"]);
66+ project.publish("bob", "Note", 6);
67+ assert.deepEqual(filesOf(same(project, store, "bob publishes into rw"), "bob"), []);
68+ project.land("ann", "Land rw", 7);
69+ same(project, store, "rw lands");
70+ project.switchTo("ann", "shared", 8);
71+ same(project, store, "ann back in shared");
72+});