Repair packed agent startup and bound activation metadata retention
This commit is contained in:
@@ -36,33 +36,37 @@ export async function loadCheckedInstallationCandidate(
|
||||
if (!rootPattern.test(root) || !(await lstat(root)).isDirectory())
|
||||
throw Error("Candidate must be an immutable Nix output directory");
|
||||
const scope = (resources.budget ?? candidateMetadataBudget).acquire(resources.owner ?? root);
|
||||
let releaseValidation = () => {};
|
||||
try {
|
||||
// Validate the duplicated source contract by digest, then discard its tree
|
||||
// before allocating the substantially larger checked execution plan.
|
||||
const workspaceDigest = await (async () => {
|
||||
const input = await readJson(root, "candidate.json", scope);
|
||||
try {
|
||||
const { executionContracts: _legacyContracts, ...workspace } = input.value;
|
||||
return hexDigest(workspace);
|
||||
} finally {
|
||||
input.releaseTree();
|
||||
}
|
||||
})();
|
||||
// Sequential reads avoid partially rejected Promise.all() work allocating
|
||||
// after the failed candidate's reservation has been released.
|
||||
const values = [];
|
||||
for (const file of [
|
||||
"candidate.json",
|
||||
"execution-plan.json",
|
||||
"execution-artifacts.json",
|
||||
"source.json",
|
||||
"entry.json",
|
||||
"kernel.json",
|
||||
"queries.json",
|
||||
"graph-execution.json",
|
||||
]) {
|
||||
const parsed = await readJson(root, file, scope);
|
||||
values.push(parsed.value);
|
||||
// candidate.json duplicates the checked plan for validation. Nothing in
|
||||
// the installed candidate retains this input tree after validation.
|
||||
if (file === "candidate.json") releaseValidation = parsed.releaseTree;
|
||||
}
|
||||
const [candidate, plan, artifacts, source, entryRequest, kernel, queries, graph] = values;
|
||||
const { executionContracts: _legacyContracts, ...workspace } = candidate;
|
||||
const [plan, artifacts, source, entryRequest, kernel, queries] = values;
|
||||
if (
|
||||
plan?.definition?.codec !== "camino-execution-plan-v1" ||
|
||||
hexDigest(plan.definition) !== plan.digest ||
|
||||
hexDigest(workspace) !== hexDigest(plan.definition.workspace)
|
||||
workspaceDigest !== hexDigest(plan.definition.workspace)
|
||||
)
|
||||
throw new ExecutionPlanError(
|
||||
"CANDIDATE_PLAN_MISMATCH",
|
||||
@@ -113,14 +117,24 @@ export async function loadCheckedInstallationCandidate(
|
||||
"Stored interpreter input must match the checked build and plan",
|
||||
);
|
||||
const expectedGraph = graphExecutionRepresentation(plan, installation, kernel, queries);
|
||||
if (hexDigest(graph) !== hexDigest(expectedGraph) || artifacts.execution !== hexDigest(graph))
|
||||
throw new ExecutionPlanError(
|
||||
"CANDIDATE_EXECUTION_MISMATCH",
|
||||
root,
|
||||
"Stored graph execution differs from checked inputs",
|
||||
);
|
||||
// The stored graph embeds the same kernel/query programs. Validate it in a
|
||||
// short-lived scope and retain the representation that shares those trees.
|
||||
await (async () => {
|
||||
const input = await readJson(root, "graph-execution.json", scope);
|
||||
try {
|
||||
const digest = hexDigest(input.value);
|
||||
if (digest !== hexDigest(expectedGraph) || artifacts.execution !== digest)
|
||||
throw new ExecutionPlanError(
|
||||
"CANDIDATE_EXECUTION_MISMATCH",
|
||||
root,
|
||||
"Stored graph execution differs from checked inputs",
|
||||
);
|
||||
} finally {
|
||||
input.releaseTree();
|
||||
}
|
||||
})();
|
||||
const provenance = {
|
||||
workspaceRevision: workspace.id as string,
|
||||
workspaceRevision: plan.definition.workspace.id as string,
|
||||
source: { repository: source.repository as string, commit: source.commit as string },
|
||||
generator: artifacts.generator as string,
|
||||
packages: (plan as ExecutionPlan).definition.packages.map((pkg) => ({
|
||||
@@ -142,9 +156,9 @@ export async function loadCheckedInstallationCandidate(
|
||||
return {
|
||||
reference,
|
||||
workspace: plan.definition.workspace.workspaceId,
|
||||
world: hexDigest(graph),
|
||||
world: hexDigest(expectedGraph),
|
||||
plan: kernel.plan as string,
|
||||
graphExecution: graph,
|
||||
graphExecution: expectedGraph,
|
||||
provenance,
|
||||
entry,
|
||||
kernel,
|
||||
@@ -161,8 +175,6 @@ export async function loadCheckedInstallationCandidate(
|
||||
} catch (error) {
|
||||
scope.release();
|
||||
throw error;
|
||||
} finally {
|
||||
releaseValidation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ export class CandidateMetadataBudget {
|
||||
private bytes = 0;
|
||||
private scopes = 0;
|
||||
private readonly owners = new Map<string, number>();
|
||||
constructor(limits = { bytes: 512 * 1024 * 1024, ownerBytes: 256 * 1024 * 1024, candidates: 128 }) {
|
||||
// A cutover holds both the serving and proposed installation plus transient
|
||||
// parsing space. The 57-repository reader retains ~133 MiB per installation;
|
||||
// a 256 MiB owner ceiling cannot admit its ordinary atomic replacement.
|
||||
// Keep the aggregate ceiling independent and leave room for parsing overlap.
|
||||
constructor(limits = { bytes: 512 * 1024 * 1024, ownerBytes: 384 * 1024 * 1024, candidates: 128 }) {
|
||||
for (const value of Object.values(limits))
|
||||
if (!Number.isSafeInteger(value) || value < 1) throw Error("INVALID_CANDIDATE_METADATA_BUDGET");
|
||||
if (limits.ownerBytes > limits.bytes) throw Error("INVALID_CANDIDATE_METADATA_BUDGET");
|
||||
|
||||
Reference in New Issue
Block a user