Skip to content

Fix sync pull getting stuck when site has broken SQLite integration#3008

Open
bcotrim wants to merge 1 commit intotrunkfrom
fix-sync-pull-broken-sqlite
Open

Fix sync pull getting stuck when site has broken SQLite integration#3008
bcotrim wants to merge 1 commit intotrunkfrom
fix-sync-pull-broken-sqlite

Conversation

@bcotrim
Copy link
Copy Markdown
Contributor

@bcotrim bcotrim commented Apr 8, 2026

Related issues

How AI was used in this PR

Claude Code was used to explore the codebase, trace the sync pull flow, identify root causes, and implement the fix. All changes were manually tested by reproducing the bug (replacing wp-content with a symlink) and verifying the pull completes successfully after the fix.

Proposed Changes

  • Restore SQLite integration before importing a site backup. When wp-content is replaced (e.g., with a symlink to a repo), the SQLite files (db.php, mu-plugins/sqlite-database-integration, database/) are lost. The importSite handler now checks hasSQLitePlugin() and reinstalls the integration if missing, so the database import can succeed.
  • Always restart the site server after import, even on failure. Previously, if importSite() threw during a sync pull, startServer() was never called, leaving the site stopped and unreachable. The import is now wrapped in try/finally so the server always restarts.
  • Export installSqliteIntegration from sqlite-versions.ts to allow force-installing SQLite integration bypassing the needsSqliteSetup check, which incorrectly skips installation when wp-config.php exists but db.php doesn't.

Testing Instructions

  • Create a new Studio site and connect it to a WordPress.com site via Sync
  • Pull the site to confirm it works normally
  • Stop the site server
  • Replace the site's wp-content folder with a symlink to an empty directory (e.g., mv wp-content wp-content-backup && ln -s /tmp/some-dir wp-content)
  • Start the site again — you should see "Error establishing a database connection"
  • Attempt a Sync Pull from the connected WordPress.com site
  • Before fix: Pull gets stuck on "Pulling..." with "Import failed" error, site stays down
  • After fix: Pull completes successfully, SQLite integration is restored into the symlinked directory, site is accessible

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@bcotrim bcotrim self-assigned this Apr 8, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing ffdb940 vs trunk

app-size

Metric trunk ffdb940 Diff Change
App Size (Mac) 1252.04 MB 1252.00 MB 0.04 MB ⚪ 0.0%

site-editor

Metric trunk ffdb940 Diff Change
load 1999 ms 1547 ms 452 ms 🟢 -22.6%

site-startup

Metric trunk ffdb940 Diff Change
siteCreation 8112 ms 8160 ms +48 ms ⚪ 0.0%
siteStartup 4181 ms 4850 ms +669 ms 🔴 16.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@bcotrim bcotrim requested a review from a team April 8, 2026 11:04
Copy link
Copy Markdown
Contributor

@nightnei nightnei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Create a new Studio site and connect it to a WordPress.com site via Sync
  2. Pull the site to confirm it works normally

I tested two times - it doesn't work for me.
The steps:

  1. nvm use npm i npm run cli:build
  2. Create a new wpcom site
  3. Created a new Studio site
  4. Connected and pulled
    No errors in Studio, only "Import failed".
Image In Logs:
#13 phar:///tmp/wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php(35): WP_CLI\bootstrap()
#14 phar:///tmp/wp-cli.phar/php/boot-phar.php(20): include('phar:///tmp/wp-...')
#15 /tmp/wp-cli.phar(4): include('phar:///tmp/wp-...')
#16 {main}
  thrown in /tmp/sqlite-command/src/SQLiteDatabaseIntegrationLoader.php on line 86

    at JetpackImporter.importDatabase (/Users/nightneia8c/projects/a8c/studio/apps/studio/dist/main/index.js:27637:17)
    at async JetpackImporter.import (/Users/nightneia8c/projects/a8c/studio/apps/studio/dist/main/index.js:27677:9)
    at async importBackup (/Users/nightneia8c/projects/a8c/studio/apps/studio/dist/main/index.js:29366:12)
    at async importSite (/Users/nightneia8c/projects/a8c/studio/apps/studio/dist/main/index.js:44688:20)
    at async Session.<anonymous> (node:electron/js2c/browser_init:2:116791)

@bcotrim
Copy link
Copy Markdown
Contributor Author

bcotrim commented Apr 8, 2026

thanks for the review @nightnei
do the same steps work for you in trunk?
I have no trouble pulling a site to a local Studio site, it seems your test failed even before breaking the wp-content folder (which is the use case for this issue)

@nightnei
Copy link
Copy Markdown
Contributor

nightnei commented Apr 9, 2026

@bcotrim yeah, it fails for my on trunk too. I will continue testing when Automattic/wp-cli-sqlite-command#24 is merged, ok?

@bcotrim
Copy link
Copy Markdown
Contributor Author

bcotrim commented Apr 9, 2026

@bcotrim yeah, it fails for my on trunk too. I will continue testing when Automattic/wp-cli-sqlite-command#24 is merged, ok?

Sounds great, thanks for checking!

@katinthehatsite
Copy link
Copy Markdown
Contributor

Automattic/wp-cli-sqlite-command#24 is merged now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants