Skip to content

Preserve configured SQLite journal mode in driver wrapper - #447

Merged
adamziel merged 1 commit into
WordPress:trunkfrom
adamziel:adamziel/sqlite-plugin-fix
Jul 3, 2026
Merged

Preserve configured SQLite journal mode in driver wrapper#447
adamziel merged 1 commit into
WordPress:trunkfrom
adamziel:adamziel/sqlite-plugin-fix

Conversation

@adamziel

@adamziel adamziel commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

What it does

Preserves the configured SQLite journal mode when WP_SQLite_Driver wraps an existing WP_SQLite_Connection in WP_PDO_MySQL_On_SQLite.

A connection opened with journal_mode = DELETE now stays in DELETE after the wrapper is created.

Rationale

SQLITE_JOURNAL_MODE was honored by the first WordPress SQLite connection, but the internal wrapper did not receive that setting. It created another WP_SQLite_Connection around the same PDO without journal_mode, which fell back to the class default:

$journal_mode = $options['journal_mode'] ?? 'WAL';

That could silently switch a DELETE-mode database back to WAL during the same connection flow.

Related Playground issue: WordPress/wordpress-playground#3883

Implementation

WP_SQLite_Driver now reads the effective mode from the existing connection and forwards it to WP_PDO_MySQL_On_SQLite:

'journal_mode' => $connection->query( 'PRAGMA journal_mode' )->fetchColumn(),

The regression test creates a file-backed DELETE connection, wraps it in WP_SQLite_Driver, and verifies the wrapped connection still reports delete.

Testing instructions

php -n -l packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-driver.php
php -n -l packages/mysql-on-sqlite/tests/WP_SQLite_Connection_Tests.php
cd packages/mysql-on-sqlite && composer run test -- tests/WP_SQLite_Connection_Tests.php
cd packages/mysql-on-sqlite && composer run test

All tests pass locally. PHP emits a startup warning about a missing local wasmtime.so, but it does not affect the test run.

@adamziel
adamziel marked this pull request as ready for review July 3, 2026 23:59
@adamziel
adamziel merged commit af1a026 into WordPress:trunk Jul 3, 2026
22 checks passed
adamziel added a commit to WordPress/wordpress-playground that referenced this pull request Jul 4, 2026
## What it does

Defaults `SQLITE_JOURNAL_MODE` to `DELETE` before PHP instances run
auto-prepended Playground code.

Explicit callers can still opt into WAL with:

```ts
constants: {
	SQLITE_JOURNAL_MODE: 'WAL',
}
```

## Rationale

Blueprint-defined constants are too late for this setting: the SQLite
integration may already be loaded by the time Blueprint steps run.
Defining `SQLITE_JOURNAL_MODE` through `bootRequestHandler()` feeds the
PHP auto-prepend path early enough.

## Implementation

Adds a request-handler boot default that only runs when the caller has
not already provided `SQLITE_JOURNAL_MODE`.

## Testing instructions

Run:

```bash
npm exec nx lint playground-wordpress
npm exec nx test playground-wordpress --testFile=database.spec.ts
```

Note: the database test requires the refreshed SQLite integration bundle
that includes WordPress/sqlite-database-integration#447. Against the
current pre-refresh bundle, the new DELETE-mode assertion still reports
`wal`.
adamziel added a commit to WordPress/wordpress-playground that referenced this pull request Jul 7, 2026
## What it does

Adds a CLI regression test for the SQLite failure mode reported in
#3914. The test boots `@wp-playground/cli` with six workers, creates 11
custom tables through `dbDelta()`, then repeatedly sends publish-like,
meta-box-loader-like, and post-list-like requests in parallel.

The test fails if the flow returns WordPress database failure pages or
if the final `PRAGMA integrity_check` does not return `ok`.

## Rationale

The reported failure only appears under realistic concurrent editor
load. A single CLI worker serializes requests too much, so this test
intentionally uses multiple workers to exercise concurrent SQLite
connections.

This covers the corruption class from #3883/#3914 and protects the
DELETE-journal-mode fix from #3909 plus the SQLite integration
propagation fix in WordPress/sqlite-database-integration#447.

## Implementation

The test writes a small set of PHP fixtures into the booted WordPress
site:

- setup: creates 11 custom tables with 11 `COMMENT`-bearing columns each
- publish: inserts a post and rows into every custom table
- meta-box-loader: reads counts and runs a wide joined custom-table
query
- post-list: runs a normal published-post `WP_Query`
- integrity: checks `PRAGMA integrity_check`

The stress test is skipped on Windows. The regression was reported on
Linux CI and reproduced with non-Windows CLI workers; running the same
multi-worker stress workload in the Windows CLI matrix hangs the
affected target until the workflow timeout rather than producing useful
signal.

I confirmed the negative control locally: the same workload fails
quickly when the CLI is booted with `SQLITE_JOURNAL_MODE=WAL`, producing
`database disk image is malformed` / `Error establishing a database
connection`. With the current DELETE default, it passes.

## Testing instructions

```bash
npm exec nx run playground-cli:typecheck
npm exec nx lint playground-cli
npm exec nx run playground-cli:test-playground-cli -- --testFile=sqlite-concurrent-publish.spec.ts
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant