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

Versions 158 to 318

Compare

+161 −20 in 12 places
Lines 4–21 at 318 (were 4–15 at 158)
44// R2 copies, edge cache, probes or disk-first writer.
55
66import { DurableObject } from "cloudflare:workers";
7−import { type Answer, answer, type Readers } from "../../worker/project/http.ts";
7+import { createHash } from "node:crypto";
8+import { type Answer, answer, type Readers, readerAnswer } from "../../worker/project/http.ts";
89import type { ProjectCalls, ProjectHistory } from "../../worker/project/project-api.ts";
10+import { ProjectError } from "../../worker/project/project-error.ts";
911import { BLOB_MAX, BlobStore } from "./blobs.ts";
1012import { DiskFirstRuntime } from "./disk-first-runtime.ts";
1113import { EngineProject, SqliteLog } from "./engine-project.ts";
1214import { artifactsOf, type Env } from "./env.ts";
15+import { GitDiskIntake } from "./git-disk-intake.ts";
16+import { GitFileContents } from "./git-file-contents.ts";
17+import { GitIntakeLimitError } from "./git-intake-limit.ts";
18+import { GitIntakeTrees } from "./git-intake-trees.ts";
1319import { pushedSince, remoteHead } from "./ingest.ts";
1420import {
1521 checkKey,
Lines 30–36 at 318 (were 24–29 at 158)
2430 revokeKey,
2531} from "./keys.ts";
2632import { type PushResult, pushShared, repoName } from "./push.ts";
33+import { pushSnapshot } from "./push-snapshot.ts";
2734import { SqliteWriterState } from "./writer-host.ts";
2835
2936const READ_OPS = new Set([
Lines 49–55 at 318 (were 42–47 at 158)
4249 "file",
4350 "files",
4451 "compare",
52+ "without",
4553 "where",
4654 "feed",
4755 "drafts",
Lines 64–74 at 318 (were 56–61 at 158)
5664export const PUSH_EVERY_MS = 60_000;
5765/** While agents are working, how often a call looks for plain-git pushes to the repo. */
5866const GIT_CHECK_MS = 15_000;
67+// Disk scratch admission limits, independent of the Worker's resident memory.
68+const GIT_PACK_MAX_BYTES = 128 * 1024 * 1024;
69+const GIT_OBJECT_MAX_BYTES = 64 * 1024 * 1024;
70+const GIT_DECODED_MAX_BYTES = 256 * 1024 * 1024;
71+const GIT_LIMIT_POLICY = `expanded-v2:${GIT_PACK_MAX_BYTES}:${GIT_OBJECT_MAX_BYTES}:${GIT_DECODED_MAX_BYTES}`;
5972
6073/**
6174 * The load guard (platform issue 46): an estimate of a loaded project's memory from its log entries, lines and claim
Lines 129–139 at 318 (were 116–121 at 158)
116129 constructor(ctx: DurableObjectState, env: Env) {
117130 super(ctx, env);
118131 this.blobs = new BlobStore(ctx.storage);
132+ if (env.ABSO_DISK_FIRST === "on") {
133+ GitDiskIntake.recover(ctx.storage);
134+ GitFileContents.recover(ctx.storage);
135+ GitIntakeTrees.recover(ctx.storage);
136+ }
119137 }
120138
121139 /** Where files kept whole go: the project's blob store. */
Lines 181–187 at 318 (were 163–168 at 158)
163181 body: unknown,
164182 how: string | undefined,
165183 revision: number,
184+ request?: { id: string; principal: string },
166185 ): Promise<Answer> {
167186 const runtime = this.diskRuntime()!;
168187 const validate = () => {
Lines 189–199 at 318 (were 170–176 at 158)
170189 throw Object.assign(Error("project authorization changed during call setup"), { code: "authority-changed" });
171190 };
172191 const progress = await this.prepareDisk(validate);
173− const known = new Set((await this.ctx.storage.get<string[]>("readers")) ?? []);
192+ const legacyReaders = (await this.ctx.storage.get<string[]>("readers")) ?? [];
193+ const storedReaders = progress?.ready
194+ ? (new SqliteWriterState(this.ctx.storage, "server-disk-v1").read("runtime", "readers") as string[] | undefined)
195+ : undefined;
196+ const known = new Set(storedReaders ?? legacyReaders);
174197 validate();
175198 let readersChanged = false;
176199 const readers: Readers = {
Lines 210–253 at 318 (were 187–211 at 158)
187210 return { status: 404, body: { error: "no such project; run init first" } };
188211 if (!progress?.ready && !(progress?.phase === "empty" && op === "init"))
189212 return { status: 503, body: { error: "project indexes are being prepared", retryAfter: 1, progress } };
213+ if (agent && op !== "reader") {
214+ const refused = readerAnswer({ status: () => undefined }, op, agent, body, readers);
215+ if (refused) return refused;
216+ }
190217 const before = new SqliteLog(this.ctx.storage).seq();
191218 const action = (calls: EngineProject) => {
192219 const result = answer(calls, op, agent, body, readers, how);
193220 if (result.status >= 500) throw Error(`project operation failed: ${JSON.stringify(result.body)}`);
221+ if (readersChanged)
222+ new SqliteWriterState(this.ctx.storage, "server-disk-v1").write("runtime", "readers", readers.list());
194223 return result;
195224 };
196225
226+ const receipt = request
227+ ? {
228+ id: `http:${createHash("sha256").update(request.principal).digest("hex")}:${request.id}`,
229+ identity: {
230+ project: name,
231+ principal: request.principal,
232+ agent: agent ?? null,
233+ operation: op,
234+ body: body ?? null,
235+ how: how ?? null,
236+ },
237+ }
238+ : undefined;
197239 const result =
198240 progress.phase === "empty"
199− ? runtime.initialize(action, validate)
241+ ? runtime.initialize(action, validate, receipt)
200242 : READ_OPS.has(op) || op.startsWith("change/")
201243 ? runtime.read(action, validate)
202− : runtime.write(action, validate);
244+ : runtime.write(action, validate, receipt);
203246 if (readersChanged) {
204247 this.authorityRevision++;
205− await this.ctx.storage.put("readers", readers.list());
206248 }
207249 const log = new SqliteLog(this.ctx.storage);
208− if (log.seq() !== before) {
250+ if (log.seq() !== before || (request && !READ_OPS.has(op))) {
209251 this.wake();
210252 await this.ctx.storage.put("name", name);
211253 await this.soon(Date.now() + 100);
Lines 387–424 at 318 (were 345–364 at 158)
345387 inFeed = false,
346388 how?: string,
347389 key?: KeyForCall,
390+ requestId?: string,
348391 ): Promise<Answer> {
349392 const revision = this.authorityRevision;
393+ let principal = "shared-token";
394+ if (
395+ requestId !== undefined &&
396+ !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(requestId)
397+ )
398+ return { status: 400, body: { error: "Idempotency-Key must be a UUID" } };
350399 if (key) {
351400 const decided = await this.checkAgentKey(key.presented, agent, key.address);
352401 if (!decided.ok) return { status: decided.status, body: { error: decided.error } };
353402 const allowed = keyAllows(decided.role, { write: key.write, agent, route: key.route });
354403 if (!allowed.ok) return { status: allowed.status, body: { error: allowed.error } };
355404 how = decided.as;
405+ principal = `key:${decided.id}`;
356406 }
357407 if (op === "feed" && !inFeed) return this.feed(name, body);
358408 if (this.diskRuntime()) {
359409 try {
360− return await this.diskCall(name, op, agent, body, how, revision);
410+ return await this.diskCall(
411+ name,
412+ op,
413+ agent,
414+ body,
415+ how,
416+ revision,
417+ requestId ? { id: requestId, principal } : undefined,
418+ );
361419 } catch (error) {
420+ if ((error as { code?: string })?.code === "request-reused")
421+ return { status: 409, body: { error: "Idempotency-Key was reused for a different request" } };
362422 if ((error as { code?: string })?.code === "authority-changed")
363423 return { status: 409, body: { error: "project authorization changed; retry the request", retryable: true } };
364424 throw error;
Lines 546–625 at 318 (were 486–512 at 158)
486546 const seen = await this.ctx.storage.get<string>("git:head");
487547 const pushed = await this.ctx.storage.get<PushResult>("pushed");
488548 const head = await remoteHead(artifacts, name);
549+ const refusal = this.diskRuntime()
550+ ? await this.ctx.storage.get<{ head: string; policy: string; kind: GitIntakeLimitError["kind"]; error: string }>(
551+ "git:size-refusal",
552+ )
553+ : undefined;
554+ if (refusal) {
555+ if (
556+ head &&
557+ head !== seen &&
558+ head !== pushed?.commit &&
559+ refusal.head === head &&
560+ refusal.policy === GIT_LIMIT_POLICY
561+ )
562+ throw new GitIntakeLimitError(refusal.kind, refusal.error);
563+ await this.ctx.storage.delete("git:size-refusal");
564+ }
489565 if (!head || head === seen || head === pushed?.commit) return null;
490566 const sharedBlobs = this.useProject((p) => p.shared().blobs ?? {});
567+ using trees = this.diskRuntime() ? new GitIntakeTrees(this.ctx.storage) : undefined;
491568 const found = await pushedSince(
492569 artifacts,
493570 name,
494571 seen,
495572 async (bytes) => (bytes.byteLength > BLOB_MAX ? null : this.blobs.putBytes(bytes)),
496573 (path) => sharedBlobs[path],
497− );
574+ trees ? (files, path, body, oid) => trees.retainFile(files, path, body, oid) : undefined,
575+ trees
576+ ? {
577+ storage: this.ctx.storage,
578+ maxPackBytes: GIT_PACK_MAX_BYTES,
579+ maxObjectBytes: GIT_OBJECT_MAX_BYTES,
580+ maxDecodedBytes: GIT_DECODED_MAX_BYTES,
581+ maxBinaryBytes: BLOB_MAX,
582+ retainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid),
583+ }
584+ : undefined,
585+ ).catch(async (error: unknown) => {
586+ if (trees && error instanceof GitIntakeLimitError) {
587+ const refusal = {
588+ head,
589+ policy: GIT_LIMIT_POLICY,
590+ kind: error.kind,
591+ error: error.message,
592+ at: new Date().toISOString(),
593+ };
594+ await this.ctx.storage.put({ "git:size-refusal": refusal, "git:error": refusal });
595+ }
596+ throw error;
597+ });
498598 if (!found || found.commits.length === 0) {
499599 if (found) await this.ctx.storage.put("git:head", found.head);
500600 return null;
501601 }
602+ // Unexpected failures leave the cursor unacknowledged for retry. Engine
603+ // refusals are recorded and acknowledged so a later fixing commit can advance.
604+ const ingest = (p: EngineProject) =>
605+ p.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now());
606+ const runtime = this.diskRuntime();
502607 let result: unknown;
503608 try {
504− result = this.useProject(
505− (p) => p.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now()),
506− true,
507− );
508− } catch (e) {
509− result = { error: e instanceof Error ? e.message : String(e) };
609+ result = runtime
610+ ? runtime.write(ingest, () => {}, {
611+ id: `git:${found.head}`,
612+ identity: {
613+ project: name,
614+ head: found.head,
615+ base: found.base,
616+ commits: found.commits.map((commit) => commit.sha),
617+ },
618+ })
619+ : this.useProject(ingest, true);
620+ } catch (error) {
621+ if (!(error instanceof ProjectError)) throw error;
622+ result = { error: error.message };
510623 }
511624 const taken = {
512625 at: new Date().toISOString(),
Lines 653–682 at 318 (were 540–554 at 158)
540653 if (!artifacts) return;
541654 const name = await this.ctx.storage.get<string>("name");
542655 if (!name || !this.useProject((p) => p.exists())) return;
656+ let intakeFailed = false;
543657 await this.gitSync().then(
544− () => this.ctx.storage.delete("git:error"),
545− (e) =>
546− this.ctx.storage.put("git:error", {
658+ async () => {
659+ await this.ctx.storage.delete("git:error");
660+ await this.ctx.storage.delete("git:retry-attempts");
661+ },
662+ async (e) => {
663+ intakeFailed = true;
664+ const attempts = ((await this.ctx.storage.get<number>("git:retry-attempts")) ?? 0) + 1;
665+ await this.ctx.storage.put("git:retry-attempts", attempts);
666+ await this.ctx.storage.put("git:error", {
547667 at: new Date().toISOString(),
548668 error: e instanceof Error ? e.message : String(e),
549− }),
669+ });
670+ await this.soon(Date.now() + (attempts === 1 ? 1 : attempts === 2 ? 5 : 15) * 60_000);
671+ },
550672 );
551− const shared = this.useProject((p) => p.shared());
673+ // Never export over a remote head whose changes could not be taken in.
674+ if (intakeFailed) return;
675+ const shared = pushSnapshot(
676+ this.useProject((p) => p.sharedPushMetadata()),
677+ (version, path) => this.useProject((current) => current.fileTextAt(version, path)),
678+ (version, paths) => this.useProject((current) => current.fileTextsAt(version, paths)),
679+ );
552680 const done = await this.ctx.storage.get<PushResult>("pushed");
553681 if (done && done.version >= shared.version) return;
554682 const pushedAt = (await this.ctx.storage.get<number>("pushedAt")) ?? 0;
Lines 686–705 at 318 (were 558–564 at 158)
558686 }
559687 let result: PushResult;
560688 try {
561− result = await pushShared(artifacts, name, shared, (sha) => this.blobs.read(sha));
689+ result = await pushShared(
690+ artifacts,
691+ name,
692+ shared,
693+ (sha) => this.blobs.read(sha),
694+ this.env.ABSO_DISK_FIRST === "on"
695+ ? {
696+ storage: this.ctx.storage,
697+ maxPackBytes: GIT_PACK_MAX_BYTES,
698+ maxObjectBytes: GIT_OBJECT_MAX_BYTES,
699+ maxDecodedBytes: GIT_DECODED_MAX_BYTES,
700+ }
701+ : undefined,
702+ );
562703 } catch (e) {
563704 // Kept for /out, and tried again with a backoff of our own (a thrown alarm is retried only six times).
564705 const was = await this.ctx.storage.get<{ attempts?: number }>("pushError");
MCP
compare on this site's /mcp
CLI
abso diff 158 318 server/src/project-object.ts --json
JSON
/christopher/abso-core/compare/158..318?file=server%2Fsrc%2Fproject-object.ts&format=json