The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(server): persist worktree runtime port when ambient PORT does not match (#1849) (#1930)
Manav Shrivastavaebf2b8ff7904
diff --git a/server/src/worktree-config.ts b/server/src/worktree-config.tsindex 913451d0be..b05686204e 100644--- a/server/src/worktree-config.ts+++ b/server/src/worktree-config.ts@@ -650,6 +650,14 @@ export function maybeRepairLegacyWorktreeConfigAndEnvFiles(): {return { repairedConfig, repairedEnv };}+function isPortPinnedByRuntimeEnv(rawValue: string | null | undefined, selectedPort: number): boolean {+ const normalized = nonEmpty(rawValue);+ if (!normalized) return false;+ const parsedPort = Number(normalized);+ if (!Number.isInteger(parsedPort) || parsedPort <= 0) return true;+ return parsedPort === selectedPort;+}+export function maybePersistWorktreeRuntimePorts(input: {serverPort: number;databasePort?: number | null;@@ -667,7 +675,7 @@ export function maybePersistWorktreeRuntimePorts(input: {const { config, changed } = applyRuntimePortSelectionToConfig(fileConfig, {serverPort: input.serverPort,databasePort: input.databasePort,- allowServerPortWrite: !nonEmpty(process.env.PORT),+ allowServerPortWrite: !isPortPinnedByRuntimeEnv(process.env.PORT, input.serverPort),allowDatabasePortWrite: !nonEmpty(process.env.DATABASE_URL),});@@ -675,3 +683,4 @@ export function maybePersistWorktreeRuntimePorts(input: {writeConfigFile(context.configPath, config);}}+