Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): service updates no longer fail on full disks or large databases #19311

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 11 commits intomain fromrefs/pull/19311/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Two ways a service update fails on a large or full disk:

  1. The launcher stopped the server and only then copied the database. If the copy did not fit, the update rolled back and the server restarted cold. On a disk with less free space than the database, every update was an outage (#14515).
  2. The new server had 120 s from spawn to report "prepared". Migrations, the open-time PRAGMA optimize (#18471) and index-building migrations such as 062 (#18628) all count toward that. On a 13-38 GB database with a cold page cache, the first analyze alone took 31 s to over 80 s. A missed window rolled back the database and threw away the new stats and indexes, so every retry paid the same cost and the update could never succeed.

This takes over #14520 by @saphid for part 1 and adds the fix for part 2.

Part 1: refuse an update whose backup cannot fit (from #14520)

@saphid's commits are imported with their authorship unchanged and rebased onto main, after #16102 (one database owner per T3 home) and #19298.

  • Before the server stops, the launcher checks that the backup fits. If it does not, or the check cannot run, the update is rejected through the existing update-rejected path and the server keeps running.
  • Backups and rollback restores clone where the filesystem can (cp -c on APFS, cp --reflink=auto on Linux), with a fallback to fs.copyFile. A clone needs only headroom for the trial's writes: max(1 GiB, 10% of the database).
  • A rollback keeps a symlinked or hard-linked database's links, including after an interrupted restore.

See #14520 for the full reasoning and measurements. My changes on top are small: copyDatabaseFile reuses runCp, one statDatabaseFiles helper replaces two copies of the same stat loop, and I removed a duplicate vi import left by the rebase. #16102's state-dir-owned path and the backup check do not overlap. The check runs before any pending update exists, and the idle path discards the backup as before.

Part 2: give the trial 30 minutes to prepare

PREPARED_TIMEOUT_MS goes from 120 s to 30 min. The client's update wait (SERVER_UPDATE_RESUME_TIMEOUT) was set to cover the old deadline, so it goes from 4 to 32 min. Without that, a slow but successful update would show as failed.

Why a longer window, and not progress reports or a timer that starts after the DB opens:

  • The SQLite writer runs synchronously on the server's main thread. During a long PRAGMA optimize or CREATE INDEX, the trial cannot send anything, so a heartbeat cannot cover the slow step.
  • Startup work after the DB opens (legacy import, recovery) also scales with the database. A short window that starts after DB open would still miss on large databases.
  • A trial that crashes is caught when it exits, not by this timer. The timer only catches a trial that is alive but stuck, which it still does, now after 30 min.

docs/internals/server-updates.md now covers the preflight and why the deadline is long.

Scope and approval

Maintainer work: Theo asked for this takeover and the prepared-window fix. Part 1 fixes triaged bug #14515. Part 2 changes two timeout constants and adds no new behavior.

Verification

  • New test "gives a trial the full prepared window" (fake setTimeout): a trial that reports prepared after 121 s commits, and a trial that never reports is rolled back with prepared-timeout. With PREPARED_TIMEOUT_MS = 120_000 the first case fails (expected '1.0.0' to equal '1.1.0').
  • vp test run apps/server/src/serviceLauncher.test.ts apps/server/src/cloud/selfUpdate.test.ts apps/server/src/cloud/serviceLauncherClient.test.ts packages/client-runtime/src/state/server.test.ts: 4 files, 58 passed.
  • Typecheck of apps/server and packages/client-runtime: clean. Lint on the changed code files: clean.
  • Not run: a real update against a large database, the macOS cp -c paths, btrfs/XFS reflinks, and Windows. Clients already installed keep their 4 min wait until they update. For them, a slow update that still commits can show as timed out, and it is active after a reconnect.

Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>

Reviewed with sol-loop: 1 round with GPT-6.1-Sol on high.

Part 1 is by @saphid with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code. The takeover, rebase, and part 2 are by Claude Opus 5.5 in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR materially changes production service updates by adding disk-space gating and cross-platform database backup/restore behavior, while extending update timing defaults to 30–32 minutes. It also adds static-analysis suppression directives, so the scope and policy-sensitive changes require human review.

      Notes:

      • Diff unchanged. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. juliusmarminge added labelsmacroscope-review

    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

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

      Baseline: 173a970 · PR result: f97fc64 · 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: e08a5c96-1cdb-4899-a9f1-a4b32dc5f259
      📥 Commits

      Reviewing files that changed from the base of the PR and between 173a97097659be5f77ab2c05cf5dfe84be3eb094 and f97fc64384dc941412194b4f7083ed8be7b1e394.

      📒 Files selected for processing: 4
      • apps/server/src/serviceLauncher.test.ts
      • apps/server/src/serviceLauncher.ts
      • docs/internals/server-updates.md
      • packages/client-runtime/src/state/server.ts

      Included review availability: This review used your included allowance. 4 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

      The launcher now allows a 30-minute prepared-trial window, checks database snapshot space before accepting updates, and uses copy-on-write cloning where available. Rollback resolves symlink destinations before restoring database files. The client resume timeout is 32 minutes.

      Changes: Server update lifecycle

      Layer / File(s)Summary
      Prepared-trial deadline
      apps/server/src/serviceLauncher.ts, apps/server/src/serviceLauncher.test.ts, packages/client-runtime/src/state/server.ts
      The prepared-trial deadline changes to 30 minutes, and tests cover the preparation and timeout boundaries. The client resume timeout changes to 32 minutes.
      Snapshot capacity and creation
      apps/server/src/serviceLauncher.ts, apps/server/src/serviceLauncher.test.ts
      The launcher checks snapshot capacity before accepting an update. It supports clone-aware space requirements, copy-on-write cloning with regular-copy fallback, and rejection when inspection fails or space is insufficient. Tests cover these checks and a disconnected requesting server.
      Database rollback restoration
      apps/server/src/serviceLauncher.ts, apps/server/src/serviceLauncher.test.ts, docs/internals/server-updates.md
      Rollback resolves symlink destinations before restoring database and sidecar files, then syncs affected directories. Tests cover regular, linked, and dangling-link cases. Documentation describes the capacity check and snapshot contents.

      Priority: ➖ Normal

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant UpdateRequester
        participant Launcher
        participant databaseBackupBlocker
        participant BackupSpaceProbe
        UpdateRequester->>Launcher: Request update
        Launcher->>databaseBackupBlocker: Check snapshot capacity
        databaseBackupBlocker->>BackupSpaceProbe: Read free space and clone eligibility
        BackupSpaceProbe-->>databaseBackupBlocker: Return probe results
        databaseBackupBlocker-->>Launcher: Return blocker or no blocker
        Launcher-->>UpdateRequester: Reject update or continue

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to f97fc

      The update can proceed through normal checks; no material unresolved failure was established.

      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 is concise, specific, and accurately summarizes the two main fixes: preventing service-update failures on full disks and large databases.
      Description checkPassedThe description covers the problem, implementation, scope, verification results, limitations, and agent attribution. It provides detailed test results and identifies untested platform-specific paths. …
      ✨ 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.