> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deepest.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Retries, idempotency, and uncertain results

> Recover the original operation after a lost response without creating duplicate Machines, replaying commands, or rolling back new data.

A request can reach the service and perform its effect even if the caller never receives the reply. Preserve the original target and intent, then recover from observed facts. The SDK does not automatically retry or create a replacement.

Use this guide with the [error vocabulary](https://docs.deepest.dev/api-and-sdk/errors.md) and the specific capability's lifecycle.

## Before an operation

For Create Computer, Create Sandbox, Clone and Snapshot Create, save one unique `idempotency_key` with the exact request and source identity before sending it. A retry of the same intent must use the same key, Memory and source where applicable.

Do not generate the key inside a general retry callback. Do not change the requested Memory while retaining a key for an uncertain Create. Do not reuse a key for unrelated tasks.

An idempotency key identifies that supported creation intent; it is not a universal header or cancellation token. Other methods do not gain idempotency by adding an undocumented field.

## Classify the result

1. A valid success lets you continue from its result. If it is marked `no-retry`, do not replay the completed effect.
2. A known refusal tells you which prerequisite to correct. A `safe` refusal may be retried explicitly after the condition clears and any stated delay.
3. A `query-first` result or lost mutation reply requires observation. Keep the original object and input even when the first read is inconclusive.

Never use “the request timed out” as evidence that the original Computer is gone, a Secret change failed, or a command did not run.

## Retry a refused action (`EXEC_BUSY`, `LIFECYCLE_BUSY`, `RATE_LIMITED`)

`LIFECYCLE_BUSY`, `EXEC_BUSY`, and `RATE_LIMITED` all return HTTP `429` with `retry: "safe"`. The action was rejected **before dispatch**, and HTTP `Retry-After` equals `error.retry_after_seconds`. Wait at least that returned interval, then explicitly retry only the rejected step if the original intent remains needed.

* **`LIFECYCLE_BUSY`:** Applies to Computer Create/Delete/Start/Stop/Resize/Clone, Snapshot Create/Delete/Restore, Storage Reclaim, and Sandbox Create/Delete/Start/Stop. Keep the exact original target and request. Where the operation supports an idempotency key—Computer or Sandbox Create, Clone, or Snapshot Create—reuse the original saved key; do not allocate a new intent.
* **`EXEC_BUSY`:** Applies to shared Account command capacity (Exec, Tools, Desktop setup).
* **`RATE_LIMITED`:** Applies to bounded human/public actions such as `invites.redeem`.

For a Stop→Resize→Start sequence, retry only the refused step. Do not repeat a completed Restore, delete data again, or restart the whole workflow. A lost response or `UNKNOWN / query-first` still requires observation; it does not become a known pre-dispatch refusal. If Create or Clone fails with `LIMIT_EXCEEDED` (`memory` or `persistent_computers`), do not loop retries—free capacity or delete unneeded Computers first.

## Recover a creation intent

The preferred first read is the original object's Get when a real ID is known. Otherwise list the owned objects and inspect likely results. A display name or a list entry alone may not conclusively identify a creation intent.

If observation remains insufficient, recover using the **identical saved request** for the same creation key. This is continuation of one intent, not authorization for a new one. An uncertain source/source-ID must not be replaced.

For example, after the caller has observed current resources and retained the original input:

```js theme={null}
import { Deepest } from "@deepest/sdk";

const {
  DEEPEST_API_URL, DEEPEST_API_KEY, DEEPEST_CREATE_KEY, DEEPEST_ORIGINAL_RAM_MIB,
} = process.env;
if (!DEEPEST_API_URL || !DEEPEST_API_KEY ||
    !DEEPEST_CREATE_KEY || !DEEPEST_ORIGINAL_RAM_MIB) {
  throw new Error("Load the saved original intent and secure caller configuration.");
}
const ram_mib = Number(DEEPEST_ORIGINAL_RAM_MIB);
if (!Number.isInteger(ram_mib) || ram_mib < 256 || ram_mib % 256 !== 0) {
  throw new Error("The saved Memory request is invalid; do not replace the intent.");
}
const deepest = new Deepest({
  baseUrl: DEEPEST_API_URL,
  apiKey: DEEPEST_API_KEY,
});
const observed = await deepest.computers.list();
if (!observed.ok) {
  throw new Error("Observation failed. Preserve the intent and inspect the failure.");
}
console.log(observed.result.map(c => ({ id: c.id, state: c.state })));

// Run this recovery step only for the already-authorized, still-needed intent.
// ram_mib and the key MUST match the original request exactly.
const recovered = await deepest.computers.create({
  idempotency_key: DEEPEST_CREATE_KEY,
  ram_mib,
});
if (!recovered.ok) {
  console.error({
    code: recovered.error.code, retry: recovered.retry,
    resource_id: recovered.resource_id,
  });
} else {
  console.log("Original intent result:", recovered.result.id, recovered.result.state);
}
```

The program is an explicit recovery tool, not an automatic polling loop. If the intent has become unwanted or its identity is ambiguous, do not run the write step. Resolve the original result first, then handle that exact asset.

For a Sandbox, repeating the original creation key does not renew its `expires_at`. After its lifetime, do not treat replay as a renewal API.

## Recovery by operation

| Uncertain operation | Read next | Avoid |
| - | - | - |
| Computer/Sandbox Create | Original ID if known, collection list, then same saved intent if needed | A new key, guessed replacement, changed Memory |
| Clone | Original source and known child; same source/key intent | Cloning a different source to “retry” |
| Snapshot Create | The source's snapshot list/get; same saved key | A second snapshot intent before resolving the first |
| Start / Stop | Original Machine Get, current Resources | Treating unknown as stopped or released Memory |
| Resize | Original Computer and Resources; inspect configured Memory | Assuming requested size applied or restarting automatically |
| Exec | Original Machine plus task-specific read-only effect checks | Using running state as proof that the command did not execute |
| Snapshot Restore | Original Computer and actual restored disk/application state | Repeating Restore, which can discard subsequent writes |
| Delete | Get the exact original asset; account usage when relevant | Deleting another ID or creating an empty replacement |
| Storage Reclaim | Original Computer and Resources | Assuming file deletion or a timeout proves quota was returned |
| Tools install | Tools inspect on the same Computer/tool | Re-running an installer without checking its existing files |
| Agent Key Create | Human key metadata list, identify and revoke lost-value key | Blindly creating a new key; plaintext cannot be read back |
| Invitation redeem | Current Resources and entitlement | Re-entering a code after activation already succeeded |
| Share Create | Share metadata list, exact target/port and creation context | Expecting the URL to be recoverable from list or blindly duplicating shares |
| Share revoke / Preview close | Current metadata or new request to the exact old entry | Assuming old downloaded data or all sockets are erased |
| Vault create/rotate/delete/grant/revoke | Original Secret metadata and affected Machine grants/dispositions | Re-sending a Secret mutation based only on a local timeout |
| Assistance change | Current assistance state and actual browser page | Assuming return to Agent means human login succeeded |

A read can itself be unknown. Stop adding mutations while the original effect remains unresolved. Keep evidence and use the support path with non-secret identifiers.

## One-time values need a different recovery

Agent Key and Share creation return a raw secret/link only once. A metadata list proves records, not the lost secret value.

For a lost Agent Key, identify and revoke the affected key before creating a replacement. For an uncertain Share, inspect metadata and decide which exact record should be revoked before intentionally making another link. Do not assume the first request failed merely because its URL was lost.

Vault metadata never reveals an existing raw value. A read-back of metadata is not a method for extracting the Secret.

## Avoid automatic cascades

Do not make `UNKNOWN` trigger create → stop → delete → recreate. This can produce duplicate effects, lose the original disk or stop unrelated work.

Do not make a resource refusal trigger automatic shrinking of another Computer. A running shrink requires an explicit interruption decision and the stated Stop→Resize→Start path.

Do not make a Viewer failure restart the entire Computer. Access sessions, app readiness and Machine lifecycle are different facts.

## Retry only the smallest known step

If a command was refused with `EXEC_BUSY`, wait the indicated interval and retry that command. If a tool download failed, inspect that tool and connectivity. If a stopped service makes Share return 503, restore the intended service on the original Computer.

After recovery, verify the user's actual result, then clean up only the explicitly selected temporary work. The goal is a known outcome on the original assets, not a green response achieved by starting over.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.