@tangle-network/agent-provider-tangle 5.0.16 → 5.0.17
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.
|
@@ -246,10 +246,10 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
246
246
|
// rebuilds and re-sorts on every page; on a busy account a page failed or
|
|
247
247
|
// repeated, deletion was never attempted, and the source was kept running.
|
|
248
248
|
const known = await findManagedCheckpoint(box, provider, request.targetId, undefined, operation?.signal);
|
|
249
|
-
if (known === "unknown") {
|
|
250
|
-
return cleanupUnknown(request,
|
|
249
|
+
if (known.state === "unknown") {
|
|
250
|
+
return cleanupUnknown(request, `Sandbox checkpoint lookup answered unknown (${known.reason}); deletion was not attempted`, true);
|
|
251
251
|
}
|
|
252
|
-
if (known ===
|
|
252
|
+
if (known.state === "absent") {
|
|
253
253
|
const acknowledgement = cleanupAlreadyAbsent(request);
|
|
254
254
|
cleanup.set(request.operationId, {
|
|
255
255
|
requestDigest: request.requestDigest,
|
|
@@ -259,19 +259,19 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
259
259
|
}
|
|
260
260
|
let result;
|
|
261
261
|
try {
|
|
262
|
-
result = await awaitWithSignal(box.deleteSnapshot?.(
|
|
262
|
+
result = await awaitWithSignal(box.deleteSnapshot?.(known.snapshotId), operation?.signal);
|
|
263
263
|
}
|
|
264
264
|
catch (error) {
|
|
265
265
|
operation?.signal?.throwIfAborted();
|
|
266
266
|
return cleanupTransportFailure(request, `Sandbox checkpoint deletion failed: ${safeError(error)}`, true);
|
|
267
267
|
}
|
|
268
268
|
const outcome = result &&
|
|
269
|
-
result.snapshotId ===
|
|
269
|
+
result.snapshotId === known.snapshotId &&
|
|
270
270
|
(result.outcome === "deleted" || result.outcome === "already_absent")
|
|
271
271
|
? result.outcome
|
|
272
272
|
: "unknown";
|
|
273
273
|
if (outcome !== "deleted" && outcome !== "already_absent") {
|
|
274
|
-
return cleanupUnknown(request, "Sandbox
|
|
274
|
+
return cleanupUnknown(request, "Sandbox delete answered unknown (deletion not attested)", true);
|
|
275
275
|
}
|
|
276
276
|
const acknowledgement = outcome === "deleted"
|
|
277
277
|
? cleanupDeleted(request)
|
|
@@ -315,12 +315,12 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
315
315
|
}
|
|
316
316
|
const checkpoint = [...checkpoints.values()].some((record) => canonicalCandidateDigest(record.checkpoint) ===
|
|
317
317
|
canonicalCandidateDigest(request.checkpoint))
|
|
318
|
-
?
|
|
318
|
+
? undefined
|
|
319
319
|
: await findManagedCheckpoint(box, provider, request.checkpoint.checkpointId, request.checkpoint, operation?.signal);
|
|
320
|
-
if (checkpoint !==
|
|
321
|
-
return forkUnknown(request, checkpoint ===
|
|
320
|
+
if (checkpoint !== undefined && checkpoint.state !== "found") {
|
|
321
|
+
return forkUnknown(request, checkpoint.state === "absent"
|
|
322
322
|
? "Requested checkpoint is absent"
|
|
323
|
-
:
|
|
323
|
+
: `Sandbox checkpoint lookup answered unknown (${checkpoint.reason})`, true);
|
|
324
324
|
}
|
|
325
325
|
const metadata = forkMarkerMetadata(request);
|
|
326
326
|
let returnedChild;
|
|
@@ -30,13 +30,32 @@ export declare function validSnapshotResult(result: SandboxSnapshotResultLike |
|
|
|
30
30
|
/** Normalize one remote checkpoint recovery attempt for every caller. */
|
|
31
31
|
export declare function reconcileCheckpoint(box: SandboxInstanceLike, provider: string, request: Pick<WorkspaceCheckpointRequest, "idempotencyKey" | "requestDigest">, signal?: AbortSignal): Promise<CheckpointReconciliation>;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* One checkpoint id resolved against its source's inventory. `snapshotId` is
|
|
34
|
+
* the physical id Sandbox lists, which is the id a delete must name: a sealed
|
|
35
|
+
* checkpoint is listed under its physical id with the acknowledged id in its
|
|
36
|
+
* one `seal.<id>` tag. `unknown` names the step that could not decide.
|
|
37
|
+
*/
|
|
38
|
+
export type ManagedCheckpoint = {
|
|
39
|
+
state: "found";
|
|
40
|
+
snapshotId: string;
|
|
41
|
+
} | {
|
|
42
|
+
state: "absent";
|
|
43
|
+
} | {
|
|
44
|
+
state: "unknown";
|
|
45
|
+
reason: "inventory unavailable" | "ambiguous seal alias" | "invalid snapshot metadata" | "not marked by this source" | "operation not confirmed";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Confirm that one checkpoint id is a settled checkpoint this provider created.
|
|
34
49
|
*
|
|
35
|
-
* `expected`
|
|
36
|
-
*
|
|
37
|
-
*
|
|
50
|
+
* Without `expected` (cleanup), a match by id or by its one seal alias is
|
|
51
|
+
* accepted only when the snapshot carries this source's own marker and the
|
|
52
|
+
* marker's operation succeeded; a seal alias also needs that operation's
|
|
53
|
+
* result to name this id with the same marker. Anything less is unknown,
|
|
54
|
+
* never absent. `expected` binds the answer to a specific checkpoint
|
|
55
|
+
* reference (fork): a reference that does not match its marker is absent, not
|
|
56
|
+
* unknown, because the caller supplied a checkpoint this source never produced.
|
|
38
57
|
*/
|
|
39
|
-
export declare function findManagedCheckpoint(box: SandboxInstanceLike, provider: string, id: string, expected?: WorkspaceCheckpointRef, signal?: AbortSignal): Promise<
|
|
58
|
+
export declare function findManagedCheckpoint(box: SandboxInstanceLike, provider: string, id: string, expected?: WorkspaceCheckpointRef, signal?: AbortSignal): Promise<ManagedCheckpoint>;
|
|
40
59
|
export declare function findForkByKey(client: SandboxClientLike, box: SandboxInstanceLike, provider: string, key: string, signal?: AbortSignal): Promise<(RecoveredForkChild & {
|
|
41
60
|
marker: ForkMarker;
|
|
42
61
|
}) | null | undefined>;
|
|
@@ -242,50 +242,59 @@ function snapshotFromOperationResult(snapshot, lookup, marker) {
|
|
|
242
242
|
return { ...snapshot, snapshotId: lookup.result.snapshotId, createdAt: lookup.result.createdAt };
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
|
-
* Confirm that one
|
|
245
|
+
* Confirm that one checkpoint id is a settled checkpoint this provider created.
|
|
246
246
|
*
|
|
247
|
-
* `expected`
|
|
248
|
-
*
|
|
249
|
-
*
|
|
247
|
+
* Without `expected` (cleanup), a match by id or by its one seal alias is
|
|
248
|
+
* accepted only when the snapshot carries this source's own marker and the
|
|
249
|
+
* marker's operation succeeded; a seal alias also needs that operation's
|
|
250
|
+
* result to name this id with the same marker. Anything less is unknown,
|
|
251
|
+
* never absent. `expected` binds the answer to a specific checkpoint
|
|
252
|
+
* reference (fork): a reference that does not match its marker is absent, not
|
|
253
|
+
* unknown, because the caller supplied a checkpoint this source never produced.
|
|
250
254
|
*/
|
|
251
255
|
export async function findManagedCheckpoint(box, provider, id, expected, signal) {
|
|
256
|
+
const unknown = (reason) => ({ state: "unknown", reason });
|
|
257
|
+
const absent = { state: "absent" };
|
|
252
258
|
try {
|
|
253
259
|
const snapshots = await awaitWithSignal(box.listSnapshots?.(), signal);
|
|
254
260
|
if (!Array.isArray(snapshots) || snapshots.length > MAX_LIST_RESULTS) {
|
|
255
|
-
return
|
|
261
|
+
return unknown("inventory unavailable");
|
|
256
262
|
}
|
|
257
263
|
const candidates = snapshots.filter((candidate) => snapshotHasId(candidate, id) !== false);
|
|
258
264
|
if (candidates.length === 0)
|
|
259
|
-
return
|
|
260
|
-
if (candidates.length !== 1)
|
|
261
|
-
return
|
|
265
|
+
return absent;
|
|
266
|
+
if (candidates.length !== 1 || snapshotHasId(candidates[0], id) !== true)
|
|
267
|
+
return unknown("ambiguous seal alias");
|
|
262
268
|
const snapshot = candidates[0];
|
|
263
|
-
if (!validSnapshotInfo(snapshot, box.id)
|
|
264
|
-
return
|
|
265
|
-
// An expected reference can prove a fork source; an alias alone never authorizes cleanup.
|
|
266
|
-
if (snapshot.snapshotId !== id && expected === undefined)
|
|
267
|
-
return "unknown";
|
|
269
|
+
if (!validSnapshotInfo(snapshot, box.id))
|
|
270
|
+
return unknown("invalid snapshot metadata");
|
|
268
271
|
const marker = checkpointMarkerFromTags(snapshot.tags, expected?.idempotencyKey);
|
|
269
|
-
if (!marker)
|
|
270
|
-
return expected ?
|
|
271
|
-
if (marker.request.source.provider !== provider ||
|
|
272
|
-
marker.request.source.environmentId !== box.id) {
|
|
273
|
-
return expected ? false : "unknown";
|
|
272
|
+
if (!marker || !checkpointMarkerBelongsToSource(marker, provider, box.id)) {
|
|
273
|
+
return expected ? absent : unknown("not marked by this source");
|
|
274
274
|
}
|
|
275
275
|
if (expected &&
|
|
276
276
|
(marker.requestDigest !== expected.requestDigest ||
|
|
277
277
|
canonicalCandidateDigest(marker.request.source) !==
|
|
278
278
|
canonicalCandidateDigest(expected.source))) {
|
|
279
|
-
return
|
|
279
|
+
return absent;
|
|
280
|
+
}
|
|
281
|
+
let lookup;
|
|
282
|
+
try {
|
|
283
|
+
lookup = await checkpointOperationLookup(box, marker, signal);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
signal?.throwIfAborted();
|
|
287
|
+
return unknown("operation not confirmed");
|
|
280
288
|
}
|
|
281
|
-
const lookup = await checkpointOperationLookup(box, marker, signal);
|
|
282
289
|
if (lookup?.outcome !== "found" || lookup.kind !== "checkpoint" || lookup.state !== "succeeded")
|
|
283
|
-
return
|
|
284
|
-
return snapshot.snapshotId === id || snapshotFromOperationResult(snapshot, lookup, marker)?.snapshotId === id
|
|
290
|
+
return unknown("operation not confirmed");
|
|
291
|
+
return snapshot.snapshotId === id || snapshotFromOperationResult(snapshot, lookup, marker)?.snapshotId === id
|
|
292
|
+
? { state: "found", snapshotId: snapshot.snapshotId }
|
|
293
|
+
: unknown("operation not confirmed");
|
|
285
294
|
}
|
|
286
295
|
catch {
|
|
287
296
|
signal?.throwIfAborted();
|
|
288
|
-
return
|
|
297
|
+
return unknown("inventory unavailable");
|
|
289
298
|
}
|
|
290
299
|
}
|
|
291
300
|
export async function findForkByKey(client, box, provider, key, signal) {
|