fix: invalidate retained context usage after compaction - #168
Merged
Merged
Conversation
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.
Change
Fixes #152. After shared
ContextManagercompaction, a small summary plus retained reply could still estimate 180,100 tokens because the reply's usage measured the old context. The synthetic regression now estimates 15 tokens and the next checkpoint stays below the trigger.Persist the retained-message count on the summary and exclude that prefix from usage anchoring. Responses appended after this boundary can supply fresh usage, including when timestamps tie or the clock moves backwards. Preserve all historical assistant usage and cost data. Legacy summaries without the boundary use the existing local runtime's timestamp freshness rule; ambiguous timestamps fall back to local estimation. Remote token counting continues to control trigger decisions.
Scope: this fixes the shared module. No direct
ContextManagerinstantiation was found in the public runtime; its separate local estimator already filters pre-compaction usage by timestamp. The issue's claim that the condition is always permanent is too broad: a new valid provider response can also replace the stale anchor. No CLI flags or documentation changes are needed.Validation
pnpm typecheck,pnpm check:source,pnpm check:tsconfig,git diff --check.pnpm verifyfull profile, all 14 gates, on clean commitc9e82774ba8f110c91d2244b4327de2eb4866c80(macOS arm64, Node 26.4.0). Includes source export, release tools, types, build, standalone/artifact checks, capabilities, status contract, smoke, offline BYOK, policy, and sandbox.Publication and contribution checks
release/public-source.jsonand declared intest/vitest-suites.json.Maintainer handoff
Publication scope: one synthetic regression test added to the reviewed source inventory. License changes: none.
Shared-source port: pending.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.