Skip to content

fix(cli): remove orphan SQLite sidecars on index deletion (#2054) - #2137

Merged
DeusData merged 2 commits into
mainfrom
fix/2054-orphan-sidecars
Sep 12, 2026
Merged

fix(cli): remove orphan SQLite sidecars on index deletion (#2054)#2137
DeusData merged 2 commits into
mainfrom
fix/2054-orphan-sidecars

Conversation

@DeusData

@DeusData DeusData commented Sep 9, 2026

Copy link
Copy Markdown
Owner

What

cbm_remove_indexes() — the single deletion chokepoint behind cbm update, cbm uninstall, and install --reset-indexes — unlinked each index *.db (and its *.db.tmp) but never the SQLite sidecar files <db>-wal / <db>-shm / <db>-journal. Every explicit index removal therefore left orphan -wal/-shm files behind (the residue of #2054, after the update-deletes-indexes bug itself was fixed by 9ecabe0).

Fix

Call the existing wide-path-safe cbm_remove_db_sidecars() helper (src/foundation/compat_fs.c) on both the live and staged db paths right after the .db unlink. It is idempotent and ENOENT-tolerant, so an orphan -wal that outlived its .db is cleaned too. Sidecars are not indexes, so the removed-count is unchanged. No pre-existing-orphan sweep (out of scope).

Test

New cli_remove_indexes_deletes_orphan_sqlite_sidecars (tests/test_cli.c, cross-platform): creates proj.db + proj.db-wal + proj.db-shm, calls cbm_remove_indexes, asserts all three are gone. RED-on-revert verified — reverting the two helper calls re-leaves the sidecars (309/1, sole failure on the new test); with the fix, 310/0. ASan/UBSan clean.

cbm_remove_indexes unlinked each *.db and *.db.tmp but never the SQLite
sidecars (<db>-wal/-shm/-journal), so `cbm update`, `cbm uninstall`, and
`install --reset-indexes` (the four callers of the single deletion
chokepoint) left orphan -wal/-shm files behind. Call the existing
wide-path-safe cbm_remove_db_sidecars() helper on both the live and staged
db paths after the .db unlink; it is idempotent and ENOENT-tolerant, so an
orphan -wal that outlived its .db is still cleaned. Sidecars are not
indexes, so the removed-count is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData DeusData added bug Something isn't working editor/integration Editor compatibility and CLI integration ux/behavior Display bugs, docs, adoption UX priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Sep 9, 2026
@DeusData
DeusData enabled auto-merge September 11, 2026 23:29
@DeusData
DeusData merged commit a0dc418 into main Sep 12, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working editor/integration Editor compatibility and CLI integration priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant