# replica out of date: stale reads from a failing replica

> Sync from the primary is failing, so db.sync() throws the underlying error and reads keep returning the last frames the replica applied.

Source: https://sqlly.app/errors/libsql/replica-paused
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error: `replica out of date`
- Category: Replicas and consistency

Error message:

```text
replica out of date with the primary
```

## What it means

An embedded replica only advances when a sync succeeds. When `db.sync()` fails, the replica stops taking new frames and reads keep answering from the last state that was applied: stale reads that fail no check of their own. The failure itself surfaces through `sync()` as whatever the underlying client error is, for example a connection failure or `SERVER_ERROR` with an HTTP status when the token is rejected. Turso's docs describe the flow: reads run locally from the file, and writes are sent to the cloud primary and then reflected back to the replica, so a sync gap sits between your writes and what your reads return.

## Common causes

- The network path to the primary dropped, and every sync since has failed.
- The auth token used for sync expired or was invalidated, so the sync request answers 401.
- Syncs run rarely (no `syncInterval` and no manual calls), so reads lag behind the primary without any failure.

## How to fix it

1. Call sync() and read the error it throws; it names the real failure:

   ```sql
   await db.sync();  // throws the underlying connect, HTTP or auth error
   ```
2. For 401-shaped failures, mint a fresh token and update the client config:

   ```sql
   turso db tokens create mydb
   ```
3. When a decision needs current data, read that one query through the remote URL instead of the replica:

   ```sql
   const primary = createClient({ url: 'libsql://mydb-myorg.turso.io', authToken });
   const row = await primary.execute('SELECT ...');
   ```

## Reproduce it safely

```sql
Local and honest: run `turso dev --db-file scratch.db`, point an embedded replica at it (a `file:` URL with `syncUrl` set to the dev server), sync once, then kill the dev server and call `db.sync()` again; it fails with a connection error while reads keep working. Restart the dev server and sync again to watch the replica catch up.
```

## How SQLly helps

SQLly opens the replica file as a plain SQLite database, so it shows exactly what the last successful sync left behind: run the same SELECT in SQLly and in the app to confirm a stale-read suspicion.

## Questions

### What happens to reads when an embedded replica sync fails?

They keep working locally and answer from the last frames that were applied, so nothing throws on read. The staleness is only visible by comparison, which is why the failing sync() call is the signal to watch.

### Does @libsql/client sync automatically?

Yes when you configure `syncInterval`; otherwise the replica syncs when your code calls db.sync(). A long interval or a missing call means reads lag by design, and failures surface wherever sync runs.

## Related errors

- [`SQLITE_BUSY: database is locked`](https://sqlly.app/errors/libsql/embedded-replica-locked): embedded replica file locked
- [`connection reset / interrupted`](https://sqlly.app/errors/libsql/connection-interrupted): Connection reset or dropped
- [`401 Unauthorized`](https://sqlly.app/errors/libsql/unauthorized-401): 401 Unauthorized: bad or missing auth token

The code and message text are from the [libSQL / Turso documentation](https://docs.turso.tech/).
