Skip to content

fix(strategy): stop condensation from resetting session token totals - #2383

Open
MuskanPaliwal wants to merge 3 commits into
entireio:mainfrom
MuskanPaliwal:fix-session-token-total-2368
Open

fix(strategy): stop condensation from resetting session token totals#2383
MuskanPaliwal wants to merge 3 commits into
entireio:mainfrom
MuskanPaliwal:fix-session-token-total-2368

Conversation

@MuskanPaliwal

@MuskanPaliwal MuskanPaliwal commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #2368

Trail: #5: Preserve session-wide token totals during condensation

SessionState.TokenUsage is the running total shown by entire status and entire session tokens. sessionData.TokenUsage serves a different purpose: it contains only the usage since the previous checkpoint.

During condensation, the checkpoint value was passed to sessionStateBackfillTokenUsage. Its final branch accepted that value for every agent when input tokens were present. applyBackfilledSessionTokenUsage then stored it as the session total.

As a result, a session with 10,000 cumulative input tokens could appear to have used only the 100 tokens recorded since its latest checkpoint. Later turns accumulated from that smaller value, leaving the total permanently undercounted.

Keep cumulative and checkpoint usage separate

This change removes the agent-agnostic checkpoint fallback.

Non-Copilot agents now retain the cumulative token total collected through their lifecycle hooks. Checkpoint metadata continues to record the smaller checkpoint-window value.

Copilot CLI keeps both existing backfill paths. Its authoritative session.shutdown record can arrive after lifecycle hooks return, so condensation still:

  1. Recomputes the full-session total from the transcript when available.
  2. Falls back to checkpoint usage when a full-session aggregate is unavailable.

If a non-Copilot agent has no cumulative hook data, the CLI now reports no session-wide total. This is deliberate: a missing total is more accurate than presenting one checkpoint鈥檚 usage as the total for the entire session.

Verification

The regression test models a session with 10,000 cumulative input tokens and a 100-token checkpoint. With the previous behavior, CondenseSessionByID saved 100 as the session total. With this change, the total remains 10,000 after the state is reloaded from disk.

Additional tests cover both Copilot backfill paths.

Checks completed:

  • Focused token-usage regression tests
  • Strategy package tests
  • Relevant status and session-token command tests
  • Full mise run check, including formatting, linting, race-enabled tests, integration tests, and deterministic E2E canaries

Entire-Checkpoint: 01M2848G1CNPKDA8YJDA1MDFJA
@MuskanPaliwal
MuskanPaliwal marked this pull request as ready for review September 11, 2026 12:08
@MuskanPaliwal
MuskanPaliwal requested a review from a team as a code owner September 11, 2026 12:08
Entire-Checkpoint: 01M28J6MX4M92Y88PWYE3WPRFK
Entire-Checkpoint: 01M2A6HV96SV0206QW63R1V23N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

applyBackfilledSessionTokenUsage overwrites the session-wide token total with the checkpoint window delta for every non-Copilot agent

1 participant