Skip to content

fix(kun): keep token economy from rewriting history#292

Open
musnows wants to merge 1 commit into
KunAgent:developfrom
musnows:codex/fix-token-economy-history-cache
Open

fix(kun): keep token economy from rewriting history#292
musnows wants to merge 1 commit into
KunAgent:developfrom
musnows:codex/fix-token-economy-history-cache

Conversation

@musnows

@musnows musnows commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

中文

变更

  • 将 token economy 的 tool result 压缩限制到当前 turn,避免改写旧历史。
  • 为 request history hygiene 增加 currentTurnId scope,并在 agent loop 中传入当前 turn。
  • 补充测试覆盖旧 turn 历史保持原样、当前 turn 仍可被压缩。

原因

历史记录压缩如果每轮改写旧 tool result,会让已进入请求历史的前缀不再稳定,破坏 provider prompt cache 命中。这个 PR 只修复历史压缩作用域,不包含 Read 工具多模态注入修复。

验证

  • npm --prefix kun test -- token-economy.test.ts request-history-hygiene.test.ts
  • npm --prefix kun test -- loop.test.ts -t "uses compact tool history for model requests without mutating persisted results|bounds tool history for model requests even when token economy is disabled"
  • npm --prefix kun run build

English

Changes

  • Limit token economy tool-result compression to the current turn.
  • Add a currentTurnId scope to request history hygiene and pass it from the agent loop.
  • Add tests that keep previous-turn history unchanged while still allowing current-turn compression.

Why

Rewriting historical tool results changes the stable request prefix between turns and can invalidate provider prompt-cache hits. This PR only fixes the history-compression scope and intentionally excludes the multimodal Read tool fix.

Validation

  • npm --prefix kun test -- token-economy.test.ts request-history-hygiene.test.ts
  • npm --prefix kun test -- loop.test.ts -t "uses compact tool history for model requests without mutating persisted results|bounds tool history for model requests even when token economy is disabled"
  • npm --prefix kun run build

@musnows musnows marked this pull request as ready for review June 14, 2026 08:06
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