MoonshotAI / MoonshotAI/kimi-code

maxRecentUserMessages配置项可能有bug。设置了该值后,可能不能正常使用

Open
#545 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

涉及文件packages/agent-core/src/agent/compaction/strategy.ts
涉及方法DefaultCompactionStrategy

问题代码

    for (; recentMessages < messages.length; recentMessages++) {
      const splitIndex = messages.length - recentMessages - 1;
      const m2 = messages[messages.length - recentMessages]!;

      if (m2.role === 'user') {
        recentUserMessages++;            
      }
      recentSize += estimateTokensForMessage(m2);

      if (canSplitAfter(messages, splitIndex)) {
        bestN = splitIndex + 1;          
      }

      const reachesMax = recentMessages >= this.config.maxRecentMessages
        || recentUserMessages >= this.config.maxRecentUserMessages  
        || recentSize >= this.maxSize * this.config.maxRecentSizeRatio;
      if (reachesMax && bestN !== undefined) {
        break;
      }
    }

复现过程:用消息序列 [asst_tc, tool, tool, user, user, user] 遍历时的过程:

轮次 recentMsgs m2角色 user计数 canSplit bestN reachesMax 行为
1 1 user 1 false undefined true(1≥1) 但 bestN=undefined 继续
2 2 user 2 false undefined true(2≥1) 但 bestN=undefined 继续
3 3 user 3 true 3 true(3≥1) 且 bestN≠undefined break → 返回 3

问题:第 3 轮时 recentUserMessages 已经是 3,却错误返回了值
原因:不知道是什么问题导致,但是看起来没有什么实际影响

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/agent-core/src/agent/compaction/strategy.ts and inspect DefaultCompactionStrategy, especially the loop and maxRecentUserMessages condition. Reproduce the behavior with [asst_tc, tool, tool, user, user, user], then determine the intended split boundary and whether the returned value is valid. Done means the expected behavior is documented and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.