Preserve authorized cold-load browser refusals and private aggregate metadata usage (#641)

This commit is contained in:
Quixos Development Agent 01f26965-84fa-4a79-8069-725682c13065
2026-10-31 14:50:06 +00:00
parent 94ddc8bedf
commit 7545f7392d
+5 -12
View File
@@ -1,12 +1,8 @@
import { constants } from "node:fs";
import { open } from "node:fs/promises";
const admissionFailure = (
code: string,
kind: "file-bytes" | "total-bytes" | "owner-bytes" | "candidates",
measured: number,
limit: number,
) => Object.assign(Error(code), { metadataAdmission: { kind, measured, limit } });
const admissionFailure = (code: string, kind: "file-bytes", measured: number, limit: number) =>
Object.assign(Error(code), { metadataAdmission: { kind, measured, limit } });
/** Admission estimates, not a hard V8 heap limit. A process/cgroup ceiling is
* still required. Charge input, parse trees and derived indexes before reading
@@ -34,8 +30,7 @@ export class CandidateMetadataBudget {
}
acquire(owner: string) {
if (!owner || owner.length > 4096) throw Error("INVALID_CANDIDATE_METADATA_OWNER");
if (this.scopes >= this.limits.candidates)
throw admissionFailure("CANDIDATE_METADATA_LIMIT", "candidates", this.scopes + 1, this.limits.candidates);
if (this.scopes >= this.limits.candidates) throw Error("CANDIDATE_METADATA_LIMIT");
this.scopes++;
let bytes = 0,
closed = false;
@@ -43,10 +38,8 @@ export class CandidateMetadataBudget {
if (closed) throw Error("CANDIDATE_METADATA_CLOSED");
if (!Number.isSafeInteger(amount) || amount < 0) throw Error("INVALID_CANDIDATE_METADATA_CHARGE");
const owned = this.owners.get(owner) ?? 0;
if (this.bytes + amount > this.limits.bytes)
throw admissionFailure("CANDIDATE_METADATA_LIMIT", "total-bytes", this.bytes + amount, this.limits.bytes);
if (owned + amount > this.limits.ownerBytes)
throw admissionFailure("CANDIDATE_METADATA_LIMIT", "owner-bytes", owned + amount, this.limits.ownerBytes);
if (this.bytes + amount > this.limits.bytes || owned + amount > this.limits.ownerBytes)
throw Error("CANDIDATE_METADATA_LIMIT");
bytes += amount;
this.bytes += amount;
this.owners.set(owner, owned + amount);