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
blame on this site's /mcp
CLI
abso blame worker/project/test/membership-cache.test.ts --json
JSON
/christopher/abso-core/blame/worker/project/test/membership-cache.test.ts?format=json
56 linescapacity 100%Last change capacity in version 200,

56 lines from 1 change in 1 version.

capacity200Project abso's memory, cut by a third (abso Capacity, prod abso hit its isolate memory limit at 7:20 and 7:25 PM CT). (1) The in-memory membership cache is one least-recently-used cache of 16 sets across every space, not up to 17 per space: each named draft cached whole copies of shared's set, 37 MB on prod abso with 106 drafts. Keyed by the space object, so a space rebuilt under the same name never gets old sets. (2) An agent keeps at most 200 unheard news lines (trimmed in batches of 50), the oldest dropped behind one line counting them: stopped agents kept every line, 7 MB. Measured on Engine's prod export of abso (81,855 entries) with measure-memory.ts --disk --reads: 96.6 MB after load before, 61.1 MB after; 105.3 MB after the heaviest reads before, 66.3 MB after. New tests membership-cache.test.ts and news-cap.test.ts.Compare1// The in-memory membership cache is bounded across every space (abso Capacity): 106 drafts on prod project abso
2// each kept whole copies of shared's set, 37 MB in all. One least-recently-used cache now holds MEMBERSHIP_SETS_KEPT.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { addVersion, MEMBERSHIP_SETS_KEPT, Membership, newSpace } from "../spaces.ts";
7
8const SHARED = "";
9
10/** Shared with `versions` versions, version v adding atom s<v>; then `drafts` drafts, each on shared's version 3. */
11function membership(versions: number, drafts: number): Membership {
12 const m = new Membership();
13 for (let v = 0; v < versions; v++)
14 addVersion(m.shared, { version: v, agent: "a", message: `v${v}`, time: 0, atoms: [`s${v}`] });
15 for (let d = 0; d < drafts; d++) {
16 const space = newSpace(`d${d}`);
17 m.spaces.set(space.name, space);
18 addVersion(space, { version: 0, agent: "a", message: "start", time: 0, atoms: [], sharedBase: 3 });
19 addVersion(space, { version: 1, agent: "a", message: "work", time: 0, atoms: [`d${d}-x`], sharedBase: 3 });
20 }
21 return m;
24test("the cache never holds more than MEMBERSHIP_SETS_KEPT sets, however many drafts are read", () => {
25 const m = membership(10, MEMBERSHIP_SETS_KEPT * 3);
26 for (let d = 0; d < MEMBERSHIP_SETS_KEPT * 3; d++) m.at(m.spaces.get(`d${d}`)!, 1);
27 assert.ok(m.setsKept <= MEMBERSHIP_SETS_KEPT, `kept ${m.setsKept}`);
28});
30test("a set that fell out of the cache is built again the same, and a kept one is the same object", () => {
31 const m = membership(10, MEMBERSHIP_SETS_KEPT * 2);
32 const first = m.spaces.get("d0")!;
33 const before = [...m.at(first, 1)].sort();
34 assert.deepEqual(before, ["d0-x", "s0", "s1", "s2", "s3"], "shared at its base, plus its own");
35 for (let d = 1; d < MEMBERSHIP_SETS_KEPT * 2; d++) m.at(m.spaces.get(`d${d}`)!, 1);
36 assert.deepEqual([...m.at(first, 1)].sort(), before, "rebuilt after eviction, same contents");
37 const again = m.at(first, 1);
38 assert.equal(m.at(first, 1), again, "while kept, the same set");
39 // Shared's history and its newest version answer as before.
40 assert.deepEqual([...m.at(m.shared, 2)].sort(), ["s0", "s1", "s2"]);
41 assert.equal(m.at(m.shared, 9), m.shared.own, "shared's newest version is its live set, never cached");
42});
44test("a draft replaced under the same name never gets the old one's set", () => {
45 const m = membership(10, 1);
46 const old = m.spaces.get("d0")!;
47 assert.ok(m.at(old, 1).has("d0-x"));
48 const replaced = newSpace("d0");
49 m.spaces.set("d0", replaced);
50 addVersion(replaced, { version: 0, agent: "a", message: "start", time: 0, atoms: [], sharedBase: 5 });
51 addVersion(replaced, { version: 1, agent: "a", message: "work", time: 0, atoms: ["new"], sharedBase: 5 });
52 const now = m.at(replaced, 1);
53 assert.equal(now.has("d0-x"), false);
54 assert.deepEqual([...now].sort(), ["new", "s0", "s1", "s2", "s3", "s4", "s5"]);
55 assert.equal(SHARED, m.shared.name);
56});