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

address review (agy): a failed installer spawn no longer wedges every later install

[._.]/ Adam Eivy626a950429a6
diff --git a/server/routes/providers.js b/server/routes/providers.js
index 4d29b44029..e247e5b853 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -205,7 +205,20 @@ export function createPortOSProviderRoutes(aiToolkit) {
send({ type: 'stage', stage: 'install', message: `Installing ${runtime.label}.` });
emit({ type: 'log', message: `Running ${describeRuntimeInstall(runtime.id)}.` });
installLog.start();
- child = spawnRuntimeInstaller(runtime.id);
+ // `spawn` can throw synchronously (a rejected argv shape, an OS-level spawn
+ // refusal). Two things must happen here that letting it bubble would not do:
+ // release the reservation — or every later install answers "another install
+ // is already running" until PortOS restarts — and report the failure as a
+ // terminal SSE frame, since the headers are already flushed and the error
+ // middleware can no longer send JSON to this response.
+ try {
+ child = spawnRuntimeInstaller(runtime.id);
+ } catch (err) {
+ finished = true;
+ if (runtimeInstallInFlight === reservation) runtimeInstallInFlight = null;
+ emit({ type: 'error', message: `${runtime.label} installer failed to start: ${err.message}` });
+ return safeEnd();
+ }
runtimeInstallInFlight = child;
const onLine = (line) => {
diff --git a/server/routes/providers.runtimeInstall.test.js b/server/routes/providers.runtimeInstall.test.js
index 3188b521bb..e078bd530b 100644
--- a/server/routes/providers.runtimeInstall.test.js
+++ b/server/routes/providers.runtimeInstall.test.js
@@ -117,6 +117,31 @@ describe('Provider runtime installer routes', () => {
expect(installer.spawnRuntimeInstaller).not.toHaveBeenCalled();
});
+ // A synchronous spawn failure must report through the already-open stream and
+ // release the one-install-at-a-time lock — otherwise the client sees a
+ // truncated stream and every later install answers "another install is
+ // already running" until the server restarts.
+ it('reports a spawn failure as a stream error and releases the install lock', async () => {
+ installer.getProviderRuntimeStatus.mockResolvedValue(statusOf('codex'));
+ installer.spawnRuntimeInstaller.mockImplementationOnce(() => { throw new Error('spawn EAGAIN'); });
+
+ const failed = await request(app()).post('/api/providers/runtimes/install?runtime=codex');
+ expect(failed.status).toBe(200);
+ expect(failed.text).toContain('Codex CLI installer failed to start: spawn EAGAIN');
+
+ // A second attempt must reach the spawn again rather than being refused.
+ const child = makeChild();
+ installer.spawnRuntimeInstaller.mockReturnValueOnce(child);
+ const responsePromise = request(app()).post('/api/providers/runtimes/install?runtime=codex').then((response) => response);
+ await vi.waitFor(() => expect(installer.spawnRuntimeInstaller).toHaveBeenCalledTimes(2));
+ child.stdout.end();
+ child.stderr.end();
+ child.emit('close', 1);
+ const response = await responsePromise;
+
+ expect(response.text).not.toContain('Another runtime install is already running');
+ });
+
// The runtime is a request value, so an unknown id must be rejected before a
// child is spawned — the installer table is the only source of commands.
it('rejects an unknown runtime without probing or spawning', async () => {