Skip to content

fix: stop blocking on balance check for autocomplete provider selection#62

Open
kilo-code-bot[bot] wants to merge 1 commit into
mainfrom
fix/autocomplete-balance-check-caching
Open

fix: stop blocking on balance check for autocomplete provider selection#62
kilo-code-bot[bot] wants to merge 1 commit into
mainfrom
fix/autocomplete-balance-check-caching

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented Mar 17, 2026

Summary

  • Removes the synchronous /api/profile/balance call from AutocompleteModel.reload() that was blocking provider selection on every model reload (startup, settings changes, snooze/unsnooze, etc.)
  • The kilocode provider is now selected immediately when a token is present, without waiting for a balance check. A few requests hitting the API with no balance is acceptable — the API returns errors which are already handled gracefully by the existing error path in fetchAndCacheSuggestion.
  • The balance check now runs as a non-blocking background task with a 5-minute TTL cache, used only to set the hasKilocodeProfileWithNoBalance flag for the status bar UI.

Impact

For an authenticated user with autocomplete enabled, this eliminates a blocking HTTP request on every model reload. Previously this could generate thousands of /api/profile/balance calls per day tied to keystroke frequency. Now the balance endpoint is hit at most once every 5 minutes, purely for UI status.

Changes

File Change
src/services/autocomplete/utils/kilocode-utils.ts Added checkKilocodeBalanceCached() with 5-minute TTL, resetBalanceCache() for testing, exported BALANCE_CACHE_TTL_MS
src/services/autocomplete/AutocompleteModel.ts Replaced blocking checkKilocodeBalance() with non-blocking void checkKilocodeBalanceCached().then(...)
src/services/autocomplete/utils/kilocode-utils.test.ts Added 7 tests for checkKilocodeBalanceCached (TTL, cache invalidation, credential changes)
src/services/autocomplete/__tests__/AutocompleteModel.spec.ts Updated provider usability tests for new non-blocking behavior

Testing

All 36 tests pass (15 in kilocode-utils.test.ts + 21 in AutocompleteModel.spec.ts).

Remove the synchronous balance check from AutocompleteModel.reload() that
was hitting /api/profile/balance on every model reload. The kilocode provider
is now selected immediately when a token is present, and the balance check
runs in the background with a 5-minute TTL cache for the status bar UI flag.

This eliminates thousands of unnecessary API calls per day per user, since
reload() is called on startup, settings changes, snooze/unsnooze, etc.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: 0cb60f5

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

This PR includes changesets to release 1 package
Name Type
kilo-code 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants