Skip to content

perf(model-info): 每次生命周期 refresh 都完整扫描 Session branch #188

Closed

Description

@tt-a1i

问题

model-info 为计算累计 cost/cache rate,在每次 refresh 时扫描当前完整 branch。refresh 会在 agent start、每个 assistant message end、turn end、compaction、tree 和 settled 等多个生命周期点触发。长工具链与长 Session 下,累计扫描成本近似 O(branch entries × refresh count),通常随消息数呈二次增长。

证据

  • extensions/model-info/index.ts:12-40:getSessionMetrics() 每次完整遍历 ctx.sessionManager.getBranch();
  • extensions/model-info/index.ts:53-78:所有 refresh 都调用完整扫描;
  • extensions/model-info/index.ts:96-225:单 turn 内可由多个 lifecycle event 重复 refresh。

期望

  • 基于 entry id/revision 增量累计 usage,branch/tree/compaction 时做确定性重建;
  • 同一 entry 不重复计费,fork/tree 后不把离开 active branch 的 usage 留在指标中;
  • live context occupancy 与累计 session cost 分开更新;
  • benchmark:1k/10k/100k entries、每 turn 1/10/100 次 tool loop,统计 branch visits 和 refresh latency;稳态新增一条消息应为摊销 O(1)。

Activity

  1. added
    bug
    on Aug 25, 2026
  2. Sun-GLiang commented on Aug 28, 2026

    @Sun-GLiang
    Contributor

    Hi! I’d like to work on this issue.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions