-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Bug: Context token count always shows 0 after compaction #50795
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.Can lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.Can lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Issue: Context Token Count Always Shows 0 After Compaction
Summary
The
📚 Contextcounter in the TUI always displays0/1.0m (0%)even after successful LLM responses. This happens because theclearStaleAssistantUsageOnSessionMessages()function incorrectly clears all assistant message usage data after any compaction, instead of only clearing usage for messages that existed before the compaction.Root Cause Analysis
Problem Location
src/agents/pi-embedded-subscribe.handlers.compaction.tsclearStaleAssistantUsageOnSessionMessages()Current (Broken) Implementation
Why This Is Wrong
Evidence
stream_options.include_usage: trueclearStaleAssistantUsageOnSessionMessages()Related Correct Implementation
The file
src/agents/pi-embedded-runner/google.tscontains a correct implementation:stripStaleAssistantUsageBeforeLatestCompaction()which only clears usage for messages older than the latest compaction.Proposed Fix
Impact
Testing
📚 Context: 0/1.0m (0%)after the responseusageobjects show zerosLabels
Pull Request: Fix context token count zeroed after compaction
Summary
Fixes the issue where
📚 Contexttoken count always shows 0 after compaction.Changes
clearStaleAssistantUsageOnSessionMessages()insrc/agents/pi-embedded-subscribe.handlers.compaction.tsparseMessageTimestamp()helper functionTesting
Related