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

Local projects run as their own processes again: no compile cache for a local command, and plain words when the server's code can't load

of shared·pinch··Not checked

At 287, every local command run as node client/abso.ts could crash with a segmentation fault (exit 139, at random, init and join included). The cause is Node's compile cache, which client/avcs.ts turns on, together with the module hook that gives the open server's code its cloudflare:workers stand-in. avcs.ts now leaves the cache off for a --local command and in a folder whose config names the server "local". The hook also stays registered rather than being removed after the import.

  • If the server's code can't load (a package missing, say), it's said as "local projects couldn't load the server's code: ..." rather than "Can't reach local ... check your connection".
  • In a local folder, status says "It's a local project, in <store>/<project>." instead of "Signed in with none.", and skips the npm newer-client check, which reaches for the network.
  • worker/project/news.ts is Biome-formatted (only formatting), so the check gets past Biome again.
  • scripts/local-measure.ts times status, log, blame, pull and push as separate processes on a small and a large local history, with peak memory and the store's size. scripts/local-writers.ts pushes from 1, 4 and 16 writers at once to measure the store lock.

Tests: client/test/local.test.ts (9, one running init, push, status and log as child processes with the cache as it is); tsc and Biome clean. Three rounds of init, push and status as processes exit 0.

Version 288 · Files at version 289

7 files, 285 lines added, 16 removed.

--- a/client/avcs.ts
+++ b/client/avcs.ts
@@ -3,15 +3,33 @@
33// `abso help` lists the commands. `abso hook` is the Claude Code hook; it
44// loads only what it needs, since every edit pays for its start-up.
55
6+import { readFileSync } from "node:fs";
67import * as nodeModule from "node:module";
8+import { dirname, join } from "node:path";
79
10+const argv = process.argv.slice(2);
12+/**
13+ * Whether this command opens a local project (abso init --local): --local, or a folder whose config names the server
14+ * "local". Those load the open server's code through a module hook, and with the compile cache on Node 24 crashes.
15+ */
16+function opensLocal(): boolean {
17+ if (argv.includes("--local")) return true;
18+ for (let dir = process.cwd(); ; dir = dirname(dir)) {
19+ for (const state of [".abso", ".avcs"]) {
20+ try {
21+ return /"server"\s*:\s*"local"/.test(readFileSync(join(dir, state, "config.json"), "utf8"));
22+ } catch {}
23+ }
24+ if (dirname(dir) === dir) return false;
25+ }
26+}
828// Node keeps the compiled modules (TypeScript already stripped) in a cache in
929// the temp folder. Loading the hook's modules drops from about 55 ms to 11 ms.
1030// Node 20 has no compile cache, and the built client runs there without one.
11−(nodeModule as { enableCompileCache?: () => unknown }).enableCompileCache?.();
31+if (!opensLocal()) (nodeModule as { enableCompileCache?: () => unknown }).enableCompileCache?.();
1232
13−const argv = process.argv.slice(2);
14−
1533if (argv[0] === "hook") {
1634 const { runHook } = await import("./src/hook.ts");
1735 const chunks: Buffer[] = [];
--- a/client/src/local-store.ts
+++ b/client/src/local-store.ts
@@ -221,24 +221,26 @@
221221 // copy has it already: the build points the import at the same file (scripts/build-client.mjs).
222222 const standIn = new URL("./durable-object-stand-in.ts", import.meta.url).href;
223223 const mod = (await import("node:module")) as unknown as {
224− registerHooks?: (hooks: unknown) => { deregister(): void };
224+ registerHooks?: (hooks: unknown) => unknown;
225225 };
226− const hooks = mod.registerHooks?.({
226+ // The hook stays for the rest of the process: deregistering it crashes Node 24 at exit when the compile cache
227+ // is on (client/avcs.ts turns it on). It answers only cloudflare:workers.
228+ mod.registerHooks?.({
227229 resolve(specifier: string, context: unknown, next: (s: string, c: unknown) => unknown) {
228230 if (specifier === "cloudflare:workers") return { url: standIn, shortCircuit: true };
229231 return next(specifier, context);
230232 },
231233 });
234+ let loaded: typeof import("./local-server.mjs");
232235 try {
233− const { handle, ProjectObject } = await import("./local-server.mjs");
234− return {
235− DatabaseSync: sqlite.DatabaseSync,
236− handle,
237− ProjectObject,
238− };
239− } finally {
240− hooks?.deregister();
236+ loaded = await import("./local-server.mjs");
237+ } catch (e) {
238+ // Nothing is reached for here: a part of the client is missing (its packages not installed, say).
239+ throw new LocalError(
240+ `local projects couldn't load the server's code: ${e instanceof Error ? e.message : String(e)}`,
241+ );
241242 }
243+ return { DatabaseSync: sqlite.DatabaseSync, handle: loaded.handle, ProjectObject: loaded.ProjectObject };
242244 })();
243245 return server;
244246}
--- a/client/src/status-commands.ts
+++ b/client/src/status-commands.ts
@@ -40,6 +40,7 @@
4040} from "./folder.ts";
4141import { fileArg } from "./history.ts";
4242import { modsBehindText } from "./install.ts";
43+import { isLocal } from "./local-store.ts";
4344import { withFolderLock } from "./lock.ts";
4445import { readKnownModes, writeKnownModes } from "./modes.ts";
4546import { queueText } from "./queue.ts";
@@ -325,9 +326,11 @@
325326 const space = (draft: string | null | undefined): string => (draft ? `draft ${draft}` : "shared");
326327 const parked = (me?.parked ?? []).filter((p) => p.draftChanges > 0);
327328 const credential = credentialLabel(root, config.server, env.env);
328− const behind = await newerClientNote(config.server);
329+ // A local project reaches for nothing on the network, npm included.
330+ const localProject = isLocal(config.server);
331+ const behind = localProject ? undefined : await newerClientNote(config.server);
329332 const lines = [
330− `Project ${config.project}: shared is at version ${status.version}. This folder is ${config.agent}${config.reader || me?.reader ? ", a reader (it records and pushes nothing)" : ""}, working in ${space(me?.draft)}.${config.follow ? ` It follows label ${config.follow}: pulls take it to the newest version with that label.` : ""} Signed in with ${credential.kind}${credential.id ? ` ${credential.id}` : ""}.`,
333+ `Project ${config.project}: shared is at version ${status.version}. This folder is ${config.agent}${config.reader || me?.reader ? ", a reader (it records and pushes nothing)" : ""}, working in ${space(me?.draft)}.${config.follow ? ` It follows label ${config.follow}: pulls take it to the newest version with that label.` : ""}${localProject ? ` It's a local project, in ${join(config.localStore ?? "", config.project)}.` : ` Signed in with ${credential.kind}${credential.id ? ` ${credential.id}` : ""}.`}`,
331334 ...(behind ? [behind] : []),
332335 // Is shared green (#39)? Right under the first line, since it decides what to do next.
333336 ...ciText(status.ci, status.version),
--- a/client/test/local.test.ts
+++ b/client/test/local.test.ts
@@ -3,10 +3,12 @@
33// call that would leave the machine fails the test.
44
55import assert from "node:assert/strict";
6+import { spawnSync } from "node:child_process";
67import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
78import { tmpdir } from "node:os";
89import { join } from "node:path";
910import { after, before, describe, it } from "node:test";
11+import { fileURLToPath } from "node:url";
1012import { main } from "../src/main.ts";
1113import { stateDir } from "../src/state-dir.ts";
1214
@@ -138,3 +140,33 @@
138140 assert.equal(existsSync(join(dir, ".abso")) || existsSync(join(dir, ".avcs")), false);
139141 });
140142});
144+describe("local commands as their own processes", () => {
145+ // The way people and agents run them: client/abso.ts, a process per command, Node's compile cache as it is.
146+ const entry = fileURLToPath(new URL("../abso.ts", import.meta.url));
147+ const cli = (cwd: string, processStore: string, ...argv: string[]) =>
148+ spawnSync(process.execPath, [entry, ...argv], {
149+ cwd,
150+ env: { ...process.env, ABSO_STORE: processStore, ABSO_SERVERS_FILE: "no-servers.json" },
151+ encoding: "utf8",
152+ });
154+ it("init, push, status and log each exit cleanly", () => {
155+ const processStore = temp("process-store");
156+ const dir = temp("process");
157+ writeFileSync(join(dir, "a.txt"), "one\n");
158+ const steps: [string, string[]][] = [
159+ ["init", ["init", "--local", "--project", "proc", "--agent", "p"]],
160+ ["push", ["push", "-m", "Two"]],
161+ ["status", ["status"]],
162+ ["log", ["log"]],
163+ ];
164+ for (const [name, argv] of steps) {
165+ if (name === "push") writeFileSync(join(dir, "a.txt"), "one\ntwo\n");
166+ const r = cli(dir, processStore, ...argv);
167+ assert.equal(r.status, 0, `${name}: exit ${r.status} ${r.signal ?? ""}\n${r.stdout}${r.stderr}`);
168+ if (name === "status") assert.match(r.stdout, /It's a local project, in /);
169+ if (name === "log") assert.match(r.stdout, /Two/);
170+ }
171+ });
172+});
--- /dev/null
+++ b/scripts/local-measure.ts
@@ -0,0 +1,123 @@
1+// Time and memory of a local project's commands (abso init --local) on a small and a large history:
2+//
3+// node scripts/local-measure.ts [versions ...] (default: 20 1000)
4+//
5+// Each history is built in this process through the client's main(); then every command is run as its own
6+// `node client/abso.ts` process, the way a person or an agent runs it, five times. It prints the median and slowest
7+// wall time, and the largest peak memory (maxRSS) of those runs, with the store's size on disk.
8+
9+import { spawnSync } from "node:child_process";
10+import { mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
11+import { tmpdir } from "node:os";
12+import { join, resolve } from "node:path";
13+import { fileURLToPath, pathToFileURL } from "node:url";
14+import { main } from "../client/src/main.ts";
16+const ROOT = resolve(fileURLToPath(new URL("..", import.meta.url)));
17+const ENTRY = join(ROOT, "client", "abso.ts");
18+const FILES = 40;
19+const RUNS = 5;
21+const sizes = process.argv.slice(2).map(Number);
22+const histories = sizes.length > 0 ? sizes : [20, 1000];
24+function sizeOf(dir: string): number {
25+ let total = 0;
26+ for (const name of readdirSync(dir)) {
27+ const path = join(dir, name);
28+ const s = statSync(path);
29+ total += s.isDirectory() ? sizeOf(path) : s.size;
30+ }
31+ return total;
32+}
34+const lines = (file: number, version: number) =>
35+ Array.from({ length: 30 }, (_, i) =>
36+ i === version % 30 ? `line ${i} of file ${file}, version ${version}` : `line ${i} of file ${file}`,
37+ )
38+ .join("\n")
39+ .concat("\n");
41+async function build(versions: number): Promise<{ store: string; alice: string; bob: string }> {
42+ const store = mkdtempSync(join(tmpdir(), "abso-measure-store-"));
43+ const alice = mkdtempSync(join(tmpdir(), "abso-measure-alice-"));
44+ const bob = mkdtempSync(join(tmpdir(), "abso-measure-bob-"));
45+ const env = { ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" };
46+ const run = async (cwd: string, ...argv: string[]) => {
47+ const r = await main(argv, { cwd, env, write: () => {} });
48+ if (r.exit !== 0) throw new Error(`${argv.join(" ")}: ${r.stdout}${r.stderr}`);
49+ };
50+ for (let f = 0; f < FILES; f++) writeFileSync(join(alice, `f${f}.txt`), lines(f, 0));
51+ await run(alice, "init", "--local", "--project", "measure", "--agent", "alice", "--as-is");
52+ for (let v = 1; v < versions; v++) {
53+ // Each version changes three files, as a small piece of work does.
54+ for (const f of [v % FILES, (v * 7) % FILES, (v * 13) % FILES])
55+ writeFileSync(join(alice, `f${f}.txt`), lines(f, v));
56+ await run(alice, "push", "-m", `Version ${v}`);
57+ }
58+ await run(bob, "join", "measure", "--local", "--agent", "bob", "--dir", bob);
59+ return { store, alice, bob };
60+}
62+function measure(cwd: string, store: string, argv: string[]): { median: number; slowest: number; rss: number } {
63+ const times: number[] = [];
64+ let rss = 0;
65+ const preload = join(tmpdir(), `abso-measure-rss-${process.pid}.mjs`);
66+ const out = join(tmpdir(), `abso-measure-rss-${process.pid}.json`);
67+ writeFileSync(
68+ preload,
69+ `import { writeFileSync } from "node:fs";\nprocess.on("exit", () => writeFileSync(${JSON.stringify(out)}, String(process.resourceUsage().maxRSS)));\n`,
70+ );
71+ for (let i = 0; i < RUNS; i++) {
72+ const started = performance.now();
73+ const r = spawnSync(process.execPath, ["--import", pathToFileURL(preload).href, ENTRY, ...argv], {
74+ cwd,
75+ env: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" },
76+ encoding: "utf8",
77+ });
78+ times.push(performance.now() - started);
79+ if (r.status !== 0 && argv[0] !== "push") throw new Error(`${argv.join(" ")}: ${r.stdout}${r.stderr}`);
80+ rss = Math.max(
81+ rss,
82+ Number(
83+ spawnSync(
84+ process.execPath,
85+ ["-e", `process.stdout.write(require("fs").readFileSync(${JSON.stringify(out)}, "utf8"))`],
86+ { encoding: "utf8" },
87+ ).stdout,
88+ ),
89+ );
90+ }
91+ times.sort((a, b) => a - b);
92+ return { median: times[Math.floor(RUNS / 2)]!, slowest: times[RUNS - 1]!, rss };
93+}
95+const kb = (n: number) => `${(n / 1024).toFixed(0)} MB`;
96+const ms = (n: number) => `${n.toFixed(0)} ms`;
97+console.log(
98+ `Node ${process.versions.node}, ${FILES} files of 30 lines, three files changed per version, ${RUNS} runs each.`,
99+);
100+console.log("history | command | median | slowest | peak memory");
101+for (const versions of histories) {
102+ const started = performance.now();
103+ const { store, alice, bob } = await build(versions);
104+ const built = performance.now() - started;
105+ const steps: [string, string, string[]][] = [
106+ ["status", alice, ["status"]],
107+ ["log", alice, ["log"]],
108+ ["blame", alice, ["blame", "f0.txt"]],
109+ ["pull (no change)", bob, ["pull"]],
110+ ["record + push", alice, ["push", "-m", "One more"]],
111+ ];
112+ for (const [name, cwd, argv] of steps) {
113+ if (argv[0] === "push") writeFileSync(join(cwd, "f1.txt"), lines(1, versions + Math.random()));
114+ const m = measure(cwd, store, argv);
115+ console.log(
116+ `${String(versions).padStart(5)} v | ${name.padEnd(20)} | ${ms(m.median).padStart(8)} | ${ms(m.slowest).padStart(8)} | ${kb(m.rss)}`,
117+ );
118+ }
119+ console.log(
120+ `${String(versions).padStart(5)} v | store on disk ${(sizeOf(store) / 1048576).toFixed(1)} MB, built in-process in ${(built / 1000).toFixed(1)} s`,
121+ );
122+ for (const d of [store, alice, bob]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
123+}
--- /dev/null
+++ b/scripts/local-writers.ts
@@ -0,0 +1,87 @@
1+// A local project's store lock under load: 1, 4 and 16 writers pushing to one local project at once.
2+//
3+// node scripts/local-writers.ts [writers ...] (default: 1 4 16; PUSHES=10 pushes per writer)
4+//
5+// Each writer is its own agent, in its own folder, changing its own file, so nothing collides: what's measured is the
6+// store's lock (one SQLite write transaction per call). Every push is its own `node client/abso.ts push` process, as
7+// an agent runs it. It prints each push's wall time (median, 95th percentile, slowest), the pushes per second across
8+// all writers, and any push that failed.
9+
10+import { spawn } from "node:child_process";
11+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
12+import { tmpdir } from "node:os";
13+import { join, resolve } from "node:path";
14+import { fileURLToPath } from "node:url";
15+import { main } from "../client/src/main.ts";
17+const ROOT = resolve(fileURLToPath(new URL("..", import.meta.url)));
18+const ENTRY = join(ROOT, "client", "abso.ts");
19+const PUSHES = Number(process.env.PUSHES ?? 10);
20+const counts = process.argv.slice(2).map(Number);
22+function push(cwd: string, store: string, message: string): Promise<{ ms: number; ok: boolean; out: string }> {
23+ const started = performance.now();
24+ return new Promise((done) => {
25+ const child = spawn(process.execPath, [ENTRY, "push", "-m", message], {
26+ cwd,
27+ env: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" },
28+ });
29+ let out = "";
30+ child.stdout.on("data", (d) => {
31+ out += d;
32+ });
33+ child.stderr.on("data", (d) => {
34+ out += d;
35+ });
36+ child.on("close", (code) => done({ ms: performance.now() - started, ok: code === 0, out }));
37+ });
38+}
40+const pct = (sorted: number[], p: number) => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))]!;
41+console.log(`Node ${process.versions.node}, ${PUSHES} pushes per writer, each writer its own agent and file.`);
42+console.log("writers | pushes | median | p95 | slowest | pushes/s | failed");
43+for (const writers of counts.length > 0 ? counts : [1, 4, 16]) {
44+ const store = mkdtempSync(join(tmpdir(), "abso-writers-store-"));
45+ const folders: string[] = [];
46+ const env = { ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" };
47+ const first = mkdtempSync(join(tmpdir(), "abso-writers-w0-"));
48+ writeFileSync(join(first, "readme.txt"), "writers\n");
49+ const init = await main(["init", "--local", "--project", "writers", "--agent", "w0", "--as-is"], {
50+ cwd: first,
51+ env,
52+ write: () => {},
53+ });
54+ if (init.exit !== 0) throw new Error(init.stdout + init.stderr);
55+ folders.push(first);
56+ for (let w = 1; w < writers; w++) {
57+ const dir = mkdtempSync(join(tmpdir(), `abso-writers-w${w}-`));
58+ const joined = await main(["join", "writers", "--local", "--agent", `w${w}`, "--dir", dir], {
59+ cwd: dir,
60+ env,
61+ write: () => {},
62+ });
63+ if (joined.exit !== 0) throw new Error(joined.stdout + joined.stderr);
64+ folders.push(dir);
65+ }
66+ const times: number[] = [];
67+ const failures: string[] = [];
68+ const started = performance.now();
69+ await Promise.all(
70+ folders.map(async (dir, w) => {
71+ for (let i = 0; i < PUSHES; i++) {
72+ writeFileSync(join(dir, `w${w}.txt`), `writer ${w}, push ${i}\n`);
73+ const r = await push(dir, store, `w${w} push ${i}`);
74+ times.push(r.ms);
75+ if (!r.ok) failures.push(`w${w} push ${i}: ${r.out.trim().split("\n").slice(-2).join(" / ")}`);
76+ }
77+ }),
78+ );
79+ const total = (performance.now() - started) / 1000;
80+ times.sort((a, b) => a - b);
81+ const ms = (n: number) => `${n.toFixed(0)} ms`.padStart(8);
82+ console.log(
83+ `${String(writers).padStart(7)} | ${String(times.length).padStart(6)} | ${ms(pct(times, 0.5))} | ${ms(pct(times, 0.95))} | ${ms(times.at(-1)!)} | ${(times.length / total).toFixed(1).padStart(8)} | ${failures.length}`,
84+ );
85+ for (const f of failures.slice(0, 5)) console.log(` ${f}`);
86+ for (const d of [store, ...folders]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
87+}
--- a/worker/project/news.ts
+++ b/worker/project/news.ts
@@ -361,7 +361,11 @@
361361 changedNames.size > 0
362362 ? host.definitionCollisions(agent, host.newerFor(agent), changedNames).filter((d) => just.has(d.by))
363363 : [];
364− const items = [...lineNews(host, agent, lines), ...definitionNews(defs), ...moveNews(host, draft, just, space, version)];
364+ const items = [
365+ ...lineNews(host, agent, lines),
366+ ...definitionNews(defs),
367+ ...moveNews(host, draft, just, space, version),
368+ ];
365369 news += items.length;
366370 host.queueNews(agent, items, entries);
367371 }