{"version":180,"agent":"codex-capacity-chair","message":"Keep Git export files and intake history on disk behind the disk-first switch; remember bounded intake refusals. In both modes, stop export after failed intake and retry in 1, 5, then 15 minutes; list refs before export cloning and propagate clone errors instead of treating failures as an empty repository. Preserve legacy cache lifetime, avoid a whole-file hash copy, and verify real Git uploads plus cold retry behavior. Review 56 cleared; activation remains off.","time":1791975298240,"timeIso":"2026-10-14T10:54:58.240Z","changes":27,"change":2889,"files":["server/src/git-delta-stream.ts","server/src/git-file-contents.ts","server/src/git-intake-limit.ts","server/src/git-object-bytes.ts","server/src/git-pack-resolver.ts","server/src/git-pack-spool.ts","server/src/memory-fs.ts","server/src/project-object.ts","server/src/push.ts","server/test/git-disk-clone.test.ts","server/test/git-export-http.test.ts","server/test/git-file-contents.test.ts","server/test/git-pack-resolver.test.ts","server/test/project-object-disk-first.test.ts","server/test/push.test.ts"],"draft":null,"diff":[{"path":"server/src/git-delta-stream.ts","added":3,"removed":1,"diff":"--- a/server/src/git-delta-stream.ts\n+++ b/server/src/git-delta-stream.ts\n@@ -39,7 +39,7 @@\n \t};\n \tif (integer() !== base.byteLength) throw Error(\"Git delta base length mismatch\");\n \tconst size = integer();\n-\tif (size > maxResultBytes) throw Error(\"Git delta result exceeds bound\");\n+\tif (size > maxResultBytes) throw new GitIntakeLimitError(\"object\", \"Git delta result exceeds bound\");\n \tconst emit = (chunk: Uint8Array) => {\n \t\tif (produced + chunk.length > size) throw Error(\"Git delta result length mismatch\");\n \t\twrite(chunk);\n@@ -71,3 +71,5 @@\n \tif (produced !== size) throw Error(\"Git delta result length mismatch\");\n \treturn size;\n }\n+\n+import { GitIntakeLimitError } from \"./git-intake-limit.ts\";"},{"path":"server/src/git-file-contents.ts","added":108,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/git-file-contents.ts\n@@ -0,0 +1,108 @@\n+import type { SqliteStorage } from \"./engine-project.ts\";\n+import type { FileContents } from \"./memory-fs.ts\";\n+\n+function initialize(storage: SqliteStorage): void {\n+\tstorage.sql.exec(\n+\t\t\"CREATE TABLE IF NOT EXISTS git_fs_meta (scope TEXT, path TEXT, bytes INTEGER, PRIMARY KEY(scope,path))\",\n+\t);\n+\tstorage.sql.exec(\n+\t\t\"CREATE TABLE IF NOT EXISTS git_fs_chunks (scope TEXT, path TEXT, part INTEGER, data BLOB NOT NULL, PRIMARY KEY(scope,path,part))\",\n+\t);\n+\tstorage.sql.exec(\"CREATE TABLE IF NOT EXISTS git_fs_budget (scope TEXT PRIMARY KEY, bytes INTEGER NOT NULL)\");\n+}\n+\n+/** One Git operation's scratch files. Reads materialize one file, never the whole filesystem. */\n+export class GitFileContents implements FileContents {\n+\tstatic recover(storage: SqliteStorage): void {\n+\t\tinitialize(storage);\n+\t\tstorage.transactionSync(() => {\n+\t\t\tfor (const table of [\"git_fs_chunks\", \"git_fs_meta\", \"git_fs_budget\"]) storage.sql.exec(`DELETE FROM ${table}`);\n+\t\t});\n+\t}\n+\treadonly scope = crypto.randomUUID();\n+\tprivate readonly storage: SqliteStorage;\n+\tprivate readonly maxFileBytes: number;\n+\tprivate readonly maxTotalBytes: number;\n+\tprivate closed = false;\n+\tconstructor(storage: SqliteStorage, maxFileBytes: number, maxTotalBytes: number) {\n+\t\tif (![maxFileBytes, maxTotalBytes].every((n) => Number.isSafeInteger(n) && n >= 0))\n+\t\t\tthrow Error(\"invalid Git scratch limits\");\n+\t\tthis.storage = storage;\n+\t\tthis.maxFileBytes = maxFileBytes;\n+\t\tthis.maxTotalBytes = maxTotalBytes;\n+\t\tinitialize(storage);\n+\t\tstorage.sql.exec(\"INSERT INTO git_fs_budget VALUES (?, 0)\", this.scope);\n+\t}\n+\tprivate active(): void {\n+\t\tif (this.closed) throw Error(\"Git scratch files are closed\");\n+\t}\n+\tprivate size(path: string): number | undefined {\n+\t\tconst rows = this.storage.sql\n+\t\t\t.exec(\"SELECT bytes FROM git_fs_meta WHERE scope = ? AND path = ?\", this.scope, path)\n+\t\t\t.toArray() as { bytes: number }[];\n+\t\treturn rows[0]?.bytes;\n+\t}\n+\twrite(path: string, bytes: Uint8Array): void {\n+\t\tthis.active();\n+\t\tif (bytes.byteLength > this.maxFileBytes) throw Error(\"Git scratch file exceeds byte limit\");\n+\t\tthis.storage.transactionSync(() => {\n+\t\t\tconst old = this.size(path) ?? 0;\n+\t\t\tconst rows = this.storage.sql.exec(\"SELECT bytes FROM git_fs_budget WHERE scope = ?\", this.scope).toArray() as {\n+\t\t\t\tbytes: number;\n+\t\t\t}[];\n+\t\t\tif (rows.length !== 1) throw Error(\"missing Git scratch budget\");\n+\t\t\tconst next = rows[0]!.bytes - old + bytes.byteLength;\n+\t\t\tif (!Number.isSafeInteger(next) || next < 0 || next > this.maxTotalBytes)\n+\t\t\t\tthrow Error(\"Git scratch exceeds total byte limit\");\n+\t\t\tthis.storage.sql.exec(\"DELETE FROM git_fs_chunks WHERE scope = ? AND path = ?\", this.scope, path);\n+\t\t\tfor (let at = 0; at < bytes.byteLength; at += 65536)\n+\t\t\t\tthis.storage.sql.exec(\n+\t\t\t\t\t\"INSERT INTO git_fs_chunks VALUES (?, ?, ?, ?)\",\n+\t\t\t\t\tthis.scope,\n+\t\t\t\t\tpath,\n+\t\t\t\t\tat / 65536,\n+\t\t\t\t\tbytes.slice(at, at + 65536),\n+\t\t\t\t);\n+\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO git_fs_meta VALUES (?, ?, ?)\", this.scope, path, bytes.byteLength);\n+\t\t\tthis.storage.sql.exec(\"UPDATE git_fs_budget SET bytes = ? WHERE scope = ?\", next, this.scope);\n+\t\t});\n+\t}\n+\tread(path: string): Uint8Array {\n+\t\tthis.active();\n+\t\tconst size = this.size(path);\n+\t\tif (size === undefined || !Number.isSafeInteger(size) || size < 0 || size > this.maxFileBytes)\n+\t\t\tthrow Error(\"invalid Git scratch file\");\n+\t\tconst bytes = new Uint8Array(size);\n+\t\tfor (let at = 0; at < size; at += 65536) {\n+\t\t\tconst rows = this.storage.sql\n+\t\t\t\t.exec(\"SELECT data FROM git_fs_chunks WHERE scope = ? AND path = ? AND part = ?\", this.scope, path, at / 65536)\n+\t\t\t\t.toArray() as { data: ArrayBuffer }[];\n+\t\t\tif (rows.length !== 1) throw Error(\"missing Git scratch chunk\");\n+\t\t\tconst chunk = new Uint8Array(rows[0]!.data);\n+\t\t\tif (chunk.byteLength !== Math.min(65536, size - at)) throw Error(\"invalid Git scratch chunk\");\n+\t\t\tbytes.set(chunk, at);\n+\t\t}\n+\t\treturn bytes;\n+\t}\n+\tremove(path: string): void {\n+\t\tthis.active();\n+\t\tthis.storage.transactionSync(() => {\n+\t\t\tconst size = this.size(path);\n+\t\t\tif (size === undefined) throw Error(\"missing Git scratch file\");\n+\t\t\tthis.storage.sql.exec(\"DELETE FROM git_fs_chunks WHERE scope = ? AND path = ?\", this.scope, path);\n+\t\t\tthis.storage.sql.exec(\"DELETE FROM git_fs_meta WHERE scope = ? AND path = ?\", this.scope, path);\n+\t\t\tthis.storage.sql.exec(\"UPDATE git_fs_budget SET bytes = bytes - ? WHERE scope = ?\", size, this.scope);\n+\t\t});\n+\t}\n+\t[Symbol.dispose](): void {\n+\t\tthis.dispose();\n+\t}\n+\tdispose(): void {\n+\t\tif (this.closed) return;\n+\t\tthis.storage.transactionSync(() => {\n+\t\t\tfor (const table of [\"git_fs_chunks\", \"git_fs_meta\", \"git_fs_budget\"])\n+\t\t\t\tthis.storage.sql.exec(`DELETE FROM ${table} WHERE scope = ?`, this.scope);\n+\t\t});\n+\t\tthis.closed = true;\n+\t}\n+}"},{"path":"server/src/git-intake-limit.ts","added":8,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/git-intake-limit.ts\n@@ -0,0 +1,8 @@\n+/** An admission refusal that is stable for the same remote head and limit policy. */\n+export class GitIntakeLimitError extends Error {\n+\treadonly kind: \"pack\" | \"object\" | \"decoded\" | \"delta\";\n+\tconstructor(kind: GitIntakeLimitError[\"kind\"], message: string) {\n+\t\tsuper(message);\n+\t\tthis.kind = kind;\n+\t}\n+}"},{"path":"server/src/git-object-bytes.ts","added":18,"removed":6,"diff":"--- a/server/src/git-object-bytes.ts\n+++ b/server/src/git-object-bytes.ts\n@@ -1,6 +1,7 @@\n import { createHash } from \"node:crypto\";\n import type { SqliteStorage } from \"./engine-project.ts\";\n import type { GitByteRanges } from \"./git-delta-stream.ts\";\n+import { GitIntakeLimitError } from \"./git-intake-limit.ts\";\n \n export type StoredGitBytes = GitByteRanges & {\n \tid: string;\n@@ -30,14 +31,21 @@\n \tprivate active(): void {\n \t\tif (this.closed) throw Error(\"Git object store is closed\");\n \t}\n-\tput(type: string, produce: (write: (bytes: Uint8Array) => void) => void, maxBytes: number): StoredGitBytes {\n+\tput(\n+\t\ttype: string,\n+\t\tproduce: (write: (bytes: Uint8Array) => void) => void,\n+\t\tmaxBytes: number,\n+\t\trawDelta = false,\n+\t): StoredGitBytes {\n \t\tthis.active();\n \t\tif (![\"blob\", \"tree\", \"commit\", \"tag\"].includes(type) || !Number.isSafeInteger(maxBytes) || maxBytes < 0)\n \t\t\tthrow Error(\"invalid Git object limits or type\");\n \t\tconst id = crypto.randomUUID();\n \t\tthis.storage.transactionSync(() => {\n+\t\t\tconst budgetScope = rawDelta ? `${this.scope}:raw` : this.scope;\n+\t\t\tif (rawDelta) this.storage.sql.exec(\"INSERT OR IGNORE INTO git_object_budget VALUES (?, 0)\", budgetScope);\n \t\t\tconst budget = this.storage.sql\n-\t\t\t\t.exec(\"SELECT decoded FROM git_object_budget WHERE scope = ?\", this.scope)\n+\t\t\t\t.exec(\"SELECT decoded FROM git_object_budget WHERE scope = ?\", budgetScope)\n \t\t\t\t.toArray() as { decoded: number }[];\n \t\t\tif (budget.length !== 1) throw Error(\"missing Git decoded budget\");\n \t\t\tconst remaining = this.maxDecodedBytes - budget[0]!.decoded;\n@@ -56,8 +64,12 @@\n \t\t\t\tused = 0;\n \t\t\t};\n \t\t\tproduce((bytes) => {\n-\t\t\t\tif (length + bytes.length > maxBytes) throw Error(\"Git object exceeds byte limit\");\n-\t\t\t\tif (length + bytes.length > remaining) throw Error(\"Git pack exceeds total decoded byte limit\");\n+\t\t\t\tif (length + bytes.length > maxBytes) throw new GitIntakeLimitError(\"object\", \"Git object exceeds byte limit\");\n+\t\t\t\tif (length + bytes.length > remaining)\n+\t\t\t\t\tthrow new GitIntakeLimitError(\n+\t\t\t\t\t\trawDelta ? \"delta\" : \"decoded\",\n+\t\t\t\t\t\trawDelta ? \"Git pack exceeds total delta byte limit\" : \"Git pack exceeds total decoded byte limit\",\n+\t\t\t\t\t);\n \t\t\t\tlength += bytes.length;\n \t\t\t\tfor (let at = 0; at < bytes.length; ) {\n \t\t\t\t\tconst count = Math.min(pending.length - used, bytes.length - at);\n@@ -78,7 +90,7 @@\n \t\t\t\tlength,\n \t\t\t\thash.digest(\"hex\"),\n \t\t\t);\n-\t\t\tthis.storage.sql.exec(\"UPDATE git_object_budget SET decoded = decoded + ? WHERE scope = ?\", length, this.scope);\n+\t\t\tthis.storage.sql.exec(\"UPDATE git_object_budget SET decoded = decoded + ? WHERE scope = ?\", length, budgetScope);\n \t\t});\n \t\treturn this.get(id);\n \t}\n@@ -140,7 +152,7 @@\n \t\tthis.storage.transactionSync(() => {\n \t\t\tthis.storage.sql.exec(\"DELETE FROM git_object_bytes WHERE scope = ?\", this.scope);\n \t\t\tthis.storage.sql.exec(\"DELETE FROM git_object_meta WHERE scope = ?\", this.scope);\n-\t\t\tthis.storage.sql.exec(\"DELETE FROM git_object_budget WHERE scope = ?\", this.scope);\n+\t\t\tthis.storage.sql.exec(\"DELETE FROM git_object_budget WHERE scope IN (?, ?)\", this.scope, `${this.scope}:raw`);\n \t\t});\n \t}\n }"},{"path":"server/src/git-pack-resolver.ts","added":1,"removed":1,"diff":"--- a/server/src/git-pack-resolver.ts\n+++ b/server/src/git-pack-resolver.ts\n@@ -46,7 +46,7 @@\n \t\t\t\tthrow Error(\"invalid delta base reference\");\n \t\t} else if (base !== undefined) throw Error(\"ordinary object has delta base\");\n \t\tthis.storage.transactionSync(() => {\n-\t\t\tconst stored = this.objects.put(type === \"delta\" ? \"blob\" : type, produce, this.maxObjectBytes);\n+\t\t\tconst stored = this.objects.put(type === \"delta\" ? \"blob\" : type, produce, this.maxObjectBytes, type === \"delta\");\n \t\t\tthis.storage.sql.exec(\n \t\t\t\t\"INSERT INTO git_pack_resolve VALUES (?, ?, ?, ?, ?, ?, ?, ?)\",\n \t\t\t\tthis.scope,"},{"path":"server/src/git-pack-spool.ts","added":3,"removed":1,"diff":"--- a/server/src/git-pack-spool.ts\n+++ b/server/src/git-pack-spool.ts\n@@ -49,7 +49,7 @@\n \t\t\t\tif (!(chunk instanceof Uint8Array)) throw Error(\"invalid pack chunk\");\n \t\t\t\tfor (let at = 0; at < chunk.length; ) {\n \t\t\t\t\tconst count = Math.min(GitPackSpool.chunkBytes - used, chunk.length - at);\n-\t\t\t\t\tif (this.size + count > maxBytes) throw Error(\"pack exceeds byte limit\");\n+\t\t\t\t\tif (this.size + count > maxBytes) throw new GitIntakeLimitError(\"pack\", \"pack exceeds byte limit\");\n \t\t\t\t\tconst piece = chunk.subarray(at, at + count);\n \t\t\t\t\tconst joined = new Uint8Array(tail.length + piece.length);\n \t\t\t\t\tjoined.set(tail);\n@@ -117,3 +117,5 @@\n \t\tthis.storage.sql.exec(\"DELETE FROM git_pack_spool WHERE id = ?\", this.id);\n \t}\n }\n+\n+import { GitIntakeLimitError } from \"./git-intake-limit.ts\";"},{"path":"server/src/memory-fs.ts","added":27,"removed":4,"diff":"--- a/server/src/memory-fs.ts\n+++ b/server/src/memory-fs.ts\n@@ -9,11 +9,18 @@\n \n type Entry =\n \t| { kind: \"dir\"; children: Set<string>; mtimeMs: number }\n-\t| { kind: \"file\"; data: Uint8Array; exec: boolean; mtimeMs: number }\n+\t| { kind: \"file\"; data: Uint8Array; byteLength?: number; exec: boolean; mtimeMs: number }\n \t| { kind: \"link\"; target: string; mtimeMs: number };\n \n const enc = new TextEncoder();\n \n+/** Optional scratch storage for file contents; directory metadata remains in memory. */\n+export interface FileContents {\n+\twrite(path: string, bytes: Uint8Array): void;\n+\tread(path: string): Uint8Array;\n+\tremove(path: string): void;\n+}\n+\n /** Plain fields, not getters: isomorphic-git writes to them when it normalizes stats. */\n class MemoryStats {\n \tsize: number;\n@@ -25,7 +32,11 @@\n \tconstructor(entry: Entry) {\n \t\tthis.kind = entry.kind;\n \t\tthis.size =\n-\t\t\tentry.kind === \"file\" ? entry.data.byteLength : entry.kind === \"link\" ? enc.encode(entry.target).byteLength : 0;\n+\t\t\tentry.kind === \"file\"\n+\t\t\t\t? (entry.byteLength ?? entry.data.byteLength)\n+\t\t\t\t: entry.kind === \"link\"\n+\t\t\t\t\t? enc.encode(entry.target).byteLength\n+\t\t\t\t\t: 0;\n \t\tthis.mtimeMs = entry.mtimeMs;\n \t\tthis.ctimeMs = entry.mtimeMs;\n \t\tthis.mode = entry.kind === \"dir\" ? 0o040000 : entry.kind === \"link\" ? 0o120000 : entry.exec ? 0o100755 : 0o100644;\n@@ -45,6 +56,10 @@\n }\n \n export class MemoryFS {\n+\tprivate readonly contents?: FileContents;\n+\tconstructor(contents?: FileContents) {\n+\t\tthis.contents = contents;\n+\t}\n \tencoder = new TextEncoder();\n \tdecoder = new TextDecoder();\n \tentries = new Map<string, Entry>([[\"/\", { kind: \"dir\", children: new Set(), mtimeMs: Date.now() }]]);\n@@ -157,10 +172,12 @@\n \t\tconst bytes =\n \t\t\ttypeof data === \"string\" ? this.encoder.encode(data) : data instanceof Uint8Array ? data : new Uint8Array(data);\n \t\tconst mode = typeof options === \"object\" && options !== null ? options.mode : undefined;\n+\t\tthis.contents?.write(target, bytes);\n \n \t\tthis.entries.set(target, {\n \t\t\tkind: \"file\",\n-\t\t\tdata: bytes,\n+\t\t\tdata: this.contents ? new Uint8Array(0) : bytes,\n+\t\t\t...(this.contents ? { byteLength: bytes.byteLength } : {}),\n \t\t\texec: mode !== undefined && (mode & 0o111) !== 0,\n \t\t\tmtimeMs: Date.now(),\n \t\t});\n@@ -174,7 +191,12 @@\n \t\t\tthrow fsError(\"EISDIR\", path);\n \t\t}\n \n-\t\tconst data = entry.kind === \"link\" ? this.encoder.encode(entry.target) : entry.data;\n+\t\tconst data =\n+\t\t\tentry.kind === \"link\"\n+\t\t\t\t? this.encoder.encode(entry.target)\n+\t\t\t\t: this.contents\n+\t\t\t\t\t? this.contents.read(this.normalize(path))\n+\t\t\t\t\t: entry.data;\n \t\tconst encoding = typeof options === \"string\" ? options : options?.encoding;\n \t\treturn encoding ? this.decoder.decode(data) : data;\n \t}\n@@ -190,6 +212,7 @@\n \t\t\tthrow fsError(\"EISDIR\", path);\n \t\t}\n \n+\t\tif (entry.kind === \"file\") this.contents?.remove(target);\n \t\tthis.entries.delete(target);\n \t\tthis.requireDir(this.parent(target)).children.delete(this.basename(target));\n \t}"},{"path":"server/src/project-object.ts","added":62,"removed":6,"diff":"--- a/server/src/project-object.ts\n+++ b/server/src/project-object.ts\n@@ -13,6 +13,8 @@\n import { EngineProject, SqliteLog } from \"./engine-project.ts\";\n import { artifactsOf, type Env } from \"./env.ts\";\n import { GitDiskIntake } from \"./git-disk-intake.ts\";\n+import { GitFileContents } from \"./git-file-contents.ts\";\n+import { GitIntakeLimitError } from \"./git-intake-limit.ts\";\n import { GitIntakeTrees } from \"./git-intake-trees.ts\";\n import { pushedSince, remoteHead } from \"./ingest.ts\";\n import {\n@@ -65,6 +67,7 @@\n const GIT_PACK_MAX_BYTES = 128 * 1024 * 1024;\n const GIT_OBJECT_MAX_BYTES = 64 * 1024 * 1024;\n const GIT_DECODED_MAX_BYTES = 256 * 1024 * 1024;\n+const GIT_LIMIT_POLICY = `expanded-v2:${GIT_PACK_MAX_BYTES}:${GIT_OBJECT_MAX_BYTES}:${GIT_DECODED_MAX_BYTES}`;\n \n /**\n  * The load guard (platform issue 46): an estimate of a loaded project's memory from its log entries, lines and claim\n@@ -127,6 +130,7 @@\n \t\tthis.blobs = new BlobStore(ctx.storage);\n \t\tif (env.ABSO_DISK_FIRST === \"on\") {\n \t\t\tGitDiskIntake.recover(ctx.storage);\n+\t\t\tGitFileContents.recover(ctx.storage);\n \t\t\tGitIntakeTrees.recover(ctx.storage);\n \t\t}\n \t}\n@@ -541,6 +545,22 @@\n \t\tconst seen = await this.ctx.storage.get<string>(\"git:head\");\n \t\tconst pushed = await this.ctx.storage.get<PushResult>(\"pushed\");\n \t\tconst head = await remoteHead(artifacts, name);\n+\t\tconst refusal = this.diskRuntime()\n+\t\t\t? await this.ctx.storage.get<{ head: string; policy: string; kind: GitIntakeLimitError[\"kind\"]; error: string }>(\n+\t\t\t\t\t\"git:size-refusal\",\n+\t\t\t\t)\n+\t\t\t: undefined;\n+\t\tif (refusal) {\n+\t\t\tif (\n+\t\t\t\thead &&\n+\t\t\t\thead !== seen &&\n+\t\t\t\thead !== pushed?.commit &&\n+\t\t\t\trefusal.head === head &&\n+\t\t\t\trefusal.policy === GIT_LIMIT_POLICY\n+\t\t\t)\n+\t\t\t\tthrow new GitIntakeLimitError(refusal.kind, refusal.error);\n+\t\t\tawait this.ctx.storage.delete(\"git:size-refusal\");\n+\t\t}\n \t\tif (!head || head === seen || head === pushed?.commit) return null;\n \t\tconst sharedBlobs = this.useProject((p) => p.shared().blobs ?? {});\n \t\tusing trees = this.diskRuntime() ? new GitIntakeTrees(this.ctx.storage) : undefined;\n@@ -560,7 +580,19 @@\n \t\t\t\t\t\tretainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid),\n \t\t\t\t\t}\n \t\t\t\t: undefined,\n-\t\t);\n+\t\t).catch(async (error: unknown) => {\n+\t\t\tif (trees && error instanceof GitIntakeLimitError) {\n+\t\t\t\tconst refusal = {\n+\t\t\t\t\thead,\n+\t\t\t\t\tpolicy: GIT_LIMIT_POLICY,\n+\t\t\t\t\tkind: error.kind,\n+\t\t\t\t\terror: error.message,\n+\t\t\t\t\tat: new Date().toISOString(),\n+\t\t\t\t};\n+\t\t\t\tawait this.ctx.storage.put({ \"git:size-refusal\": refusal, \"git:error\": refusal });\n+\t\t\t}\n+\t\t\tthrow error;\n+\t\t});\n \t\tif (!found || found.commits.length === 0) {\n \t\t\tif (found) await this.ctx.storage.put(\"git:head\", found.head);\n \t\t\treturn null;\n@@ -619,14 +651,25 @@\n \t\tif (!artifacts) return;\n \t\tconst name = await this.ctx.storage.get<string>(\"name\");\n \t\tif (!name || !this.useProject((p) => p.exists())) return;\n+\t\tlet intakeFailed = false;\n \t\tawait this.gitSync().then(\n-\t\t\t() => this.ctx.storage.delete(\"git:error\"),\n-\t\t\t(e) =>\n-\t\t\t\tthis.ctx.storage.put(\"git:error\", {\n+\t\t\tasync () => {\n+\t\t\t\tawait this.ctx.storage.delete(\"git:error\");\n+\t\t\t\tawait this.ctx.storage.delete(\"git:retry-attempts\");\n+\t\t\t},\n+\t\t\tasync (e) => {\n+\t\t\t\tintakeFailed = true;\n+\t\t\t\tconst attempts = ((await this.ctx.storage.get<number>(\"git:retry-attempts\")) ?? 0) + 1;\n+\t\t\t\tawait this.ctx.storage.put(\"git:retry-attempts\", attempts);\n+\t\t\t\tawait this.ctx.storage.put(\"git:error\", {\n \t\t\t\t\tat: new Date().toISOString(),\n \t\t\t\t\terror: e instanceof Error ? e.message : String(e),\n-\t\t\t\t}),\n+\t\t\t\t});\n+\t\t\t\tawait this.soon(Date.now() + (attempts === 1 ? 1 : attempts === 2 ? 5 : 15) * 60_000);\n+\t\t\t},\n \t\t);\n+\t\t// Never export over a remote head whose changes could not be taken in.\n+\t\tif (intakeFailed) return;\n \t\tconst shared = pushSnapshot(\n \t\t\tthis.useProject((p) => p.sharedPushMetadata()),\n \t\t\t(version, path) => this.useProject((current) => current.fileTextAt(version, path)),\n@@ -641,7 +684,20 @@\n \t\t}\n \t\tlet result: PushResult;\n \t\ttry {\n-\t\t\tresult = await pushShared(artifacts, name, shared, (sha) => this.blobs.read(sha));\n+\t\t\tresult = await pushShared(\n+\t\t\t\tartifacts,\n+\t\t\t\tname,\n+\t\t\t\tshared,\n+\t\t\t\t(sha) => this.blobs.read(sha),\n+\t\t\t\tthis.env.ABSO_DISK_FIRST === \"on\"\n+\t\t\t\t\t? {\n+\t\t\t\t\t\t\tstorage: this.ctx.storage,\n+\t\t\t\t\t\t\tmaxPackBytes: GIT_PACK_MAX_BYTES,\n+\t\t\t\t\t\t\tmaxObjectBytes: GIT_OBJECT_MAX_BYTES,\n+\t\t\t\t\t\t\tmaxDecodedBytes: GIT_DECODED_MAX_BYTES,\n+\t\t\t\t\t\t}\n+\t\t\t\t\t: undefined,\n+\t\t\t);\n \t\t} catch (e) {\n \t\t\t// Kept for /out, and tried again with a backoff of our own (a thrown alarm is retried only six times).\n \t\t\tconst was = await this.ctx.storage.get<{ attempts?: number }>(\"pushError\");"},{"path":"server/src/push.ts","added":61,"removed":19,"diff":"--- a/server/src/push.ts\n+++ b/server/src/push.ts\n@@ -3,9 +3,14 @@\n // is created on first use. isomorphic-git works in an in-memory filesystem:\n // a depth-1 clone of main with nothing checked out, then a new tree from\n // shared's files that compresses and writes only what changed (abso issue 293).\n+import { createHash } from \"node:crypto\";\n import git from \"isomorphic-git\";\n import http from \"isomorphic-git/http/web\";\n import type { FileModes } from \"../../worker/project/project-api.ts\";\n+import type { SqliteStorage } from \"./engine-project.ts\";\n+import { GitDiskIntake } from \"./git-disk-intake.ts\";\n+import { GitFileContents } from \"./git-file-contents.ts\";\n+import { gitHttp } from \"./git-http.ts\";\n import { MemoryFS } from \"./memory-fs.ts\";\n \n export interface PushResult {\n@@ -33,28 +38,23 @@\n \tprefix = \"\",\n \tfiles = new Map<string, TreeFile>(),\n \ttrees = new Map<string, string>(),\n+\tcache?: object,\n ): Promise<{ files: Map<string, TreeFile>; trees: Map<string, string> }> {\n \ttrees.set(prefix, oid);\n-\tconst { tree } = await git.readTree({ fs, dir, oid });\n+\tconst { tree } = await git.readTree({ fs, dir, oid, cache });\n \tfor (const e of tree) {\n \t\tconst path = prefix === \"\" ? e.path : `${prefix}/${e.path}`;\n-\t\tif (e.type === \"tree\") await readTreeFiles(fs, dir, e.oid, path, files, trees);\n+\t\tif (e.type === \"tree\") await readTreeFiles(fs, dir, e.oid, path, files, trees, cache);\n \t\telse if (e.type === \"blob\") files.set(path, { oid: e.oid, mode: e.mode });\n \t}\n \treturn { files, trees };\n }\n \n /**\n- * A blob's git oid, with the platform's SHA-1 (abso issue 293): native and awaited, so hashing every file of a big\n- * project neither burns the object's CPU in JavaScript nor holds its other requests back for long.\n+ * Hash the Git header and content separately so export does not allocate a second whole-file buffer.\n  */\n export async function blobOid(bytes: Uint8Array): Promise<string> {\n-\tconst head = new TextEncoder().encode(`blob ${bytes.byteLength}\\0`);\n-\tconst all = new Uint8Array(head.byteLength + bytes.byteLength);\n-\tall.set(head);\n-\tall.set(bytes, head.byteLength);\n-\tconst d = new Uint8Array(await crypto.subtle.digest(\"SHA-1\", all));\n-\treturn [...d].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n+\treturn createHash(\"sha1\").update(`blob ${bytes.byteLength}\\0`).update(bytes).digest(\"hex\");\n }\n \n const parentOf = (path: string) => {\n@@ -152,9 +152,18 @@\n \tshared: SharedFiles,\n \treadBlob: (sha256: string) => Uint8Array | null,\n \tpart: (commit: string) => Promise<void> = async () => {},\n+\tcache?: object,\n ): Promise<{ commit: string; changed: number }> {\n \tconst old = head\n-\t\t? await readTreeFiles(fs, dir, (await git.readCommit({ fs, dir, oid: head })).commit.tree)\n+\t\t? await readTreeFiles(\n+\t\t\t\tfs,\n+\t\t\t\tdir,\n+\t\t\t\t(await git.readCommit({ fs, dir, oid: head, cache })).commit.tree,\n+\t\t\t\t\"\",\n+\t\t\t\tnew Map(),\n+\t\t\t\tnew Map(),\n+\t\t\t\tcache,\n+\t\t\t)\n \t\t: { files: new Map<string, TreeFile>(), trees: new Map<string, string>() };\n \tconst blobs = shared.blobs ?? {};\n \tconst now = new Map<string, TreeFile>();\n@@ -187,6 +196,7 @@\n \t\tfor (const [path, f] of old.files) if (!files.has(path) && path in blobs) files.set(path, f);\n \t\tconst tree = await writeTrees(fs, dir, files, old.trees, changed);\n \t\tparent = await git.commit({\n+\t\t\tcache,\n \t\t\tfs,\n \t\t\tdir,\n \t\t\tmessage,\n@@ -226,27 +236,59 @@\n \tshared: SharedFiles,\n \t/** A binary file's bytes by SHA-256 (#27), from the project's blob store. */\n \treadBlob: (sha256: string) => Uint8Array | null = () => null,\n+\tdisk?: { storage: SqliteStorage; maxPackBytes: number; maxObjectBytes: number; maxDecodedBytes: number },\n ): Promise<PushResult> {\n \tconst t0 = Date.now();\n \tconst name = repoName(project);\n \tconst { remote, secret } = await writeAccess(artifacts, name);\n \tconst onAuth = () => ({ username: \"x\", password: secret });\n-\tlet fs = new MemoryFS();\n+\tusing contents = disk ? new GitFileContents(disk.storage, disk.maxObjectBytes, disk.maxDecodedBytes) : undefined;\n+\tusing intake = disk\n+\t\t? new GitDiskIntake(disk.storage, disk.maxPackBytes, disk.maxObjectBytes, disk.maxDecodedBytes)\n+\t\t: undefined;\n+\tconst cache = disk ? {} : undefined;\n+\tif (intake && cache) intake.attach(cache);\n+\tconst transport = disk ? gitHttp() : http;\n+\tlet fs = new MemoryFS(contents);\n \tconst dir = \"/repo\";\n \t// A new repo has no main yet. isomorphic-git \"clones\" an empty repo without\n \t// an error but leaves HEAD on master, so check for main and start clean.\n \t// Nothing is checked out: the new tree is built from tree objects (293).\n-\tconst head = await git\n-\t\t.clone({ fs, http, dir, url: remote, ref: \"main\", singleBranch: true, depth: 1, noCheckout: true, onAuth })\n-\t\t.then(() => git.resolveRef({ fs, dir, ref: \"main\" }))\n-\t\t.catch(() => null);\n+\t// Only an explicitly absent main is an empty repository. Transport, decode,\n+\t// and size failures must never become permission to replace remote history.\n+\tconst refs = await git.listServerRefs({ http: transport, url: remote, onAuth, prefix: \"refs/heads/main\" });\n+\tlet head: string | null = null;\n+\tif (refs.some((ref) => ref.ref === \"refs/heads/main\")) {\n+\t\tawait git.clone({\n+\t\t\tfs,\n+\t\t\thttp: transport,\n+\t\t\tcache,\n+\t\t\tdir,\n+\t\t\turl: remote,\n+\t\t\tref: \"main\",\n+\t\t\tsingleBranch: true,\n+\t\t\tdepth: 1,\n+\t\t\tnoCheckout: true,\n+\t\t\tonAuth,\n+\t\t});\n+\t\tintake?.assertReady();\n+\t\thead = await git.resolveRef({ fs, dir, ref: \"main\" });\n+\t}\n \tif (head === null) {\n-\t\tfs = new MemoryFS();\n+\t\tfs = new MemoryFS(contents);\n \t\tawait git.init({ fs, dir, defaultBranch: \"main\" });\n \t}\n \tconst t1 = Date.now();\n-\tconst push = () => git.push({ fs, http, dir, url: remote, ref: \"main\", remoteRef: \"main\", onAuth });\n-\tconst { commit, changed } = await commitShared(fs, dir, head, shared, readBlob, async () => void (await push()));\n+\tconst push = () => git.push({ fs, http: transport, cache, dir, url: remote, ref: \"main\", remoteRef: \"main\", onAuth });\n+\tconst { commit, changed } = await commitShared(\n+\t\tfs,\n+\t\tdir,\n+\t\thead,\n+\t\tshared,\n+\t\treadBlob,\n+\t\tasync () => void (await push()),\n+\t\tcache,\n+\t);\n \tconst t2 = Date.now();\n \tawait push();\n \tconsole.log("},{"path":"server/test/git-disk-clone.test.ts","added":31,"removed":1,"diff":"--- a/server/test/git-disk-clone.test.ts\n+++ b/server/test/git-disk-clone.test.ts\n@@ -3,9 +3,11 @@\n import { test } from \"node:test\";\n import git, { type HttpClient } from \"isomorphic-git\";\n import { GitDiskIntake } from \"../src/git-disk-intake.ts\";\n+import { GitFileContents } from \"../src/git-file-contents.ts\";\n import { GitIntakeTrees } from \"../src/git-intake-trees.ts\";\n import { pushedSince } from \"../src/ingest.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n+import { commitShared } from \"../src/push.ts\";\n import { memoryStorage } from \"./helpers.ts\";\n \n const packet = (text: string | Uint8Array) => {\n@@ -117,7 +119,8 @@\n \t\t};\n \t\tconst cache = {};\n \t\tintake.attach(cache);\n-\t\tconst fs = new MemoryFS();\n+\t\tconst contents = new GitFileContents(storage, 1000000, 2000000);\n+\t\tconst fs = new MemoryFS(contents);\n \t\tconst write = fs.promises.writeFile;\n \t\tfs.promises.writeFile = async (path, ...args) => {\n \t\t\tassert.ok(!/\\.(pack|idx)$/.test(path), \"clone must not persist a collected pack or index\");\n@@ -206,7 +209,34 @@\n \t\t\tassert.equal(await git.resolveRef({ fs, dir, ref: \"main\" }), head);\n \t\t\tassert.equal((await git.readCommit({ fs, dir, cache, oid: head })).commit.tree, tree);\n \t\t\tassert.deepEqual(Buffer.from((await git.readBlob({ fs, dir, cache, oid: blobOid })).blob), blob);\n+\t\t\tconst exported = await commitShared(\n+\t\t\t\tfs,\n+\t\t\t\tdir,\n+\t\t\t\thead,\n+\t\t\t\t{\n+\t\t\t\t\tversion: 1,\n+\t\t\t\t\tfiles: { \"new.txt\": \"Disk export fixture\" },\n+\t\t\t\t\tblobs: { \"large.bin\": \"fixture-blob\" },\n+\t\t\t\t},\n+\t\t\t\t() => blob,\n+\t\t\t\tundefined,\n+\t\t\t\tcache,\n+\t\t\t);\n+\t\t\tconst next = await git.readCommit({ fs, dir, cache, oid: exported.commit });\n+\t\t\tassert.deepEqual(next.commit.parent, [head]);\n+\t\t\tassert.deepEqual(\n+\t\t\t\tBuffer.from((await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: \"large.bin\" })).blob),\n+\t\t\t\tblob,\n+\t\t\t);\n+\t\t\tassert.equal(\n+\t\t\t\tBuffer.from(\n+\t\t\t\t\t(await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: \"new.txt\" })).blob,\n+\t\t\t\t).toString(),\n+\t\t\t\t\"Disk export fixture\",\n+\t\t\t);\n+\t\t\tfor (const entry of fs.entries.values()) if (entry.kind === \"file\") assert.equal(entry.data.byteLength, 0);\n \t\t} finally {\n+\t\t\tcontents.dispose();\n \t\t\tintake.dispose();\n \t\t\tstorage.db.close();\n \t\t}"},{"path":"server/test/git-export-http.test.ts","added":128,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/git-export-http.test.ts\n@@ -0,0 +1,128 @@\n+import assert from \"node:assert/strict\";\n+import { execFileSync, spawn } from \"node:child_process\";\n+import { randomBytes } from \"node:crypto\";\n+import { mkdtempSync, rmSync } from \"node:fs\";\n+import { createServer } from \"node:http\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { pushShared } from \"../src/push.ts\";\n+import { memoryStorage } from \"./helpers.ts\";\n+\n+test(\"disk export streams to real Git receive-pack and preserves remote ancestry\", async (t) => {\n+\tconst root = mkdtempSync(join(tmpdir(), \"abso-export-\"));\n+\tt.after(() => rmSync(root, { recursive: true, force: true }));\n+\tconst repo = join(root, \"fixture.git\");\n+\tconst command = (...args: string[]) => execFileSync(\"git\", args);\n+\tcommand(\"init\", \"--bare\", \"--initial-branch=main\", repo);\n+\tcommand(\"--git-dir\", repo, \"config\", \"http.receivepack\", \"true\");\n+\tlet uploads = 0;\n+\tlet rejectClone = false;\n+\tconst server = createServer((request, response) => {\n+\t\tconst url = new URL(request.url!, \"http://fixture.invalid\");\n+\t\tif (rejectClone && url.pathname.endsWith(\"git-upload-pack\")) {\n+\t\t\tresponse.writeHead(503).end(\"injected upload-pack failure\");\n+\t\t\treturn;\n+\t\t}\n+\t\tif (url.pathname.endsWith(\"git-receive-pack\")) uploads++;\n+\t\tconst child = spawn(\"git\", [\"http-backend\"], {\n+\t\t\tenv: {\n+\t\t\t\t...process.env,\n+\t\t\t\tGIT_PROJECT_ROOT: root,\n+\t\t\t\tGIT_HTTP_EXPORT_ALL: \"1\",\n+\t\t\t\tPATH_INFO: url.pathname,\n+\t\t\t\tQUERY_STRING: url.search.slice(1),\n+\t\t\t\tREQUEST_METHOD: request.method!,\n+\t\t\t\tCONTENT_TYPE: request.headers[\"content-type\"] ?? \"\",\n+\t\t\t\tREMOTE_USER: \"fixture\",\n+\t\t\t\tSERVER_PROTOCOL: \"HTTP/1.1\",\n+\t\t\t},\n+\t\t});\n+\t\trequest.pipe(child.stdin);\n+\t\tlet headers = Buffer.alloc(0),\n+\t\t\tstarted = false;\n+\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n+\t\t\tif (started) {\n+\t\t\t\tresponse.write(chunk);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\theaders = Buffer.concat([headers, chunk]);\n+\t\t\tconst boundary = headers.indexOf(\"\\r\\n\\r\\n\");\n+\t\t\tif (boundary < 0) return;\n+\t\t\tfor (const line of headers.subarray(0, boundary).toString().split(\"\\r\\n\")) {\n+\t\t\t\tconst colon = line.indexOf(\":\");\n+\t\t\t\tconst key = line.slice(0, colon),\n+\t\t\t\t\tvalue = line.slice(colon + 1).trim();\n+\t\t\t\tif (key.toLowerCase() === \"status\") response.statusCode = Number(value.split(\" \")[0]);\n+\t\t\t\telse response.setHeader(key, value);\n+\t\t\t}\n+\t\t\tstarted = true;\n+\t\t\tresponse.write(headers.subarray(boundary + 4));\n+\t\t\theaders = Buffer.alloc(0);\n+\t\t});\n+\t\tchild.stdout.on(\"end\", () => response.end());\n+\t\tchild.on(\"error\", (error) => response.destroy(error));\n+\t\tchild.stderr.resume();\n+\t});\n+\tawait new Promise<void>((resolve) => server.listen(0, \"127.0.0.1\", resolve));\n+\tt.after(() => {\n+\t\tserver.closeAllConnections();\n+\t\treturn new Promise<void>((resolve) => server.close(() => resolve()));\n+\t});\n+\tconst address = server.address() as { port: number };\n+\tconst remote = `http://127.0.0.1:${address.port}/fixture.git`;\n+\tconst artifacts = {\n+\t\tget: async () => ({\n+\t\t\tinfo: async () => ({ remote }),\n+\t\t\tcreateToken: async () => ({ plaintext: \"synthetic-token\" }),\n+\t\t\t[Symbol.dispose]() {},\n+\t\t}),\n+\t};\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tconst disk = { storage, maxPackBytes: 8000000, maxObjectBytes: 4000000, maxDecodedBytes: 16000000 };\n+\tconst binary = randomBytes(1500000);\n+\tconst first = await pushShared(\n+\t\tartifacts as never,\n+\t\t\"fixture\",\n+\t\t{\n+\t\t\tversion: 1,\n+\t\t\tfiles: { \"a.txt\": \"first\\n\" },\n+\t\t\tblobs: { \"large.bin\": \"binary\" },\n+\t\t},\n+\t\t() => binary,\n+\t\tdisk,\n+\t);\n+\tconst second = await pushShared(\n+\t\tartifacts as never,\n+\t\t\"fixture\",\n+\t\t{\n+\t\t\tversion: 2,\n+\t\t\tfiles: { \"a.txt\": \"second\\n\", \"new.txt\": \"new\\n\" },\n+\t\t\tblobs: { \"large.bin\": \"binary\" },\n+\t\t},\n+\t\t() => binary,\n+\t\tdisk,\n+\t);\n+\tassert.equal(command(\"--git-dir\", repo, \"rev-parse\", \"main^\").toString().trim(), first.commit);\n+\tassert.equal(command(\"--git-dir\", repo, \"rev-parse\", \"main\").toString().trim(), second.commit);\n+\tassert.equal(command(\"--git-dir\", repo, \"show\", \"main:a.txt\").toString(), \"second\\n\");\n+\tassert.deepEqual(execFileSync(\"git\", [\"--git-dir\", repo, \"show\", \"main:large.bin\"], { maxBuffer: 4000000 }), binary);\n+\tassert.equal(uploads, 2);\n+\trejectClone = true;\n+\tawait assert.rejects(() =>\n+\t\tpushShared(artifacts as never, \"fixture\", { version: 3, files: { \"bad.txt\": \"must not push\" } }, undefined, disk),\n+\t);\n+\tassert.equal(uploads, 2, \"failed clone must never become an empty-repository push\");\n+\tfor (const table of [\n+\t\t\"git_fs_chunks\",\n+\t\t\"git_fs_meta\",\n+\t\t\"git_fs_budget\",\n+\t\t\"git_pack_spool\",\n+\t\t\"git_pack_resolve\",\n+\t\t\"git_object_bytes\",\n+\t\t\"git_object_meta\",\n+\t\t\"git_object_budget\",\n+\t])\n+\t\tassert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0, table);\n+});"},{"path":"server/test/git-file-contents.test.ts","added":88,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/git-file-contents.test.ts\n@@ -0,0 +1,88 @@\n+import assert from \"node:assert/strict\";\n+import { randomBytes } from \"node:crypto\";\n+import { test } from \"node:test\";\n+import git from \"isomorphic-git\";\n+import { GitFileContents } from \"../src/git-file-contents.ts\";\n+import { MemoryFS } from \"../src/memory-fs.ts\";\n+import { memoryStorage } from \"./helpers.ts\";\n+\n+test(\"Git writes and reads exact objects while filesystem entries retain no content bytes\", async (t) => {\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tusing contents = new GitFileContents(storage, 1000000, 10000000);\n+\tconst fs = new MemoryFS(contents),\n+\t\tdir = \"/repo\";\n+\tawait git.init({ fs, dir, defaultBranch: \"main\" });\n+\tconst entries = [],\n+\t\tbodies: Uint8Array[] = [];\n+\tfor (let index = 0; index < 20; index++) {\n+\t\tconst body = randomBytes(70000);\n+\t\tbodies.push(body);\n+\t\tentries.push({\n+\t\t\tmode: \"100644\",\n+\t\t\tpath: `file-${index}`,\n+\t\t\toid: await git.writeBlob({ fs, dir, blob: body }),\n+\t\t\ttype: \"blob\" as const,\n+\t\t});\n+\t}\n+\tconst tree = await git.writeTree({ fs, dir, tree: entries });\n+\tconst commit = await git.commit({\n+\t\tfs,\n+\t\tdir,\n+\t\ttree,\n+\t\tparent: [],\n+\t\tmessage: \"Scratch fixture\",\n+\t\tauthor: { name: \"Fixture\", email: \"fixture@example.invalid\" },\n+\t});\n+\tfor (let index = 0; index < 20; index++) {\n+\t\tconst blob = await git.readBlob({ fs, dir, oid: commit, filepath: `file-${index}` });\n+\t\tassert.deepEqual(new Uint8Array(blob.blob), new Uint8Array(bodies[index]!));\n+\t}\n+\tfor (const entry of fs.entries.values()) if (entry.kind === \"file\") assert.equal(entry.data.byteLength, 0);\n+\tassert.ok(Number(storage.db.prepare(\"SELECT MAX(length(data)) AS n FROM git_fs_chunks\").get()!.n) <= 65536);\n+\tconst reference = \"/repo/.git/refs/heads/main\";\n+\tassert.equal((await fs.stat(reference)).size, ((await fs.readFile(reference)) as Uint8Array).byteLength);\n+});\n+\n+test(\"Git scratch replacement failure preserves old contents, metadata and budget\", async (t) => {\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tusing contents = new GitFileContents(storage, 100000, 150000);\n+\tconst fs = new MemoryFS(contents);\n+\tawait fs.writeFile(\"/file\", new Uint8Array([7]));\n+\tconst exec = storage.sql.exec.bind(storage.sql);\n+\tconst failure = t.mock.method(storage.sql, \"exec\", (query: string, ...bindings: unknown[]) => {\n+\t\tif (query.startsWith(\"INSERT INTO git_fs_chunks\") && bindings[2] === 1) throw Error(\"injected chunk failure\");\n+\t\treturn exec(query, ...bindings);\n+\t});\n+\tawait assert.rejects(() => fs.writeFile(\"/file\", new Uint8Array(70000)), /injected chunk failure/);\n+\tassert.deepEqual(await fs.readFile(\"/file\"), new Uint8Array([7]));\n+\tassert.equal((await fs.stat(\"/file\")).size, 1);\n+\tassert.equal(storage.db.prepare(\"SELECT bytes FROM git_fs_budget\").get()!.bytes, 1);\n+\tfailure.mock.restore();\n+\tawait fs.writeFile(\"/file\", new Uint8Array(70000));\n+\tawait assert.rejects(() => fs.writeFile(\"/other\", new Uint8Array(90000)), /total byte limit/);\n+\tawait assert.rejects(() => fs.stat(\"/other\"), /ENOENT/);\n+\tawait fs.unlink(\"/file\");\n+\tassert.equal(storage.db.prepare(\"SELECT bytes FROM git_fs_budget\").get()!.bytes, 0);\n+});\n+\n+test(\"cold Git file recovery preserves canonical rows and active scopes dispose independently\", (t) => {\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tstorage.sql.exec(\"CREATE TABLE canonical_fs_fixture (value TEXT)\");\n+\tstorage.sql.exec(\"INSERT INTO canonical_fs_fixture VALUES ('preserved')\");\n+\tconst first = new GitFileContents(storage, 10, 20),\n+\t\tsecond = new GitFileContents(storage, 10, 20);\n+\tfirst.write(\"/a\", new Uint8Array([1]));\n+\tsecond.write(\"/b\", new Uint8Array([2]));\n+\tfirst.dispose();\n+\tassert.deepEqual(second.read(\"/b\"), new Uint8Array([2]));\n+\tGitFileContents.recover(storage);\n+\tGitFileContents.recover(storage);\n+\tfor (const table of [\"git_fs_meta\", \"git_fs_chunks\", \"git_fs_budget\"])\n+\t\tassert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0);\n+\tassert.equal(storage.db.prepare(\"SELECT value FROM canonical_fs_fixture\").get()!.value, \"preserved\");\n+\tassert.throws(() => second.read(\"/b\"), /invalid Git scratch file/);\n+\tsecond.dispose();\n+});"},{"path":"server/test/git-pack-resolver.test.ts","added":13,"removed":5,"diff":"--- a/server/test/git-pack-resolver.test.ts\n+++ b/server/test/git-pack-resolver.test.ts\n@@ -24,26 +24,34 @@\n test(\"delta results consume budget and failed resolution rolls back all accounting\", (t) => {\n \tconst storage = memoryStorage();\n \tt.after(() => storage.db.close());\n-\tconst resolver = new GitPackResolver(storage, 100, 12);\n+\tconst resolver = new GitPackResolver(storage, 100, 6);\n \tresolver.add(12, \"blob\", new TextEncoder().encode(\"abc\"));\n \tresolver.add(30, \"delta\", new Uint8Array([3, 4, 0x90, 3, 1, 100]), 12);\n \tassert.throws(() => resolver.resolve(), /total decoded byte limit/);\n-\tassert.equal(storage.db.prepare(\"SELECT decoded FROM git_object_budget\").get()!.decoded, 9);\n+\tassert.equal(\n+\t\tstorage.db.prepare(\"SELECT decoded FROM git_object_budget WHERE scope NOT LIKE '%:raw'\").get()!.decoded,\n+\t\t3,\n+\t);\n \tassert.equal(storage.db.prepare(\"SELECT COUNT(*) AS n FROM git_object_meta\").get()!.n, 2);\n \tassert.throws(() => resolver.get(oid(\"abcd\")), /missing/);\n \tresolver.dispose();\n });\n \n-test(\"resolved delta instructions are deleted without refunding decoded work\", (t) => {\n+test(\"raw deltas have a separate bounded budget and are not counted as expanded versions\", (t) => {\n \tconst storage = memoryStorage();\n \tt.after(() => storage.db.close());\n-\tconst resolver = new GitPackResolver(storage, 100, 13);\n+\tconst resolver = new GitPackResolver(storage, 100, 7);\n \tresolver.add(12, \"blob\", new TextEncoder().encode(\"abc\"));\n \tresolver.add(30, \"delta\", new Uint8Array([3, 4, 0x90, 3, 1, 100]), 12);\n \tresolver.resolve();\n \tassert.equal(text(resolver.get(oid(\"abcd\"))), \"abcd\");\n \tassert.equal(storage.db.prepare(\"SELECT SUM(bytes) AS n FROM git_object_meta\").get()!.n, 7);\n-\tassert.equal(storage.db.prepare(\"SELECT decoded FROM git_object_budget\").get()!.decoded, 13);\n+\tassert.equal(\n+\t\tstorage.db.prepare(\"SELECT decoded FROM git_object_budget WHERE scope NOT LIKE '%:raw'\").get()!.decoded,\n+\t\t7,\n+\t);\n+\tassert.equal(storage.db.prepare(\"SELECT decoded FROM git_object_budget WHERE scope LIKE '%:raw'\").get()!.decoded, 6);\n+\tassert.throws(() => resolver.add(45, \"delta\", new Uint8Array([3, 4, 0x90, 3, 1, 100]), 12), /total delta byte limit/);\n \tassert.throws(() => resolver.add(50, \"blob\", new Uint8Array(1)), /total decoded byte limit/);\n \tresolver.resolve();\n \tresolver.dispose();"},{"path":"server/test/project-object-disk-first.test.ts","added":165,"removed":1,"diff":"--- a/server/test/project-object-disk-first.test.ts\n+++ b/server/test/project-object-disk-first.test.ts\n@@ -5,6 +5,7 @@\n import { Project } from \"../../worker/project/project.ts\";\n import { EngineProject } from \"../src/engine-project.ts\";\n import { GitDiskIntake } from \"../src/git-disk-intake.ts\";\n+import { GitIntakeLimitError } from \"../src/git-intake-limit.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n import { memoryStorage } from \"./helpers.ts\";\n \n@@ -21,6 +22,160 @@\n const { ProjectObject } = await import(\"../src/project-object.ts\");\n hooks.deregister();\n \n+for (const disk of [false, true])\n+\ttest(`failed intake retries across cold objects with disk mode ${disk}`, async (t) => {\n+\t\tconst storage = memoryStorage();\n+\t\tt.after(() => storage.db.close());\n+\t\tconst values = new Map<string, unknown>();\n+\t\tlet alarm: number | null = null;\n+\t\tconst context = {\n+\t\t\tid: { toString: () => \"retry\" },\n+\t\t\tstorage: {\n+\t\t\t\t...storage,\n+\t\t\t\tget: async (key: string) => values.get(key),\n+\t\t\t\tput: async (key: string | Record<string, unknown>, value?: unknown) => {\n+\t\t\t\t\tif (typeof key === \"string\") values.set(key, value);\n+\t\t\t\t\telse for (const [name, item] of Object.entries(key)) values.set(name, item);\n+\t\t\t\t},\n+\t\t\t\tdelete: async (key: string) => values.delete(key),\n+\t\t\t\tgetAlarm: async () => alarm,\n+\t\t\t\tsetAlarm: async (value: number) => {\n+\t\t\t\t\talarm = value;\n+\t\t\t\t},\n+\t\t\t},\n+\t\t};\n+\t\tconst object = (enabled: boolean) =>\n+\t\t\tnew ProjectObject(\n+\t\t\t\tcontext as never,\n+\t\t\t\t{\n+\t\t\t\t\tABSO_DISK_FIRST: disk ? \"on\" : \"off\",\n+\t\t\t\t\tABSO_ARTIFACTS: enabled ? \"on\" : \"off\",\n+\t\t\t\t\tARTIFACTS: {},\n+\t\t\t\t} as never,\n+\t\t\t);\n+\t\tassert.equal((await object(false).call(\"retry\", \"init\", undefined, { files: { \"a.txt\": \"first\\n\" } })).status, 200);\n+\t\tlet ready = false;\n+\t\tfor (let page = 0; page < 100; page++) {\n+\t\t\tif ((await object(false).call(\"retry\", \"status\", undefined, {})).status === 200) {\n+\t\t\t\tready = true;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tassert.equal(ready, true);\n+\t\tlet fails = true;\n+\t\tt.mock.method(ProjectObject.prototype, \"gitSync\", async () => {\n+\t\t\tif (fails) throw Error(\"transient intake failure\");\n+\t\t\treturn null;\n+\t\t});\n+\t\tfor (const [index, minutes] of [1, 5, 15, 15].entries()) {\n+\t\t\talarm = null;\n+\t\t\tconst before = Date.now();\n+\t\t\tawait object(true).alarm();\n+\t\t\tassert.equal(values.get(\"git:retry-attempts\"), index + 1);\n+\t\t\tassert.ok(alarm !== null && alarm >= before + minutes * 60000 && alarm <= Date.now() + minutes * 60000);\n+\t\t\tassert.equal(values.get(\"pushed\"), undefined);\n+\t\t}\n+\t\tfails = false;\n+\t\tvalues.set(\"pushed\", { version: Number.MAX_SAFE_INTEGER });\n+\t\talarm = null;\n+\t\tawait object(true).alarm();\n+\t\tassert.equal(values.has(\"git:retry-attempts\"), false);\n+\t\tassert.equal(values.has(\"git:error\"), false);\n+\t});\n+\n+test(\"size refusals survive cold objects, retry changed heads or policy, and prevent outgoing pushes\", async (t) => {\n+\tlet scheduled = 0;\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tconst values = new Map<string, unknown>();\n+\tconst context = {\n+\t\tid: { toString: () => \"size-refusal\" },\n+\t\tstorage: {\n+\t\t\t...storage,\n+\t\t\tget: async (key: string) => values.get(key),\n+\t\t\tput: async (key: string | Record<string, unknown>, value?: unknown) => {\n+\t\t\t\tif (typeof key === \"string\") values.set(key, value);\n+\t\t\t\telse for (const [name, item] of Object.entries(key)) values.set(name, item);\n+\t\t\t},\n+\t\t\tdelete: async (key: string) => values.delete(key),\n+\t\t\tgetAlarm: async () => null,\n+\t\t\tsetAlarm: async (value: number) => {\n+\t\t\t\tscheduled = value;\n+\t\t\t},\n+\t\t},\n+\t};\n+\tconst artifacts = {\n+\t\tget: async () => ({\n+\t\t\tinfo: async () => ({ remote: \"https://artifacts.invalid/size\" }),\n+\t\t\tcreateToken: async () => ({ plaintext: \"invented-test-token\" }),\n+\t\t\t[Symbol.dispose]() {},\n+\t\t}),\n+\t};\n+\tconst object = (enabled = true) =>\n+\t\tnew ProjectObject(\n+\t\t\tcontext as never,\n+\t\t\t{\n+\t\t\t\tABSO_DISK_FIRST: \"on\",\n+\t\t\t\tABSO_ARTIFACTS: enabled ? \"on\" : \"off\",\n+\t\t\t\tARTIFACTS: artifacts,\n+\t\t\t} as never,\n+\t\t);\n+\tassert.equal(\n+\t\t(await object(false).call(\"size-refusal\", \"init\", undefined, { files: { \"a.txt\": \"original\\n\" } })).status,\n+\t\t200,\n+\t);\n+\tlet ready = false;\n+\tfor (let page = 0; page < 100; page++) {\n+\t\tconst result = await object(false).call(\"size-refusal\", \"status\", undefined, {});\n+\t\tif (result.status === 200) {\n+\t\t\tready = true;\n+\t\t\tbreak;\n+\t\t}\n+\t\tassert.equal(result.status, 503);\n+\t}\n+\tassert.equal(ready, true, \"project indexing must finish before testing intake refusals\");\n+\tlet head = \"a\".repeat(40),\n+\t\tdownloads = 0,\n+\t\tpushes = 0,\n+\t\ttransient = false;\n+\tt.mock.method(git, \"listServerRefs\", async () => [{ ref: \"refs/heads/main\", oid: head }]);\n+\tt.mock.method(git, \"clone\", async () => {\n+\t\tdownloads++;\n+\t\tif (transient) throw Error(\"temporary network failure\");\n+\t\tthrow new GitIntakeLimitError(\"decoded\", \"Git pack exceeds total decoded byte limit\");\n+\t});\n+\tt.mock.method(git, \"push\", async () => {\n+\t\tpushes++;\n+\t\treturn { ok: true };\n+\t});\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 1);\n+\tassert.equal(values.get(\"git:head\"), undefined);\n+\tassert.equal((await object().out()).version, 0);\n+\tassert.match(JSON.stringify((await object().out()).git.error), /decoded byte limit/);\n+\tawait object().alarm();\n+\tassert.ok(scheduled >= Date.now() + 59_000);\n+\tassert.equal(values.get(\"git:retry-attempts\"), 1);\n+\tassert.equal(downloads, 1);\n+\tassert.equal(pushes, 0);\n+\thead = \"b\".repeat(40);\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 2);\n+\tvalues.set(\"git:size-refusal\", { ...(values.get(\"git:size-refusal\") as object), policy: \"old-policy\" });\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 3);\n+\thead = \"c\".repeat(40);\n+\ttransient = true;\n+\tawait assert.rejects(() => object().gitSync(), /temporary network failure/);\n+\tawait assert.rejects(() => object().gitSync(), /temporary network failure/);\n+\tassert.equal(downloads, 5);\n+\tassert.equal(values.has(\"git:size-refusal\"), false);\n+\tawait object().alarm();\n+\tassert.equal(pushes, 0);\n+\tassertGitScratchEmpty(storage);\n+});\n+\n function assertGitScratchEmpty(storage: ReturnType<typeof memoryStorage>) {\n \tfor (const table of [\n \t\t\"git_pack_spool\",\n@@ -333,7 +488,16 @@\n \t\tconst blob = await git.readBlob({ fs: options.fs, dir: options.dir, oid, filepath: \"a.txt\" });\n \t\tassert.equal(new TextDecoder().decode(blob.blob), \"Alice's change\\n\");\n \t\tpushed++;\n-\t\tremoteFiles = options.fs as MemoryFS;\n+\t\t// The remote owns its copy; the export's scratch files expire when push returns.\n+\t\tremoteFiles = new MemoryFS();\n+\t\tfor (const [path, entry] of (options.fs as MemoryFS).entries) {\n+\t\t\tremoteFiles.entries.set(\n+\t\t\t\tpath,\n+\t\t\t\tentry.kind === \"file\"\n+\t\t\t\t\t? { ...entry, data: new Uint8Array((await (options.fs as MemoryFS).readFile(path)) as Uint8Array) }\n+\t\t\t\t\t: { ...entry },\n+\t\t\t);\n+\t\t}\n \t\treturn { ok: true };\n \t});\n \tconst artifacts = {"},{"path":"server/test/push.test.ts","added":7,"removed":1,"diff":"--- a/server/test/push.test.ts\n+++ b/server/test/push.test.ts\n@@ -3,8 +3,14 @@\n import git from \"isomorphic-git\";\n import { absoVersion } from \"../src/ingest.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n-import { commitShared, projectOfRepo, readTreeFiles, repoName } from \"../src/push.ts\";\n+import { blobOid, commitShared, projectOfRepo, readTreeFiles, repoName } from \"../src/push.ts\";\n \n+it(\"hashes exact Git blob bytes including a nonzero buffer offset\", async () => {\n+\tassert.equal(await blobOid(new Uint8Array()), \"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\");\n+\tconst bytes = new TextEncoder().encode(\"prefixhello\\nsuffix\");\n+\tassert.equal(await blobOid(bytes.subarray(6, 12)), \"ce013625030ba8dba906f756967f9e9ca394464a\");\n+});\n+\n describe(\"repo names\", () => {\n \tit(\"names a project's Artifacts repo abso-<project>, and back\", () => {\n \t\tassert.equal(repoName(\"game\"), \"abso-game\");"}],"ci":null}