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: give each boot smoke a kernel-assigned loopback port (#12543)

[._.]/ Adam Eivy42e4db3323bc
diff --git a/scripts/smoke-boot.js b/scripts/smoke-boot.js
index 709d67d913..31b354a9b1 100644
--- a/scripts/smoke-boot.js
+++ b/scripts/smoke-boot.js
@@ -101,11 +101,15 @@ export function buildSmokeEnv({ root, parentEnv = process.env }) {
TMP: tmp,
TEMP: tmp,
PGDATABASE: SMOKE_DATABASE,
- // Loopback only, on dedicated ports so a running PortOS instance doesn't
- // collide and nothing on the network can reach the throwaway server.
+ // Loopback only, so nothing on the network can reach the throwaway server.
+ // Port 0 lets the kernel pick a free port per child, so concurrent smokes
+ // (parallel worktree pregates, #12543) and a running install never share a
+ // listener; readiness arrives over this child's IPC, never a port probe.
+ // An explicit SMOKE_PORT / SMOKE_HTTP_PORT still pins one, and an empty
+ // value counts as unset rather than falling through to the production port.
HOST: '127.0.0.1',
- PORT: parentEnv.SMOKE_PORT ?? '55559',
- PORTOS_HTTP_PORT: parentEnv.SMOKE_HTTP_PORT ?? '55557',
+ PORT: parentEnv.SMOKE_PORT || '0',
+ PORTOS_HTTP_PORT: parentEnv.SMOKE_HTTP_PORT || '0',
NODE_OPTIONS: `${existingNodeOpts}--unhandled-rejections=strict`
};
}
@@ -150,7 +154,8 @@ export function monitorSmokeChild(child, {
if (phase !== 'startup' || message?.type !== 'portos:smoke-ready') return;
clearTimeout(timer);
phase = 'survival';
- console.log('🚀 Smoke child is ready; starting survival window.');
+ const where = Number.isInteger(message.port) ? ` on 127.0.0.1:${message.port}` : '';
+ console.log(`🚀 Smoke child is ready${where}; starting survival window.`);
timer = setTimeout(shutdown, windowMs);
};
const onExit = (code, signal) => {
diff --git a/scripts/smoke-boot.test.js b/scripts/smoke-boot.test.js
index e99dec2e02..f0d9bb38a2 100644
--- a/scripts/smoke-boot.test.js
+++ b/scripts/smoke-boot.test.js
@@ -61,6 +61,17 @@ describe('buildSmokeEnv', () => {
});
expect(SMOKE_DATABASE).toMatch(/_test$/);
});
+
+ // #12543: fixed default ports made parallel worktree pregates collide with
+ // EADDRINUSE; an empty override must not fall through to the production port.
+ it.each([
+ [{}, '0', '0'],
+ [{ SMOKE_PORT: '', SMOKE_HTTP_PORT: '' }, '0', '0'],
+ [{ SMOKE_PORT: '56001', SMOKE_HTTP_PORT: '56002' }, '56001', '56002']
+ ])('binds kernel-assigned loopback ports unless explicitly pinned (%o)', (overrides, port, httpPort) => {
+ const env = buildSmokeEnv({ root: join(tmpdir(), 'portos-smoke-example'), parentEnv: { PORT: '5555', ...overrides } });
+ expect(env).toMatchObject({ HOST: '127.0.0.1', PORT: port, PORTOS_HTTP_PORT: httpPort });
+ });
});
describe('createSmokeRoot', () => {
diff --git a/server/index.js b/server/index.js
index a695c683b3..9cfde156c5 100644
--- a/server/index.js
+++ b/server/index.js
@@ -572,7 +572,8 @@ getBuildIdentity().catch((err) => console.error(`❌ Build identity probe failed
registerShutdownHandlers({ io, httpServer, localHttpServer });
if (isSmokeBoot() && process.send) {
httpServer.once('listening', () => {
- process.send({ type: 'portos:smoke-ready' });
+ // The smoke binds port 0 (#12543); report the port the kernel assigned.
+ process.send({ type: 'portos:smoke-ready', port: httpServer.address()?.port });
});
}
diff --git a/server/services/bootstrap.js b/server/services/bootstrap.js
index 57c2f30a69..e817d41b76 100644
--- a/server/services/bootstrap.js
+++ b/server/services/bootstrap.js
@@ -869,7 +869,9 @@ const announceListening = ({ io, httpServer, localHttpServer, httpsEnabled, port
// One canonical "where do I open this" banner — :5555 is always user-facing
// (HTTP or HTTPS), :PORTOS_HTTP_PORT (default 5553) is the loopback HTTP
// mirror that only spawns when HTTPS is active. See docs/PORTS.md.
- console.log(`🚀 PortOS listening on :${port} (${httpsEnabled ? 'https' : 'http'})`);
+ // A smoke boot requests port 0 (#12543), so log the port actually bound.
+ const boundPort = httpServer.address()?.port ?? port;
+ console.log(`🚀 PortOS listening on :${boundPort} (${httpsEnabled ? 'https' : 'http'})`);
// Which code is up. One PM2-managed portos-server serves :5555 for the whole
// machine while any number of worktrees hold different code, so `pm2 logs
// portos-server` should answer "which commit is this?" without a request
@@ -901,11 +903,15 @@ const announceListening = ({ io, httpServer, localHttpServer, httpsEnabled, port
.catch((err) => logBootstrapFailure('❌ Build identity probe failed', err));
}
if (!httpsEnabled) {
- console.log(` 🌐 http://localhost:${port}`);
+ console.log(` 🌐 http://localhost:${boundPort}`);
console.log(`⚠️ HTTP only — getUserMedia (mic) won't work over Tailscale IP. Run "npm run setup:cert" to enable HTTPS.`);
return;
}
- const localHttpPort = Number(process.env.PORTOS_HTTP_PORT) || PORTS.API_LOCAL;
+ // Only the boot smoke may ask for a kernel-assigned mirror (#12543); elsewhere
+ // 0, empty or invalid keeps meaning the shipped default.
+ const localHttpPort = isSmokeBoot() && process.env.PORTOS_HTTP_PORT === '0'
+ ? 0
+ : Number(process.env.PORTOS_HTTP_PORT) || PORTS.API_LOCAL;
// Lead with the URL that works from THIS machine with no cert warnings:
// the loopback HTTP mirror. http://localhost:${port} does NOT work in
// HTTPS mode (the :${port} socket speaks TLS only), so local users who