Skip to content

[Bug]: active-memory plugin infinite retry on API timeout causes token waste #74054

Description

@ariesy

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

When using xiaomi/mimo-v2-flash model with the active-memory plugin, API calls frequently timeout (15s threshold), but the plugin continues to retry indefinitely without any retry limit configuration. This causes:

  1. Token waste (API requests are sent and tokens consumed even on timeout)
  2. Context overflow when messages pile up
  3. Stuck sessions that remain in processing state for 10+ minutes

Steps to reproduce

  1. Configure OpenClaw with a slow-responding model (e.g., xiaomi/mimo-v2-flash with 15s+ response times)
  2. Enable active-memory plugin with default settings
  3. Have multiple conversations that trigger active-memory recall
  4. Observe repeated timeout events in gateway logs
  5. Check token usage - tokens are consumed despite timeouts

Expected behavior

When an API call times out:

  1. The plugin should stop retrying after a configurable number of attempts
  2. Token consumption should be minimized on timeout
  3. The system should gracefully degrade (skip memory recall) instead of infinite retry

Actual behavior

  1. No retry limit: The agent-runner layer retries indefinitely on timeout
  2. Token waste: Each timeout still consumes tokens (API request is sent)
  3. Context overflow: Messages pile up during retry loops, causing Context overflow: estimated context size exceeds safe threshold
  4. Stuck sessions: Sessions remain in processing state for 10+ minutes
  5. No circuit breaker: No mechanism to stop retries after repeated failures

OpenClaw version

2026.4.26 (be8c246)

Install method

npm global

Model

xiaomi/mimo-v2-flash

Provider / routing chain

openclaw -> xiaomi (direct API)

Additional provider/model setup details

"active-memory": {
  "enabled": true,
  "config": {
    "agents": ["main"],
    "queryMode": "recent",
    "promptStyle": "balanced",
    "maxSummaryChars": 220,
    "logging": true,
    "timeoutMs": 15000
  }
}

Logs, screenshots, and evidence

API Timeout Events

[02:16:05.824] active-memory: agent=main session=agent:main:main 
               activeProvider=xiaomi activeModel=mimo-v2-flash 
               start timeoutMs=15000 queryChars=962

[02:16:24.172] active-memory: agent=main session=agent:main:main 
               activeProvider=xiaomi activeModel=mimo-v2-flash 
               done status=timeout elapsedMs=18350 summaryChars=0
[03:01:58.709] active-memory: agent=main session=... 
               activeProvider=xiaomi activeModel=mimo-v2-flash 
               start timeoutMs=15000 queryChars=434

[03:02:33.908] active-memory: agent=main session=... 
               activeProvider=xiaomi activeModel=mimo-v2-flash 
               done status=timeout elapsedMs=35201 summaryChars=0

Context Overflow

[03:06:57.804] [context-overflow-diag] sessionKey=agent:main:feishu:group:... 
               provider=xiaomi/mimo-v2-flash 
               source=assistantError 
               messages=116 
               error=Context overflow: estimated context size exceeds safe threshold during tool loop

Stuck Session

[03:15:46] stuck session: sessionId=main 
           sessionKey=agent:main:feishu:group:... 
           state=processing 
           age=493s (8+ minutes)

[03:17:46] stuck session: ... age=613s (10+ minutes)

Token Consumption

  • Timeout rate: 100% (4/4 calls timed out)
  • Average response time: 20.89s (threshold: 15s)
  • Longest response: 35.20s (135% over threshold)
  • Estimated token waste: Hundreds of thousands of tokens

Impact and severity

Affected: All users using slow-responding models with active-memory plugin

Severity: High

  • Token waste (direct cost impact)
  • Session stuck (blocks user interactions)
  • Context overflow (degrades system stability)

Frequency: 100% timeout rate observed during testing

Consequence:

  • Unnecessary token consumption
  • Poor user experience (long waits, no responses)
  • System instability (stuck sessions, context overflow)

Additional information

Root Cause Analysis

From source code analysis (/dist/extensions/active-memory/index.js):

  1. Plugin has no retry limit configuration: The plugin only handles single-call timeout (15s), returns status: "timeout", and does not retry internally.

  2. Agent-runner layer has no retry limit: When active-memory times out, the agent-runner triggers failover decisions but has no configurable retry limit.

  3. Token already consumed on timeout: The API request is sent and tokens are consumed even when the response times out.

Suggested Fixes

  1. Add retry limit configuration: Add maxRetries config option to active-memory plugin (e.g., 0-3 retries)

  2. Add circuit breaker: Stop retries after N consecutive failures

  3. Add timeout-aware token tracking: Track and report token consumption on timeout

  4. Improve timeout handling: Cancel API request on client-side timeout to potentially save tokens

Temporary Workaround

Disable active-memory plugin or use a faster model:

"active-memory": {
  "enabled": false
}

Or configure with a faster fallback model:

"active-memory": {
  "config": {
    "model": "deepseek/deepseek-v4-flash",
    "modelFallback": "deepseek/deepseek-v4-flash"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions