Skip to content

Conversation

@mortenoh
Copy link
Contributor

Summary

Add WAL checkpoint before disposing SQLite file-based databases to ensure data is flushed to disk.

Problem

When using SQLite WAL mode:

  • Data stays in WAL buffer and isn't flushed to the main database file
  • External readers (like CLI tools) can't see committed data while service is running
  • Service may hang on shutdown waiting for WAL to flush

Solution

Override dispose() in SqliteDatabase to execute PRAGMA wal_checkpoint(TRUNCATE) before closing the database engine. This:

  • Flushes all WAL data to the main database file
  • Truncates the WAL file to zero bytes
  • Allows external readers to see all committed data
  • Enables clean shutdown

Changes

  • src/servicekit/database.py: Add dispose() override with WAL checkpoint
  • tests/test_database.py: Add test for WAL checkpoint behavior
  • pyproject.toml: Bump version to 0.6.0

Test plan

  • Existing tests pass
  • New test verifies WAL is checkpointed on dispose
  • Manual test: chapkit CLI can read database while service running

Add WAL checkpoint (TRUNCATE) before disposing SQLite file-based
databases. This ensures:
- Data is flushed to the main database file
- External readers can see committed data
- Clean shutdown without hanging

Bump version to 0.6.0

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/servicekit/database.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mortenoh mortenoh merged commit 145b1c8 into main Jan 13, 2026
2 checks passed
@mortenoh mortenoh deleted the fix/wal-checkpoint-on-dispose branch January 13, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant