- MCP
- blame on this site's /mcp
- CLI
- abso blame src/engine/test/projection-scratch.test.ts --json
- JSON
- /christopher/abso-core/blame/src/engine/test/projection-scratch.test.ts?format=json
101 linescodex-capacity-chair 97% · capacity 3%Last change capacity in version 253,
101 lines from 3 changes in 3 versions.
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { withProjectionScratch } from "../projection-scratch.ts";
4import { CachedStateStorage, type GraphStateStorage } from "../state-source.ts";
5import { SqlState } from "./storage-helper.ts";
7test("projection scratch is isolated, detached and rolled back inside canonical transactions", () => {
8 const source = new SqlState();
9 const storage = new CachedStateStorage(source);
10 try {
11 storage.transaction(() => {
12 storage.write("canonical", "before", 1);
13 let escaped: GraphStateStorage | undefined;
14 const result = withProjectionScratch(
15 storage,
16 () => {},
17 (scratch) => {
18 escaped = scratch;
19 scratch.write("canonical", "before", 99);
20 const inner = withProjectionScratch(
21 storage,
22 () => {},
23 (nested) => {
24 assert.equal(nested.read("canonical", "before"), undefined);
25 nested.write("canonical", "before", 101);
26 return nested.read("canonical", "before");
27 },
28 );
29 assert.equal(inner, 101);
30 return { value: scratch.read("canonical", "before"), data: new Int32Array([1, 2]) };
31 },
32 );
33 assert.deepEqual(result, { value: 99, data: new Int32Array([1, 2]) });
34 assert.throws(() => escaped!.write("x", "y", true), /ended/);
capacity253The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).
- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.
- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.
On a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.
Tests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.
codex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.Compare35 // A scratch rollback drops only what the scratch wrote (abso Capacity): the canonical value written before it, in
36 // the outer transaction, stays cached and is still right.
37 assert.equal(storage.retainedEntries, 1, "only the canonical value written before the scratch remains");
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare38 assert.equal(storage.read("canonical", "before"), 1);
39 storage.write("canonical", "after", 2);
40 });
41 assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 2);
codex-capacity-chair145Cache successful integer writes within existing storage limits (#16)Compare42 assert.equal(storage.retainedEntries, 2, "only the canonical read and successful counter write remain");
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare43 assert.equal(storage.read("canonical", "after"), 2);
44 } finally {
45 source.db.close();
46 }
47});
49test("projection errors, changed identities and escaping capabilities cannot commit scratch", () => {
50 const source = new SqlState();
51 try {
52 let checks = 0;
53 assert.throws(
54 () =>
55 withProjectionScratch(
56 source,
57 () => {
58 if (++checks === 2) throw new Error("identity changed");
59 },
60 (scratch) => {
61 scratch.write("x", "y", 1);
62 return 2;
63 },
64 ),
65 /identity changed/,
66 );
67 assert.throws(
68 () =>
69 withProjectionScratch(
70 source,
71 () => {},
72 (scratch) => {
73 scratch.write("x", "y", 1);
74 throw new Error("failed computation");
75 },
76 ),
77 /failed computation/,
78 );
79 assert.throws(
80 () =>
81 withProjectionScratch(
82 source,
83 () => {},
84 (scratch) => scratch,
85 ),
86 /clone|cloned/i,
87 );
88 assert.throws(
89 () =>
90 withProjectionScratch(
91 source,
92 () => {},
93 () => Promise.resolve(1),
94 ),
95 /synchronously/,
96 );
97 assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 0);
98 } finally {
99 source.db.close();
100 }
101});