fix: checkpoint WebKit LocalStorage WAL on startup to prevent unbounded growth#662
Open
kckylechen1 wants to merge 1 commit intojlcodes99:mainfrom
Open
fix: checkpoint WebKit LocalStorage WAL on startup to prevent unbounded growth#662kckylechen1 wants to merge 1 commit intojlcodes99:mainfrom
kckylechen1 wants to merge 1 commit intojlcodes99:mainfrom
Conversation
…ed growth WebKit WKWebView uses WAL mode for LocalStorage SQLite databases but never checkpoints them. When the app writes large blobs frequently (e.g. Windsurf account caches with quota snapshots), the WAL file grows unbounded — observed at 13 GB for only ~5 MB of actual data. Add a startup maintenance step that: - Locates all LocalStorage SQLite databases under the WebKit data directory - Runs PRAGMA wal_checkpoint(TRUNCATE) on each - Runs in a background thread to avoid blocking startup - Logs success/failure for observability
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Problem
WebKit WKWebView uses WAL mode for LocalStorage SQLite databases but never checkpoints them. When the app writes large blobs frequently (e.g. Windsurf/Codex account caches with quota snapshots, written every few minutes via auto-refresh), the WAL file grows unbounded.
Observed on my machine: 13 GB WAL file for only ~5 MB of actual data (45 key-value pairs).
After running
PRAGMA wal_checkpoint(TRUNCATE)manually, the WAL dropped to 0 bytes.Root Cause
The frontend writes full JSON-serialized account arrays to localStorage on:
11 platform account stores + 11 instance stores = 22 caches being rewritten continuously. The heaviest key (
agtools.windsurf.accounts.cacheat ~5 MB) includes raw API response blobs (copilot_quota_snapshots,windsurf_user_status, etc.) with no size reduction.WKWebView doesn't auto-checkpoint its SQLite databases, so the WAL accumulates indefinitely.
Fix
Add a startup maintenance step (
modules/webkit_cache_maintenance.rs) that:localstorage.sqlite3files under the WebKit data directoryPRAGMA wal_checkpoint(TRUNCATE)on eachRuns at startup in
lib.rssetup, before the WebView is fully loaded — so the lock is available.Testing
cargo check(no new warnings)Future Improvements (not in this PR)