Repository navigation
fix(agent-core-v2): keep token counting and compaction anchored to usage - #4907
Merged
wbxl2000 merged 2 commits intoNov 13, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: dbfa963 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
This was referenced Nov 13, 2026
Merged
6 tasks done
11 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
将 #4883 的同一修复 backport 到
release/2026-11-13。长会话中的工具结果一旦带分页
note、错误状态、空输出或Wall time头,Token 实测锚点就可能停止更新。后续请求退回偏低的本地字符估算,导致真实上下文已达到窗口上限时自动压缩仍不触发,可能出现长时间预填充后空回复,或在 Gemini 超限报错后才进入兜底压缩。本 PR 让 release 分支在这些场景下持续使用真实用量,并在首步请求前完成必要的自动压缩。Bug Reproduction Steps
note、错误状态、空输出或耗时头的工具调用。Root Cause
根本修复,与 #4883 相同,按 release 当前接口适配:
note、错误状态、空输出和耗时头,而历史侧将这些信息保存在独立字段;原有逐字节content比较因此返回 false,停止写入token_counting.measured。usage,所以存量会话在实测锚点缺失或停更后仍会漏掉自动压缩与压缩预裁剪。Code Changes
tokenCountingAgentModel.ts:复用 release 已有的工具结果渲染器,对齐原始、note 追加及完整投影后的工具消息,同时拒绝不一致的 note 和错误状态。requestObservation.ts:普通请求使用原始请求消息;媒体降级或剥离恢复后使用实际出站消息,避免给未降级上下文写入错误锚点。fullCompactionService.ts:以最近 assistant usage 加尾部估算作为真实用量下界,并将该口径用于自动压缩判定、tokensBefore、预裁剪和溢出缩减。按相邻 usage 锚点差值校准各段消息权重,避免字符估算偏低时漏掉预裁剪。Behavior Changes and Affected Users
未改变 wire、配置、SDK 或客户端 API 契约,也未改变默认阈值。
验证:
tsc --noEmit通过。lint:imports仍有 4 个 release 基线既有违规,本次 diff 未新增违规。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.