Summary
Improve token-estimate accuracy so the /context view and compaction triggers agree with reality. The current estimator is a len/4 chars-per-token heuristic (+5 overhead) in compaction.EstimateMessageTokens.
Proposed behavior
- Reconcile the heuristic against provider-reported usage per message (already available via
MessageUsage, pkg/runtime/event.go ~line 372).
- Keep a conservative bias so we compact slightly early rather than overflow.
Implementation notes (starting points)
pkg/compaction/compaction.go
pkg/runtime/compactor/compactor.go
- Extend estimator tests
Complexity: S–M.
Background: shared plan context-management-gap-analysis (Phase 2, item 6).
Dependencies / Relationships
Summary
Improve token-estimate accuracy so the
/contextview and compaction triggers agree with reality. The current estimator is alen/4chars-per-token heuristic (+5 overhead) incompaction.EstimateMessageTokens.Proposed behavior
MessageUsage,pkg/runtime/event.go~line 372).Implementation notes (starting points)
pkg/compaction/compaction.gopkg/runtime/compactor/compactor.goComplexity: S–M.
Background: shared plan
context-management-gap-analysis(Phase 2, item 6).Dependencies / Relationships
/contextcommand with a categorized context-window breakdown #3432 (improves accuracy of the breakdown numbers), feat(config): make the auto-compaction threshold configurable (compaction_threshold) #3433 (compaction-trigger accuracy)