Skip to content

fix: 实时跟踪当前并发(Acquire/Release) - #366

Merged
caigee-cmd merged 1 commit into
mainfrom
fix/live-inflight-tracking
Oct 23, 2026
Merged

caigee-cmd merged 1 commit into
mainfrom
fix/live-inflight-tracking

Conversation

@caigee-cmd

Copy link
Copy Markdown
Owner

根因

  • Item.InFlight 只在 MergeHealth(约 30s 探活 / 手动刷新)里写入;请求开始/结束不加减。
  • WorkBuddy/Trae 等 in-process Probe 不填 InFlight(恒为 0)。
  • Qoder worker 有准确 inFlight,但主进程只在探活时抄一次,UI 仍滞后。
  • 侧边栏 InFlightIndicator 还在打 /api/overview/summary,与概览 LiveStrip(/api/live)不同源。

修法

  1. Pool.Acquire / Pool.Release:持锁加减;MaxInFlight>0 且已满则 Acquire 失败。
  2. MergeHealth 不再覆盖 InFlight(只更新 ready/hot/restarts/lastError/runtime_state);注释标明执行器是 in-flight 源。
  3. ChatNonStream / chatStreamProxy(含 native responses):pickNext 后立刻 Acquire;失败则 exclude 继续(防 TOCTOU)。非流式各路径 Release;流式成功返回时在 Body Close() 时 Release;X-Qoder-Account 改写后仍按 Acquire 时的 pool id Release。
  4. Upsert 保留现有 InFlight,避免注册/刷新把进行中的计数清零。
  5. 侧边栏改为 fetchLive(),约 2.5s、仅可见时轮询。

容量公式未改(enabled 账号 max_inflight 之和,默认 4)。未改 RPM。

测试

  • go test ./... 通过
  • 新增:Acquire 到 cap 失败、Release 回落、MergeHealth 不改 InFlight、Upsert 保留 InFlight
  • scripts/release-notes.py validate 通过
  • 前端已 npm run sync 嵌入 static

自测建议

  1. 启动服务,开控制台概览 + 侧边栏。
  2. 发一条较长的流式/非流式请求:/api/live 与侧边栏「当前并发」应在一轮轮询(~2.5s)内升高,结束后回落。
  3. 手动刷新账号健康:进行中的并发不应被探活打回旧值。

剩余风险

  • 若调用方拿到流式 Response 却从不 Close() Body,对应 slot 会泄漏到进程重启(与连接泄漏同类)。
  • 非 chat 路径若另有代理流量且未走 executor,不会计入(当前 UI「当前并发」语义是经代理的 chat/responses 请求)。

不要 merge / 不要打 tag。

InFlight was only refreshed by MergeHealth (~30s probes), so the overview
live strip and sidebar lagged and WorkBuddy/Trae stayed at 0. Count slots
on the chat attempt path instead; probes no longer overwrite InFlight.
Sidebar polls /api/live like the overview strip.
@caigee-cmd
caigee-cmd merged commit 55998c5 into main Oct 23, 2026
6 checks passed
@caigee-cmd
caigee-cmd deleted the fix/live-inflight-tracking branch October 23, 2026 02:10
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.

1 participant