@tangle-network/agent-provider-tangle 3.5.1 → 3.5.2

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.
@@ -299,22 +299,31 @@ export function createTangleProvider(options) {
299
299
  operation?.signal?.throwIfAborted();
300
300
  if (!box || boundedIdentifier(box.id, "Tangle environment id") !== id)
301
301
  return null;
302
- if (options.requireNativeSessionCapture)
302
+ if (options.requireNativeSessionCapture) {
303
303
  requireNativeCaptureProof(box);
304
+ // Native capture admits only the backend the live container reports, so a
305
+ // suspended sandbox must run again before anything can reconnect to it.
306
+ await resumeForReconnect(box, options.client, readyTimeoutMs, operation?.signal);
307
+ }
304
308
  let backendType;
309
+ let backendReadError;
305
310
  if (box.status === "running" && box.backend) {
306
311
  try {
307
312
  const status = await awaitWithSignal(box.backend.status(), operation?.signal);
308
313
  backendType = boundedIdentifier(status.type, "Tangle current backend");
309
314
  }
310
- catch {
315
+ catch (error) {
311
316
  operation?.signal?.throwIfAborted();
317
+ backendReadError = error;
312
318
  }
313
319
  }
314
320
  let captureCapabilities;
315
321
  if (options.requireNativeSessionCapture) {
316
- if (backendType === undefined)
317
- throw new Error("Tangle native capture requires the current selected backend before reconnect");
322
+ if (backendType === undefined) {
323
+ // The read's own failure (a 429 or 503 while the platform suspends the box)
324
+ // stays the cause, so a caller classifies it as the transport fault it is.
325
+ throw new Error("Tangle native capture requires the current selected backend before reconnect", backendReadError === undefined ? undefined : { cause: backendReadError });
326
+ }
318
327
  captureCapabilities = await awaitWithSignal(requireNativeCaptureCapability(box, backendType), operation?.signal);
319
328
  }
320
329
  const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
@@ -400,6 +409,38 @@ export function createTangleProvider(options) {
400
409
  : {}),
401
410
  };
402
411
  }
412
+ /**
413
+ * Bring a suspended sandbox back before a reconnect reads its container.
414
+ *
415
+ * The platform suspends a sandbox after its idle timeout (30 minutes by
416
+ * default) and nothing resumes it on access. A root turn stalled on an
417
+ * upstream 429 for that long comes back to a stopped box; without a resume,
418
+ * every later reconnect finds no live backend and refuses identically until
419
+ * the driver exhausts its attempts. After the resume the sidecar reports the
420
+ * interrupted execution as a terminal failure, so the caller settles that
421
+ * execution and replaces it once instead of dispatching beside it.
422
+ */
423
+ async function resumeForReconnect(box, client, timeoutMs, signal) {
424
+ if (box.status === "running")
425
+ return;
426
+ if (box.status === "stopped") {
427
+ if (!box.resume) {
428
+ throw new Error(`Tangle sandbox ${box.id} is stopped and the linked client cannot resume it`);
429
+ }
430
+ try {
431
+ await awaitWithSignal(box.resume({ timeoutMs, ...(signal ? { signal } : {}) }), signal);
432
+ }
433
+ catch (error) {
434
+ signal?.throwIfAborted();
435
+ // Another reconnect may have resumed the same box first; its state decides.
436
+ await box.refresh?.(signal).catch(() => undefined);
437
+ const after = statusFromUnknown(box.status);
438
+ if (after !== "running" && after !== "pending" && after !== "provisioning")
439
+ throw error;
440
+ }
441
+ }
442
+ await awaitSandboxRunning(box, client, { timeoutMs, ...(signal ? { signal } : {}) });
443
+ }
403
444
  async function resolveBackend(client, backendType) {
404
445
  if (backendType === undefined)
405
446
  return undefined;
@@ -537,6 +537,14 @@ export interface SandboxInstanceLike {
537
537
  signal?: AbortSignal;
538
538
  }): Promise<void>;
539
539
  refresh?(signal?: AbortSignal): Promise<void>;
540
+ /**
541
+ * Resume a stopped sandbox. An idle or lifetime suspend stops the container
542
+ * and preserves the workspace; nothing resumes it on access.
543
+ */
544
+ resume?(options?: {
545
+ timeoutMs?: number;
546
+ signal?: AbortSignal;
547
+ }): Promise<void>;
540
548
  delete?(options?: {
541
549
  signal?: AbortSignal;
542
550
  }): Promise<unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",