{"record":{"id":"8355edf293275e05","repo":"thedotmack/claude-mem","slug":"claude-mem-host-observer-port-configuredraw-is","errorCode":null,"errorMessage":"CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.","messagePattern":"CLAUDE_MEM_HOST_OBSERVER_PORT=(.+?) is not a valid port\\. Set it to the port your OpenAI-compatible observer already listens on\\.","errorType":"exception","errorClass":"HostObserverUnavailableError","httpStatus":null,"severity":"error","filePath":"src/npx-cli/cmem-memory-credentials.ts","lineNumber":237,"sourceCode":"    };\n  }\n\n  return null;\n}\n\n/** Atomically move staged/current credentials into the active provider slot. */\n\nexport function resolveHostObserverPort(\n  workerPort: string | number | undefined,\n  env: NodeJS.ProcessEnv = process.env,\n  probe: HostObserverPortProbe = probeHostObserverPortSync,\n): string {\n  const worker = parsePort(typeof workerPort === 'number' ? workerPort : nonEmptyString(workerPort));\n  const configuredRaw = nonEmptyString(env.CLAUDE_MEM_HOST_OBSERVER_PORT);\n  if (configuredRaw) {\n    const configured = parsePort(configuredRaw);\n    if (configured == null) {\n      throw new HostObserverUnavailableError(\n        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.`,\n      );\n    }\n    if (worker != null && configured === worker) {\n      throw new HostObserverUnavailableError(\n        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} is the claude-mem worker port. Point it at your OpenAI-compatible observer instead.`,\n      );\n    }\n    const status = probe(configured);\n    if (status === 'observer') return String(configured);\n    if (status === 'occupied') {\n      throw new HostObserverUnavailableError(\n        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} is occupied by a process that is not an OpenAI-compatible observer. Stop that process or point CLAUDE_MEM_HOST_OBSERVER_PORT at your observer.`,\n      );\n    }\n    throw new HostObserverUnavailableError(\n      `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} has nothing listening. Start your OpenAI-compatible observer on that port, then rerun with --provider host.`,\n    );","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/npx-cli/cmem-memory-credentials.ts#L219-L255","documentation":"Host observer mode connects to an OpenAI-compatible server you already run, identified by CLAUDE_MEM_HOST_OBSERVER_PORT. resolveHostObserverPort parses that env var as a TCP port; if it is non-empty but not a valid port number (e.g. non-numeric, out of range), it throws HostObserverUnavailableError. The library refuses to guess which port you meant.","triggerScenarios":"Running `cmem memory` / install with --provider host while CLAUDE_MEM_HOST_OBSERVER_PORT is set to something parsePort() rejects: e.g. 'abc', 'http://localhost:8080', '99999', or a value with whitespace.","commonSituations":"Typos in shell profiles; pasting a full URL into a port variable; setting a port above 65535; exporting the variable with a trailing comment or unit suffix.","solutions":["Set CLAUDE_MEM_HOST_OBSERVER_PORT to a plain integer between 1 and 65535, e.g. export CLAUDE_MEM_HOST_OBSERVER_PORT=4141.","Verify the value with `echo \"$CLAUDE_MEM_HOST_OBSERVER_PORT\"` and unset it if you don't need an explicit port (auto-discovery will then run).","Check where it is exported (shell rc, .env, launchd/systemd unit) and correct it there."],"exampleFix":"// before\nexport CLAUDE_MEM_HOST_OBSERVER_PORT=http://localhost:8080\n// after\nexport CLAUDE_MEM_HOST_OBSERVER_PORT=8080","handlingStrategy":"validation","validationCode":"const raw = process.env.CLAUDE_MEM_HOST_OBSERVER_PORT;\nif (raw && !/^(\\d{1,5})$/.test(raw.trim())) throw new Error(`CLAUDE_MEM_HOST_OBSERVER_PORT=${raw} is not a valid port`);\nif (raw) { const n = Number(raw); if (!(n >= 1 && n <= 65535)) throw new Error(`port ${raw} out of range`); }","typeGuard":"const isPort = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535;","tryCatchPattern":"try { const port = resolveHostObserverPort(workerPort); } catch (e) { if (e instanceof HostObserverUnavailableError && /not a valid port/.test(e.message)) { delete process.env.CLAUDE_MEM_HOST_OBSERVER_PORT; /* retry with discovery */ } else throw e; }","preventionTips":["Store only bare integers in port env vars, never URLs","Check shell rc files for typos after editing","Validate env at process startup with a small config schema"],"tags":["configuration","env-var","port-validation"],"backgroundTag":"invalid-env-var-value","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}