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: fence database health probes during maintenance

[._.]/ Adam Eivyfe197626110f
diff --git a/server/lib/databaseMaintenanceJournal.test.js b/server/lib/databaseMaintenanceJournal.test.js
index ad18cdaa12..9afdf1323b 100644
--- a/server/lib/databaseMaintenanceJournal.test.js
+++ b/server/lib/databaseMaintenanceJournal.test.js
@@ -65,7 +65,7 @@ describe('persistent database maintenance boundary', () => {
}`);
const dbUrl = new URL('./db.js', import.meta.url).href;
const guardsUrl = new URL('../services/agentGuards.js', import.meta.url).href;
- const code = `import {query, withTransaction, withDatabaseMaintenance, ensureSchema} from ${JSON.stringify(dbUrl)};
+ const code = `import {query, withTransaction, withDatabaseMaintenance, ensureSchema, checkHealth} from ${JSON.stringify(dbUrl)};
import {withSpawnDedupGuard} from ${JSON.stringify(guardsUrl)};
const outcomes = [];
for (const call of [
@@ -75,12 +75,15 @@ describe('persistent database maintenance boundary', () => {
() => ensureSchema(),
() => withSpawnDedupGuard(new Set(), 'example', () => {throw Error('SPAWN_REACHED')})
]) { try { await call(); outcomes.push('unexpected'); } catch(e) {outcomes.push(e.code || e.message);} }
+ const health=await checkHealth();
+ if(health.connected || !health.error?.includes('Persistent database maintenance')) throw Error('HEALTH_BYPASSED');
+ outcomes.push('DATABASE_MAINTENANCE');
console.log(JSON.stringify(outcomes));`;
// A second invocation is a restarted process, not a module-cache reset.
for (let attempt = 0; attempt < 2; attempt++) {
const result = node(code, ['--loader', pathToFileURL(loader).href]);
expect(result.status, result.stderr).toBe(0);
- expect(JSON.parse(result.stdout.trim())).toEqual(Array(5).fill('DATABASE_MAINTENANCE'));
+ expect(JSON.parse(result.stdout.trim())).toEqual(Array(6).fill('DATABASE_MAINTENANCE'));
}
const bootUrl = new URL('../services/databaseBootFence.js', import.meta.url).href;
const boot = node(`try {await import(${JSON.stringify(bootUrl)}); process.exitCode=2;}
diff --git a/server/lib/db.js b/server/lib/db.js
index 3e9041e02d..62a7ad187a 100644
--- a/server/lib/db.js
+++ b/server/lib/db.js
@@ -343,14 +343,14 @@ export async function checkHealth() {
};
}
try {
- const result = await pool.query(`
+ const result = await databaseOperation(() => pool.query(`
SELECT
EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'memories') AS has_memories,
EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'memory_links') AS has_links,
EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = 'memories' AND column_name = 'sync_sequence') AS has_sync,
EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'catalog_ingredients') AS has_catalog,
EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'catalog_scraps') AS has_catalog_scraps
- `);
+ `));
const { has_memories, has_links, has_sync, has_catalog, has_catalog_scraps } = result.rows?.[0] ?? {};
return {
connected: true,