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

# Storage errors

> Look up the typed errors that Atomic's session storage, database handles, and atomic storage join raise, with each error's fields and what to do.

This reference is for developers who handle storage errors in code and for anyone fixing a store from an Atomic error message. It lists each typed error that storage operations raise, with its code, its fields, what it means, and what to do. For choosing and configuring a store, see [Storage](https://docs.bastani.ai/storage.md).

In code, inspect the error class, `code`, and structured fields rather than matching message text. Unless noted otherwise, classes are exported from `@bastani/atomic/storage` and re-exported from `@bastani/atomic`.

## Common errors

The following table lists the errors any store can raise:

| Error | What it means | What to do |
| - | - | - |
| `StorageConfigError` | Invalid storage setting, flag, or environment variable (`code: "invalid-config"`, `source`, `field`, `reason`, optional `hint`). | Fix the option named in `field`. Atomic never falls back to another store. |
| `StorageConfigError` (`libsql-removed`) | A setting, variable, or command references libSQL, Turso, or removed team-profile variables. | Follow [Move off libSQL](https://docs.bastani.ai/storage.md#moving-off-libsql). |
| `StorageAdapterLoadError` | Adapter module failed to load (`module`, `cause`). | Check that the adapter package is installed and has a default export. |
| `StorageUnavailableError` | Store could not be reached or opened (`adapter`, `location`, `cause`). | Restore connectivity or file access, then retry. |
| `StoragePrefixError` | Invalid `prefix` (`prefix`, `reason`: `pattern`, `reserved`, `too-long` with `maxLength`, `identifier-collision` with `identifier`, or `uppercase` on PostgreSQL). | Choose a valid prefix (at most 24 lowercase characters on PostgreSQL). |
| `StorageSchemaVersionError` | Store was upgraded by a newer Atomic release (`domain`: `sessions` \| `intercom`, `found`, `supported`). | Upgrade Atomic. See [Upgrade older stores](https://docs.bastani.ai/storage.md#upgrading-older-stores). |
| `StoragePayloadTooLargeError` | Value or response exceeded backend limits (`code: "payload-too-large"`, `kind`: `value` \| `response`, `limitBytes`, `actualBytes`, `adapter`, `location`, `retryable: false`, `hint`, `cause`). | Do not retry. Reduce value size or raise custom backend limits. See [Size limits](https://docs.bastani.ai/storage.md#size-limits). |
| `StorageTransientError` | Temporary network, lock, or server failure (`code`: `stream-expired`, `transaction-timeout`, `connection-refused`, `connection-lost`, `lock-conflict`, `read-only-server`; fields: `adapter`, `location`, `outcome`, `attempts`, `retryable: true`, `cause`, optional `hop` and `hopFailure`). It also covers a call that did not run because an earlier one stalled (`call-queue-stalled`, `attempts: 0`). Atomic can retry a call up to 5 total attempts if nothing was written. | Check server or proxy (`hop`) health and retry. If `outcome` is `"unknown"`, read state back before repeating a write. |
| `StorageOutcomeUnknownError` | Driver could not confirm whether a write committed (`domain`, `id`, `key`). | Read the record back before retrying. |
| `StorageTransferError` | Export or import failed before writing anything (`path`, optional `line`, `id`, `reason`, `cause`). Exported from `@bastani/atomic`. | Fix the reported file or line and re-run export/import. |
| `StorageImportIncompleteError` | Import failed after writing some sessions (`written`, `notWritten`, `cause`). Exported from `@bastani/atomic`. | Fix the underlying storage error and re-run `atomic storage import` to finish remaining sessions. |

## Session errors

The following table lists the errors a session store raises for tool output files and released session history:

| Error | Code | What it means | What to do |
| - | - | - | - |
| `SessionBlobError` | `blobs-unsupported` | Store cannot hold tool output files needed by import, fork, branch, or `tool-output://` reads (`sessionId`, `adapter`). | Use SQLite or PostgreSQL, or implement `putBlob`/`getBlob` in a custom store. |
| `SessionBlobError` | `blob-missing` | A `tool-output://<sha256>` file is missing. Copies, forks, and exports continue with a warning (`sessionId`, `hash`, optional `missing`). | Re-run the tool to regenerate output. |
| `SessionBlobError` | `blob-incomplete` | Part of a stored tool output file is missing (`sessionId`, `hash`, `bytes`). | Re-run the tool to regenerate output. |
| `SessionBlobError` | `blob-corrupt` | Imported tool output failed its SHA-256 check; nothing was written (`sessionId`, `hash`, `actualHash`). | Re-export the session from its source store. |
| `SessionSpillError` | `spill-read-failed` | An in-memory store failed to read released session history spilled under `<agentDir>/released-history` (`directory`, `sessionId`, `bytes`, `errno`, `cause`). Retryable for `EMFILE`, `ENFILE`, `EAGAIN`, `EBUSY`, `EINTR`. | Check permissions and open-file limits, then reopen the session. |
| `SessionSpillError` | `spill-missing`, `spill-corrupt` | Spilled history file is missing, truncated, or corrupt. That history is lost and the session is omitted from lists. | Leave `released-history` untouched while Atomic runs, or use a persistent store. |
| `SessionSpillError` | `spill-write-failed`, `spill-dir-refused`, `spill-cleanup-failed` | Spilling or cleanup failed; Atomic warns once and keeps history in memory. Never thrown. The warning names the filesystem error code after the path, such as `…/released-history/…: EACCES (spill-dir-refused)`. | Free disk space or make the agent directory writable. |

Other session errors: `SessionNotFoundError` (`sessionId`), `SessionExistsError` (`sessionId`), `SessionIdMismatchError` (`requested`, `found`), `SessionConflictError` (`sessionId`, `expectedSeq`, `actualSeq`), `SessionFormatVersionError` (`path`, `found`, `supported`), `SessionInvalidTextError` (`field`, `reason`), `SessionInvalidTimestampError` (`field`, `reason`, `value`), and `JsonlStoragePoisonedError` (`location`, `cause`, `rollbackCause`). After `SessionConflictError`, another process wrote first—reopen the session before writing again.

> [!NOTE]
>
> **When a live PostgreSQL session is waiting to save:** Leave it running if you see **Waiting for PostgreSQL to save this session**. Atomic keeps retrying pending saves in order, even in print and JSON modes. See [What to do while PostgreSQL is unavailable](https://docs.bastani.ai/storage/postgres.md#when-a-live-session-is-waiting-for-postgresql) for notices, wait settings, and a PgBouncer example.
>
> **When a save fails instead of waiting:** Atomic reports `could not persist the <role> message` along with the reason and stops the current run. Print and JSON modes exit `1`. Interactive mode stays open so you can fix the reported problem and try again.

## Database handle errors

Direct `SqliteDatabase` handles that SDK applications open raise these errors. The first four apply to local SQLite handles only (see [SDK and local SQLite API](https://docs.bastani.ai/storage/sqlite.md#sdk-and-local-sqlite-api)).

| Error | Code | What it means | What to do |
| - | - | - | - |
| `StorageWriteLockTimeoutError` | `write-lock-timeout` | A write waited `lockWaitMs` with no commit occurring; nothing ran (`adapter`, `location`, `timeoutMs`, `elapsedMs`, `phase`, `holderPid`, `holderHeldMs` or `holderCandidates`, `retryable: true`, `cause`). | Inspect the holding process or raise `lockWaitMs`, then retry. |
| `StorageWriterQueueUnusableError` | `writer-queue-unusable` | Cross-process queue directories next to the SQLite file (`<file>-writers`, `<file>-wakes`) were inaccessible; nothing ran (`adapter`, `location`, `errno`, `cause`). | Ensure the database directory and queue directories are readable and writable for every writer user. |
| `StorageWriterQueueDegradedError` | `writer-queue-degraded` | Writes continue, but queue coordination degraded (`watch-unavailable`, `wake-failed`, `stale-ticket-kept`, `holder-record-unavailable`). Logged once per reason; never thrown. | Raise the OS file-watch limit, fix queue permissions, or clean abandoned queue entries. |
| `StorageUnsupportedOperationError` | `unsupported-operation` | `getWriterQueueStats` or `getWriterQueueDegradation` was called on a non-local-SQLite handle (`operation`, `adapter`, `location`). | Pass a handle from `openNodeSqliteDatabase` or `wrapNodeSqliteDatabase`. |
| `StorageInvalidTextError` | — | A text binding contains U+0000 (`parameterIndex`, `reason`). | Strip U+0000, or store the value as JSON or binary (`Uint8Array`). |
| `StoreClosedError`, `StorageTransactionClosedError` | — | Store is closed, or a transaction handle was used after its callback settled. | Open a new store, or use only the active callback's transaction handle. |
| `StorageRollbackError` | — | Rollback failed after a transaction error (`cause`, `rollbackCause`). | Do not assume the transaction rolled back cleanly. |

## Handle storage errors in code

The storage modules export these helpers for checking and passing errors:

* **Cross-process type guards:** `isStorageConfigError`, `isStorageWriteLockTimeoutError`, `isStorageUnsupportedOperationError`, `isStorageWriterQueueDegradedError`, `isStorageWriterQueueUnusableError`, `isStorageTransientError`, `isSessionBlobError`, `isSessionSpillError`, and `isStorageError`. Code lists: `STORAGE_TRANSIENT_ERROR_CODES`, `SESSION_BLOB_ERROR_CODES`, and `SESSION_SPILL_ERROR_CODES`.
* **Cause-chain inspection:** `findStorageWriteLockTimeoutError(error)` and `isRetryableStorageError(error)` inspect up to 8 levels of `cause`.
* **Cross-process serialization:** `serializeStorageError(error)` and `rehydrateStorageError(json)` preserve class, fields, `cause`, `rollbackCause`, and `cleanupCause`. Unknown subclasses rehydrate as `StorageError` retaining `name`, `code`, and fields.
* **Cancellation:** Session listings accept an `AbortSignal` and reject with the signal's `reason` (such as `AbortError`).

## Errors from `atomic storage join`

`atomic storage join`, `atomic storage migrate --db`, [`atomic team status`](https://docs.bastani.ai/guides/team-setup), and the SDK's `getTeamProfile()` raise `TeamProfileConfigError` (invalid inputs; nothing changed) or `TeamProfileError` (runtime failure after inputs validated). Error messages name variables, flags, and file paths, never credentials.

The following table lists the codes of `TeamProfileConfigError`:

| `TeamProfileConfigError` code | When |
| - | - |
| `libsql-removed` | A libSQL URL is passed, `atomic team join`/`leave` is invoked, or legacy team variables (`ATOMIC_PROFILE`, `ATOMIC_TEAM_URL`, `ATOMIC_TEAM_TOKEN`, `ATOMIC_TEAM_TOKEN_FILE`, `ATOMIC_TEAM_PREFIX`) are set. See [Move off libSQL](https://docs.bastani.ai/storage.md#moving-off-libsql). |
| `unsupported-url` | URL does not start with `postgres://` or `postgresql://`. |
| `credential-in-url` | URL embeds a password. |
| `missing-token` | None of `--password-file`, `--token-file`, or `--auth` was provided. |
| `conflicting-token` | More than one of `--password-file`, `--token-file`, and `--auth` was provided. |
| `unsupported-auth` | `--auth` is not `azure`, `aws`, or `gcp` (or their long forms). |
| `unreadable-token-file` | Password or token file cannot be read (`path` names it). |
| `empty-token` | Password or token file is empty. |
| `invalid-prefix` | Prefix breaks PostgreSQL [prefix rules](https://docs.bastani.ai/storage/postgres.md#share-one-database-between-teams). |
| `unknown-command`, `unknown-option`, `unexpected-argument` | Invalid `atomic team` CLI arguments. |

`TeamProfileError` carries `code`, `subject`, `hint`, `retryable`, and optional `detail` and `cause`. The following table lists its codes:

| `TeamProfileError` code | When | What to do |
| - | - | - |
| `settings-unreadable` | Settings file (`subject`) cannot be read or parsed. Nothing changed. | Fix the settings file and retry. |
| `adapter-not-installed` | `@bastani/atomic-storage-postgres` cannot be loaded. Nothing changed. | Run `atomic install npm:@bastani/atomic-storage-postgres`. |
| `auth-unavailable` | Cloud IAM sign-in failed during `--auth` (missing cloud SDK library or unavailable identity). Nothing changed. Not retryable. | Install the cloud library named in the error and check the machine's cloud identity. |
| `connection-failed` | Server refused the connection or `SELECT 1` failed. Nothing changed. Retryable. | Check the URL, credentials, and network, then retry. |
| `connection-timeout` | Server did not answer within 15 seconds (thrown as `TeamProfileTimeoutError`). Nothing changed. Retryable. | Verify database reachability, then retry. |
| `token-write-failed` | Private password file could not be written in the agent directory. Nothing changed. | Make the agent directory writable. |
| `settings-write-failed` | Settings could not be saved; previous setting and password file stay intact. | Make the settings file writable or free disk space. |
| `settings-locked` | Another process held the settings lock. Nothing changed. Retryable. | Retry after a few seconds (stale locks expire after 10 seconds). |

In code, check these across processes with `isTeamProfileError()`, `isTeamProfileTimeoutError()`, `isTeamProfileConfigError()`, and `isRetryableTeamProfileError()` (walks up to 8 levels of `cause`). Use `serializeTeamError(error)` and `rehydrateTeamError(json)` to pass them across processes without credentials. `POSTGRES_STORAGE_JOIN_HINT` holds `atomic storage join <postgres-url> --password-file <path>`.


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