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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
guard the apps launch spawns against an unlistened child 'error' event
[._.]/ Adam Eivyb9f78034d864
diff --git a/server/routes/apps/launch.js b/server/routes/apps/launch.jsindex 1a90fd5d22..790738ceeb 100644--- a/server/routes/apps/launch.js+++ b/server/routes/apps/launch.js@@ -18,21 +18,34 @@ import { loadApp, pathExists } from './shared.js';const router = Router();/**- * Hand a path to the OS's default handler, detached. `open`/`explorer`/`xdg-open`- * all take the path as their only argument, so folder-opening and- * project-opening share this one launcher.+ * Spawn a detached launcher and drop it. Every launch route responds as soon as+ * the child is handed off, so a spawn failure (binary missing, no desktop+ * session) has no request left to fail — but an unlistened `error` event on a+ * ChildProcess is an uncaught exception that takes the server down, so it is+ * logged instead.+ */+function spawnDetached(cmd, args, options = {}) {+ const child = spawn(cmd, args, {+ detached: true,+ stdio: 'ignore',+ windowsHide: true,+ ...options+ });+ child.on('error', (err) => console.error(`❌ Failed to launch '${cmd}': ${err.message}`));+ child.unref();+}++/**+ * Hand a path to the OS's default handler. `open`/`explorer`/`xdg-open` all take+ * the path as their only argument, so folder-opening and project-opening share+ * this one launcher.*/function openWithSystemHandler(targetPath) {const cmd = process.platform === 'darwin'? 'open': process.platform === 'win32' ? 'explorer' : 'xdg-open';- const child = spawn(cmd, [targetPath], {- detached: true,- stdio: 'ignore',- windowsHide: true- });- child.unref();+ spawnDetached(cmd, [targetPath]);}// Allowlist of safe editor commands@@ -96,14 +109,10 @@ router.post('/:id/open-editor', loadApp, asyncHandler(async (req, res) => {// `cursor.cmd`) which Node refuses to spawn without a shell since 20.12.2 — so we// opt into the shell on win32. Args are pre-sanitized for shell metacharacters// above, and the command is allowlisted.- const child = spawn(cmd, args, {+ spawnDetached(cmd, args, {cwd: app.repoPath,- detached: true,- stdio: 'ignore',- shell: process.platform === 'win32',- windowsHide: true+ shell: process.platform === 'win32'});- child.unref();res.json({ success: true, command: editorCommand, path: app.repoPath });}));@@ -118,14 +127,10 @@ router.post('/:id/open-claude', loadApp, asyncHandler(async (req, res) => {// shell:true on Windows so `claude.cmd` resolves (see open-editor above for the// Node 20.12.2 rationale). No user args reach the command line here.- const child = spawn('claude', [], {+ spawnDetached('claude', [], {cwd: app.repoPath,- detached: true,- stdio: 'ignore',- shell: process.platform === 'win32',- windowsHide: true+ shell: process.platform === 'win32'});- child.unref();console.log(`🤖 Opened Claude Code in ${app.name}`);res.json({ success: true, path: app.repoPath });diff --git a/server/routes/apps/launch.test.js b/server/routes/apps/launch.test.jsindex 5587b51523..f1678f6fce 100644--- a/server/routes/apps/launch.test.js+++ b/server/routes/apps/launch.test.js@@ -22,7 +22,7 @@ vi.mock('fs/promises', async (importOriginal) => ({vi.mock('child_process', async (importOriginal) => ({...(await importOriginal()),- spawn: vi.fn(() => ({ unref: vi.fn() }))+ spawn: vi.fn(() => ({ on: vi.fn(), unref: vi.fn() }))}));import * as appsService from '../../services/apps.js';@@ -108,6 +108,22 @@ describe('Apps Launch Routes — POST /:id/open-xcode', () => {expect(deriveProjectInfo).not.toHaveBeenCalled();});+ it('logs a launcher failure instead of letting the unlistened error event kill the process', async () => {+ deriveProjectInfo.mockResolvedValue({ targetName: 'MyClient', bundleId: 'com.example.MyClient' });+ existingPaths(REPO_PATH, join(REPO_PATH, 'MyClient.xcodeproj'));+ const handlers = {};+ spawn.mockReturnValue({ on: (event, fn) => { handlers[event] = fn; }, unref: vi.fn() });+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});++ const response = await request(app).post('/api/apps/app-001/open-xcode');++ expect(response.status).toBe(200);+ expect(handlers.error).toBeTypeOf('function');+ handlers.error(new Error('spawn ENOENT'));+ expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('spawn ENOENT'));+ consoleError.mockRestore();+ });+it('returns 404 when the app does not exist', async () => {appsService.getAppById.mockResolvedValue(null);