Skip to content

运行容量把其它程序的内存占用算进「内存紧张」,编译 Rust 时网关整片 503(且设置里关不掉) #653

Open

Description

@isee22

现象

编译 Rust 或机器上跑着别的吃内存程序时,经网关的所有对话请求(Claude Code 等客户端)整片返回 503,文案是:

API Error: 503 系统或容器可用内存紧张,排队等待已结束,请稍后重试

而网关进程本身只占几百 MB,没有任何异常。同机实测:总内存 15.94 GB、可用 2.14 GB(13.5%),真正吃内存的是 rustc 3.2 GB + cargo 137 MB。

原因

core/runtime_capacity 的内存压力判据是:

  • 系统可用内存 < 总内存 10%;
  • 或本进程 / 容器占用 ≥ 总内存 4/5。

命中任一条,Class::Conversation | Request 类请求不再进入排队,而是等满「最长排队时间」(默认 10 秒)后返回 503(memory_pressure,Retry-After: 2)。

第一条判据把「别人的程序占了多少内存」算到网关头上:只要整机可用内存被压到 10% 以下,一个自身占用很小的网关就被判定为「内存紧张」并拒绝服务。而网关实际能用多少内存本来就由它自己的分配预算(MemoryBudget)卡住,系统层面再拦一道只会误伤。

另外,这个行为在设置里关不掉:运行容量 的 mode(自动 / 手动)只影响并发上限的算法,两条内存压力判据都照旧生效,面板上也没有对应开关。

期望

  • 内存压力只看网关自己:自身占用超过「运行内存预算」(设置项)才算紧张;总内存 4/5 的硬顶保留,防的是真正的 OOM;macOS 内核 critical 等级同样按开关处理。
  • 系统可用内存比例不再参与判定 —— 编译、浏览器、其它容器占多少内存不影响网关接单。
  • 设置 → 运行容量 增加「内存紧张保护」开关(默认开=只看自身占用),关掉后只保留 4/5 硬顶。

范围

config/runtime_capacity.rs(新增 memoryGuard)、core/runtime_capacity/mod.rs(判据)、ui-shared/runtime-capacity-panel.tsx(开关与文案)、五语文案与前端产物。

修复 PR:#654

🤖 本条回复由 AI Agent 生成

Activity

  1. coderabbitai commented on Nov 21, 2026

    @coderabbitai
    🔗 Related PRs

    #627 - 修复 macOS 内存压力误判:改读内核压力等级 [open]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions