Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

14.2 KB
Raw Blame

Password-change (rekey) recovery

A password change re-encrypts the user's SQLCipher database under the new password (PRAGMA rekey). Local Deep Research stores no password hash: a login works only if the password decrypts the user's database. To make the change safe across crashes and across several server processes, the rekey is fenced by a few small files kept next to each user database. This page explains those files, the "pending maintenance" message, and how to recover by hand when the automatic recovery cannot finish.

The files

User databases live in {data_directory}/encrypted_databases/. For a user whose username hashes to {user_hash} (the first 16 hex characters of the SHA-256 of the username), the files are:

File What it is Safe to delete with the server stopped?
ldr_user_{user_hash}.db The encrypted database Never
ldr_user_{user_hash}.db-wal SQLite write-ahead log; can hold committed pages, including the re-encrypted pages of a recent rekey Never
ldr_user_{user_hash}.db-shm SQLite shared-memory index for the WAL Leave it; SQLite rebuilds it
ldr_user_{user_hash}.db.salt Per-database key-derivation salt Never: without it no password opens the database
ldr_user_{user_hash}.db.rekey.lock Lock file that serializes password changes, logins and cache checks across processes Not needed. Remove it only if it is not a regular file (a symlink, FIFO or directory); it is recreated
ldr_user_{user_hash}.db.rekey.epoch The committed epoch: a random UUID that changes on every password change and lets every process reject a connection it cached under an earlier password Yes
ldr_user_{user_hash}.db.rekey.pending Present only while a password change is in progress or its outcome has not been resolved yet Yes

The epoch files hold only a UUID: no key material and no user data. The epoch is a cache token, not a credential. SQLCipher still verifies the key on every open, so deleting the epoch files cannot let a wrong password in and cannot change which password opens the database. When .rekey.epoch is missing, the next login creates a new one. With the server running, though, .rekey.pending is what keeps every process from trusting a connection it cached under the old password: deleting it then can let such a connection be used again, which is why the steps below stop the server first.

See the warning under Manual recovery for the risks of deleting only one rekey file.

A hard-linked .rekey.lock (for example from a backup or snapshot tool that hard-links the data directory) is used as is; its permissions are not changed. While another directory entry still names the same inode, a .rekey.lock that is a hard link to another file in the same directory (the user's own or another user's .db, -wal or -shm file, or anything else there) is refused without being opened (EMLINK): closing a descriptor to a database would drop SQLite's locks on it. Links whose other names are outside the directory are accepted. These checks inspect current names, not the inode's history: removing the other name before the check leaves one link and defeats this detection. The data directory must remain trusted; its writers can already replace or remove database files.

How a password change resolves itself

  1. A new .rekey.pending UUID is written. From now on, no process trusts a connection it cached for this user.
  2. The database is re-encrypted under the new password and reopened with it. The new password is proven when it decrypts the database's schema page: SQLCipher authenticates every page, so one database state never opens under both passwords.
  3. The pending UUID is committed to .rekey.epoch and .rekey.pending is removed.

If step 3 cannot finish (disk full, an I/O error) after the new password was proven, the change is reported as completed. .rekey.pending stays on disk and the next login with the new password commits it. The old password is refused from that point on.

If the server cannot tell which password is active (it crashed or failed mid-rekey), the change is reported as possibly completed: every session of the user is ended on every device, and the user sees "Your password change may have completed. Try your NEW password first; if it does not work, use your old one." The first login with whichever password opens the database resolves .rekey.pending. A wrong password at that point is an ordinary failed login and counts toward the account lockout.

When such a login resolves a pending change, it checks each of the user's backups with the now-active password (the old password is not known at that point). This cleanup holds the rekey lock through backup checks and deletion. If another password change has already advanced the database's epoch, the earlier login skips cleanup instead of treating newer backups as obsolete:

  • A backup whose schema page the active password decrypts is kept.
  • A backup in which no page at all authenticates under the active key, and whose salt is the live database's own (a password change never changes the salt), is under the superseded password and is deleted. A backup whose .salt is missing or differs from the live database's is kept: it may only need its salt restored.
  • A backup in which the schema page fails but other pages authenticate is under the active key with a damaged first page. It is renamed to ldr_backup_<...>.db.damaged-<UTC timestamp> (its salt to the same name plus .salt), mode 0600, in the same backup directory, and the log says Backup <name> is under the current key but its first page is damaged; moved aside as <new name>. Such files are excluded from restore choices, daily verification and the ordinary backup list. They still participate in configured age/count retention and later password-change cleanup. Usable restore candidates take priority over damaged copies within the count limit. A later recovery checks the quarantined copy again under its active key: current-key damage is kept without another rename; a proven superseded key is removed. An unknown key or missing/mismatched salt is kept during recovery. Salvage a damaged copy before retention or a later completed password change removes it.
  • After schema verification fails with "not a database" and the backup salt matches the live database's, a file whose size is not a multiple of the configured SQLCipher page size is classified as unknown and kept before the full page HMAC check. This intentional fail-safe can retain even a superseded backup: size alone neither proves its key nor makes deletion safe.
  • A backup that cannot be checked (locked, an I/O error) is kept.

A completed password change deletes all old backups and makes a fresh one directly.

After an integrity finding (see below) the password change still completes, or the old password stays active if the re-encryption could not be applied (for example because of a damaged page).

"Your account database is pending maintenance"

A login shows this message (HTTP 503, not counted toward the lockout) when the password could not be checked against the database because the rekey state needs attention. A signed-in request in the same situation gets a 503 with Retry-After and keeps its session. The cause is logged as:

Login refused for <user>: rekey state requires operator attention (<ErrorType>)
Login refused for <user>: rekey state requires operator attention (RekeySidecarIOError) (sidecar <operation> failed, errno=<n>)
<ErrorType> Meaning Usually resolves itself?
RekeyLockContentionError Another holder kept the user's .rekey.lock for more than 5 seconds: a password change of a large database, another worker's cold open, a stopped process or a hung mount Yes, when the holder finishes
RekeySidecarIOError .rekey.lock could not be opened or locked, or an epoch file could not be written (operation is open, acquire, unlock, close or publish; check the errno: ENOSPC, EROFS, EACCES, EMFILE, ELOOP for a symlink, EINVAL for a non-regular file, EMLINK for an already-unlinked lock file or one hard-linked to another file in the same directory) Once the cause is fixed
RekeyEpochUnreadableError An epoch file exists but cannot be read (I/O error, permissions, a symlink or non-regular file planted at its name) Once the cause is fixed
DatabaseKeyCheckUnavailableError Outside pending-rekey recovery, the database could not be opened to check the password: SQLite reported it locked or busy past the busy timeout (db_config.busy_timeout_ms), an I/O error, or a file it cannot open. The password was not checked, so no lockout strike is counted Yes, once the lock holder finishes or the I/O problem is fixed
RekeyRecoveryRequiredError The epoch files do not vouch for a stable state (a malformed token or .rekey.pending without .rekey.epoch), or pending-rekey recovery failed while opening/verifying the surviving key or publishing the pending epoch. Recovery also wraps SQLite busy/locked errors during key proof in this type Yes for transient contention once the lock holder finishes; persistent failures or malformed metadata need attention (see below)

RekeyRecoveryRequiredError alone does not establish that the password was verified or that the epoch files are malformed. During pending-rekey recovery, a key-proof failure can be wrapped in this type before a password verdict is available. It still produces the login 503 above, without a lockout strike; this is not an invalid-password response.

For transient contention, let the lock holder finish and retry the login before attempting manual recovery. Use manual recovery only if the 503 persists after the underlying cause is fixed, or if the epoch files are malformed. Do not delete the rekey files to bypass a transient lock; the server-stop, backup and file-protection requirements below still apply.

Related log lines

Log line (abridged) Meaning
Rekey epoch publication failed for <user> after the new key was verified (...) The password change completed; the next login with the new password commits the pending epoch
Password change outcome indeterminate for <user>: revoking all sessions; the next login resolves the pending rekey The server could not prove which password is active
Password change failed for <user>: rekey outcome unavailable Nothing was changed; the old password is still valid
PRAGMA rekey did not change the key of <db> (...); the old password remains active Another connection held a write transaction past the busy timeout, or a damaged page stopped the re-encryption
PRAGMA quick_check reported <n> problem(s) for <db> after the active key was proven (first: ...) / PRAGMA cipher_integrity_check reported ... The active password is known, but the database file has damage that predates or survived the rekey. Run the integrity check (/auth/integrity-check) and consider restoring from a backup
Post-rekey WAL checkpoint for <db> did not complete ... / ... failed: <error> The re-encrypted pages are still only in the -wal file; the main .db file alone opens with the old password until a later checkpoint
Pending rekey cleanup failed for <user>: <error> The epoch was committed but .rekey.pending could not be removed; the next login removes it
Purged <n> backup(s) under the superseded key for <user> after pending rekey recovery Old-password backups were deleted after a pending change was resolved
Backup <name> is under the current key but its first page is damaged; moved aside as <new name> A damaged current-key backup was renamed out of the backup set (see above)

Manual recovery

Warning — do not delete only one rekey file. Deleting only .rekey.pending can leave a stale engine using the old key unfenced, allowing a live session to reuse that engine. Before deleting either file, stop the server and every worker or other process using the data directory, and verify that no server process remains running. Delete both .rekey.pending and .rekey.epoch as described below.

Use this only when the 503 persists after the cause (disk space, permissions, a stuck process) has been fixed, or when the epoch files are malformed.

  1. Stop the server, every worker and process that uses the data directory, then confirm that no LDR server process is left, for example with pgrep -af 'ldr-web|local_deep_research' (bare-metal) or docker ps (Docker). The server makes itself non-dumpable at startup, so Linux makes its open-file entries under /proc readable only by root: fuser or lsof run as the same user as the server report nothing even while the server holds the lock. If you also check the lock file, run them as root, for example sudo fuser -v ldr_user_{user_hash}.db.rekey.lock or sudo lsof ldr_user_{user_hash}.db.rekey.lock.
  2. Back up every file of that user first: copy all ldr_user_{user_hash}.db* files (database, -wal, -shm, .salt and the .rekey.* files) together, outside the data directory.
  3. Fix the underlying cause: free disk space, make the files owned by the account the server runs as with mode 0600, and remove anything planted at an epoch or lock file name that is not a regular file.
  4. Delete ldr_user_{user_hash}.db.rekey.pending and ldr_user_{user_hash}.db.rekey.epoch. Delete both: .rekey.pending without .rekey.epoch is itself a state that needs recovery. Do not delete the .db, -wal or .salt files.
  5. Start the server. The user logs in; after a password change whose outcome was unclear, they try the new password first and then the old one. Only the active password opens the database, and the login creates a fresh .rekey.epoch.
  6. Because the pending state was removed by hand, old-password backups are not purged automatically. If the new password is the active one, delete that user's backups under {data_directory}/encrypted_databases/backups/{user_hash}/ (each .db with its .salt) that were made before the password change; see the database backup guide.