{"record":{"id":"3d469e577b2e5975","repo":"paperclipai/paperclip","slug":"could-not-allocate-a-free-loopback-port-for-a-mana","errorCode":null,"errorMessage":"Could not allocate a free loopback port for a managed runtime service after ${PORT_ALLOCATION_ATTEMPTS} attempts (last candidate ${lastCandidate}).","messagePattern":"Could not allocate a free loopback port for a managed runtime service after (.+?) attempts \\(last candidate (.+?)\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/workspace-runtime.ts","lineNumber":4519,"sourceCode":" * live process owns. Callers must {@link releasePortReservation} once the service either\n * reached a terminal state or bound the port itself.\n */\nexport async function allocateRuntimeServicePort(overrides?: {\n  probe?: () => Promise<number>;\n  portOwnerLookup?: (port: number) => Promise<number | null>;\n}): Promise<number> {\n  const probe = overrides?.probe ?? probeEphemeralPort;\n  const portOwnerLookup = overrides?.portOwnerLookup ?? readLocalServicePortOwner;\n  let lastCandidate: number | null = null;\n  for (let attempt = 0; attempt < PORT_ALLOCATION_ATTEMPTS; attempt += 1) {\n    const candidate = await probe();\n    lastCandidate = candidate;\n    if (!reservePortIfFree(candidate)) continue;\n    const ownerPid = await portOwnerLookup(candidate);\n    if (!ownerPid) return candidate;\n    releasePortReservation(candidate);\n  }\n  throw new Error(\n    `Could not allocate a free loopback port for a managed runtime service after ${PORT_ALLOCATION_ATTEMPTS} attempts`\n      + `${lastCandidate ? ` (last candidate ${lastCandidate})` : \"\"}.`,\n  );\n}\n\nfunction buildTemplateData(input: {\n  workspace: RealizedExecutionWorkspace;\n  agent: ExecutionWorkspaceAgentRef;\n  issue: ExecutionWorkspaceIssueRef | null;\n  adapterEnv: Record<string, string>;\n  port: number | null;\n}) {\n  return {\n    workspace: {\n      cwd: input.workspace.cwd,\n      branchName: input.workspace.branchName ?? \"\",\n      worktreePath: input.workspace.worktreePath ?? \"\",\n      repoUrl: input.workspace.repoUrl ?? \"\",","sourceCodeStart":4501,"sourceCodeEnd":4537,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/workspace-runtime.ts#L4501-L4537","documentation":"allocateRuntimeServicePort probed candidates for a free loopback port but every one of the PORT_ALLOCATION_ATTEMPTS candidates was owned by another local process. Port exhaustion or heavy port churn on the host prevents starting the managed service.","triggerScenarios":"Thrown at server/src/services/workspace-runtime.ts:4366 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Free up loopback ports used by other managed runtime services, then retry the start.","Configure an explicit free port for the service instead of relying on automatic allocation."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}