@tangle-network/agent-provider-tangle 4.4.5 → 4.4.7

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.
package/README.md CHANGED
@@ -653,6 +653,12 @@ const environment = await provider.exactProcess!.create({
653
653
 
654
654
  The adapter rejects ordinary sandboxes during create, recovery, and list operations.
655
655
 
656
+ ## Disposable workspaces
657
+
658
+ Set `ephemeral: true` in `createTangleProvider` for work whose sandbox state should be discarded after execution. The provider sends the existing Sandbox `ephemeral` create option for every managed-agent environment it creates. Omission preserves the existing storage behavior.
659
+
660
+ An ephemeral provider refuses `requireNativeSessionCapture: true` and workspace checkpoint restoration before provisioning, and offers no snapshot branching capability. Keep the deciding result outside the disposable workspace, then destroy the environment through the provider. Destruction requests `until: "removed"` and refuses an unknown or pending removal acknowledgement. This option does not delete a previously retained sandbox or its snapshots, and the caller still owns snapshot absence verification.
661
+
656
662
  ## Private session evidence
657
663
 
658
664
  Set `requireNativeSessionCapture: true` when the provider must retain complete native evidence.
@@ -1,5 +1,9 @@
1
1
  import type { AgentSessionRef, AgentTurnInput } from "@tangle-network/agent-interface/environment-provider";
2
2
  import type { SandboxInstanceLike, SandboxSessionLike } from "./tangle-types.js";
3
+ /** Concurrent owners join one successful destroy; a failed request remains retryable. */
4
+ export declare function environmentDestruction(box: SandboxInstanceLike, ephemeral?: boolean): (options?: {
5
+ signal?: AbortSignal;
6
+ }) => Promise<void>;
3
7
  export declare function sessionPromptRequestDigest(input: AgentTurnInput, provider: string, environmentId: string, sessionId: string, options?: {
4
8
  executionId?: string;
5
9
  nonce?: string;
@@ -1,5 +1,29 @@
1
1
  import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
2
2
  import { backendFromTurnInput, backendRequestIdentity, } from "./tangle-prompt.js";
3
+ import { awaitWithSignal } from "./tangle-contract-safety.js";
4
+ import { assertOptionKeys } from "./tangle-environment-validation.js";
5
+ /** Concurrent owners join one successful destroy; a failed request remains retryable. */
6
+ export function environmentDestruction(box, ephemeral = false) {
7
+ let destruction;
8
+ return async (options) => {
9
+ if (!box.delete)
10
+ throw new Error("Tangle sandbox client cannot delete this environment");
11
+ assertOptionKeys(options, ["signal"], "Tangle destroy");
12
+ options?.signal?.throwIfAborted();
13
+ destruction ??= awaitWithSignal(box.delete(ephemeral ? { ...options, until: "removed" } : options), options?.signal)
14
+ .then((receipt) => {
15
+ if (!ephemeral)
16
+ return;
17
+ const proof = receipt;
18
+ if (!proof || !["destroyed", "already_absent"].includes(String(proof.outcome)) || (proof.removal !== undefined && proof.removal !== "complete")) {
19
+ throw new Error("Tangle ephemeral sandbox removal was not confirmed");
20
+ }
21
+ })
22
+ .catch((error) => { destruction = undefined; throw error; });
23
+ await awaitWithSignal(destruction, options?.signal);
24
+ options?.signal?.throwIfAborted();
25
+ };
26
+ }
3
27
  export function sessionPromptRequestDigest(input, provider, environmentId, sessionId, options = {}) {
4
28
  const backend = backendRequestIdentity(backendFromTurnInput(input));
5
29
  return canonicalCandidateDigest({
@@ -34,6 +34,7 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
34
34
  rebindProxySecrets?: boolean;
35
35
  confidentialAttestationVerifier?: TangleConfidentialAttestationVerifier;
36
36
  requireNativeSessionCapture?: boolean;
37
+ ephemeral?: boolean;
37
38
  requireCliAuthReferences?: boolean;
38
39
  credentialSource?: ProfileCredentialSource;
39
40
  credentialHarness?: string;
@@ -13,7 +13,7 @@ import { profileCredentialSource } from "./model-credential-source.js";
13
13
  import { deploymentCapabilitySupport, readDeploymentCapabilitySupport } from "./tangle-deployment-capabilities.js";
14
14
  import { awaitWithSignal, assertBoundedJson, boundedIdentifier, boundedString, MAX_PAYLOAD_STRING_BYTES, } from "./tangle-contract-safety.js";
15
15
  import { assertExecOptions, assertOptionKeys, } from "./tangle-environment-validation.js";
16
- import { interruptExecutionAfterAbort, } from "./tangle-environment-control.js";
16
+ import { environmentDestruction, interruptExecutionAfterAbort, } from "./tangle-environment-control.js";
17
17
  import { dispatchEnvironmentRun } from "./tangle-environment-dispatch.js";
18
18
  import { sandboxSessionAsAgentSession } from "./tangle-environment-session.js";
19
19
  import { tangleInteractionResponder } from "./tangle-interaction-response.js";
@@ -266,7 +266,6 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
266
266
  };
267
267
  };
268
268
  // The single destroy this handle performs, once it has been asked for.
269
- let destruction;
270
269
  const terminals = capabilities.interactiveTerminal?.attach === true
271
270
  ? createTangleTerminalRegistry(box)
272
271
  : undefined;
@@ -520,42 +519,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
520
519
  await awaitWithSignal(box.refresh?.(options?.signal), options?.signal);
521
520
  options?.signal?.throwIfAborted();
522
521
  },
523
- ...(support.destroy
524
- ? {
525
- async destroy(options) {
526
- if (!box.delete)
527
- throw new Error("Tangle sandbox client cannot delete this environment");
528
- assertOptionKeys(options, ["signal"], "Tangle destroy");
529
- options?.signal?.throwIfAborted();
530
- // One environment has more than one owner of its end. A runtime
531
- // that destroys on settle AND tears the executor down calls this
532
- // twice for the same box, and the platform refuses the second
533
- // DELETE with "A sandbox lifecycle operation is already in
534
- // progress" while the first one's cleanup still holds the
535
- // sandbox's lifecycle lease. Measured 2026-09-01 on
536
- // `sandbox-b525e04a551b`: of two concurrent deletes one answered
537
- // 200 `destroyed` and the other 409, and a third delete 0.4 s
538
- // after the 200 was still refused. That refusal cost two
539
- // completed agent turns their result
540
- // (tangle-network/agent-sdk#280), because the second destroy ran
541
- // in a caller's `finally` and its throw replaced the run's own
542
- // outcome.
543
- //
544
- // So destroy is answered once per environment and every later
545
- // caller joins that answer. This is not a retry and hides no
546
- // platform error: a delete that fails is not remembered, and the
547
- // next caller issues a real one.
548
- destruction ??= awaitWithSignal(box.delete(options), options?.signal)
549
- .then(() => undefined)
550
- .catch((error) => {
551
- destruction = undefined;
552
- throw error;
553
- });
554
- await awaitWithSignal(destruction, options?.signal);
555
- options?.signal?.throwIfAborted();
556
- },
557
- }
558
- : {}),
522
+ ...(support.destroy ? { destroy: environmentDestruction(box, request?.ephemeral === true) } : {}),
559
523
  };
560
524
  if (proxySecretReceipt !== undefined) {
561
525
  Object.defineProperty(environment, "proxySecretReceipt", {
@@ -18,6 +18,8 @@ export interface PreparedNativeEvidence {
18
18
  native: RetainedNativeEvidence | undefined;
19
19
  payloads: WeakMap<object, NativePayloadFile>;
20
20
  directory?: string;
21
+ /** Wall time of the bounded export that copied the session's native store out of the sandbox. */
22
+ copyMs?: number;
21
23
  remove(): Promise<void>;
22
24
  }
23
25
  export declare const MAX_METADATA_BYTES: number;
@@ -102,9 +102,11 @@ export async function prepareNativeDirectoryEvidence(session, maxBytes, signal)
102
102
  const destination = join(temporary, "export");
103
103
  const remove = () => rm(temporary, { recursive: true, force: true });
104
104
  try {
105
+ const copyStarted = performance.now();
105
106
  const response = record(await session.exportRawEvidence(destination, { maxBytes, maxFiles: MAX_ENTRIES, omitContent: NATIVE_OMIT_CONTENT_DIRECTORIES, signal }));
107
+ const copyMs = Math.round(performance.now() - copyStarted);
106
108
  if (response.status === "unavailable") {
107
- return { native: response, payloads: new WeakMap(), remove };
109
+ return { native: response, payloads: new WeakMap(), copyMs, remove };
108
110
  }
109
111
  if ((response.status !== "captured" && response.status !== "partial") || response.directory !== destination ||
110
112
  typeof response.manifestPath !== "string" || !response.manifestPath.startsWith(destination + "/") ||
@@ -171,7 +173,7 @@ export async function prepareNativeDirectoryEvidence(session, maxBytes, signal)
171
173
  const { schema: _schema, ...legacyMetadata } = manifest;
172
174
  // The existing evidence validator checks all identity, attribution and completeness fields.
173
175
  const native = { ...legacyMetadata, files, processIo, processTerminals, processSources, events };
174
- return { native, payloads, directory: destination, remove };
176
+ return { native, payloads, directory: destination, copyMs, remove };
175
177
  }
176
178
  catch (error) {
177
179
  await remove();
@@ -121,6 +121,11 @@ export interface TangleEnvironmentEvidence {
121
121
  skippedEntries: number;
122
122
  } | null;
123
123
  complete: boolean;
124
+ /**
125
+ * Wall time, in ms, of the bounded export that copied this session's
126
+ * native store out of the sandbox. Directory capture only.
127
+ */
128
+ copyMs?: number;
124
129
  entries: Array<{
125
130
  sourceId?: string;
126
131
  rootScope: "session-home" | "workspace-session";
@@ -502,6 +502,7 @@ async function captureSandboxEvidence(box, options, writer) {
502
502
  };
503
503
  const nativeStore = {
504
504
  scope: "session", roots: [], inventory: null, complete: false, entries: [], excludedPaths: [],
505
+ ...(prepared?.copyMs === undefined ? {} : { copyMs: prepared.copyMs }),
505
506
  };
506
507
  const processStreams = {
507
508
  complete: false, streamCount: 0, processCount: 0, terminalCount: 0,
@@ -13,25 +13,44 @@ import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-
13
13
  import { profileCredentialSource } from "./model-credential-source.js";
14
14
  import { requestedResourceProfile } from "./tangle-resources.js";
15
15
  import { assertBoundedJson, attachCleanupHandle, awaitWithSignal, boundedIdentifier, boundedString, MAX_LIST_RESULTS, PROFILE_AT_ROOT, SANDBOX_LIST_PAGE_SIZE, } from "./tangle-contract-safety.js";
16
+ function providerReadyTimeout(options) {
17
+ boundedIdentifier(options.name ?? "tangle-sandbox", "Tangle provider name");
18
+ if (options.requireNativeSessionCapture !== undefined && typeof options.requireNativeSessionCapture !== "boolean") {
19
+ throw new Error("Tangle requireNativeSessionCapture must be a boolean");
20
+ }
21
+ if (options.ephemeral !== undefined && typeof options.ephemeral !== "boolean") {
22
+ throw new Error("Tangle ephemeral must be a boolean");
23
+ }
24
+ if (options.ephemeral && options.requireNativeSessionCapture) {
25
+ throw new Error("Tangle ephemeral workspaces cannot require retained native-session capture");
26
+ }
27
+ const timeout = options.readyTimeoutMs ?? DEFAULT_TANGLE_READY_TIMEOUT_MS;
28
+ if (!Number.isFinite(timeout) || timeout <= 0) {
29
+ throw new Error("Tangle readyTimeoutMs must be a positive number of milliseconds");
30
+ }
31
+ return timeout;
32
+ }
33
+ function ephemeralCapabilityCeiling(capabilities, ephemeral) {
34
+ if (!ephemeral)
35
+ return capabilities;
36
+ return {
37
+ ...capabilities,
38
+ branching: { checkpoint: false, fork: false, confidential: false },
39
+ create: { ...capabilities.create, workspaceCheckpoint: false },
40
+ };
41
+ }
16
42
  export function createTangleProvider(options) {
43
+ const readyTimeoutMs = providerReadyTimeout(options);
17
44
  const resolveModelCredentials = typeof options.modelCredentials === "function"
18
45
  ? options.modelCredentials : undefined;
19
46
  const modelCredentials = resolveModelCredentials === undefined
20
47
  ? captureModelCredentials(options.modelCredentials)
21
48
  : undefined;
22
- if (options.requireNativeSessionCapture !== undefined && typeof options.requireNativeSessionCapture !== "boolean") {
23
- throw new Error("Tangle requireNativeSessionCapture must be a boolean");
24
- }
25
49
  const mapCreateInput = options.mapCreateInput;
26
50
  if ((modelCredentials !== undefined || resolveModelCredentials !== undefined) && mapCreateInput !== undefined) {
27
51
  throw new Error("Tangle modelCredentials cannot be combined with mapCreateInput");
28
52
  }
29
53
  const providerName = options.name ?? "tangle-sandbox";
30
- boundedIdentifier(providerName, "Tangle provider name");
31
- const readyTimeoutMs = options.readyTimeoutMs ?? DEFAULT_TANGLE_READY_TIMEOUT_MS;
32
- if (!Number.isFinite(readyTimeoutMs) || readyTimeoutMs <= 0) {
33
- throw new Error("Tangle readyTimeoutMs must be a positive number of milliseconds");
34
- }
35
54
  const exactProcess = options.exactProcess
36
55
  ? createTangleExactProcessProvider({
37
56
  client: options.client,
@@ -48,6 +67,7 @@ export function createTangleProvider(options) {
48
67
  ? await options.capabilities()
49
68
  : options.capabilities
50
69
  : defaultTangleSandboxCapabilities(harness.success ? harness.data : undefined);
70
+ configured = ephemeralCapabilityCeiling(configured, options.ephemeral === true);
51
71
  const proxyCapability = proxySecretCapabilityFromDocument(await options.client.capabilities?.());
52
72
  // Configured adapter ceilings never confer authority that the connected API did not prove.
53
73
  configured = { ...configured, profile: { ...configured.profile },
@@ -156,6 +176,7 @@ export function createTangleProvider(options) {
156
176
  }
157
177
  const createOptions = deepFreeze(structuredClone({
158
178
  ...mappedOptions,
179
+ ...(options.ephemeral === undefined ? {} : { ephemeral: options.ephemeral }),
159
180
  ...(selectedProxySecrets === undefined ? {} : {
160
181
  metadata: { ...mappedOptions.metadata, [PROXY_SECRETS_METADATA_KEY]: selectedProxySecrets },
161
182
  }),
@@ -167,6 +188,9 @@ export function createTangleProvider(options) {
167
188
  }
168
189
  assertMappedSecretNames(createOptions);
169
190
  const checkpoint = parsedWorkspace?.checkpoint;
191
+ if (options.ephemeral && checkpoint !== undefined) {
192
+ throw new Error("Tangle ephemeral workspaces cannot restore a retained checkpoint");
193
+ }
170
194
  if (checkpoint !== undefined) {
171
195
  // A checkpoint names a snapshot this provider took. Another provider's id means nothing to
172
196
  // Sandbox, and a mapper that drops the restore would return an empty workspace as if full.
@@ -261,6 +285,7 @@ export function createTangleProvider(options) {
261
285
  ? {}
262
286
  : { resources: requestedResources }),
263
287
  credentialSource,
288
+ ...(options.ephemeral ? { ephemeral: true } : {}),
264
289
  ...(selectedProxySecrets === undefined ? {} : { proxySecrets: selectedProxySecrets }),
265
290
  ...(resolveModelCredentials === undefined ? {} : { resolveModelCredentials }),
266
291
  ...(createOptions.backend?.model?.cliAuth === undefined ? {} : {
@@ -295,7 +320,7 @@ export function createTangleProvider(options) {
295
320
  throw error;
296
321
  }
297
322
  };
298
- const workspaceBranching = options.client.get
323
+ const workspaceBranching = !options.ephemeral && options.client.get
299
324
  ? {
300
325
  async forEnvironment(sourceEnvironmentId, operation) {
301
326
  assertProviderOperationOptions(operation, "Tangle workspaceBranching.forEnvironment");
@@ -400,6 +425,7 @@ export function createTangleProvider(options) {
400
425
  const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
401
426
  return await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, operation?.signal ? { signal: operation.signal } : undefined, {
402
427
  ...confidentialVerifierOption(options.confidentialAttestationVerifier),
428
+ ...(options.ephemeral ? { ephemeral: true } : {}),
403
429
  ...(reconnectBindings === undefined ? {} : { proxySecrets: reconnectBindings, rebindProxySecrets: true }),
404
430
  ...(resolveModelCredentials === undefined ? {} : { resolveModelCredentials }),
405
431
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
@@ -576,6 +576,7 @@ export interface SandboxInstanceLike {
576
576
  }): Promise<void>;
577
577
  delete?(options?: {
578
578
  signal?: AbortSignal;
579
+ until?: "removed";
579
580
  }): Promise<unknown>;
580
581
  /** Managed whole-workspace checkpoint operation. */
581
582
  snapshot?(options?: {
@@ -829,6 +830,8 @@ export interface TangleProviderOptions {
829
830
  defaultBackend?: BackendType;
830
831
  /** Require the selected Sandbox host to prove native session capture for every create. */
831
832
  requireNativeSessionCapture?: boolean;
833
+ /** Disposable managed-agent workspaces use Sandbox scratch storage and never restore a checkpoint. */
834
+ ephemeral?: boolean;
832
835
  /**
833
836
  * Available stored credentials selected through exact profile credential intent.
834
837
  * Managed profiles skip selectors and native references; explicit managed intent skips all references.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "4.4.5",
3
+ "version": "4.4.7",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",