Skip to content

feat(compaction): add modelFallbacks for compaction model resolution#1211

Open
BingqingLyu wants to merge 1 commit into
mainfrom
fork-pr-52012-feat-compaction-model-fallbacks
Open

feat(compaction): add modelFallbacks for compaction model resolution#1211
BingqingLyu wants to merge 1 commit into
mainfrom
fork-pr-52012-feat-compaction-model-fallbacks

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Closes openclaw#52011

Summary

When the primary compaction model override is unreachable (e.g. a local vLLM server is down), compaction currently fails immediately. This adds a modelFallbacks array to AgentCompactionConfig that allows specifying fallback models tried in order before giving up.

Changes

  • src/config/types.agent-defaults.ts: Add modelFallbacks?: string[] to AgentCompactionConfig
  • src/agents/pi-embedded-runner/compact.ts: When primary resolveModelAsync fails, iterate through configured fallbacks. Auth profile is reset when fallback provider differs from primary.
  • docs/concepts/compaction.md: Document the new config option with examples

Config Example

{
  "agents": {
    "defaults": {
      "compaction": {
        "model": "vllm/qwen3-coder-next",
        "modelFallbacks": ["anthropic/claude-haiku-4-5"]
      }
    }
  }
}

Testing

  • When modelFallbacks is unset: no behavior change (backward compatible)
  • When primary model resolves: fallbacks are never tried
  • When primary model fails + fallbacks configured: tries each in order, uses first that resolves
  • When all fail: returns the original error (same as current behavior)

Adds modelFallbacks?: string[] to AgentCompactionConfig. When the
primary compaction model fails (resolution, auth, or runtime), each
fallback is tried in order before giving up.

Changes:
- types.agent-defaults.ts: add modelFallbacks?: string[]
- zod-schema.agent-defaults.ts: add modelFallbacks schema
- compact.ts:
  - Model resolution fallback loop (primary model not in registry)
  - Auth fallback loop with tryAuthForModel returning hasExchange
  - Runtime fallback loop: on session.compact() throw, retry with full
    re-resolve + re-auth + createAgentSession per fallback
  - fbEffectiveModel now passes through applyLocalNoAuthHeaderOverride
    and applyAuthHeaderOverride using fbKeyInfo/fbHasExchange (P1 fix)
  - tryCompactWithModel disposes fbSession in finally block (P2 fix)
  - All error messages surface tried models list
  - Backward compatible when modelFallbacks is unset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: compaction model fallbacks when primary model is unreachable

2 participants