Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop fsyncing SQLite on every commit so slow disks no longer drop clients #19205

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19205/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Problem

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.ts passes 5/5. Lint and format pass.
  • GPT-6.1 Sol reviewed the change and approved it. It confirmed that every production connection to statev2.sqlite goes 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

    2. juliusmarminge added labelsmacroscope-review

    3. 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).
    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−24 B (−0.5%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−24 B (−2.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: aef0e9c · PR result: d72c261 · Source CI: success

      Scenario 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.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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 as 1.

      Changes: SQLite persistence

      Layer / File(s)Summary
      Set and verify synchronous mode
      apps/server/src/persistence/Sqlite.ts, apps/server/src/persistence/Sqlite.test.ts
      The 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: Passed 4
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly and concisely describes the main change: changing SQLite commit durability behavior to prevent slow-disk client disconnects.
      Description checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.