iflytek/astron-agent · error · IllegalStateException

Mem0 request failed

Error message

Mem0 request failed

What it means

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.

Solutions

  1. Verify the Mem0 service is up and the configured base URL/port is correct (curl the Mem0 endpoint from the backend host).
  2. Check network/firewall/DNS between console backend and Mem0 (docker network, k8s service name).
  3. Inspect the chained cause (e.getCause()) for the concrete IOException to distinguish timeout vs connection refused.
  4. Add or increase HTTP connect/read timeouts and a retry policy for transient network failures.

Example fix

// before
throw new IllegalStateException("Mem0 request failed", e);
// after
// keep the wrapper but surface the cause and retry transient failures
log.warn("Mem0 provider request failed: {}", e.getMessage(), e);
if (isTransient(e.getCause())) {
    return retryOnce(request);
}
throw new IllegalStateException("Mem0 request failed", e);
Defensive patterns

Strategy: retry

Validate before calling

// pre-check Mem0 reachability
boolean reachable = new java.net.Socket().isConnected() || ping(mem0BaseUrl); // or use actuator/health endpoint
if (!reachable) throw new IllegalStateException("Mem0 endpoint unreachable before request");

Try / catch

try {
    mem0Provider.search(query);
} catch (IllegalStateException e) {
    if (e.getCause() instanceof java.io.IOException io && isTransient(io)) {
        return retryWithBackoff(() -> mem0Provider.search(query), 3);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/3f91faf5b0cb9b26. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/provider/Mem0MemoryProvider.java:163

    private String send(HttpRequest request) {
        try {
            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
            int statusCode = response.statusCode();
            if (statusCode >= 200 && statusCode < 300) {
                return StringUtils.defaultString(response.body());
            }
            throw new IllegalStateException("Mem0 request failed with HTTP " + statusCode
                    + ": " + StringUtils.abbreviate(StringUtils.defaultString(response.body()), 300));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException("Mem0 request interrupted", e);
        } catch (java.io.IOException e) {
            log.warn("Mem0 provider request failed: {}", e.getMessage());
            throw new IllegalStateException("Mem0 request failed", e);
        }
    }

    private List<AgentMemoryItem> parseItems(String responseBody) {
        if (StringUtils.isBlank(responseBody)) {
            return List.of();
        }
        JSONArray array = extractArray(responseBody);
        if (array == null || array.isEmpty()) {
            return List.of();
        }
        List<AgentMemoryItem> items = new ArrayList<>();
        for (int i = 0; i < array.size(); i++) {
            JSONObject item = array.getJSONObject(i);
            if (item == null) {
                continue;
            }
            String memory = firstString(item, "memory", "text", "content");
            if (StringUtils.isBlank(memory)) {
                continue;
            }

View on GitHub (pinned to 5e758547a8)