Skip to content

UMO 专属配置的 max_context_length 不生效,or 短路导致永远走全局配置 #9573

Description

@vcvcvcvcvcvcvcvcvc

Bug 描述

在 WebUI 中为某个会话单独设置 max_context_length(压缩前最多保留对话轮数),该设置不生效。实际上下文无限增长。

版本

AstrBot v4.27.2 (Docker)

根因

astrbot/core/astr_main_agent.py_decorate_llm_request() 函数中:

cfg = config.provider_settings or plugin_context.get_config(
    umo=event.unified_msg_origin
).get("provider_settings", {})

使用了 or 短路逻辑。全局 provider_settings 永远是非空 dict,因此 plugin_context.get_config(umo=...) 永远不会执行,UMO 专属配置被跳过。

实际影响

  • UMO 级 max_context_length 设置无效
  • 上下文无限堆积(实测 94K tokens,202 轮历史消息)
  • LLM API 响应延迟严重(单次 50-60 秒)
  • 即使全局设为 -1,用户也无法通过 UMO 配置覆盖

修复建议

改为 merge 而非短路:

global_cfg = config.provider_settings or {}
umo_cfg = plugin_context.get_config(umo=event.unified_msg_origin).get("provider_settings", {})
cfg = {**global_cfg, **umo_cfg}  # UMO 覆盖全局

备注

疑似近期更新引入(仓库迁移前旧版本 UMO 配置正常生效)。


🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions