Skip to content

[Critical Bug] Session Model Override Prevents Fallback Mechanism #58496

Description

@Jiangqi-7

Bug Report: Session Model Override Prevents Fallback Mechanism

Summary

Critical Bug: Session-level model override (providerOverride/modelOverride) prevents fallback mechanism from working when primary model encounters rate limits (429 errors). This causes the system to enter a dead loop where fallback attempts are blocked by session model override, rendering the agent unusable.

Environment

  • OpenClaw Version: Latest (as of 2026-03-31)
  • OS: Linux WSL2
  • Node: v24.14.0
  • Model Provider: volcengine-plan/glm-4.7 (primary), llama/qwen3.5-9b (fallback 1), deepseek/deepseek-chat (fallback 2)

Problem Description

When the primary model (volcengine-plan/glm-4.7) encounters rate limits (429 errors), the fallback mechanism attempts to switch to backup models. However, session model override (providerOverride/modelOverride stored in session state) blocks this switch, causing a dead loop:

  1. Primary model fails with 429 rate limit
  2. System attempts to fallback to llama/qwen3.5-9b
  3. resolveLiveSessionModelSelection() detects session has volcengine-plan/glm-4.7 override
  4. System throws LiveSessionModelSwitchError and forces switch back to primary model
  5. Primary model still has rate limit → repeat from step 2

Evidence

1. Error Logs (Detailed)

Rate Limit Error:

⚠️ API rate limit reached. Please try again later.
429 Requests are too frequent. Please reduce your request frequency
429 You have exceeded the 5-hour usage quota. It will reset at 2026-04-01 00:31:32 +0800 CST.

Fallback Attempts Blocked by Session Model Override:

"live session model switch detected before attempt for 73b0ad9b-b1e0-4073-a8fc-8fbc0598722b: llama/qwen3.5-9b -> volcengine-plan/glm-4.7"
"live session model switch detected before attempt for 73b0ad9b-b1e0-4073-a8fc-8fbc0598722b: deepseek/deepseek-chat -> volcengine-plan/glm-4.7"

2. Session State (sessions.json)

{
  "agent:main:feishu:direct:ou_280e9cf79ba5eb54f1478e545aa29d9a": {
    "sessionId": "73b0ad9b-b1e0-4073-a8fc-8fbc0598722b",
    "updatedAt": 1774971555933,
    "modelProvider": "volcengine-plan",
    "model": "glm-4.7",
    "provider": "volcengine-plan",
    "model": "glm-4.7",
    "status": "failed",
    "startedAt": 1774970111377,
    "totalTokensFresh": false
  }
}

Code Analysis

Relevant Code Location

File: /usr/local/nodejs/lib/node_modules/openclaw/dist/auth-profiles-B5ypC5S-.js

1. resolveLiveSessionModelSelection() Function (Lines 161503-161518)

function resolveLiveSessionModelSelection(params) {
  const sessionKey = params.sessionKey?.trim();
  const cfg = params.cfg;
  if (!cfg || !sessionKey) return null;
  
  const agentId = params.agentId?.trim();
  const defaultModelRef = agentId ? resolveDefaultModelForAgent({
    cfg,
    agentId
  }) : {
    provider: params.defaultProvider,
    model: params.defaultModel
  };
  
  const entry = loadSessionStore(resolveStorePath(cfg.session?.store, { agentId }), { skipCache: true })[sessionKey];
  const provider = entry?.providerOverride?.trim() || defaultModelRef.provider;
  const model = entry?.modelOverride?.trim() || defaultModelRef.model;
  const authProfileId = entry?.authProfileId?.trim() || void 0;
  // ... rest of function
}

2. Live Session Model Switch Detection (Lines 169324-169327)

const nextSelection = resolvePersistedLiveSelection();
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
  log$41.info(`live session model switch detected before attempt for ${params.sessionId}: ${provider}/${modelId} -> ${nextSelection.provider}/${nextSelection.model}`);
  throw new LiveSessionModelSwitchError(nextSelection);
}

Root Cause Analysis

Priority Conflict

  1. Session Model Override Priority: Intended for user-initiated model switches (should be remembered)
  2. Fallback Mechanism Priority: Intended for error recovery (should override user preference when primary model fails)
  3. Current Implementation: Session override has higher priority than fallback, causing dead loop

Proposed Solutions

Solution 1: Priority Adjustment (Recommended)

Modify resolveLiveSessionModelSelection() to ignore session override during fallback scenarios:

function resolveLiveSessionModelSelection(params) {
  // ... existing code ...
  
  // Check if this is a fallback scenario
  const isFallback = params.context?.isFallback || 
                     params.cfg?.currentAttempt?.isFallbackRetry ||
                     params.cfg?.lastError?.code === 429; // Rate limit
  
  // During fallback, ignore session override
  if (isFallback) {
    return {
      provider: params.defaultProvider,
      model: params.defaultModel,
      authProfileId: void 0,
      authProfileIdSource: void 0
    };
  }
  
  // Normal logic...
  const entry = loadSessionStore(resolveStorePath(cfg.session?.store, { agentId }), { skipCache: true })[sessionKey];
  // ... rest of function
}

Test Case

Steps to Reproduce

  1. Configure primary model with rate limits (e.g., volcengine-plan with 5-hour quota)
  2. Configure fallback models in openclaw.json
  3. Start agent and use until primary model hits rate limit
  4. Observe in logs:
    • 429 rate limit errors
    • Fallback attempts to backup models
    • "live session model switch detected" errors
    • System enters dead loop

Expected Behavior

  • System detects rate limit on primary model
  • Successfully switches to first fallback model (llama/qwen3.5-9b)
  • Agent continues functioning with fallback model

Actual Behavior

  • System detects rate limit
  • Attempts to switch to fallback model
  • Session model override blocks the switch
  • System forces switch back to primary model
  • Primary model still has rate limit
  • Repeat indefinitely → dead loop
  • Agent becomes completely unusable

Recommendation

Immediate Action Required

Implement Solution 1 (Priority Adjustment) as it:

  1. Preserves intent: Session override still works for user-initiated switches
  2. Fixes critical bug: Allows fallback during errors
  3. Minimal changes: Small code modification
  4. Backward compatible: Doesn't break existing functionality

Reported by: jiuchengba
Date: 2026-03-31
Priority: Critical
Status: New
Version: OpenClaw Latest
Related Components: auth-profiles, session management, model selection

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