Skip to content

fix(backup): skip ephemeral coordinator lock databases - #119792

Closed
ayaangazali wants to merge 1 commit into
openclaw:mainfrom
ayaangazali:fix/backup-skip-ephemeral-lock-databases
Closed

ayaangazali wants to merge 1 commit into
openclaw:mainfrom
ayaangazali:fix/backup-skip-ephemeral-lock-databases

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #119757.

openclaw backup create --output <dir> --verify cannot back up a running gateway. It fails on a zero-byte ephemeral lock database the gateway holds open:

Error: SQLite database cannot be compacted safely for backup:
 ~/.openclaw/tmp/openclaw-502/gateway.<id>.lock.sqlite
 ... database is locked | ERR_SQLITE_ERROR

No archive is produced, so the documented pre-upgrade backup step cannot run without stopping the gateway first, which the docs never say.

Refusing an unsafe raw copy is correct, and I did not touch that. The bug is that the file is in the backup set at all. It is a process-lifetime coordination lock, not user data: src/infra/gateway-lock.ts:491 acquires the coordinator as `${lockPath}.sqlite` over gateway.<hash>.lock, producing exactly the gateway.<hash>.lock.sqlite in the report. src/infra/device-identity-coordinator.ts:48 builds device-identity.<hash>.lock.sqlite the same way.

Why This Change Was Made

The repo already has the right mechanism, and this class of file was already understood to be non-backup material. SQLITE_BACKUP_EXCLUDED_SUFFIXES in src/infra/backup-create.ts is a suffix list consulted both when classifying a source path and when walking directories. It listed .reindex-lock.sqlite and nothing else, so reindex locks were skipped while coordinator locks were not.

So this adds one entry rather than inventing an exclusion path:

const SQLITE_BACKUP_EXCLUDED_SUFFIXES = [".reindex-lock.sqlite", ".lock.sqlite"] as const;

That covers the gateway config and state locks and the device-identity lock. The existing entry has to stay, because .reindex-lock.sqlite ends in -lock.sqlite with a hyphen and would not match the new suffix.

I chose the suffix over excluding tmp/ wholesale. The suffix targets the actual property that makes these files unbackupable, which is that they are exclusive coordinators held for the life of a process, and it keeps working if a coordinator is ever placed outside tmp/, as the device-identity one already is.

User Impact

backup create works against a running gateway again, which is the documented pre-upgrade path. Nothing that belongs in a backup is dropped: these files carry no durable state, are zero-byte in the reported case, and are recreated on demand by whichever process next takes the lock.

No config, schema, or default surface changes. Production delta is +5/-1 in one file, four of which are the comment explaining why the entry exists.

Evidence

Regression coverage in src/infra/backup-create.test.ts, added as a sibling to the existing transient-reindex exclusion test so both live in the same place. It writes the real path shapes a running gateway leaves behind, including the sidecars:

tmp/openclaw-502/gateway.a1b2c3d4.lock.sqlite
tmp/openclaw-502/gateway.state.e5f6a7b8.lock.sqlite
tmp/device-identity.9c8d7e6f.lock.sqlite

each with "", -wal, -shm, and -journal, then asserts none appear in the produced archive.

I confirmed the test pins the fix by reverting the suffix list to its previous value and rerunning:

× omits ephemeral coordinator lock databases held open by a running gateway
Tests  1 failed | 69 passed (70)

then restored it for 70/70.

Verification: src/infra/backup-create.test.ts 70 tests, src/commands/backup 3 files / 16 tests, tsgo -p tsconfig.core.json and tsgo -p test/tsconfig/tsconfig.core.test.json both clean, git diff --check clean.

I did not reproduce the original failure end to end against a live gateway, since that means holding the operator's running service open, which the repo rules put off limits without explicit approval. The test reproduces the file shape and the archive assertion instead, and the lock-path construction is cited above rather than assumed.

AI-assisted: written with AI assistance. I read the backup classifier, the directory walk, the gateway lock acquisition, and the device-identity coordinator myself before changing anything.

A running gateway holds gateway.<hash>.lock.sqlite open, so compaction fails and
no archive is produced. The exclusion list already covered reindex locks; extend
it to the .lock.sqlite coordinators. Fixes openclaw#119757.
@ayaangazali
ayaangazali marked this pull request as ready for review August 6, 2026 00:59
Copilot AI lite review requested due to automatic review settings August 6, 2026 00:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@vincentkoc vincentkoc added close:superseded PR close reason dedupe:child Duplicate issue/PR child in dedupe cluster labels Aug 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks for independently tracing the lock-database failure. Closing this in favor of #119782, which was already open for #119757 and owns the canonical repair.

This patch’s global .lock.sqlite suffix exclusion is too broad for the backup owner boundary. backup create discovers every SQLite database under the state tree, including plugin-owned durable databases, so names such as state/plugins/.../cache.lock.sqlite would be silently omitted along with their sidecars.

#119782 limits exclusion to exact gateway/device coordinator basenames inside the authoritative CLI and managed-service lock directories, while preserving durable lock-named and coordinator-shaped databases elsewhere. The regression shapes here are already covered more strongly there, including a real held gateway coordinator, verification, sidecars, and durable lookalike preservation, so there is no test to transplant.

#119782 is still awaiting publication of its exact-head ClawSweeper review. #119757 will remain open until the canonical fix lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close:superseded PR close reason dedupe:child Duplicate issue/PR child in dedupe cluster size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backup create fails on running gateway's ephemeral lock database

3 participants