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

Allow transactional bulk cleanup of temporary projection pages (#16)

of shared·codex-capacity-chair··Not checked

Version 143 · Files at version 144

2 files, 43 lines added, 2 removed.

--- a/src/engine/experimental/projection-overlay-storage.ts
+++ b/src/engine/experimental/projection-overlay-storage.ts
@@ -6,11 +6,13 @@
66export class ProjectionOverlayStorage implements GraphStateStorage {
77 readonly #base: GraphStateStorage;
88 readonly #collection: string;
9+ readonly #clearCollection?: (collection: string) => void;
910 #open = true;
10− constructor(base: GraphStateStorage, namespace: string) {
11+ constructor(base: GraphStateStorage, namespace: string, clearCollection?: (collection: string) => void) {
1112 if (!namespace) throw Error("missing projection overlay namespace");
1213 this.#base = base;
1314 this.#collection = `projection:temporary:${namespace}`;
15+ this.#clearCollection = clearCollection;
1416 for (const _ of base.entries(this.#collection)) throw Error("projection overlay namespace is occupied");
1517 }
1618 #check(): void {
@@ -64,7 +66,13 @@
6466 close(): void {
6567 if (!this.#open) return;
6668 this.#base.transaction(() => {
67− for (const [key] of this.#base.entries(this.#collection)) this.#base.remove(this.#collection, key);
69+ if (this.#clearCollection) {
70+ const result: unknown = this.#clearCollection(this.#collection);
71+ if (result && typeof result === "object" && "then" in result)
72+ throw Error("overlay cleanup must be synchronous");
73+ } else {
74+ for (const [key] of this.#base.entries(this.#collection)) this.#base.remove(this.#collection, key);
75+ }
6876 });
6977 this.#open = false;
7078 }
--- a/src/engine/test/projection-overlay-storage.test.ts
+++ b/src/engine/test/projection-overlay-storage.test.ts
@@ -3,6 +3,39 @@
33import { ProjectionOverlayStorage } from "../experimental/projection-overlay-storage.ts";
44import { SqlState } from "./storage-helper.ts";
55
6+test("host cleanup deletes only its overlay and a failed deletion rolls back without scanning", (t) => {
7+ const storage = new SqlState();
8+ try {
9+ let fail = true;
10+ const overlay = new ProjectionOverlayStorage(storage, "bulk", (collection) => {
11+ assert.equal(collection, "projection:temporary:bulk");
12+ storage.db.prepare("DELETE FROM state WHERE collection = ?").run(collection);
13+ if (fail) throw Error("cleanup failed after deletion");
14+ });
15+ storage.write("pages", "durable", 1);
16+ storage.write("projection:temporary:other", "other", 2);
17+ for (let i = 0; i < 100; i++) overlay.write("pages", String(i), i);
18+ const before = storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
19+ t.mock.method(storage, "entries", () => {
20+ throw Error("cleanup must not enumerate rows");
21+ });
22+ assert.throws(() => overlay.close(), /cleanup failed/);
23+ assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
24+ assert.equal(overlay.read("pages", "99"), 99);
25+ fail = false;
26+ overlay.close();
27+ assert.equal(storage.read("pages", "durable"), 1);
28+ assert.equal(storage.read("projection:temporary:other", "other"), 2);
29+ assert.equal(
30+ storage.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection = ?").get("projection:temporary:bulk")!.n,
31+ 0,
32+ );
33+ assert.throws(() => overlay.read("pages", "99"), /closed/);
34+ } finally {
35+ storage.db.close();
36+ }
37+});
639test("temporary projection pages shadow committed pages and cleanup preserves durable writes", () => {
740 const storage = new SqlState();
841 try {