Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: also refuse mode-only cutovers until coordinated restart (#8804)

[._.]/ Adam Eivy5f71ea004055
diff --git a/client/src/components/settings/DatabaseTab.jsx b/client/src/components/settings/DatabaseTab.jsx
index 416bd429e8..a1b3b70543 100644
--- a/client/src/components/settings/DatabaseTab.jsx
+++ b/client/src/components/settings/DatabaseTab.jsx
@@ -1,10 +1,10 @@
import { useState, useEffect, useRef, useCallback } from 'react';
-import { Container, HardDrive, Download, ArrowRightLeft, Wrench, RefreshCw, Square, RotateCw, Play, Trash2 } from 'lucide-react';
+import { Container, HardDrive, Download, Wrench, RefreshCw, Square, RotateCw, Play, Trash2 } from 'lucide-react';
import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
import { formatBytes, formatCount } from '../../utils/formatters';
import {
- getDatabaseStatus, switchDatabase, setupNativeDatabase, exportDatabase, fixDatabase,
+ getDatabaseStatus, setupNativeDatabase, exportDatabase, fixDatabase,
syncDatabase, startDatabase, stopDatabase, destroyDatabase
} from '../../services/api';
import socket from '../../services/socket';
@@ -99,20 +99,6 @@ function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runAction
{/* Non-active backend actions */}
{!isActive && (data?.installed || data?.configured) && (
<>
- {/* Switch without migration */}
- <button
- onClick={() => setConfirmAction({
- type: 'switch',
- label: `Switch to ${displayLabel} without migrating data?`,
- action: () => runAction(`switch-${backend}`, () => switchDatabase(backend, false), `Switched to ${displayLabel}`)
- })}
- disabled={busy}
- className={`${btnClass} bg-port-border hover:bg-port-border/70 text-white`}
- >
- <ArrowRightLeft size={12} />
- Switch
- </button>
-
{/* Sync data from active into this backend */}
<button
onClick={() => setConfirmAction({
@@ -262,7 +248,7 @@ export function DatabaseTab() {
</div>
<p className="text-sm text-port-warning">
- Database migration is temporarily unavailable to protect writes made while PortOS is running.
+ Database migration and switching are temporarily unavailable to protect writes made while PortOS is running.
Keep using the current backend until a coordinated shutdown and restart is available.
Backups remain available.
</p>
diff --git a/docs/BACKUP.md b/docs/BACKUP.md
index 2d6c4585d9..d903b2ebcb 100644
--- a/docs/BACKUP.md
+++ b/docs/BACKUP.md
@@ -13,8 +13,8 @@ Implementation: `server/services/backup.js` (snapshot/dump/restore), `server/ser
## Database backend migration
-Migration between Docker and native PostgreSQL is temporarily unavailable in
-Settings and `scripts/db.sh migrate`. Copying a live database and switching
+Migration and switching between Docker and native PostgreSQL are temporarily
+unavailable in Settings. `scripts/db.sh migrate` also refuses. Copying a live database and switching
mode can strand writes accepted after the snapshot. Backups and standalone
exports remain available; they do not make a new backend authoritative.
diff --git a/docs/STORAGE.md b/docs/STORAGE.md
index 49e069da4a..a2bb0e7816 100644
--- a/docs/STORAGE.md
+++ b/docs/STORAGE.md
@@ -203,8 +203,8 @@ The escape hatch is **guarded from bitrot by the test suite** (tests boot with `
### Moving between Docker and native
-Automatic backend migration is temporarily unavailable. Both the Settings
-migration request and `scripts/db.sh migrate` refuse before copying data or
+Automatic backend migration and switching are temporarily unavailable.
+The Settings switch/migration requests and `scripts/db.sh migrate` refuse before copying data or
changing mode. The former path could accept writes after its dump snapshot
and strand them on the source; changing `.env` also leaves the running server
connected to its original pool.
diff --git a/server/routes/database.test.js b/server/routes/database.test.js
index 76ade47910..59680b0cd1 100644
--- a/server/routes/database.test.js
+++ b/server/routes/database.test.js
@@ -106,13 +106,11 @@ describe('database route boundary', () => {
// Regression: an API migration must not start the unfenced snapshot/cutover,
// even for an older client that still exposes the migration button.
describe('database migration admission', () => {
- it.each(['docker', 'native'])('refuses repeated migrations to %s without side effects', async (target) => {
+ it.each([['docker', true], ['native', true], ['docker', false], ['native', false]])('refuses repeated cutovers to %s (migrate=%s) without side effects', async (target, migrate) => {
vi.clearAllMocks();
const app = makeApp();
- const io = { emit: vi.fn() };
- app.set('io', io);
for (let attempt = 0; attempt < 2; attempt++) {
- const res = await request(app).post('/api/database/switch').send({ target, migrate: true });
+ const res = await request(app).post('/api/database/switch').send({ target, migrate });
expect(res.status).toBe(409);
expect(res.body.code).toBe('DATABASE_CUTOVER_UNAVAILABLE');
expect(res.body.error).toMatch(/coordinated shutdown and restart/);
@@ -121,7 +119,6 @@ describe('database migration admission', () => {
expect(spawn).not.toHaveBeenCalled();
expect(query).not.toHaveBeenCalled();
expect(checkHealth).not.toHaveBeenCalled();
- expect(io.emit).not.toHaveBeenCalled();
});
});
diff --git a/server/services/dbAdmin.js b/server/services/dbAdmin.js
index 70c6fa8744..250671b508 100644
--- a/server/services/dbAdmin.js
+++ b/server/services/dbAdmin.js
@@ -225,42 +225,15 @@ export async function getStatus() {
}
/**
- * Switch database backends, optionally migrating data first.
+ * Backend changes require a coordinated stop and verified restart. Neither a
+ * snapshot nor a mode-only switch can rebind this process's existing pool.
*/
-async function switchDatabaseImpl({ target, migrate }, io) {
- const emit = (event, data) => io?.emit('database:progress', { event, ...data });
-
- if (migrate) {
- // A shell child cannot fence the CoS runner or rebind this server's pool.
- // Re-enable only with the durable, verified offline cutover in #8805.
- throw new ServerError(
- 'Database migration is temporarily unavailable: a coordinated shutdown and restart is required to preserve writes. Keep using the current backend; backups remain available.',
- { status: 409, code: 'DATABASE_CUTOVER_UNAVAILABLE' }
- );
- }
-
- // Just switch mode without migrating
- emit('start', { message: `Switching to ${target}...` });
- const switchResult = await runDbScript([target === 'docker' ? 'use-docker' : 'use-native']);
- if (switchResult.exitCode !== 0) {
- emit('error', { message: 'Switch failed' });
- throw new ServerError('Switch failed', {
- status: 500,
- context: { details: switchResult.stderr || switchResult.stdout }
- });
- }
-
- const startResult = await runDbScript(['start']);
- if (startResult.exitCode !== 0) {
- emit('error', { message: `Failed to start ${target} database` });
- throw new ServerError(`Failed to start ${target} database`, {
- status: 500,
- context: { details: startResult.stderr || startResult.stdout }
- });
- }
-
- emit('complete', { message: `Switched to ${target}` });
- return { success: true, output: switchResult.stdout + '\n' + startResult.stdout };
+async function switchDatabaseImpl() {
+ // Re-enable only with the durable, verified offline cutover in #8805.
+ throw new ServerError(
+ 'Database migration and switching are temporarily unavailable: a coordinated shutdown and restart is required to preserve writes. Keep using the current backend; backups remain available.',
+ { status: 409, code: 'DATABASE_CUTOVER_UNAVAILABLE' }
+ );
}
const pgUser = POOL_CONFIG.user;