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
fix([issue-4821]): stop PortOS's own PORT from leaking into the vLLM compose start
[._.]/ Adam Eivy5ee970fea229
diff --git a/server/lib/streamingSpawn.js b/server/lib/streamingSpawn.jsindex d3b84f4748..9604d655b2 100644--- a/server/lib/streamingSpawn.js+++ b/server/lib/streamingSpawn.js@@ -39,7 +39,14 @@ const CANCEL_POLL_MS = 1_000;* line readers — pass `/[\r\n]+/` for a tool whose progress bar redraws the* same line with a bare `\r`, so each redraw surfaces instead of the stream* going silent for the length of a multi-gigabyte download. `isCancelled` is- * polled while the command runs; see CANCEL_POLL_MS.+ * polled while the command runs; see CANCEL_POLL_MS. An unset `env` inherits+ * this whole process's environment — fine for most callers, but `docker+ * compose` substitutes `${VAR}` refs in a compose file from ITS OWN caller's+ * env before falling back to the project's `.env`, so a compose-based target+ * whose file happens to reuse a name PortOS also sets (`PORT` is the+ * recurring offender — see `services/vllmQwenManager.js#startVllmQwenProject`)+ * gets silently remapped. Audit a new docker-compose target's variable names+ * against `lib/ports.js` before assuming the default inheritance is safe.* @returns {Promise<{success: boolean, error?: string}>}*/export function runStreamingCommand(cmd, args, onLine, { timeoutMs = 0, cwd, env, spawnImpl = spawn, splitRe, isCancelled } = {}) {diff --git a/server/services/vllmQwenManager.js b/server/services/vllmQwenManager.jsindex ad3e8f9c6b..2a7a660bff 100644--- a/server/services/vllmQwenManager.js+++ b/server/services/vllmQwenManager.js@@ -30,6 +30,8 @@ import { join } from 'path';import { atomicWrite, formatBytes, tryReadFile } from '../lib/fileUtils.js';import { runStreamingCommand } from '../lib/streamingSpawn.js';import { findCommandOnPath } from '../lib/processEnv.js';+import { localEndpointPort } from '../lib/localProviderRuntime.js';+import { PORTS } from '../lib/ports.js';import {inspectVllmQwenProject,vllmProjectSetupState,@@ -264,20 +266,37 @@ export async function provisionVllmQwenProject({ emit, isCancelled }) {* `lib/vllmQwenProject.js` for why each refusal exists. No image build, no* weight download: those are `provisionVllmQwenProject`, behind their own button.*- * @param {{emit: (line: string) => void, isCancelled: () => boolean}} ctx+ * The compose file maps `"${PORT:-18020}:${PORT:-18020}"` and its healthcheck+ * probes `http://127.0.0.1:${PORT:-18020}/health` — both resolved by `docker+ * compose` from ITS OWN caller's environment, not from the project's `.env`+ * (shell env wins over `.env` in compose's variable-substitution precedence).+ * `runStreamingCommand` spawns `docker` inheriting the full PortOS server+ * environment by default, and PortOS's own `PORT` (its API server's port,+ * 5555) collides with the SAME variable name — so an unset `env` here silently+ * remaps the container onto PortOS's own port instead of vLLM's 18020, and the+ * readiness probe (hardcoded to 18020) then reports ECONNREFUSED forever, even+ * though the container is up and healthy. Confirmed on a real RTX 3090 run+ * (#4821) — `docker inspect` showed the resulting bind as literally invalid+ * (`{invalid IP 5555}`) rather than a working mapping on the wrong port.+ * Passing `PORT` explicitly, derived from the endpoint this checklist actually+ * probes, is what keeps compose's substitution aligned with it regardless of+ * whatever `PORT` PortOS's own process happens to be running under.+ *+ * @param {{emit: (line: string) => void, endpoint?: string, isCancelled: () => boolean}} ctx* @returns {Promise<{success: boolean, error?: string}>}*/-export async function startVllmQwenProject({ emit, isCancelled }) {+export async function startVllmQwenProject({ emit, endpoint, isCancelled }) {const project = await inspectVllmQwenProject();const blocked = vllmStartBlockedReason(project);if (blocked) return { success: false, error: blocked };if (isCancelled()) return { success: false, error: 'Cancelled before the container was started.' };+ const port = localEndpointPort(endpoint) || PORTS.VLLM_QWEN;emit(`Starting the vLLM container from ${project.dir} (${project.composeFile}).`);emit('The image and weights are already on disk — this only brings the service up.');return runStreamingCommand('docker',['compose', '--profile', 'single', 'up', '-d'],emit,- { timeoutMs: CONTROL_TIMEOUT_MS, cwd: project.dir },+ { timeoutMs: CONTROL_TIMEOUT_MS, cwd: project.dir, env: { PORT: String(port) } },);}diff --git a/server/services/vllmQwenManager.test.js b/server/services/vllmQwenManager.test.jsindex 6eba550971..d7078d32f9 100644--- a/server/services/vllmQwenManager.test.js+++ b/server/services/vllmQwenManager.test.js@@ -320,6 +320,34 @@ describe('startVllmQwenProject', () => {);});+ // Regression for #4821: the compose file maps "${PORT:-18020}:${PORT:-18020}"+ // and resolves that against docker's OWN caller environment, not the+ // project's .env — an unset `env` here lets PortOS's own PORT (its API+ // server's port, 5555 by default) leak into the child process and collide,+ // remapping the container onto the wrong port. Confirmed on a real RTX 3090+ // run: the resulting bind was literally invalid rather than just wrong.+ it('pins PORT to the vLLM loopback port so PortOS\'s own PORT cannot leak into compose', async () => {+ await startVllmQwenProject({ emit: () => {}, isCancelled: () => false });++ expect(streaming.runStreamingCommand).toHaveBeenCalledWith(+ 'docker',+ ['compose', '--profile', 'single', 'up', '-d'],+ expect.any(Function),+ expect.objectContaining({ env: { PORT: '18020' } }),+ );+ });++ it('derives PORT from a non-default endpoint rather than assuming 18020', async () => {+ await startVllmQwenProject({ emit: () => {}, endpoint: 'http://127.0.0.1:19999/v1', isCancelled: () => false });++ expect(streaming.runStreamingCommand).toHaveBeenCalledWith(+ 'docker',+ ['compose', '--profile', 'single', 'up', '-d'],+ expect.any(Function),+ expect.objectContaining({ env: { PORT: '19999' } }),+ );+ });+it('refuses to run compose when the project is not demonstrably prepared', async () => {project.vllmStartBlockedReason.mockReturnValue('no Qwen weights are cached yet');