fix(agent,desktop): align context gauge with compaction trigger / 对齐上下文容量条与压缩触发器 - #8329
Merged
SivanCola merged 2 commits intoAug 11, 2026
Conversation
The desktop context gauge measured something different from the compaction trigger, in both directions: - The backend gauge (ContextUsedTokens) used the message-only estimator while the trigger sizes messages + role projection + tool schemas (estimatedVisibleRequestTokens). With a non-empty tool registry the gauge under-reported the fill, so a session could display below compact_ratio while the trigger had already crossed it (the esengine#8221 test passed only because its tool registry was empty). - The desktop frontend overwrote the backend gauge with the last turn's real usage and added completion tokens to the used figure. A long output round inflated the displayed fill (e.g. 90%) while the trigger, which only counts the next request's prompt, still sat below the configured 85% — compaction never fired and the session ran into a real overflow. Both now use one measurement: the gauge calls the trigger's own estimator, and the frontend counts prompt tokens only. Completion stays in the output metrics, not the occupancy gauge. Refs: esengine#8191
xiaotaoya2022-cell
requested review from
SivanCola and
esengine
as code owners
August 11, 2026 05:06
Problem: - Context usage stayed cached after live MCP tool changes. - Completion-only latest usage could collapse prompt occupancy to zero. - The PR also tripped formatting and repository budget gates. Root cause: - The memoization key omitted the provider-visible tool registry revision. - Frontend fallback selected context prompt data based on unrelated completion data. Fix: - Track tool schema revisions and include registry identity plus revision in the gauge cache key. - Select prompt and completion fallbacks independently and align ContextFillTokens with prompt occupancy. - Add deterministic backend and frontend regression coverage while removing budget-breaking comments. Verification: - go test ./... - go test -race ./internal/tool ./internal/agent - go vet ./... - pnpm build - go run ./tools/repolint
SivanCola
enabled auto-merge (squash)
August 11, 2026 07:17
SivanCola
added a commit
to SivanCola/DeepSeek-Reasonix
that referenced
this pull request
Aug 11, 2026
Problem: - main-v2 advanced again with esengine#8329 after the catalog integration merge had been fully tested. Root cause: - The context gauge and compaction trigger previously measured different provider-visible inputs, and the frontend counted completion tokens as prompt occupancy. Fix: - Integrate the latest prompt/tool-schema accounting and frontend prompt-occupancy semantics without conflicts. Verification: - go test -count=1 ./internal/agent ./internal/provider ./internal/tool - go test -race -count=1 ./internal/agent ./internal/provider ./internal/tool - pnpm exec tsx src/__tests__/use-controller-stream-progress.test.ts - pnpm build - go run ./tools/repolint - gofmt -l internal desktop - git diff --cached --check
complyue
pushed a commit
to complyue/DeepSeek-Reasonix
that referenced
this pull request
Aug 11, 2026
…efresh Keeps the review-endorsed parts of the original four-threshold PR esengine#8256, rescaled to the single compact_ratio architecture of esengine#8244: - over-threshold resume guard, asked BEFORE the mutating ResumeSessionPageForTab / OpenChannelSessionPageForTab calls via a read-only PreviewSession estimate, so cancelling leaves the session untouched - immediate context + balance refresh on compaction_done (the coalesced BalanceForTab query is invalidated first so the refresh reads fresh data) Drops everything tied to the multi-threshold model removed by esengine#8244 (soft/snip/force ratios, the four-thumb slider, thresholdLayout, SetCompactionThresholds, CLI snip-ratio, the widened compact-ratio range) and does not reintroduce the ContextPanel maintenance block removed by esengine#8265. The live capacity visualization already aligns with the single Compact threshold on current main-v2 (esengine#8329/esengine#8307), so the gauge is unchanged.
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.
What breaks today
The desktop context gauge measured something different from the compaction trigger in both directions:
ContextUsedTokens()used the message-only estimator, while the trigger sizes messages, role projection, and tool schemas.Fix
estimatedVisibleRequestTokens()for both the gauge and compaction trigger.ContextFillTokens()helper with prompt occupancy.Verification
go test ./...go test -race ./internal/tool ./internal/agentgo vet ./...go run ./tools/repolintpnpm buildindesktop/frontendmain-v2virtual merge: relevant Go tests, frontend reducer test, frontend build, and repolint passedRefs: #8191, #8221
Documentation-impact: none - this aligns internal context-capacity measurement with the existing compaction semantics and does not change configuration or user workflows.
Cache-impact: none - the revision is internal bookkeeping only; tool schema bytes, ordering, and provider request construction are unchanged.
Cache-guard:
go test ./internal/tool ./internal/agent ./internal/providercovers registry revision changes, live add/remove/suspend invalidation, and prompt-only occupancy fallbacks.