fix(state): register atexit WAL checkpoint to prevent unbounded WAL growth#16510
Open
chinadbo wants to merge 1 commit into
Open
fix(state): register atexit WAL checkpoint to prevent unbounded WAL growth#16510chinadbo wants to merge 1 commit into
chinadbo wants to merge 1 commit into
Conversation
…rowth SessionDB.close() was never called in practice, causing SQLite WAL files to grow unboundedly on long-running gateway and CLI processes (field reports of 100+ MB WAL files). - Add `atexit.register(self.close)` in SessionDB.__init__ so the WAL checkpoint always runs on process exit, even without an explicit close() - Add __enter__/__exit__ so SessionDB can be used as a context manager - Fix the silent `except Exception: pass` in close() to log a warning for non-ENOENT errors, aiding operator diagnostics - Add explicit close() call in the CLI atexit cleanup path as a belt-and- suspenders measure alongside the atexit registration - Add TestWALCheckpointOnClose test class (6 tests) covering: WAL file is empty/absent after close, idempotent close, context manager closes on normal and exceptional exit, atexit registration present in source, and PRAGMA wal_checkpoint return value verification Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5bd03f5 to
8f35d50
Compare
This was referenced Apr 29, 2026
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.
Summary
SessionDB.close()existed but was never called — SQLite WAL files grew unboundedly on long-running gateway processes (field reports: 100+ MB WAL files degrading read performance)atexit.register(self.close)inSessionDB.__init__()so the WAL is always checkpointed on process exit__enter__/__exit__context manager support toSessionDBclose()call in CLI atexit cleanup pathclose()error handling: log a warning for unexpected errors instead of silently swallowing all exceptionsTest plan
tests/test_hermes_state.py— 6 new tests inTestWALCheckpointOnCloseincluding PRAGMA return value verification🤖 Generated with Claude Code