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: graceful shutdown handler, asyncHandler on systemHealth routes, iframe listener cleanup

Adam Eivy40705cd4725f
diff --git a/client/src/components/messages/MessageDetail.jsx b/client/src/components/messages/MessageDetail.jsx
index f7b6290499..bed4436a84 100644
--- a/client/src/components/messages/MessageDetail.jsx
+++ b/client/src/components/messages/MessageDetail.jsx
@@ -47,7 +47,7 @@ function SafeHtmlBody({ html }) {
};
resize();
// Resize again after images load
- doc.querySelectorAll('img').forEach(img => img.addEventListener('load', resize));
+ doc.querySelectorAll('img').forEach(img => img.addEventListener('load', resize, { once: true }));
}, [html]);
useEffect(() => {
diff --git a/server/index.js b/server/index.js
index 0ac3c6edf0..cd78a224a8 100644
--- a/server/index.js
+++ b/server/index.js
@@ -300,7 +300,7 @@ app.use('/api/openclaw', openclawRoutes);
// Initialize agent automation scheduler and action executor
automationScheduler.init().catch(err => console.error(`❌ Agent scheduler init failed: ${err.message}`));
-agentActionExecutor.init();
+agentActionExecutor.init().catch(err => console.error(`❌ agentActionExecutor init failed: ${err.message}`));
// Recover any inbox entries stuck in 'classifying' from a previous crash/restart
recoverStuckClassifications().catch(err => console.error(`❌ Brain recovery failed: ${err.message}`));
@@ -444,3 +444,21 @@ ensureSelf()
console.error(`❌ Instance init failed: ${err.message}`);
process.exit(1);
});
+
+let shuttingDown = false;
+const shutdown = async (signal) => {
+ if (shuttingDown) return;
+ shuttingDown = true;
+ console.log(`🛑 Received ${signal} - shutting down gracefully`);
+ httpServer.close(() => console.log('✅ HTTP server closed'));
+ try {
+ const { close } = await import('./lib/db.js');
+ if (typeof close === 'function') await close();
+ console.log('✅ DB pool closed');
+ } catch (err) {
+ console.error(`⚠️ Error during shutdown: ${err.message}`);
+ }
+ process.exit(0);
+};
+process.on('SIGTERM', () => shutdown('SIGTERM'));
+process.on('SIGINT', () => shutdown('SIGINT'));
diff --git a/server/routes/systemHealth.js b/server/routes/systemHealth.js
index 1a2309711e..c1f6e13733 100644
--- a/server/routes/systemHealth.js
+++ b/server/routes/systemHealth.js
@@ -7,10 +7,11 @@ import * as cos from '../services/cos.js';
import { getSelf } from '../services/instances.js';
import { checkHealth } from '../lib/db.js';
import { getCurrentVersion } from '../services/updateChecker.js';
+import { asyncHandler } from '../lib/errorHandler.js';
const router = Router();
-router.get('/health', async (req, res) => {
+router.get('/health', asyncHandler(async (req, res) => {
const [self, version] = await Promise.all([
getSelf().catch(() => null),
getCurrentVersion()
@@ -23,13 +24,13 @@ router.get('/health', async (req, res) => {
hostname: os.hostname(),
instanceId: self?.instanceId ?? null
});
-});
+}));
/**
* GET /api/system/health/details - Comprehensive system health summary
* Returns system metrics, app status, and CoS status for dashboard display
*/
-router.get('/health/details', async (req, res) => {
+router.get('/health/details', asyncHandler(async (req, res) => {
const startTime = Date.now();
// Gather data in parallel
@@ -207,6 +208,6 @@ router.get('/health/details', async (req, res) => {
cos: cosInfo,
database: dbHealth
});
-});
+}));
export default router;