fix(server): stop fsyncing SQLite on every commit so slow disks no longer drop clients #19205
main fromrefs/pull/19205/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
Users keep seeing "reconnecting" while agents run. SQLite runs at the default synchronous = FULL, so every commit fsyncs the WAL on the main thread, and every provider event is its own commit. On a slow or busy disk (HDD, LUKS/btrfs, ext4 under build load, WSL with discard), one fsync takes 100 ms to several seconds. The event loop stops, heartbeats miss the timeout, and clients drop. The data is in #15707.
Change#
Set PRAGMA synchronous = NORMAL with the other connection pragmas. In WAL mode this fsyncs at checkpoints, not on every commit.
Tradeoff: an app crash still loses nothing, and the database cannot corrupt. An OS crash or power loss can roll back commits made since the last checkpoint. That is the standard WAL setting, and macOS FULL already does not use F_FULLFSYNC (#13544).
Scope and approval#
Maintainer change. It is the first option in the #15707 triage, and users have measured it on live servers. It does not move SQLite off the main thread (#18736, #14703), so slow reads (#14701) still stall.
Verification#
- User A/B on a live server in #15707: fsync time went from 17.6 s to 0.4 s per minute, the slowest single fsync from 6.7 s to 0.25 s, and the reconnects stopped. On the slow disk from the original report, median commit time went from 41.8 ms to 0.05 ms.
- Local real-disk benchmark (ext4), 500 commits shaped like event writes: fsyncs went from 514 to 11, and median commit time from 1.85 ms to 0.60 ms.
- New test in
Sqlite.test.ts: it checks that a file-backed database opens at NORMAL. It fails without the change (expected 2 to equal 1).Sqlite.test.tspasses 5/5. Lint and format pass. - GPT-6.1 Sol reviewed the change and approved it. It confirmed that every production connection to
statev2.sqlitegoes through this setup.
Created with Claude Opus 5.5 in Claude Code, running in T3 Code. Reviewed with sol-loop: 1 round with GPT-6.1 Sol.
🤖 Generated with Claude Code
Closes #15707
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
juliusmarminge added labelsmacroscope-review
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −24 B (−0.5%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −24 B (−2.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB −41 B (−0.2%) 29.3 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
aef0e9c· PR result:d72c261· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
8b1682fb-1446-4f82-9388-3423f44e5d77
📥 Commits
-
Reviewing files that changed from the base of the PR and between aef0e9ca401acb40057a286a19de8768809db960 and d72c2611c6e329144b5b4e416d106fee1976f37d.
📒 Files selected for processing: 2
-
apps/server/src/persistence/Sqlite.test.tsapps/server/src/persistence/Sqlite.ts
Included review availability: This review used your included allowance. 8 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.
-
📝 Walkthrough
-
SQLite connections now use
synchronous = NORMAL. A persistence test opens a temporary file-backed database and verifies that SQLite reports the setting as1.Changes: SQLite persistence
Layer / File(s) Summary Set and verify synchronous mode
apps/server/src/persistence/Sqlite.ts,apps/server/src/persistence/Sqlite.test.tsThe shared SQLite setup sets synchronous = NORMAL. A test verifies the setting on a temporary file-backed database. Comments describe the WAL durability tradeoff.Priority: ⬆️ High
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
otavio
Merge Risk: ⚪ Minimal · up to
d72c2-
This change trades some power-loss durability for lower commit latency, as intended. No merge-blocking issue is established by the supplied evidence.
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly and concisely describes the main change: changing SQLite commit durability behavior to prevent slow-disk client disconnects. Description check The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the durability tradeoff, approval context, test coverage, benchmark results, and limit…
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This changes SQLite's automatic durability setting for all server persistence connections, trading per-commit fsync latency for possible loss of commits since the last checkpoint after an OS or power failure. The production default change and its persistence tradeoff warrant human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).