Files
HomeAgent/internal
JianFeeeee 26dcf63fd5 fix(context): 让段页式统计跟随 InactivePages
## 生产故障

2026-11-02 20:58:24:

    air-interrupt prune: 12→5 events (44185→39714 tokens), ratio=1.21
    context overflow: recover budget exhausted (2/2)

段页式淘汰已经把工具页标成 InactivePages,渲染层也确实跳过了这些页,
但 overflow.go 的 eventTokens 仍把事件里的全部 ToolResults 算进去。

结果是「渲染视图变小、统计视图不变」:页剔除后水位不降,L4 反复触发,
最终耗尽恢复预算并终止本轮。

## 修复

让 eventTokens 使用 process.go 同一套 toolResultPageIndex 配对规则:

- InactivePages 对应的工具页不再占预算
- llm_round(第 1 页)始终保留
- 配不上的工具结果仍按原策略保守保留

因此 accumulatedTokens、overflowRatioNow、evictPagesLocked 三条调用链
都自动使用与实际渲染一致的 token 口径。

## 判据

- TestEventTokens_ExcludesInactivePages
- TestEventTokens_LLMRoundNeverExcluded
- TestOverflowRatio_DropsAfterPageEviction

变异验证:去掉 InactivePages 判断 ⇒ 前两类核心判据变红。

go build/vet/gofmt 干净;go test ./... -count=1 -race = 62 ok / 0 FAIL / 0 RACE
2026-11-02 21:54:35 +08:00
..