The best way to control Claude Code, Codex and more from any computer or phone
perf(server): CLI startup no longer takes the write lock when the schema is current (#37564)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
fast-fourier-transfem | yuridkowskian catgirlmbinator committed
Nov 16, 2026 at 03:35 UTC
4da2bc520c38cd6b36014d2888774168fbf4c77f
2 files changed
+11
-3
apps/server/src/persistence/Migrations.test.ts
+7
-1
@@ -69,12 +69,18 @@ describe("runMigrations", () => {
69
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
70
);
71
72
- it.effect("upgrades a database at exactly 54", () =>
72
+ it.effect("upgrades a database at exactly 54, then rechecks it without a write lock", () =>
73
Effect.gen(function* () {
74
+ const sql = yield* SqlClient.SqlClient;
75
yield* runMigrations({ toMigrationInclusive: 54 });
76
assert.deepStrictEqual(yield* runMigrations(), v2Migrations);
77
assert.deepStrictEqual(yield* history, migrationManifest);
78
assert.isAbove(yield* v2TableCount, 0);
79
+
80
+ // query_only rejects BEGIN IMMEDIATE, which CLI startup would otherwise take on the live database.
81
+ yield* sql`PRAGMA query_only = ON`;
82
+ assert.deepStrictEqual(yield* runMigrations(), []);
83
+ assert.deepStrictEqual(yield* history, migrationManifest);
84
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
85
);
86
apps/server/src/persistence/Migrations.ts
+4
-2
@@ -290,10 +290,12 @@ export const runMigrations = Effect.fn("runMigrations")(function* ({
290
toMigrationInclusive,
291
}: RunMigrationsOptions = {}) {
292
// The desktop waits past its readiness budget until the finished line follows this one.
293
- if (yield* hasPendingMigrations()) yield* Effect.log(DATABASE_MIGRATIONS_STARTED_MESSAGE);
293
+ const hasPending = yield* hasPendingMigrations();
294
+ if (hasPending) yield* Effect.log(DATABASE_MIGRATIONS_STARTED_MESSAGE);
295
const includesV2 =
296
toMigrationInclusive === undefined || toMigrationInclusive >= FIRST_V2_MIGRATION_ID;
296
- const previewMigrations = includesV2 ? yield* reconcileV2PreviewMigration() : [];
297
+ // The reconcile takes the write lock; CLI startup must not contend with the server for a no-op.
298
+ const previewMigrations = includesV2 && hasPending ? yield* reconcileV2PreviewMigration() : [];
299
if (includesV2) {
300
yield* assertV2MigrationsCanRun(toMigrationInclusive);
301
}