Skip to content

Commit 967d8fa

Browse files
committed
Fixes #4529 improves retries w/ Copilot models
1 parent 0d97a3a commit 967d8fa

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2727
- Changes branch favoriting to apply to both local and remote branch pairs ([#4497](https://github.com/gitkraken/vscode-gitlens/issues/4497))
2828
- Supports opening an explain summary document before summary content is generated ([#4328](https://github.com/gitkraken/vscode-gitlens/issues/4328))
2929

30+
### Fixed
31+
32+
- Fixes issues with handling token limits when using Copilot models ([#4529](https://github.com/gitkraken/vscode-gitlens/issues/4529))
33+
3034
## [17.3.4] - 2025-08-11
3135

3236
### Added

src/plus/ai/vscodeProvider.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,20 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
129129

130130
if (ex instanceof Error && 'cause' in ex && ex.cause instanceof Error) {
131131
message += `\n${ex.cause.message}`;
132+
}
132133

133-
if (ex.cause.message.includes('exceeds token limit')) {
134-
if (retries++ < 2) {
135-
maxInputTokens -= 500 * retries;
136-
continue;
137-
}
134+
if (message.includes('exceeds token limit')) {
135+
if (++retries <= 3) {
136+
// Reduce by 10%, then 25%, then 50% on retries 1, 2, 3 respectively
137+
const reductionPercents = [0, 0.1, 0.25, 0.5] as const;
138+
const reduction = reductionPercents[retries] ?? 0.5;
138139

139-
Logger.error(ex, scope, `Unable to ${getActionName(action)}: (${model.provider.name})`);
140-
throw new AIError(AIErrorReason.RequestTooLarge, ex);
140+
maxInputTokens -= Math.min(5000 * retries, maxInputTokens * reduction);
141+
continue;
141142
}
143+
144+
Logger.error(ex, scope, `Unable to ${getActionName(action)}: (${model.provider.name})`);
145+
throw new AIError(AIErrorReason.RequestTooLarge, ex);
142146
}
143147

144148
Logger.error(ex, scope, `Unable to ${getActionName(action)}: (${model.provider.name})`);

0 commit comments

Comments
 (0)