{"record":{"id":"b92fe34071e0ad3e","repo":"Fosowl/agenticSeek","slug":"str-e-connection-to-self-server-ip-failed","errorCode":null,"errorMessage":"{str(e)}\nConnection to {self.server_ip} failed.","messagePattern":"(.+?)\nConnection to (.+?) failed\\.","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":88,"sourceCode":"        load_dotenv()\n        url = os.getenv(\"DOCKER_INTERNAL_URL\")\n        if not url: # running on host\n            return \"http://localhost\", False\n        return url, True\n\n    def respond(self, history, verbose=True):\n        \"\"\"\n        Use the choosen provider to generate text.\n        \"\"\"\n        llm = self.available_providers[self.provider_name]\n        self.logger.info(f\"Using provider: {self.provider_name} at {self.server_ip}\")\n        try:\n            thought = llm(history, verbose)\n        except KeyboardInterrupt:\n            self.logger.warning(\"User interrupted the operation with Ctrl+C\")\n            return \"Operation interrupted by user. REQUEST_EXIT\"\n        except ConnectionError as e:\n            raise ConnectionError(f\"{str(e)}\\nConnection to {self.server_ip} failed.\")\n        except AttributeError as e:\n            raise NotImplementedError(f\"{str(e)}\\nIs {self.provider_name} implemented ?\")\n        except ModuleNotFoundError as e:\n            raise ModuleNotFoundError(\n                f\"{str(e)}\\nA import related to provider {self.provider_name} was not found. Is it installed ?\")\n        except Exception as e:\n            if \"try again later\" in str(e).lower():\n                return f\"{self.provider_name} server is overloaded. Please try again later.\"\n            if \"refused\" in str(e):\n                return f\"Server {self.server_ip} seem offline. Unable to answer.\"\n            raise Exception(f\"Provider {self.provider_name} failed: {str(e)}\") from e\n        return thought\n\n    def is_ip_online(self, address: str, timeout: int = 10) -> bool:\n        \"\"\"\n        Check if an address is online by sending a ping request.\n        \"\"\"\n        if not address:","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L70-L106","documentation":"In respond(), a ConnectionError raised while calling the provider's llm(history, verbose) is re-raised with an appended '\\nConnection to {self.server_ip} failed.' so the developer knows which endpoint was unreachable. It means the HTTP request to the LLM backend (local server or cloud endpoint) could not establish/receive a connection.","triggerScenarios":"Calling sync_llm_request/respond while the local inference server (e.g. Ollama, LM Studio) is not running or listening on a different port than self.server_ip; wrong host/port in provider config; server crashed mid-session; network/firewall blocking the endpoint; container networking where in_docker host resolution fails (get_internal_url picked the wrong URL).","commonSituations":"Forgetting to start `ollama serve` before running the agent; using localhost inside Docker when the server runs on the host; the model server bound to 127.0.0.1 while accessed from another container; wrong port after a version update of the local server.","solutions":["Start/verify the local LLM server and confirm it listens on the host:port in self.server_ip (curl the endpoint).","Correct the server IP/port configuration (get_internal_url result) for your environment, especially inside Docker (use host.docker.internal or the service name).","Read the original str(e) above the appended message — it contains the underlying request failure (refused/timeout/DNS).","Retry with backoff if the server was temporarily restarting; verify with the same URL from the same network context as the app."],"exampleFix":"// before\nprovider = LLMProvider(\"ollama\")  # server_ip points at localhost:11434 but nothing is listening\nresult = provider.respond(history)  # ConnectionError: ... Connection to 127.0.0.1 failed.\n// after (terminal)\n$ ollama serve &            # start the backend\n$ curl http://localhost:11434/api/tags  # verify reachable\nthen rerun provider.respond(history)","handlingStrategy":"retry","validationCode":"import socket\n\ndef server_reachable(host_port) -> bool:\n    host, port = host_port.rsplit(\":\", 1)\n    try:\n        with socket.create_connection((host, int(port)), timeout=3):\n            return True\n    except OSError:\n        return False\n\nassert server_reachable(provider.server_ip), f\"LLM server {provider.server_ip} is down\"","typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        return provider.respond(history)\n    except ConnectionError as e:\n        if attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","preventionTips":["Start the local LLM server (e.g. ollama serve) before launching the app; health-check it in a startup script.","In Docker, use host.docker.internal or the compose service name instead of localhost for self.server_ip.","Add exponential-backoff retries around respond() for transient connection drops.","Log provider.server_ip at startup and curl it once to confirm reachability in the same network context."],"tags":["network","connection","llm","http"],"backgroundTag":"connection-refused","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}