Conversation
SQLite DELETE leaves free pages and WAL growth, so the store file can grow when docs are removed. Checkpoint the WAL after bulk deletes without blocking readers, and add a compact command that vacuums when idle. Fixes #476
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of correctness/robustness issues in the new compaction flow (filesystem size accounting can throw, and service logging can be misleading when WAL truncation reclaims space without VACUUM).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses SQLite database file growth after document removals by adding lightweight post-delete WAL maintenance and introducing an explicit compaction flow (VACUUM) that can be triggered when the store is idle.
Changes:
- Run a best-effort non-blocking WAL checkpoint after bulk deletes to curb WAL growth without blocking readers.
- Add an explicit compaction API/CLI path (
compact) that can runVACUUM(exclusive lock) and report reclaimed space. - Add a small
formatByteshelper plus targeted tests, and update docs/skill guidance to explain WAL vs VACUUM behavior.
File summaries
| File | Description |
|---|---|
| src/utils/string.ts | Adds formatBytes() helper for human-readable size output. |
| src/utils/string.test.ts | Unit tests for formatBytes(). |
| src/store/types.ts | Introduces CompactResult type for compaction reporting. |
| src/store/trpc/router.ts | Adds compact mutation to the data router. |
| src/store/trpc/router.test.ts | Tests compact behavior for in-memory store. |
| src/store/trpc/interfaces.ts | Extends IDocumentManagement with compact(). |
| src/store/DocumentStore.ts | Implements size accounting and compact() (checkpoint + optional VACUUM). |
| src/store/DocumentStore.test.ts | Adds integration-style tests for compaction behavior. |
| src/store/DocumentManagementService.ts | Runs checkpoint after bulk deletes; adds service-level compact() wrapper + logging. |
| src/store/DocumentManagementService.test.ts | Updates mocks/assertions and adds coverage for compaction failure tolerance and explicit compaction. |
| src/store/DocumentManagementClient.ts | Adds client wrapper for compact mutation. |
| src/cli/index.ts | Registers new compact CLI command. |
| src/cli/commands/compact.ts | Adds docs-mcp-server compact command implementation and output. |
| src/cli/commands/compact.test.ts | Unit test for the compact command output and invocation. |
| skills/docs-manage/SKILL.md | Documents the new compact workflow for agents. |
| docs/guides/basic-usage.md | Adds compact to CLI command list and output behavior notes. |
| docs/concepts/data-storage.md | Explains WAL checkpoint vs VACUUM and when each is used. |
Review details
- Files reviewed: 17/17 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #476.
SQLite does not shrink the store file on
DELETE. Removed rows become free pages, and WAL mode records those deletes indocuments.db-wal, so on-disk size can grow after a remove.Changes
remove/removeAllDocuments), runwal_checkpoint(PASSIVE)only. That never waits on readers or writers, so search stays available. It clears WAL growth from the delete; it does not rewritedocuments.db.docs-mcp-server compact(and a tRPCcompactmutation) for an explicitVACUUM. This takes an exclusive lock and may block searches — run it when the store is idle.Docs
docs/concepts/data-storage.md,docs/guides/basic-usage.md, andskills/docs-manage/SKILL.mdcover the WAL vs VACUUM split.