Skip to content

Model fallback fails when session has modelOverride: LiveSessionModelSwitchError not recognized as failover error #58392

Closed

Description

@woaim65

Bug Description

The model fallback mechanism fails entirely when a session has a set (e.g., from a previous model selection). All 6 fallback candidates fail with errors like:

All models failed (6):
github/gpt-4.1: HTTP 404: 404 page not found (model_not_found)
minimax-portal/MiniMax-M2.7: Live session model switch requested: github/gpt-4.1 (unknown)
qiniu/qwen3.5-397b-a17b: Live session model switch requested: github/gpt-4.1 (unknown)
modelscope/deepseek-ai/DeepSeek-R1-0528: Live session model switch requested: github/gpt-4.1 (unknown)
...

Root Cause Analysis

Two related issues:

1. LiveSessionModelSwitchError not classified as failover error

In resolveFailoverReasonFromError(), LiveSessionModelSwitchError is not recognized as a failover-triggering error. The function checks for HTTP status codes and symbolic error codes, but LiveSessionModelSwitchError is neither — it is thrown from the embedded run loop when it detects a session model override that conflicts with the requested fallback model.

When coerceToFailoverError() returns null for this error, isKnownFailover = false, causing the fallback chain to throw immediately instead of continuing to the next candidate.

2. Session modelOverride not cleared on fallback

Even if LiveSessionModelSwitchError were properly classified, the session's modelOverride = github/gpt-4.1 persists across fallback attempts. Each fallback attempt re-reads the session store, sees the stale modelOverride, and throws the same error again. The fallback chain cannot make progress because the lock is never cleared.

Expected Behavior

  1. When a fallback candidate fails with LiveSessionModelSwitchError, it should be treated as a retryable failover error and the chain should continue to the next candidate.
  2. Alternatively, the session's modelOverride should be cleared when a fallback is triggered, so subsequent candidates use the default model.

Environment

  • OpenClaw version: 2026.3.28
  • Node.js: v22.22.1
  • Channel: Telegram
  • Models: minimax-portal/MiniMax-M2.7 (primary), github/gpt-4.1, qiniu/qwen3.5-397b-a17b, modelscope/DeepSeek-R1-0528, modelscope/DeepSeek-V3.2, nvidia/llama-3.3-70b-instruct

Activity

  1. jsompis commented on Mar 31, 2026

    @jsompis

    +1
    info agent/embedded {"subsystem":"agent/embedded"} live session model switch detected before attempt for fc95b21e-7946-42e9-bb44-a73f4734fae7: openai-codex/gpt-5.4 -> anthropic/claude-sonnet-4-6

  2. steipete commented on Apr 25, 2026

    @steipete
    Contributor

    Closing this as implemented after Codex review.

    Current main already addresses both parts of the report: fallback now treats LiveSessionModelSwitchError as a failover condition and continues the model chain, and session-scoped auto failover overrides are cleared so stale modelOverride values do not pin subsequent attempts to the wrong model.

    What I checked:

    • Fallback now normalizes live model switch errors: runWithModelFallback explicitly catches LiveSessionModelSwitchError, wraps it as a FailoverError, records the failed candidate, and continues to the next fallback candidate instead of rethrowing. (src/agents/model-fallback.ts:921)
    • Regression tests cover the reported fallback failure mode: There are dedicated tests asserting that LiveSessionModelSwitchError is treated as failover on the last candidate and that the fallback chain continues to the next candidate. (src/agents/model-fallback.test.ts:644)
    • Auto failover session override is now self-healed: createModelSelectionState detects direct session entries with modelOverrideSource === "auto", clears the stored override back to the configured default, and resets in-memory provider/model to the primary before allowlist validation or retry selection. (src/auto-reply/reply/model-selection.ts:173)
    • Regression tests cover stale auto override clearing: Tests assert that an auto failover override is cleared from session state, that the configured primary is retried, and that a preloaded fallback selection is reset in memory for the current turn. (src/auto-reply/reply/model-selection.test.ts:635)
    • Docs and release tag show the fix shipped: The docs now state that LiveSessionModelSwitchError is normalized into the failover path, and git grep against tag v2026.4.23 found the same model-fallback and model-selection fix blocks plus their regression tests in that release. Public docs: docs/concepts/model-failover.md. (docs/concepts/model-failover.md:258, a9797214338b)

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review notes: reviewed against 11ad1919edc7; fix evidence: release v2026.4.23.

  3. locked as resolved and limited conversation to collaborators on Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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