{"record":{"id":"3f91faf5b0cb9b26","repo":"iflytek/astron-agent","slug":"mem0-request-failed","errorCode":null,"errorMessage":"Mem0 request failed","messagePattern":"Mem0 request failed","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/provider/Mem0MemoryProvider.java","lineNumber":163,"sourceCode":"\n    private String send(HttpRequest request) {\n        try {\n            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());\n            int statusCode = response.statusCode();\n            if (statusCode >= 200 && statusCode < 300) {\n                return StringUtils.defaultString(response.body());\n            }\n            throw new IllegalStateException(\"Mem0 request failed with HTTP \" + statusCode\n                    + \": \" + StringUtils.abbreviate(StringUtils.defaultString(response.body()), 300));\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new IllegalStateException(\"Mem0 request interrupted\", e);\n        } catch (java.io.IOException e) {\n            log.warn(\"Mem0 provider request failed: {}\", e.getMessage());\n            throw new IllegalStateException(\"Mem0 request failed\", e);\n        }\n    }\n\n    private List<AgentMemoryItem> parseItems(String responseBody) {\n        if (StringUtils.isBlank(responseBody)) {\n            return List.of();\n        }\n        JSONArray array = extractArray(responseBody);\n        if (array == null || array.isEmpty()) {\n            return List.of();\n        }\n        List<AgentMemoryItem> items = new ArrayList<>();\n        for (int i = 0; i < array.size(); i++) {\n            JSONObject item = array.getJSONObject(i);\n            if (item == null) {\n                continue;\n            }\n            String memory = firstString(item, \"memory\", \"text\", \"content\");\n            if (StringUtils.isBlank(memory)) {\n                continue;\n            }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/provider/Mem0MemoryProvider.java#L145-L181","documentation":"Mem0MemoryProvider wraps every I/O failure of its HTTP call to the Mem0 memory service in an IllegalStateException with the message \"Mem0 request failed\". It is thrown from the shared request method when OkHttp returns a java.io.IOException (connection failure, timeout, stream reset). The original IOException is chained as the cause, and the provider logs a warning before rethrowing.","triggerScenarios":"Any call through Mem0MemoryProvider's request path (e.g. add/search/delete memory operations) where httpClient execute() raises IOException: Mem0 endpoint unreachable, DNS failure, connection reset, TLS error, or read timeout.","commonSituations":"Mem0 service not running or wrong MEM0 base URL configured; network partition between console backend and Mem0; Mem0 restarted during a request; container DNS issues in docker-compose/Kubernetes environments; firewall blocking the port.","solutions":["Verify the Mem0 service is up and the configured base URL/port is correct (curl the Mem0 endpoint from the backend host).","Check network/firewall/DNS between console backend and Mem0 (docker network, k8s service name).","Inspect the chained cause (e.getCause()) for the concrete IOException to distinguish timeout vs connection refused.","Add or increase HTTP connect/read timeouts and a retry policy for transient network failures."],"exampleFix":"// before\nthrow new IllegalStateException(\"Mem0 request failed\", e);\n// after\n// keep the wrapper but surface the cause and retry transient failures\nlog.warn(\"Mem0 provider request failed: {}\", e.getMessage(), e);\nif (isTransient(e.getCause())) {\n    return retryOnce(request);\n}\nthrow new IllegalStateException(\"Mem0 request failed\", e);","handlingStrategy":"retry","validationCode":"// pre-check Mem0 reachability\nboolean reachable = new java.net.Socket().isConnected() || ping(mem0BaseUrl); // or use actuator/health endpoint\nif (!reachable) throw new IllegalStateException(\"Mem0 endpoint unreachable before request\");","typeGuard":null,"tryCatchPattern":"try {\n    mem0Provider.search(query);\n} catch (IllegalStateException e) {\n    if (e.getCause() instanceof java.io.IOException io && isTransient(io)) {\n        return retryWithBackoff(() -> mem0Provider.search(query), 3);\n    }\n    throw e;\n}","preventionTips":["Monitor Mem0 service health and alert on endpoint unavailability.","Configure explicit connect/read timeouts on the OkHttp client.","Use a service discovery name (k8s service / docker network alias) instead of hard-coded IPs.","Log the chained cause, not just getMessage()."],"tags":["network","http-client","mem0","io-exception"],"backgroundTag":"api-request-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}