{"draft":null,"from":178,"to":318,"files":[{"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 }"}],"unmatched":[]}