niceeval 0.14.3-canary.53 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -249,7 +249,40 @@ async function reconcileDomain(repository, control, scope) {
249
249
  for (const volume of reconciledVolumes) {
250
250
  if (volume.config[control_ts_1.INCUS_METADATA.executionDomainId] !== scope.executionDomainId)
251
251
  continue;
252
- const owned = next.some((intent) => isActiveIntent(intent) && volumeMetadataMatchesIntent(volume, intent));
252
+ let owned = next.some((intent) => isActiveIntent(intent)
253
+ && intent.executionDomainId === scope.executionDomainId
254
+ && intent.project === scope.project
255
+ && volumeMetadataMatchesIntent(volume, intent));
256
+ if (!owned) {
257
+ for (const observed of next) {
258
+ if (observed.executionDomainId !== scope.executionDomainId || observed.project !== scope.project
259
+ || (observed.state !== "reserved" && observed.state !== "creating"))
260
+ continue;
261
+ // Inventory requests are separate snapshots: a copy can appear after
262
+ // listInstances, and its disk keeps source metadata until PATCH.
263
+ // Re-read the exact allocation and object instead of treating that
264
+ // acceptance window as an unregistered resource.
265
+ const current = await readAllocationIntent(repository, observed.allocationId);
266
+ if (current === undefined || current.generation !== observed.generation
267
+ || current.executionDomainId !== scope.executionDomainId || current.project !== scope.project
268
+ || current.storagePool !== scope.storagePool
269
+ || current.dockerDataVolume !== volume.name || current.providerLocator === undefined)
270
+ continue;
271
+ if (current.state === "creating") {
272
+ const instance = await control.getInstance(scope.project, current.providerLocator);
273
+ owned = instance !== undefined && instance.name === current.providerLocator
274
+ && volumeIsDependentOnExactInstance(instance, volume, current);
275
+ }
276
+ else if (isActiveIntent(current)) {
277
+ // A completed PATCH may also have overtaken the volume snapshot.
278
+ // Stable allocations must still present their own exact metadata.
279
+ const refreshed = await control.getVolume(scope.project, scope.storagePool, volume.name);
280
+ owned = refreshed !== undefined && volumeMetadataMatchesIntent(refreshed, current);
281
+ }
282
+ if (owned)
283
+ break;
284
+ }
285
+ }
253
286
  if (owned)
254
287
  continue;
255
288
  throw (0, errors_ts_1.incusError)("sandbox-allocation-lost", `Incus volume ${JSON.stringify(volume.name)} claims execution domain ${JSON.stringify(scope.executionDomainId)} but has no exact IncusRepository allocation intent.`, ["Keep the volume in place and restore or explicitly maintain the durable registry; never infer ownership from a name or delete an unregistered object."]);
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.js","sourceRoot":"","sources":["ledger.ts"],"names":[],"mappings":";;;AAkBA,0DAEC;AACD,gEAEC;AACD,oDAEC;AACD,sDAEC;AACD,0CAGC;AACD,sCAGC;AACD,wCAEC;AACD,oCAMC;AACD,gCAsCC;AACD,sDAQC;AAID,4DA+BC;AACD,wDAKC;AACD,kEAaC;AAmBD,0CA0FC;AACD,8CAkEC;AACD,wCAEC;AACD,wCAEC;AAMD,gEAiCC;AACD,kDAEC;AAtXD,qCAAmC;AACnC,wDAAyD;AACzD,6CAAuG;AACvG,2CAAkE;AAElE,iDAAoD;AAA3C,kHAAA,iBAAiB,OAAA;AAE1B,MAAM,eAAe,GAAG,IAAI,GAAG,CAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAkB;IAC9C,UAAU;IACV,UAAU;IACV,OAAO;IACP,YAAY;IACZ,mBAAmB;IACnB,MAAM;CACT,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,SAAgB,uBAAuB,CAAC,UAA2B,EAAE,MAAwB;IACzF,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AACD,SAAgB,0BAA0B,CAAC,UAA2B,EAAE,OAAyB,EAAE,IAAsB;IACrH,OAAO,UAAU,CAAC,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AACD,SAAgB,oBAAoB,CAAC,UAA2B,EAAE,YAAoB;IAClF,OAAO,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC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AM,IAAA,sBAAU,EAAC,8BAA8B,EAAE,wBAAwB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,yCAAyC,EAAE,CAAC,2EAA2E,CAAC,CAAC,CAAC;oBACxO,CAAC;gBACL,CAAC;aACJ,CAAC;QACN,CAAC;QACD,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAA,sBAAU,EAAC,8BAA8B,EAAE,6DAA6D,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,mFAAmF,CAAC,CAAC,CAAC;QAC/O,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IACvE,CAAC;AACL,CAAC;AACD,SAAgB,mBAAmB,CAAC,YAAoB;IACpD,OAAO,IAAA,sBAAU,EAAC,yBAAyB,EAAE,sBAAsB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,qDAAqD,EAAE,CAAC,6FAA6F,CAAC,CAAC,CAAC;AAC3P,CAAC","sourcesContent":["import { hostname } from \"node:os\";\nimport { classifyRunIdentity } from \"../run-identity.ts\";\nimport { INCUS_METADATA, type IncusControl, type IncusInstance, type IncusVolume } from \"./control.ts\";\nimport { incusError, type IncusProviderError } from \"./errors.ts\";\nimport { type AllocationIntent, type AllocationOwner, type AllocationState, type IncusAdmissionLease, type IncusRepository, } from \"./repository.ts\";\nexport { ALLOCATION_STATES } from \"./repository.ts\";\nexport type { AllocationIntent, AllocationOwner, AllocationState } from \"./repository.ts\";\nconst RELEASED_STATES = new Set<AllocationState>([\"destroyed\"]);\nconst OCCUPYING_STATES = new Set<AllocationState>([\n \"reserved\",\n \"creating\",\n \"ready\",\n \"handed-off\",\n \"destroy-requested\",\n \"lost\",\n]);\nconst LOCK_WAIT_MS = 15000;\nconst LOCK_RETRY_MS = 50;\nexport function reserveAllocationIntent(repository: IncusRepository, intent: AllocationIntent): Promise<AllocationIntent> {\n return repository.reserveAllocation(intent);\n}\nexport function transitionAllocationIntent(repository: IncusRepository, current: AllocationIntent, next: AllocationIntent): Promise<AllocationIntent> {\n return repository.transitionAllocation(current, next);\n}\nexport function readAllocationIntent(repository: IncusRepository, allocationId: string): Promise<AllocationIntent | undefined> {\n return repository.getAllocation(allocationId);\n}\nexport function listAllocationIntents(repository: IncusRepository): Promise<readonly AllocationIntent[]> {\n return repository.listAllocations();\n}\nexport function instanceNameFor(allocationId: string): string {\n const compact = allocationId.replaceAll(\"-\", \"\").toLowerCase();\n return `ne-${compact.slice(0, 20)}`;\n}\nexport function volumeNameFor(allocationId: string): string {\n const compact = allocationId.replaceAll(\"-\", \"\").toLowerCase();\n return `ne-${compact.slice(0, 18)}-dd`;\n}\nexport function executionIdFor(allocationId: string): string {\n return `exec-${allocationId}`;\n}\nexport function currentOwner(): AllocationOwner {\n return Object.freeze({\n host: hostname(),\n pid: process.pid,\n startedAt: new Date().toISOString(),\n });\n}\nexport function metadataOf(instance: IncusInstance): {\n readonly allocationId?: string;\n readonly executionId?: string;\n readonly generation?: number;\n readonly artifactDigest?: string;\n readonly executionDomainId?: string;\n readonly provisionToken?: string;\n readonly host?: string;\n readonly pid?: number;\n readonly startedAt?: string;\n} {\n const generationRaw = instance.config[INCUS_METADATA.generation];\n const generation = generationRaw === undefined ? undefined : Number(generationRaw);\n const pidRaw = instance.config[INCUS_METADATA.pid];\n const pid = pidRaw === undefined ? undefined : Number(pidRaw);\n return {\n ...(instance.config[INCUS_METADATA.allocationId] === undefined\n ? {}\n : { allocationId: instance.config[INCUS_METADATA.allocationId] }),\n ...(instance.config[INCUS_METADATA.executionId] === undefined\n ? {}\n : { executionId: instance.config[INCUS_METADATA.executionId] }),\n ...(generation !== undefined && Number.isSafeInteger(generation) ? { generation } : {}),\n ...(instance.config[INCUS_METADATA.artifactDigest] === undefined\n ? {}\n : { artifactDigest: instance.config[INCUS_METADATA.artifactDigest] }),\n ...(instance.config[INCUS_METADATA.executionDomainId] === undefined\n ? {}\n : { executionDomainId: instance.config[INCUS_METADATA.executionDomainId] }),\n ...(instance.config[INCUS_METADATA.provisionToken] === undefined\n ? {}\n : { provisionToken: instance.config[INCUS_METADATA.provisionToken] }),\n ...(instance.config[INCUS_METADATA.host] === undefined ? {} : { host: instance.config[INCUS_METADATA.host] }),\n ...(pid !== undefined && Number.isSafeInteger(pid) ? { pid } : {}),\n ...(instance.config[INCUS_METADATA.startedAt] === undefined\n ? {}\n : { startedAt: instance.config[INCUS_METADATA.startedAt] }),\n };\n}\nexport function metadataMatchesIntent(instance: IncusInstance, intent: AllocationIntent): boolean {\n const meta = metadataOf(instance);\n return meta.allocationId === intent.allocationId\n && meta.generation === intent.generation\n && meta.executionDomainId === intent.executionDomainId\n && meta.artifactDigest === intent.artifactDigest\n && meta.provisionToken === intent.provisionToken\n && meta.executionId === intent.executionId;\n}\nfunction ownerProvenDead(owner: AllocationOwner): boolean {\n return classifyRunIdentity(owner) === \"orphan\";\n}\nexport function unionActiveAllocationIds(intents: readonly AllocationIntent[], instances: readonly IncusInstance[], scope: {\n readonly executionDomainId: string;\n readonly project: string;\n}, volumes: readonly IncusVolume[] = []): ReadonlySet<string> {\n const ids = new Set<string>();\n for (const intent of intents) {\n if (OCCUPYING_STATES.has(intent.state)\n && intent.executionDomainId === scope.executionDomainId\n && intent.project === scope.project) {\n ids.add(intent.allocationId);\n }\n }\n for (const instance of instances) {\n const meta = metadataOf(instance);\n if (meta.allocationId !== undefined\n && meta.generation !== undefined\n && meta.executionDomainId === scope.executionDomainId\n && meta.artifactDigest !== undefined\n && meta.provisionToken !== undefined\n && meta.executionId !== undefined) {\n ids.add(meta.allocationId);\n }\n }\n for (const volume of volumes) {\n const allocationId = volume.config[INCUS_METADATA.allocationId];\n const executionDomainId = volume.config[INCUS_METADATA.executionDomainId];\n if (allocationId !== undefined && executionDomainId === scope.executionDomainId) {\n ids.add(allocationId);\n }\n }\n return ids;\n}\nexport function countActiveAllocations(intents: readonly AllocationIntent[], instances: readonly IncusInstance[], executionDomainId: string, project: string, volumes: readonly IncusVolume[] = []): number {\n return unionActiveAllocationIds(intents, instances, {\n executionDomainId,\n project,\n }, volumes).size;\n}\nexport function volumeMetadataMatchesIntent(volume: IncusVolume, intent: AllocationIntent): boolean {\n const allocationId = volume.config[INCUS_METADATA.allocationId];\n const generation = volume.config[INCUS_METADATA.generation];\n const executionDomainId = volume.config[INCUS_METADATA.executionDomainId];\n const artifactDigest = volume.config[INCUS_METADATA.artifactDigest];\n const provisionToken = volume.config[INCUS_METADATA.provisionToken];\n const executionId = volume.config[INCUS_METADATA.executionId];\n return allocationId === intent.allocationId\n && generation === String(intent.generation)\n && executionDomainId === intent.executionDomainId\n && artifactDigest === intent.artifactDigest\n && provisionToken === intent.provisionToken\n && executionId === intent.executionId;\n}\n/**\n * Incus creates a cross-project copy's dependent volume atomically with its\n * VM. There is a narrow acceptance window before the follow-up volume PATCH\n * can replace the source artifact metadata. During that window, the VM is\n * still the durable allocation's exact object, and its expanded `dockerdata`\n * device is the only evidence that permits deleting the copied volume.\n */\nfunction volumeIsDependentOnExactInstance(instance: IncusInstance, volume: IncusVolume, intent: AllocationIntent): boolean {\n if (!metadataMatchesIntent(instance, intent))\n return false;\n const dockerData = instance.expandedDevices?.dockerdata;\n return volume.type === \"custom\"\n && volume.contentType === \"block\"\n && dockerData?.type === \"disk\"\n && dockerData.pool === intent.storagePool\n && dockerData.source === volume.name\n && dockerData.dependent === \"true\";\n}\nexport async function reconcileDomain(repository: IncusRepository, control: IncusControl, scope: {\n readonly executionDomainId: string;\n readonly project: string;\n readonly storagePool: string;\n}): Promise<{\n readonly intents: readonly AllocationIntent[];\n readonly instances: readonly IncusInstance[];\n}> {\n const intents = await listAllocationIntents(repository);\n const instances = await control.listInstances(scope.project);\n const volumes = await control.listVolumes(scope.project, scope.storagePool);\n const next: AllocationIntent[] = [];\n for (const intent of intents) {\n if (intent.executionDomainId !== scope.executionDomainId || intent.project !== scope.project) {\n next.push(intent);\n continue;\n }\n if (RELEASED_STATES.has(intent.state)) {\n next.push(intent);\n continue;\n }\n const instance = instances.find((candidate) => metadataMatchesIntent(candidate, intent));\n const volume = volumes.find((candidate) => volumeMetadataMatchesIntent(candidate, intent));\n const ownerAlive = !ownerProvenDead(intent.owner);\n if (instance === undefined && volume === undefined) {\n if (intent.quarantined === true) {\n next.push(intent);\n continue;\n }\n if (ownerAlive && (intent.state === \"reserved\" || intent.state === \"creating\")) {\n next.push(intent);\n continue;\n }\n if (ownerAlive) {\n next.push(intent);\n continue;\n }\n // Even an absent allocation must cross the repository's fenced\n // destroy-requested state. In particular, a process can die after the\n // allocation became ready while an operator independently removes the\n // exact VM and volume; skipping the destroy protocol would attempt the\n // invalid ready -> destroyed transition.\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n if (intent.state === \"destroy-requested\") {\n const awaitedObject = intent.acceptanceUnknown === \"volume-create\" ? volume : instance;\n if (intent.quarantined === true && awaitedObject === undefined) {\n next.push(intent);\n continue;\n }\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n if (ownerProvenDead(intent.owner)) {\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n next.push(intent);\n }\n // Re-read after detached destroy. The initial inventory can contain an\n // accepted clone whose dependent volume still has the source artifact's\n // metadata; classifying that already-destroyed snapshot as unregistered\n // would turn successful reconciliation into a false lost-allocation error.\n const reconciledInstances = await control.listInstances(scope.project);\n const reconciledVolumes = await control.listVolumes(scope.project, scope.storagePool);\n for (const instance of reconciledInstances) {\n const meta = metadataOf(instance);\n if (meta.executionDomainId !== scope.executionDomainId)\n continue;\n const owned = next.some((intent) => isActiveIntent(intent)\n && intent.executionDomainId === scope.executionDomainId\n && intent.project === scope.project\n && metadataMatchesIntent(instance, intent));\n if (owned)\n continue;\n throw incusError(\"sandbox-allocation-lost\", `Incus instance ${JSON.stringify(instance.name)} claims execution domain ${JSON.stringify(scope.executionDomainId)} but has no exact IncusRepository allocation intent.`, [\"Keep the instance in place and restore or explicitly maintain the durable registry; never infer ownership from a name or delete an unregistered object.\"]);\n }\n for (const volume of reconciledVolumes) {\n if (volume.config[INCUS_METADATA.executionDomainId] !== scope.executionDomainId)\n continue;\n const owned = next.some((intent) => isActiveIntent(intent) && volumeMetadataMatchesIntent(volume, intent));\n if (owned)\n continue;\n throw incusError(\"sandbox-allocation-lost\", `Incus volume ${JSON.stringify(volume.name)} claims execution domain ${JSON.stringify(scope.executionDomainId)} but has no exact IncusRepository allocation intent.`, [\"Keep the volume in place and restore or explicitly maintain the durable registry; never infer ownership from a name or delete an unregistered object.\"]);\n }\n return Object.freeze({\n intents: Object.freeze(next),\n instances: reconciledInstances,\n });\n}\nexport async function destroyAllocation(repository: IncusRepository, control: IncusControl, intent: AllocationIntent, project: string): Promise<AllocationIntent> {\n const current = await readAllocationIntent(repository, intent.allocationId);\n if (current === undefined) {\n throw incusError(\"sandbox-allocation-lost\", `Sandbox allocation ${JSON.stringify(intent.allocationId)} disappeared from the ledger before destroy.`, [\"Reconcile the ledger against Incus inventory.\"]);\n }\n if (current.generation !== intent.generation) {\n throw incusError(\"sandbox-destroy-incomplete\", `Destroy fenced: ledger generation ${current.generation} does not match caller generation ${intent.generation}.`, [\"Retry destroy from the current generation only.\"]);\n }\n if (current.executionDomainId !== intent.executionDomainId || current.project !== project) {\n throw incusError(\"sandbox-destroy-incomplete\", \"Destroy fenced: execution domain or project does not match the caller.\", [\"Destroy only from the owning execution domain and project.\"]);\n }\n const requested = current.state === \"destroy-requested\"\n ? current\n : await transitionAllocationIntent(repository, current, { ...current, state: \"destroy-requested\" });\n const instances = await control.listInstances(project);\n const volumes = await control.listVolumes(project, requested.storagePool);\n const matchingInstance = instances.find((candidate) => metadataMatchesIntent(candidate, requested));\n const matchingVolume = volumes.find((candidate) => volumeMetadataMatchesIntent(candidate, requested));\n const instanceName = matchingInstance?.name ?? requested.providerLocator ?? instanceNameFor(requested.allocationId);\n const volumeName = matchingVolume?.name ?? requested.dockerDataVolume ?? volumeNameFor(requested.allocationId);\n const namedInstance = matchingInstance ?? instances.find((candidate) => candidate.name === instanceName);\n const namedVolume = matchingVolume ?? volumes.find((candidate) => candidate.name === volumeName);\n if (namedInstance !== undefined && !metadataMatchesIntent(namedInstance, requested)) {\n throw incusError(\"sandbox-destroy-incomplete\", `Refusing to destroy Incus instance ${JSON.stringify(instanceName)} with mismatched allocation metadata.`, [\"Inspect the instance identity; NiceEval only destroys the exact allocation generation it owns.\"]);\n }\n const inheritedCloneVolume = namedInstance !== undefined\n && namedVolume !== undefined\n && volumeIsDependentOnExactInstance(namedInstance, namedVolume, requested);\n if (namedVolume !== undefined\n && !volumeMetadataMatchesIntent(namedVolume, requested)\n && !inheritedCloneVolume) {\n throw incusError(\"sandbox-destroy-incomplete\", `Refusing to destroy Incus volume ${JSON.stringify(volumeName)} with mismatched allocation metadata.`, [\"Inspect the volume identity; NiceEval only destroys the exact allocation generation it owns.\"]);\n }\n if (requested.quarantined === true) {\n const awaitedObject = requested.acceptanceUnknown === \"volume-create\" ? namedVolume : namedInstance;\n if (awaitedObject === undefined) {\n throw incusError(\"sandbox-destroy-incomplete\", `Incus allocation ${JSON.stringify(requested.allocationId)} still has an acceptance-unknown create operation.`, [\"Keep the allocation quarantined until the expected Incus object appears and can be destroyed by exact metadata.\"]);\n }\n }\n try {\n if (namedInstance !== undefined)\n await control.deleteInstance(project, namedInstance.name);\n if (namedVolume !== undefined)\n await control.deleteVolume(project, requested.storagePool, namedVolume.name);\n await control.waitAbsent(project, instanceName);\n await control.waitVolumeAbsent(project, requested.storagePool, volumeName);\n const confirmAbsent = async (): Promise<void> => {\n const leftoverInstance = await control.getInstance(project, instanceName);\n const leftoverVolume = await control.getVolume(project, requested.storagePool, volumeName);\n if (leftoverInstance !== undefined || leftoverVolume !== undefined) {\n throw incusError(\"sandbox-destroy-incomplete\", `Incus allocation ${JSON.stringify(requested.allocationId)} still has a VM or custom volume.`, [\"Retry destroy; do not mark destroyed without absent receipts for both the VM and volume.\"]);\n }\n };\n await confirmAbsent();\n }\n catch (cause) {\n throw incusError(\"sandbox-destroy-incomplete\", `Failed to prove Incus allocation ${JSON.stringify(requested.allocationId)} is absent.`, [\"Retry destroy from the Incus control plane; NiceEval will not mark the allocation destroyed without absent receipts for the VM and volume.\"], cause);\n }\n return transitionAllocationIntent(repository, requested, {\n ...requested,\n state: \"destroyed\",\n providerLocator: undefined,\n dockerDataVolume: undefined,\n quarantined: undefined,\n acceptanceUnknown: undefined,\n });\n}\nexport function nextGeneration(existing: AllocationIntent | undefined): number {\n return existing === undefined ? 1 : existing.generation + 1;\n}\nexport function isActiveIntent(intent: AllocationIntent): boolean {\n return OCCUPYING_STATES.has(intent.state);\n}\nexport interface AdmissionLock {\n readonly executionDomainId: string;\n readonly fencingToken: number;\n release(): Promise<void>;\n}\nexport async function acquireDomainAdmissionLock(repository: IncusRepository, executionDomainId: string, options: {\n readonly waitMs?: number;\n} = {}): Promise<AdmissionLock> {\n const owner = currentOwner();\n const waitMs = options.waitMs ?? LOCK_WAIT_MS;\n if (!Number.isFinite(waitMs) || waitMs < 0) {\n throw new TypeError(\"Incus admission lock waitMs must be a finite non-negative number.\");\n }\n const deadline = Date.now() + waitMs;\n let expected: IncusAdmissionLease | undefined;\n for (;;) {\n const acquired = await repository.acquireAdmission(executionDomainId, owner, expected);\n if (acquired.acquired) {\n let released = false;\n return {\n executionDomainId,\n fencingToken: acquired.lease.fencingToken,\n release: async () => {\n if (released)\n return;\n released = true;\n if (!(await repository.releaseAdmission(acquired.lease))) {\n throw incusError(\"sandbox-capacity-unavailable\", `Incus admission lock ${JSON.stringify(executionDomainId)} lost its fencing token before release.`, [\"Stop new admission and reconcile the current IncusRepository lease owner.\"]);\n }\n },\n };\n }\n expected = ownerProvenDead(acquired.lease.owner) ? acquired.lease : undefined;\n if (Date.now() >= deadline) {\n throw incusError(\"sandbox-capacity-unavailable\", `Timed out waiting for the Incus admission lock for domain ${JSON.stringify(executionDomainId)}.`, [\"Retry after the owning control process exits; do not break a live admission lock.\"]);\n }\n await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_MS));\n }\n}\nexport function lostAllocationError(allocationId: string): IncusProviderError {\n return incusError(\"sandbox-allocation-lost\", `Sandbox allocation ${JSON.stringify(allocationId)} is active in the ledger but has no Incus instance.`, [\"Reconcile again after Incus inventory is available; do not recreate from a guessed locator.\"]);\n}\n"]}
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["ledger.ts"],"names":[],"mappings":";;;AAkBA,0DAEC;AACD,gEAEC;AACD,oDAEC;AACD,sDAEC;AACD,0CAGC;AACD,sCAGC;AACD,wCAEC;AACD,oCAMC;AACD,gCAsCC;AACD,sDAQC;AAID,4DA+BC;AACD,wDAKC;AACD,kEAaC;AAmBD,0CA2HC;AACD,8CAkEC;AACD,wCAEC;AACD,wCAEC;AAMD,gEAiCC;AACD,kDAEC;AAvZD,qCAAmC;AACnC,wDAAyD;AACzD,6CAAuG;AACvG,2CAAkE;AAElE,iDAAoD;AAA3C,kHAAA,iBAAiB,OAAA;AAE1B,MAAM,eAAe,GAAG,IAAI,GAAG,CAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAkB;IAC9C,UAAU;IACV,UAAU;IACV,OAAO;IACP,YAAY;IACZ,mBAAmB;IACnB,MAAM;CACT,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,SAAgB,uBAAuB,CAAC,UAA2B,EAAE,MAAwB;IACzF,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AACD,SAAgB,0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,SAAgB,mBAAmB,CAAC,YAAoB;IACpD,OAAO,IAAA,sBAAU,EAAC,yBAAyB,EAAE,sBAAsB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,qDAAqD,EAAE,CAAC,6FAA6F,CAAC,CAAC,CAAC;AAC3P,CAAC","sourcesContent":["import { hostname } from \"node:os\";\nimport { classifyRunIdentity } from \"../run-identity.ts\";\nimport { INCUS_METADATA, type IncusControl, type IncusInstance, type IncusVolume } from \"./control.ts\";\nimport { incusError, type IncusProviderError } from \"./errors.ts\";\nimport { type AllocationIntent, type AllocationOwner, type AllocationState, type IncusAdmissionLease, type IncusRepository, } from \"./repository.ts\";\nexport { ALLOCATION_STATES } from \"./repository.ts\";\nexport type { AllocationIntent, AllocationOwner, AllocationState } from \"./repository.ts\";\nconst RELEASED_STATES = new Set<AllocationState>([\"destroyed\"]);\nconst OCCUPYING_STATES = new Set<AllocationState>([\n \"reserved\",\n \"creating\",\n \"ready\",\n \"handed-off\",\n \"destroy-requested\",\n \"lost\",\n]);\nconst LOCK_WAIT_MS = 15000;\nconst LOCK_RETRY_MS = 50;\nexport function reserveAllocationIntent(repository: IncusRepository, intent: AllocationIntent): Promise<AllocationIntent> {\n return repository.reserveAllocation(intent);\n}\nexport function transitionAllocationIntent(repository: IncusRepository, current: AllocationIntent, next: AllocationIntent): Promise<AllocationIntent> {\n return repository.transitionAllocation(current, next);\n}\nexport function readAllocationIntent(repository: IncusRepository, allocationId: string): Promise<AllocationIntent | undefined> {\n return repository.getAllocation(allocationId);\n}\nexport function listAllocationIntents(repository: IncusRepository): Promise<readonly AllocationIntent[]> {\n return repository.listAllocations();\n}\nexport function instanceNameFor(allocationId: string): string {\n const compact = allocationId.replaceAll(\"-\", \"\").toLowerCase();\n return `ne-${compact.slice(0, 20)}`;\n}\nexport function volumeNameFor(allocationId: string): string {\n const compact = allocationId.replaceAll(\"-\", \"\").toLowerCase();\n return `ne-${compact.slice(0, 18)}-dd`;\n}\nexport function executionIdFor(allocationId: string): string {\n return `exec-${allocationId}`;\n}\nexport function currentOwner(): AllocationOwner {\n return Object.freeze({\n host: hostname(),\n pid: process.pid,\n startedAt: new Date().toISOString(),\n });\n}\nexport function metadataOf(instance: IncusInstance): {\n readonly allocationId?: string;\n readonly executionId?: string;\n readonly generation?: number;\n readonly artifactDigest?: string;\n readonly executionDomainId?: string;\n readonly provisionToken?: string;\n readonly host?: string;\n readonly pid?: number;\n readonly startedAt?: string;\n} {\n const generationRaw = instance.config[INCUS_METADATA.generation];\n const generation = generationRaw === undefined ? undefined : Number(generationRaw);\n const pidRaw = instance.config[INCUS_METADATA.pid];\n const pid = pidRaw === undefined ? undefined : Number(pidRaw);\n return {\n ...(instance.config[INCUS_METADATA.allocationId] === undefined\n ? {}\n : { allocationId: instance.config[INCUS_METADATA.allocationId] }),\n ...(instance.config[INCUS_METADATA.executionId] === undefined\n ? {}\n : { executionId: instance.config[INCUS_METADATA.executionId] }),\n ...(generation !== undefined && Number.isSafeInteger(generation) ? { generation } : {}),\n ...(instance.config[INCUS_METADATA.artifactDigest] === undefined\n ? {}\n : { artifactDigest: instance.config[INCUS_METADATA.artifactDigest] }),\n ...(instance.config[INCUS_METADATA.executionDomainId] === undefined\n ? {}\n : { executionDomainId: instance.config[INCUS_METADATA.executionDomainId] }),\n ...(instance.config[INCUS_METADATA.provisionToken] === undefined\n ? {}\n : { provisionToken: instance.config[INCUS_METADATA.provisionToken] }),\n ...(instance.config[INCUS_METADATA.host] === undefined ? {} : { host: instance.config[INCUS_METADATA.host] }),\n ...(pid !== undefined && Number.isSafeInteger(pid) ? { pid } : {}),\n ...(instance.config[INCUS_METADATA.startedAt] === undefined\n ? {}\n : { startedAt: instance.config[INCUS_METADATA.startedAt] }),\n };\n}\nexport function metadataMatchesIntent(instance: IncusInstance, intent: AllocationIntent): boolean {\n const meta = metadataOf(instance);\n return meta.allocationId === intent.allocationId\n && meta.generation === intent.generation\n && meta.executionDomainId === intent.executionDomainId\n && meta.artifactDigest === intent.artifactDigest\n && meta.provisionToken === intent.provisionToken\n && meta.executionId === intent.executionId;\n}\nfunction ownerProvenDead(owner: AllocationOwner): boolean {\n return classifyRunIdentity(owner) === \"orphan\";\n}\nexport function unionActiveAllocationIds(intents: readonly AllocationIntent[], instances: readonly IncusInstance[], scope: {\n readonly executionDomainId: string;\n readonly project: string;\n}, volumes: readonly IncusVolume[] = []): ReadonlySet<string> {\n const ids = new Set<string>();\n for (const intent of intents) {\n if (OCCUPYING_STATES.has(intent.state)\n && intent.executionDomainId === scope.executionDomainId\n && intent.project === scope.project) {\n ids.add(intent.allocationId);\n }\n }\n for (const instance of instances) {\n const meta = metadataOf(instance);\n if (meta.allocationId !== undefined\n && meta.generation !== undefined\n && meta.executionDomainId === scope.executionDomainId\n && meta.artifactDigest !== undefined\n && meta.provisionToken !== undefined\n && meta.executionId !== undefined) {\n ids.add(meta.allocationId);\n }\n }\n for (const volume of volumes) {\n const allocationId = volume.config[INCUS_METADATA.allocationId];\n const executionDomainId = volume.config[INCUS_METADATA.executionDomainId];\n if (allocationId !== undefined && executionDomainId === scope.executionDomainId) {\n ids.add(allocationId);\n }\n }\n return ids;\n}\nexport function countActiveAllocations(intents: readonly AllocationIntent[], instances: readonly IncusInstance[], executionDomainId: string, project: string, volumes: readonly IncusVolume[] = []): number {\n return unionActiveAllocationIds(intents, instances, {\n executionDomainId,\n project,\n }, volumes).size;\n}\nexport function volumeMetadataMatchesIntent(volume: IncusVolume, intent: AllocationIntent): boolean {\n const allocationId = volume.config[INCUS_METADATA.allocationId];\n const generation = volume.config[INCUS_METADATA.generation];\n const executionDomainId = volume.config[INCUS_METADATA.executionDomainId];\n const artifactDigest = volume.config[INCUS_METADATA.artifactDigest];\n const provisionToken = volume.config[INCUS_METADATA.provisionToken];\n const executionId = volume.config[INCUS_METADATA.executionId];\n return allocationId === intent.allocationId\n && generation === String(intent.generation)\n && executionDomainId === intent.executionDomainId\n && artifactDigest === intent.artifactDigest\n && provisionToken === intent.provisionToken\n && executionId === intent.executionId;\n}\n/**\n * Incus creates a cross-project copy's dependent volume atomically with its\n * VM. There is a narrow acceptance window before the follow-up volume PATCH\n * can replace the source artifact metadata. During that window, the VM is\n * still the durable allocation's exact object, and its expanded `dockerdata`\n * device is the only evidence that permits deleting the copied volume.\n */\nfunction volumeIsDependentOnExactInstance(instance: IncusInstance, volume: IncusVolume, intent: AllocationIntent): boolean {\n if (!metadataMatchesIntent(instance, intent))\n return false;\n const dockerData = instance.expandedDevices?.dockerdata;\n return volume.type === \"custom\"\n && volume.contentType === \"block\"\n && dockerData?.type === \"disk\"\n && dockerData.pool === intent.storagePool\n && dockerData.source === volume.name\n && dockerData.dependent === \"true\";\n}\nexport async function reconcileDomain(repository: IncusRepository, control: IncusControl, scope: {\n readonly executionDomainId: string;\n readonly project: string;\n readonly storagePool: string;\n}): Promise<{\n readonly intents: readonly AllocationIntent[];\n readonly instances: readonly IncusInstance[];\n}> {\n const intents = await listAllocationIntents(repository);\n const instances = await control.listInstances(scope.project);\n const volumes = await control.listVolumes(scope.project, scope.storagePool);\n const next: AllocationIntent[] = [];\n for (const intent of intents) {\n if (intent.executionDomainId !== scope.executionDomainId || intent.project !== scope.project) {\n next.push(intent);\n continue;\n }\n if (RELEASED_STATES.has(intent.state)) {\n next.push(intent);\n continue;\n }\n const instance = instances.find((candidate) => metadataMatchesIntent(candidate, intent));\n const volume = volumes.find((candidate) => volumeMetadataMatchesIntent(candidate, intent));\n const ownerAlive = !ownerProvenDead(intent.owner);\n if (instance === undefined && volume === undefined) {\n if (intent.quarantined === true) {\n next.push(intent);\n continue;\n }\n if (ownerAlive && (intent.state === \"reserved\" || intent.state === \"creating\")) {\n next.push(intent);\n continue;\n }\n if (ownerAlive) {\n next.push(intent);\n continue;\n }\n // Even an absent allocation must cross the repository's fenced\n // destroy-requested state. In particular, a process can die after the\n // allocation became ready while an operator independently removes the\n // exact VM and volume; skipping the destroy protocol would attempt the\n // invalid ready -> destroyed transition.\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n if (intent.state === \"destroy-requested\") {\n const awaitedObject = intent.acceptanceUnknown === \"volume-create\" ? volume : instance;\n if (intent.quarantined === true && awaitedObject === undefined) {\n next.push(intent);\n continue;\n }\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n if (ownerProvenDead(intent.owner)) {\n next.push(await destroyAllocation(repository, control, intent, scope.project));\n continue;\n }\n next.push(intent);\n }\n // Re-read after detached destroy. The initial inventory can contain an\n // accepted clone whose dependent volume still has the source artifact's\n // metadata; classifying that already-destroyed snapshot as unregistered\n // would turn successful reconciliation into a false lost-allocation error.\n const reconciledInstances = await control.listInstances(scope.project);\n const reconciledVolumes = await control.listVolumes(scope.project, scope.storagePool);\n for (const instance of reconciledInstances) {\n const meta = metadataOf(instance);\n if (meta.executionDomainId !== scope.executionDomainId)\n continue;\n const owned = next.some((intent) => isActiveIntent(intent)\n && intent.executionDomainId === scope.executionDomainId\n && intent.project === scope.project\n && metadataMatchesIntent(instance, intent));\n if (owned)\n continue;\n throw incusError(\"sandbox-allocation-lost\", `Incus instance ${JSON.stringify(instance.name)} claims execution domain ${JSON.stringify(scope.executionDomainId)} but has no exact IncusRepository allocation intent.`, [\"Keep the instance in place and restore or explicitly maintain the durable registry; never infer ownership from a name or delete an unregistered object.\"]);\n }\n for (const volume of reconciledVolumes) {\n if (volume.config[INCUS_METADATA.executionDomainId] !== scope.executionDomainId)\n continue;\n let owned = next.some((intent) => isActiveIntent(intent)\n && intent.executionDomainId === scope.executionDomainId\n && intent.project === scope.project\n && volumeMetadataMatchesIntent(volume, intent));\n if (!owned) {\n for (const observed of next) {\n if (observed.executionDomainId !== scope.executionDomainId || observed.project !== scope.project\n || (observed.state !== \"reserved\" && observed.state !== \"creating\"))\n continue;\n // Inventory requests are separate snapshots: a copy can appear after\n // listInstances, and its disk keeps source metadata until PATCH.\n // Re-read the exact allocation and object instead of treating that\n // acceptance window as an unregistered resource.\n const current = await readAllocationIntent(repository, observed.allocationId);\n if (current === undefined || current.generation !== observed.generation\n || current.executionDomainId !== scope.executionDomainId || current.project !== scope.project\n || current.storagePool !== scope.storagePool\n || current.dockerDataVolume !== volume.name || current.providerLocator === undefined)\n continue;\n if (current.state === \"creating\") {\n const instance = await control.getInstance(scope.project, current.providerLocator);\n owned = instance !== undefined && instance.name === current.providerLocator\n && volumeIsDependentOnExactInstance(instance, volume, current);\n }\n else if (isActiveIntent(current)) {\n // A completed PATCH may also have overtaken the volume snapshot.\n // Stable allocations must still present their own exact metadata.\n const refreshed = await control.getVolume(scope.project, scope.storagePool, volume.name);\n owned = refreshed !== undefined && volumeMetadataMatchesIntent(refreshed, current);\n }\n if (owned)\n break;\n }\n }\n if (owned)\n continue;\n throw incusError(\"sandbox-allocation-lost\", `Incus volume ${JSON.stringify(volume.name)} claims execution domain ${JSON.stringify(scope.executionDomainId)} but has no exact IncusRepository allocation intent.`, [\"Keep the volume in place and restore or explicitly maintain the durable registry; never infer ownership from a name or delete an unregistered object.\"]);\n }\n return Object.freeze({\n intents: Object.freeze(next),\n instances: reconciledInstances,\n });\n}\nexport async function destroyAllocation(repository: IncusRepository, control: IncusControl, intent: AllocationIntent, project: string): Promise<AllocationIntent> {\n const current = await readAllocationIntent(repository, intent.allocationId);\n if (current === undefined) {\n throw incusError(\"sandbox-allocation-lost\", `Sandbox allocation ${JSON.stringify(intent.allocationId)} disappeared from the ledger before destroy.`, [\"Reconcile the ledger against Incus inventory.\"]);\n }\n if (current.generation !== intent.generation) {\n throw incusError(\"sandbox-destroy-incomplete\", `Destroy fenced: ledger generation ${current.generation} does not match caller generation ${intent.generation}.`, [\"Retry destroy from the current generation only.\"]);\n }\n if (current.executionDomainId !== intent.executionDomainId || current.project !== project) {\n throw incusError(\"sandbox-destroy-incomplete\", \"Destroy fenced: execution domain or project does not match the caller.\", [\"Destroy only from the owning execution domain and project.\"]);\n }\n const requested = current.state === \"destroy-requested\"\n ? current\n : await transitionAllocationIntent(repository, current, { ...current, state: \"destroy-requested\" });\n const instances = await control.listInstances(project);\n const volumes = await control.listVolumes(project, requested.storagePool);\n const matchingInstance = instances.find((candidate) => metadataMatchesIntent(candidate, requested));\n const matchingVolume = volumes.find((candidate) => volumeMetadataMatchesIntent(candidate, requested));\n const instanceName = matchingInstance?.name ?? requested.providerLocator ?? instanceNameFor(requested.allocationId);\n const volumeName = matchingVolume?.name ?? requested.dockerDataVolume ?? volumeNameFor(requested.allocationId);\n const namedInstance = matchingInstance ?? instances.find((candidate) => candidate.name === instanceName);\n const namedVolume = matchingVolume ?? volumes.find((candidate) => candidate.name === volumeName);\n if (namedInstance !== undefined && !metadataMatchesIntent(namedInstance, requested)) {\n throw incusError(\"sandbox-destroy-incomplete\", `Refusing to destroy Incus instance ${JSON.stringify(instanceName)} with mismatched allocation metadata.`, [\"Inspect the instance identity; NiceEval only destroys the exact allocation generation it owns.\"]);\n }\n const inheritedCloneVolume = namedInstance !== undefined\n && namedVolume !== undefined\n && volumeIsDependentOnExactInstance(namedInstance, namedVolume, requested);\n if (namedVolume !== undefined\n && !volumeMetadataMatchesIntent(namedVolume, requested)\n && !inheritedCloneVolume) {\n throw incusError(\"sandbox-destroy-incomplete\", `Refusing to destroy Incus volume ${JSON.stringify(volumeName)} with mismatched allocation metadata.`, [\"Inspect the volume identity; NiceEval only destroys the exact allocation generation it owns.\"]);\n }\n if (requested.quarantined === true) {\n const awaitedObject = requested.acceptanceUnknown === \"volume-create\" ? namedVolume : namedInstance;\n if (awaitedObject === undefined) {\n throw incusError(\"sandbox-destroy-incomplete\", `Incus allocation ${JSON.stringify(requested.allocationId)} still has an acceptance-unknown create operation.`, [\"Keep the allocation quarantined until the expected Incus object appears and can be destroyed by exact metadata.\"]);\n }\n }\n try {\n if (namedInstance !== undefined)\n await control.deleteInstance(project, namedInstance.name);\n if (namedVolume !== undefined)\n await control.deleteVolume(project, requested.storagePool, namedVolume.name);\n await control.waitAbsent(project, instanceName);\n await control.waitVolumeAbsent(project, requested.storagePool, volumeName);\n const confirmAbsent = async (): Promise<void> => {\n const leftoverInstance = await control.getInstance(project, instanceName);\n const leftoverVolume = await control.getVolume(project, requested.storagePool, volumeName);\n if (leftoverInstance !== undefined || leftoverVolume !== undefined) {\n throw incusError(\"sandbox-destroy-incomplete\", `Incus allocation ${JSON.stringify(requested.allocationId)} still has a VM or custom volume.`, [\"Retry destroy; do not mark destroyed without absent receipts for both the VM and volume.\"]);\n }\n };\n await confirmAbsent();\n }\n catch (cause) {\n throw incusError(\"sandbox-destroy-incomplete\", `Failed to prove Incus allocation ${JSON.stringify(requested.allocationId)} is absent.`, [\"Retry destroy from the Incus control plane; NiceEval will not mark the allocation destroyed without absent receipts for the VM and volume.\"], cause);\n }\n return transitionAllocationIntent(repository, requested, {\n ...requested,\n state: \"destroyed\",\n providerLocator: undefined,\n dockerDataVolume: undefined,\n quarantined: undefined,\n acceptanceUnknown: undefined,\n });\n}\nexport function nextGeneration(existing: AllocationIntent | undefined): number {\n return existing === undefined ? 1 : existing.generation + 1;\n}\nexport function isActiveIntent(intent: AllocationIntent): boolean {\n return OCCUPYING_STATES.has(intent.state);\n}\nexport interface AdmissionLock {\n readonly executionDomainId: string;\n readonly fencingToken: number;\n release(): Promise<void>;\n}\nexport async function acquireDomainAdmissionLock(repository: IncusRepository, executionDomainId: string, options: {\n readonly waitMs?: number;\n} = {}): Promise<AdmissionLock> {\n const owner = currentOwner();\n const waitMs = options.waitMs ?? LOCK_WAIT_MS;\n if (!Number.isFinite(waitMs) || waitMs < 0) {\n throw new TypeError(\"Incus admission lock waitMs must be a finite non-negative number.\");\n }\n const deadline = Date.now() + waitMs;\n let expected: IncusAdmissionLease | undefined;\n for (;;) {\n const acquired = await repository.acquireAdmission(executionDomainId, owner, expected);\n if (acquired.acquired) {\n let released = false;\n return {\n executionDomainId,\n fencingToken: acquired.lease.fencingToken,\n release: async () => {\n if (released)\n return;\n released = true;\n if (!(await repository.releaseAdmission(acquired.lease))) {\n throw incusError(\"sandbox-capacity-unavailable\", `Incus admission lock ${JSON.stringify(executionDomainId)} lost its fencing token before release.`, [\"Stop new admission and reconcile the current IncusRepository lease owner.\"]);\n }\n },\n };\n }\n expected = ownerProvenDead(acquired.lease.owner) ? acquired.lease : undefined;\n if (Date.now() >= deadline) {\n throw incusError(\"sandbox-capacity-unavailable\", `Timed out waiting for the Incus admission lock for domain ${JSON.stringify(executionDomainId)}.`, [\"Retry after the owning control process exits; do not break a live admission lock.\"]);\n }\n await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_MS));\n }\n}\nexport function lostAllocationError(allocationId: string): IncusProviderError {\n return incusError(\"sandbox-allocation-lost\", `Sandbox allocation ${JSON.stringify(allocationId)} is active in the ledger but has no Incus instance.`, [\"Reconcile again after Incus inventory is available; do not recreate from a guessed locator.\"]);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "niceeval",
3
- "version": "0.14.3-canary.53",
3
+ "version": "0.14.3",
4
4
  "description": "Agent-native eval tool — eval agents, services, functions, and coding-agent fixtures",
5
5
  "type": "module",
6
6
  "license": "MIT",