- MCP
- show on this site's /mcp
- CLI
- abso show 158 --json
- JSON
- /christopher/abso-core/versions/158?format=json
Integrate opt-in disk-first project runtime with cold-object transactions
of shared·codex-capacity-chair··Not checked
Version 157 · Files at version 158
12 files, 814 lines added, 51 removed.
--- /dev/null
+++ b/server/src/disk-first-runtime.ts
@@ -0,0 +1,167 @@
7+
9+type Progress = { ready: boolean; phase: "empty" | "writer" | "projection" | "ready"; next: number };
10+
18+ constructor(storage: SqliteStorage, database: string, namespace: string, services: Services = {}) {
34+ return new SqliteWriterHost(this.#storage, this.#namespace, this.#projection, { indexProjectionAtoms: true });
58+ const project = new Project(log, { ...this.#services, now: () => Date.now(), shapes: log.shapes() });
112+ return { ready: page.ready, phase: page.ready ? "ready" : "projection", next: root.logLength };
117+ this.#storage.sql.exec("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'writer_state'").toArray()
121+ if (this.#state().read("runtime", "format") !== 1 || this.#state().read("runtime", "ready") !== true)
145+ if (request && (!request.id || request.id.length > 128)) throw Error("invalid disk-first request identity");
148+ const receipt = state.read("runtime:receipts", request.id) as { identity: string; result: T } | undefined;
--- a/server/src/engine-project.ts
+++ b/server/src/engine-project.ts
@@ -536,14 +536,23 @@
536536 if (!this.read) throw Object.assign(new Error("the feed needs the log"), { code: "not-implemented" });
539− const entries = start < end ? this.read(start, Math.min(limit, end - start)) : [];
541− const events = feedEvents(entries, start).map((e) => {
546− return { next: start + entries.length, end, events };
548557
--- a/server/src/project-object.ts
+++ b/server/src/project-object.ts
@@ -7,6 +7,7 @@
@@ -23,7 +24,34 @@
2628
54+
2755/** At most one push out a minute: each one clones the repo, so publishes in a burst share one. */
@@ -78,6 +106,7 @@
@@ -94,8 +123,109 @@
94123 return { keep: (text: string) => this.blobs.putText(text), read: (sha: string) => this.blobs.textOf(sha) };
96125
149+ new SqliteWriterState(this.ctx.storage, "server-disk-v1").read("runtime", "format") !== undefined
154+ if (runtime) return write ? runtime.write(operation, () => {}) : runtime.read(operation, () => {});
170+ throw Object.assign(Error("project authorization changed during call setup"), { code: "authority-changed" });
189+ return { status: 503, body: { error: "project indexes are being prepared", retryAfter: 1, progress } };
193+ if (result.status >= 500) throw Error(`project operation failed: ${JSON.stringify(result.body)}`);
196+
221+ if (result.status === 200 && op === "starting") result.body = await this.startingHooks(name, result.body);
225+
97226 /** The project, loaded from its log on first use. A log too big for memory is refused, not loaded. */
@@ -216,6 +346,7 @@
@@ -224,6 +355,17 @@
363+ return { status: 409, body: { error: "project authorization changed; retry the request", retryable: true } };
368+ return { status: 409, body: { error: "disk-first indexes exist; enable ABSO_DISK_FIRST before writing" } };
@@ -332,16 +474,20 @@
333475
334476 private async gitSyncOnce(): Promise<{ head: string; commits: number; answer: unknown } | null> {
339− if (!name || !this.project.exists()) return null;
344− const sharedBlobs = this.project.shared().blobs ?? {};
@@ -355,7 +501,10 @@
358− result = this.project.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now());
505+ (p) => p.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now()),
@@ -383,10 +532,14 @@
383532 * most once a minute, backing off on failure. Without an ARTIFACTS binding (local dev) it does nothing.
389− if (!name || !this.ensure()?.exists()) return;
@@ -395,7 +548,7 @@
398− const shared = this.project.shared();
@@ -422,17 +575,16 @@
422575 await this.ctx.storage.put({ pushed: result, "git:head": result.commit, pushedAt: Date.now() });
425− if (this.project.shared().version > result.version) await this.soon(Date.now() + PUSH_EVERY_MS);
578+ if (this.useProject((p) => p.shared().version) > result.version) await this.soon(Date.now() + PUSH_EVERY_MS);
427580
431− const p = this.ensure();
435− version: p?.exists() ? p.shared().version : null,
@@ -471,6 +623,7 @@
473625 const issued = await issueKey(state, secret, agent, "admin", Date.now(), address, when, role);
@@ -480,6 +633,7 @@
@@ -492,9 +646,11 @@
492646
495− const p = this.ensure();
496− if (!p?.exists()) return [];
497− return p.status().agents.map((a) => a.agent);
499655
@@ -502,33 +658,41 @@
505− const p = this.ensure();
506− if (!p?.exists()) return items.map(() => ({ to: [] }));
507− const engine = p as ProjectCalls & ProjectHistory;
508− const out: { to: string[] }[] = [];
509− for (const item of items) {
510− const status = p.status() as { agents: { agent: string; starting?: { issue?: number } }[] };
511− const known = new Set(status.agents.map((a) => a.agent));
512− const to = new Set([
513− ...(item.issue !== null
514− ? status.agents.filter((a) => a.starting?.issue === item.issue).map((a) => a.agent)
515− : []),
516− ...(item.to ?? []).filter((t) => known.has(t)),
517− ]);
518− to.delete(item.from);
519− if (to.size === 0) {
520− out.push({ to: [] });
521− continue;
523− try {
524− engine.announce(item.from, item.text, [...to]);
525− out.push({ to: [...to] });
526− } catch (e) {
527− console.log(JSON.stringify({ event: "issues-news", error: String(e).slice(0, 200) }));
528− out.push({ to: [] });
529− }
530− }
531− this.wake();
532− return out;
--- a/server/src/writer-host.ts
+++ b/server/src/writer-host.ts
@@ -351,7 +351,7 @@
354− const result = input.operation(new EngineProject(project));
354+ const result = input.operation(new EngineProject(project, (from, limit) => this.#log.since(from, limit)));
357357 if (!SqliteWriterHost.#same(source, this.source())) throw new Error("reader source changed");
--- /dev/null
+++ b/server/test/disk-first-runtime.test.ts
@@ -0,0 +1,132 @@
11+
28+ storage.db.prepare("SELECT COUNT(*) AS n FROM sqlite_master WHERE name = 'writer_state'").get()!.n,
33+ runtime().initialize((calls) => answer(calls, "init", undefined, { files: { "a.txt": "one\ntwo\n" } }), validate)
45+ const req = { id: "record-1", identity: { agent: "alice", operation: "record", files: { "a.txt": "changed\n" } } };
64+ assert.throws(() => runtime().write(operation, validate, { ...req, identity: { agent: "bob" } }), /reused/);
77+ runtime().write((calls) => answer(calls, "publish", "alice", { message: "Publish" }), validate).status,
91+
101+ const tables = storage.db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name").all();
104+ storage.db.prepare(`SELECT * FROM "${String(row.name).replaceAll('"', '""')}" ORDER BY rowid`).all(),
--- a/server/test/engine-project.test.ts
+++ b/server/test/engine-project.test.ts
@@ -5,6 +5,26 @@
66
19+ t.mock.method(SqliteLog.prototype, "since", function (this: SqliteLog, from: number, limit: number) {
--- /dev/null
+++ b/server/test/project-object-disk-first.test.ts
@@ -0,0 +1,168 @@
7+
12+ url: `data:text/javascript,${encodeURIComponent("export class DurableObject { constructor(ctx, env) { this.ctx = ctx; this.env = env; } }")}`,
20+
21+test("empty disk projects and unloadable legacy projects preserve lookup fallbacks", async (t) => {
24+ const context = { id: { toString: () => "empty" }, storage: { ...storage, get: async () => undefined } };
31+ assert.deepEqual(await disk.news("empty", [{ from: "alice", issue: null, text: "Hello" }]), [{ to: [] }]);
38+ assert.deepEqual(await legacy.news("empty", [{ from: "alice", issue: null, text: "Hello" }]), [{ to: [] }]);
41+
74+ { ABSO_DISK_FIRST: "on", ABSO_ARTIFACTS: "off", KEY_HMAC_SECRET: "invented-test-secret" } as never,
91+ assert.equal((await call("init", undefined, { files: { "a.txt": "one\ntwo\n" } })).status, 200);
105+ assert.deepEqual(await object().news("project", [{ from: "bob", issue: null, text: "Hello", to: ["alice"] }]), [
109+ for (const agent of ["alice", "bob"]) assert.equal((await call("sync", agent, {})).status, 200);
110+ assert.equal((await call("record", "alice", { files: { "a.txt": "Alice's change\n" } })).status, 200);
111+ assert.equal((await call("record", "bob", { files: { "a.txt": "Bob's change\n" } })).status, 200);
121+ state: storage.db.prepare("SELECT * FROM writer_state ORDER BY namespace,collection,key,part").all(),
125+ const held = await disabled.call("project", "record", "alice", { files: { "a.txt": "legacy write\n" } });
130+ assert.equal((await call("status", undefined, {})).status, 200, "re-enabling disk mode preserves the valid root");
141+ () => object().news("project", [{ from: "bob", issue: null, text: "Must roll back", to: ["alice"] }]),
150+ const revoked = await current.call("project", "record", "alice", { files: { "a.txt": "unauthorized\n" } });
--- a/src/engine/experimental/projection-locator.ts
+++ b/src/engine/experimental/projection-locator.ts
@@ -120,6 +120,24 @@
127+ function* visit(current: Page, parent?: string, digit?: string, depth = 0): IterableIterator<readonly [number, T]> {
140+
--- a/src/engine/experimental/projection-reader.ts
+++ b/src/engine/experimental/projection-reader.ts
@@ -23,18 +23,31 @@
26− this.graph.has(id) &&
27− (this.#adapter.members.get(this.#state.membership, this.graph.atom(id).seq)?.present ?? false);
26+ this.graph.has(id) && (this.#adapter.members.get(this.#state.membership, Number(id.slice(1)))?.present ?? false);
35− values(): SetIterator<string> {
37− throw Error("unsupported projected membership enumeration");
--- /dev/null
+++ b/src/engine/test/projection-membership-iterator.test.ts
@@ -0,0 +1,71 @@
9+
42+
43+test("projected membership streams without atom payload reads and expires with its scope", () => {
47+ const atoms = [repo.graph.atom("a0"), repo.edit({ edits: [{ file: "a.txt", old: "one\n", new: "two\n" }] })];
--- a/worker/project/changes-since.ts
+++ b/worker/project/changes-since.ts
@@ -26,11 +26,10 @@
29− for (const file of host.touchedFiles(
30− [...a].filter((id) => !b.has(id)),
31− [before, after],
32− ))
33− touched.add(file);