- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/test/view-cache.test.ts --json
- JSON
- /christopher/abso-core/blame/worker/project/test/view-cache.test.ts?format=json
187 linescodex-capacity-policy 52% · capacity 33% · codex-capacity-chair 15%Last change capacity in version 263,
187 lines from 6 changes in 6 versions.
codex-capacity-policy104Enforce retained view cache budget on accessCompare1import assert from "node:assert/strict";
2import { test } from "node:test";
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare3import type { ReadView } from "../../../src/engine/index.ts";
codex-capacity-policy104Enforce retained view cache budget on accessCompare4import { buildBase, Graph, View } from "../../../src/engine/index.ts";
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare5import { StableOverlaySet } from "../../../src/engine/state-source.ts";
6import type { AtomId } from "../../../src/engine/types.ts";
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare7import { VIEW_COUNT, ViewCache } from "../views.ts";
9const VIEW_BUDGET = 24_000_000;
11test("indexed view cache keys never enumerate membership and remain bounded by eviction", () => {
12 class Counted extends StableOverlaySet<AtomId> {
13 iterations = 0;
14 override values(): SetIterator<AtomId> {
15 this.iterations++;
16 return super.values();
17 }
18 }
19 const graph = new Graph();
20 graph.add(buildBase({ "a.txt": "one\n" }, { author: "test", message: "base" }));
21 const cache = new ViewCache(graph);
22 const set = new Counted(["a0"]);
23 const view = cache.view(set);
24 assert.equal(set.iterations, 1, "only View closure validation enumerates membership");
25 assert.equal(cache.view(set), view);
26 assert.equal(set.iterations, 1, "cache hit must not construct a full-history key");
27 assert.equal(view.text("a.txt"), "one\n");
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare28 for (let i = 0; i < VIEW_COUNT + 1; i++) cache.view(new Counted(["a0"]));
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare29 assert.notEqual(cache.view(set), view, "indexed identities obey the same cache eviction limit");
30 assert.equal(set.iterations, 2);
31});
33type WeightControls = {
34 setIncomingWeights(values: number[]): void;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare35 setWeight(view: ReadView, weight: number): void;
38function withControlledWeights(run: (controls: WeightControls) => void): void {
39 const original = Object.getOwnPropertyDescriptor(View.prototype, "weight")!;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare40 const weights = new WeakMap<ReadView, number>();
codex-capacity-policy104Enforce retained view cache budget on accessCompare41 let newWeights: number[] = [];
42 Object.defineProperty(View.prototype, "weight", {
43 configurable: true,
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare44 value(this: ReadView) {
codex-capacity-policy104Enforce retained view cache budget on accessCompare45 if (!weights.has(this)) weights.set(this, newWeights.shift() ?? 0);
46 return weights.get(this)!;
47 },
48 });
49 const controls: WeightControls = {
50 setWeight: (view, weight) => {
51 weights.set(view, weight);
52 },
53 setIncomingWeights: (values) => {
54 newWeights = [...values];
55 },
56 };
57 try {
58 run(controls);
59 } finally {
60 Object.defineProperty(View.prototype, "weight", original);
61 }
62}
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare64function get(cache: ViewCache, key: string): ReadView {
codex-capacity-policy104Enforce retained view cache budget on accessCompare65 return cache.keyed(key, () => new Set());
66}
68test("the incoming view counts toward the retained byte budget", () => {
69 withControlledWeights((control) => {
70 const cache = new ViewCache(new Graph());
71 control.setIncomingWeights([10_000_000, 15_000_001]);
72 const old = get(cache, "old");
73 const incoming = get(cache, "incoming");
74 assert.equal(get(cache, "incoming"), incoming);
75 assert.notEqual(get(cache, "old"), old);
76 });
77});
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare79test("the cache retains exactly VIEW_COUNT views and evicts the least recently used one", () => {
codex-capacity-policy104Enforce retained view cache budget on accessCompare80 withControlledWeights((control) => {
81 const cache = new ViewCache(new Graph());
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare82 control.setIncomingWeights(Array(VIEW_COUNT + 1).fill(0));
codex-capacity-policy104Enforce retained view cache budget on accessCompare83 const first = get(cache, "key-0");
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare84 const retained = Array.from({ length: VIEW_COUNT - 1 }, (_, i) => get(cache, `key-${i + 1}`));
codex-capacity-policy104Enforce retained view cache budget on accessCompare85 assert.equal(get(cache, "key-0"), first);
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare86 const last = get(cache, `key-${VIEW_COUNT}`);
codex-capacity-policy104Enforce retained view cache budget on accessCompare87 assert.equal(get(cache, "key-0"), first);
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare88 assert.equal(get(cache, `key-${VIEW_COUNT}`), last);
codex-capacity-policy104Enforce retained view cache budget on accessCompare89 for (let i = 1; i < retained.length; i++) assert.equal(get(cache, `key-${i + 1}`), retained[i]);
90 assert.notEqual(get(cache, "key-1"), retained[0]);
91 });
92});
94test("a repeated hit reweighs lazy growth and evicts older entries", () => {
95 withControlledWeights((control) => {
96 const cache = new ViewCache(new Graph());
97 control.setIncomingWeights([10_000_000, 10_000_000]);
98 const growing = get(cache, "growing");
99 const older = get(cache, "older");
100 control.setWeight(growing, 16_000_000);
101 assert.equal(get(cache, "growing"), growing);
102 assert.notEqual(get(cache, "older"), older);
103 });
104});
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664).
What a kept reader held on abso, measured per question without the answer itself (heap snapshot after tree with authors, 56.9 MB held): the view cache 38.3 MB against its 24 MB budget, the agents read 6.5 to 7.7 MB, the move skeleton 2.4 MB, the state cache 2.3 MB; the rest is the engine's indexes.
- Project.afterRead: the view cache trimmed to its budget (ViewCache.trim) and the agents the read decoded let go (WriterAgents.release). Views grow while a call lays files out and the cache weighed them only when asked for again; a read-only reader never flushed its agents, so it held every agent's news told.
- View weight: a laid-out line's text counts a 16-byte header and a byte a character (two outside Latin-1), rounded to 8, as V8 holds it. It counted 8 and two a character, so abso's whole shared layout (22.7 MB held) weighed about 28 MB, over the budget alone: once trimmed, it was laid out again for every question (blame folder 2.5 s became 14.4 s).
Full warm run on the abso export: held heap at most 41.7 MB (was 56.9), 24 to 29 MB between the big reads (was 32 to 37); every answer the same. Status and drafts take about 30 ms more (agents read again); blame folder 1.7 s instead of 2.5 s.
Tests: view-cache (trim reweighs growth with no further hit), after-read (new: reads before and after it, and a write after it, against the in-memory project), and the collision, path and compare tests: 21 of 21.Compare106test("trim reweighs growth with no further hit and evicts until the views fit (abso Capacity)", () => {
107 withControlledWeights((control) => {
108 const cache = new ViewCache(new Graph());
109 control.setIncomingWeights([10_000_000, 10_000_000]);
110 const growing = get(cache, "growing");
111 const newer = get(cache, "newer");
112 // A call lays files out in the older view after the cache last weighed it, and nothing asks for it again.
113 control.setWeight(growing, 16_000_000);
114 cache.trim();
115 assert.equal(get(cache, "newer"), newer);
116 assert.notEqual(get(cache, "growing"), growing);
117 });
118});
codex-capacity-policy104Enforce retained view cache budget on accessCompare120test("an oversized view is returned but not retained", () => {
121 withControlledWeights((control) => {
122 const cache = new ViewCache(new Graph());
123 control.setIncomingWeights([VIEW_BUDGET + 1, 0]);
124 const oversized = get(cache, "large");
125 assert.ok(oversized instanceof View);
126 assert.notEqual(get(cache, "large"), oversized);
127 });
128});
130test("cache eviction preserves real Graph and View layouts", () => {
131 const graph = new Graph();
132 graph.add(
133 buildBase(
134 { "notes.txt": "one\ntwo\n", "folder/readme.md": "cached view\n" },
135 { author: "test", message: "view cache" },
136 ),
137 );
138 const set = new Set(["a0"]);
139 const cache = new ViewCache(graph);
140 const cached = cache.view(set);
141 const expected = new View(graph, set);
142 assert.deepEqual(cached.files(), expected.files());
143 assert.equal(cached.text("notes.txt"), expected.text("notes.txt"));
144 for (let i = 0; i < 40; i++) cache.keyed(`other-${i}`, () => set);
145 assert.deepEqual(cache.view(set).files(), new View(graph, set).files());
146});
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare147
148test("trim lets go of the least recently used file layouts across views before whole views (abso Capacity)", () => {
149 const graph = new Graph();
150 const lines = (name: string) => Array.from({ length: 40 }, (_, i) => `${name} line ${i}\n`).join("");
151 graph.add(
152 buildBase({ "a.txt": lines("a"), "b.txt": lines("b"), "c.txt": lines("c") }, { author: "test", message: "base" }),
153 );
154 const set = new Set(["a0"]);
155 // a.txt in x first, then b.txt in y, then c.txt in x: a.txt is the least recently used.
156 const use = (cache: ViewCache) => {
157 const x = cache.keyed("x", () => set);
158 const y = cache.keyed("y", () => set);
159 x.text("a.txt");
160 y.text("b.txt");
161 x.text("c.txt");
162 return { x: x as View, y: y as View };
163 };
164 const probe = use(new ViewCache(graph));
165 const total = probe.x.weight() + probe.y.weight();
166 const cache = new ViewCache(graph, undefined, total - 1);
167 const { x, y } = use(cache);
168 cache.trim();
169 assert.deepEqual(
170 [...x.laidOut()].map((f) => f.path),
171 ["c.txt"],
172 );
173 assert.deepEqual(
174 [...y.laidOut()].map((f) => f.path),
175 ["b.txt"],
176 );
177 assert.equal(
178 cache.keyed("x", () => set),
179 x,
180 "both views are still cached",
181 );
182 assert.equal(
183 cache.keyed("y", () => set),
184 y,
185 );
186 assert.equal(x.text("a.txt"), lines("a"), "a.txt is laid out again, the same");
187});