Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

The context indicator in the bottom right was showing 0% and flickering when a new API request started. This happened because when a new API request begins, a placeholder api_req_started message is created with only apiProtocol (no token data). The context calculation was using this placeholder message, causing the indicator to show 0% until the real token data arrived.

Solution

Added logic to skip placeholder api_req_started messages and find the last message with actual token data. A message is considered a placeholder if it has neither tokensIn nor tokensOut as numbers.

@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

🦋 Changeset detected

Latest commit: 18706f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 16, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR fixes a bug where the CLI context indicator was showing incorrect values (flickering to 0%) when a new API request starts. The fix correctly identifies and skips placeholder api_req_started messages that only contain apiProtocol but no token data, falling back to the previous message with valid token data.

Key Changes

  1. cli/src/utils/context.ts - Added logic to skip placeholder messages without valid token data (tokensIn or tokensOut as numbers)
  2. src/shared/getApiMetrics.ts - Same fix applied to the shared metrics function, using a foundValidTokenData flag to continue searching backwards when encountering placeholders
  3. Comprehensive test coverage - Both CLI and shared code have thorough tests covering:
    • Placeholder message skipping
    • Multiple consecutive placeholders
    • Edge cases (explicit tokensIn: 0, condense_context followed by placeholder)
    • State update simulation to verify no flickering

Code Quality

  • ✅ Proper kilocode_change markers added to shared code
  • ✅ Consistent logic between CLI and shared implementations
  • ✅ Edge case handling for explicitly set tokensIn: 0 vs missing token data
  • ✅ Changeset included with appropriate description
Files Reviewed (5 files)
  • .changeset/fix-cli-context-indicator.md - Changeset for CLI patch
  • cli/src/utils/__tests__/context.test.ts - New tests for placeholder handling
  • cli/src/utils/context.ts - Fix for CLI context calculation
  • src/shared/__tests__/getApiMetrics-context-indicator.spec.ts - New regression tests
  • src/shared/__tests__/getApiMetrics.spec.ts - Updated test expectation
  • src/shared/getApiMetrics.ts - Fix for shared metrics function

@marius-kilocode marius-kilocode force-pushed the fix/context-indicator-placeholder-handling branch from 06ad9d7 to ce7be0d Compare January 16, 2026 08:42
@marius-kilocode marius-kilocode requested review from a team and chrarnoldus January 16, 2026 08:44
When a new API request starts, a placeholder api_req_started message is
created with only apiProtocol (no token data). This caused the context
indicator to show 0% and flicker when the real data arrived.

The fix adds logic to skip placeholder messages and find the last message
with actual token data (tokensIn or tokensOut as numbers).

Changes:
- src/shared/getApiMetrics.ts: Skip placeholder messages in VSCode extension
- cli/src/utils/context.ts: Apply same fix for CLI context calculation
- Added comprehensive regression tests for both implementations
@marius-kilocode marius-kilocode force-pushed the fix/context-indicator-placeholder-handling branch from ce7be0d to 18706f4 Compare January 16, 2026 08:46
@marius-kilocode marius-kilocode added the CLI Kilo Code CLI label Jan 16, 2026
@marius-kilocode marius-kilocode merged commit a49868e into main Jan 16, 2026
13 checks passed
@marius-kilocode marius-kilocode deleted the fix/context-indicator-placeholder-handling branch January 16, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Kilo Code CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants