From 32617605ebe1eaac554ecc2a3a77fac27f5730c3 Mon Sep 17 00:00:00 2001 From: liangfung Date: Mon, 30 Dec 2024 20:07:59 +0800 Subject: [PATCH 01/17] feat(vscode): show status of rate limited --- clients/tabby-agent/src/http/tabbyApiClient.ts | 11 +++++++++++ clients/tabby-agent/src/protocol.ts | 3 ++- clients/tabby-agent/src/status.ts | 5 +++++ clients/tabby-agent/src/utils/error.ts | 4 ++++ clients/vscode/src/StatusBarItem.ts | 3 ++- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 445c697bd9b5..a05ae49477f5 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -26,6 +26,7 @@ import { isUnauthorizedError, isCanceledError, isTimeoutError, + isRateLimitedError, } from "../utils/error"; import { RequestStats } from "./statistics"; @@ -48,6 +49,7 @@ export class TabbyApiClient extends EventEmitter { private readonly completionRequestStats = new RequestStats(); private completionResponseIssue: "highTimeoutRate" | "slowResponseTime" | undefined = undefined; + private rateLimited = false; private connectionErrorMessage: string | undefined = undefined; private serverHealth: TabbyApiComponents["schemas"]["HealthState"] | undefined = undefined; @@ -214,6 +216,10 @@ export class TabbyApiClient extends EventEmitter { return !!this.completionResponseIssue; } + isRateLimited(): boolean { + return this.rateLimited; + } + getServerHealth(): TabbyApiComponents["schemas"]["HealthState"] | undefined { return this.serverHealth; } @@ -334,6 +340,7 @@ export class TabbyApiClient extends EventEmitter { } } + // todo async fetchCompletion( request: TabbyApiComponents["schemas"]["CompletionRequest"], signal?: AbortSignal, @@ -353,6 +360,7 @@ export class TabbyApiClient extends EventEmitter { canceled: false, timeout: false, notAvailable: false, + rateLimited: false }; try { @@ -383,6 +391,9 @@ export class TabbyApiClient extends EventEmitter { this.logger.debug(`Completion request failed due to unauthorized. [${requestId}]`); statsData.notAvailable = true; this.connect(); // schedule a reconnection + } else if (isRateLimitedError(error)) { + this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); + statsData.rateLimited = true } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; diff --git a/clients/tabby-agent/src/protocol.ts b/clients/tabby-agent/src/protocol.ts index 5c96c6b64eb2..dc8b8993baea 100644 --- a/clients/tabby-agent/src/protocol.ts +++ b/clients/tabby-agent/src/protocol.ts @@ -849,7 +849,8 @@ export type StatusInfo = { | "readyForAutoTrigger" | "readyForManualTrigger" | "fetching" - | "completionResponseSlow"; + | "completionResponseSlow" + | "rateLimited"; tooltip?: string; /** * The health information of the server if available. diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 53cf852ab9c8..01bae8edfc07 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -205,6 +205,8 @@ export class StatusProvider extends EventEmitter implements Feature { const ignored = this.dataStore.data.statusIgnoredIssues ?? []; if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { statusInfo = { status: "completionResponseSlow" }; + } else if (this.tabbyApiClient.isRateLimited()) { + statusInfo = { status: "rateLimited" } } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; } else { @@ -264,6 +266,9 @@ export class StatusProvider extends EventEmitter implements Feature { case "completionResponseSlow": statusInfo.tooltip = "Tabby: Slow Completion Response Detected"; break; + case "rateLimited": + statusInfo.tooltip = "Tabby: Too many request"; + break; default: break; } diff --git a/clients/tabby-agent/src/utils/error.ts b/clients/tabby-agent/src/utils/error.ts index cce6fb11a185..ad017fe5ef1a 100644 --- a/clients/tabby-agent/src/utils/error.ts +++ b/clients/tabby-agent/src/utils/error.ts @@ -35,6 +35,10 @@ export function isUnauthorizedError(error: any) { return error instanceof HttpError && [401, 403].includes(error.status); } +export function isRateLimitedError(error: any) { + return error instanceof HttpError && [429].includes(error.status); +} + export function errorToString(error: Error) { let message = error.message || error.toString(); if (error.cause instanceof Error) { diff --git a/clients/vscode/src/StatusBarItem.ts b/clients/vscode/src/StatusBarItem.ts index 7b7c2908ad6a..751df388e942 100644 --- a/clients/vscode/src/StatusBarItem.ts +++ b/clients/vscode/src/StatusBarItem.ts @@ -93,7 +93,8 @@ export class StatusBarItem { this.setTooltip(statusInfo.tooltip); break; } - case "completionResponseSlow": { + case "completionResponseSlow": + case "rateLimited": { this.setColorWarning(); this.setIcon(iconWarning); this.setTooltip(statusInfo.tooltip); From 7bf4ff34043607f5b1dbb449720b149e5ecb2f76 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:09:28 +0000 Subject: [PATCH 02/17] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/http/tabbyApiClient.ts | 4 ++-- clients/tabby-agent/src/status.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index a05ae49477f5..b3923f87a29d 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -360,7 +360,7 @@ export class TabbyApiClient extends EventEmitter { canceled: false, timeout: false, notAvailable: false, - rateLimited: false + rateLimited: false, }; try { @@ -393,7 +393,7 @@ export class TabbyApiClient extends EventEmitter { this.connect(); // schedule a reconnection } else if (isRateLimitedError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); - statsData.rateLimited = true + statsData.rateLimited = true; } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 01bae8edfc07..ccdd1d31e745 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -206,7 +206,7 @@ export class StatusProvider extends EventEmitter implements Feature { if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { statusInfo = { status: "completionResponseSlow" }; } else if (this.tabbyApiClient.isRateLimited()) { - statusInfo = { status: "rateLimited" } + statusInfo = { status: "rateLimited" }; } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; } else { From 31eac32ddbfacec711c98c2c742c27abb3c33d56 Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 02:10:55 +0800 Subject: [PATCH 03/17] update --- clients/tabby-agent/src/http/tabbyApiClient.ts | 12 +++++++++++- clients/tabby-agent/src/status.ts | 3 +++ clients/vscode/src/commands/commandPalette.ts | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index b3923f87a29d..6894238bcba0 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -49,7 +49,7 @@ export class TabbyApiClient extends EventEmitter { private readonly completionRequestStats = new RequestStats(); private completionResponseIssue: "highTimeoutRate" | "slowResponseTime" | undefined = undefined; - private rateLimited = false; + private rateLimited: boolean = false; private connectionErrorMessage: string | undefined = undefined; private serverHealth: TabbyApiComponents["schemas"]["HealthState"] | undefined = undefined; @@ -178,6 +178,14 @@ export class TabbyApiClient extends EventEmitter { } } + private updateIsRateLimited(isRateLimited: boolean) { + if (this.rateLimited != isRateLimited) { + this.logger.debug(`updateIsRateLimited, next:${isRateLimited}`) + this.rateLimited = isRateLimited; + this.emit('isRateLimitedUpdated', isRateLimited); + } + } + getCompletionRequestStats(): RequestStats { return this.completionRequestStats; } @@ -401,6 +409,8 @@ export class TabbyApiClient extends EventEmitter { } throw error; // rethrow error } finally { + this.updateIsRateLimited(statsData.rateLimited); + if (!statsData.notAvailable) { stats?.addRequestStatsEntry(statsData); } diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index ccdd1d31e745..3597dbb20914 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -70,6 +70,9 @@ export class StatusProvider extends EventEmitter implements Feature { this.tabbyApiClient.on("hasCompletionResponseTimeIssueUpdated", async () => { this.notify(); }); + this.tabbyApiClient.on('isRateLimitedUpdated', async () => { + this.notify(); + }) this.configurations.on( "clientProvidedConfigUpdated", diff --git a/clients/vscode/src/commands/commandPalette.ts b/clients/vscode/src/commands/commandPalette.ts index 254b852d0f59..b7c95e05be3c 100644 --- a/clients/vscode/src/commands/commandPalette.ts +++ b/clients/vscode/src/commands/commandPalette.ts @@ -209,6 +209,13 @@ export class CommandPalette { }, }; } + case "rateLimited": { + return { + label: `${STATUS_PREFIX}Too Many Request`, + description: "Request limit exceeded, please try again later.", + command: "tabby.outputPanel.focus", + } + } default: { return { label: `${STATUS_PREFIX}Unknown Status`, From eadf8732eedad10868e9ab9bcb0fda7f049affa3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 02:33:35 +0000 Subject: [PATCH 04/17] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/http/tabbyApiClient.ts | 4 ++-- clients/tabby-agent/src/status.ts | 4 ++-- clients/vscode/src/commands/commandPalette.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 6894238bcba0..d344c9b5f699 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -180,9 +180,9 @@ export class TabbyApiClient extends EventEmitter { private updateIsRateLimited(isRateLimited: boolean) { if (this.rateLimited != isRateLimited) { - this.logger.debug(`updateIsRateLimited, next:${isRateLimited}`) + this.logger.debug(`updateIsRateLimited, next:${isRateLimited}`); this.rateLimited = isRateLimited; - this.emit('isRateLimitedUpdated', isRateLimited); + this.emit("isRateLimitedUpdated", isRateLimited); } } diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 3597dbb20914..731c27784300 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -70,9 +70,9 @@ export class StatusProvider extends EventEmitter implements Feature { this.tabbyApiClient.on("hasCompletionResponseTimeIssueUpdated", async () => { this.notify(); }); - this.tabbyApiClient.on('isRateLimitedUpdated', async () => { + this.tabbyApiClient.on("isRateLimitedUpdated", async () => { this.notify(); - }) + }); this.configurations.on( "clientProvidedConfigUpdated", diff --git a/clients/vscode/src/commands/commandPalette.ts b/clients/vscode/src/commands/commandPalette.ts index b7c95e05be3c..415c201544a9 100644 --- a/clients/vscode/src/commands/commandPalette.ts +++ b/clients/vscode/src/commands/commandPalette.ts @@ -214,7 +214,7 @@ export class CommandPalette { label: `${STATUS_PREFIX}Too Many Request`, description: "Request limit exceeded, please try again later.", command: "tabby.outputPanel.focus", - } + }; } default: { return { From a0d177207f5b1709d0d5f8ab2cbc515eed359e6d Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 10:46:13 +0800 Subject: [PATCH 05/17] update --- clients/tabby-agent/src/http/tabbyApiClient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index d344c9b5f699..1b384c66d7e3 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -348,7 +348,6 @@ export class TabbyApiClient extends EventEmitter { } } - // todo async fetchCompletion( request: TabbyApiComponents["schemas"]["CompletionRequest"], signal?: AbortSignal, From 61cff29e0cca4a955f6cb350ea9578db98c183ae Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 10:48:28 +0800 Subject: [PATCH 06/17] update --- clients/tabby-agent/src/utils/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/utils/error.ts b/clients/tabby-agent/src/utils/error.ts index ad017fe5ef1a..0df1fd0b4a03 100644 --- a/clients/tabby-agent/src/utils/error.ts +++ b/clients/tabby-agent/src/utils/error.ts @@ -36,7 +36,7 @@ export function isUnauthorizedError(error: any) { } export function isRateLimitedError(error: any) { - return error instanceof HttpError && [429].includes(error.status); + return error instanceof HttpError && error.status === 429; } export function errorToString(error: Error) { From e0f75f61a56f71e880cef21c2fe018d2ac044b95 Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 12:19:00 +0800 Subject: [PATCH 07/17] update --- clients/tabby-agent/src/http/tabbyApiClient.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 1b384c66d7e3..63da0e4bb231 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -180,7 +180,7 @@ export class TabbyApiClient extends EventEmitter { private updateIsRateLimited(isRateLimited: boolean) { if (this.rateLimited != isRateLimited) { - this.logger.debug(`updateIsRateLimited, next:${isRateLimited}`); + this.logger.debug(`updateIsRateLimited: ${isRateLimited}`); this.rateLimited = isRateLimited; this.emit("isRateLimitedUpdated", isRateLimited); } @@ -401,6 +401,7 @@ export class TabbyApiClient extends EventEmitter { } else if (isRateLimitedError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); statsData.rateLimited = true; + statsData.notAvailable = true; } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; @@ -413,6 +414,7 @@ export class TabbyApiClient extends EventEmitter { if (!statsData.notAvailable) { stats?.addRequestStatsEntry(statsData); } + if (!statsData.notAvailable && !statsData.canceled) { this.completionRequestStats.add(statsData.latency); const statsResult = this.completionRequestStats.stats(); From 900e3eeabf7e86467700c74143b3b545c79a133e Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 14:44:28 +0800 Subject: [PATCH 08/17] update --- clients/tabby-agent/src/http/tabbyApiClient.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 63da0e4bb231..8ee4f557b62d 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -367,7 +367,6 @@ export class TabbyApiClient extends EventEmitter { canceled: false, timeout: false, notAvailable: false, - rateLimited: false, }; try { @@ -385,6 +384,7 @@ export class TabbyApiClient extends EventEmitter { } this.logger.trace(`Completion response data: [${requestId}]`, response.data); statsData.latency = performance.now() - requestStartedAt; + this.updateIsRateLimited(false); return response.data; } catch (error) { this.updateIsFetchingCompletion(false); @@ -397,20 +397,20 @@ export class TabbyApiClient extends EventEmitter { } else if (isUnauthorizedError(error)) { this.logger.debug(`Completion request failed due to unauthorized. [${requestId}]`); statsData.notAvailable = true; + this.updateIsRateLimited(false); this.connect(); // schedule a reconnection } else if (isRateLimitedError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); - statsData.rateLimited = true; statsData.notAvailable = true; + this.updateIsRateLimited(true) } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; + this.updateIsRateLimited(false); this.connect(); // schedule a reconnection } throw error; // rethrow error } finally { - this.updateIsRateLimited(statsData.rateLimited); - if (!statsData.notAvailable) { stats?.addRequestStatsEntry(statsData); } From ec4b26c391538b936f89109dca9a8fd4fba7ffa7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 06:45:51 +0000 Subject: [PATCH 09/17] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/http/tabbyApiClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 8ee4f557b62d..df064ffbcc34 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -402,7 +402,7 @@ export class TabbyApiClient extends EventEmitter { } else if (isRateLimitedError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); statsData.notAvailable = true; - this.updateIsRateLimited(true) + this.updateIsRateLimited(true); } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; From f24d6c93287ab0219ba7723a0aa7cffc4c7561cc Mon Sep 17 00:00:00 2001 From: aliang Date: Tue, 31 Dec 2024 14:46:53 +0800 Subject: [PATCH 10/17] Update clients/tabby-agent/src/protocol.ts Co-authored-by: Zhiming Ma --- clients/tabby-agent/src/protocol.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/protocol.ts b/clients/tabby-agent/src/protocol.ts index dc8b8993baea..63006e711d5e 100644 --- a/clients/tabby-agent/src/protocol.ts +++ b/clients/tabby-agent/src/protocol.ts @@ -850,7 +850,7 @@ export type StatusInfo = { | "readyForManualTrigger" | "fetching" | "completionResponseSlow" - | "rateLimited"; + | "rateLimitExceeded"; tooltip?: string; /** * The health information of the server if available. From b2128aa5bb8e6cc13dff1364fc6d8884eebf5963 Mon Sep 17 00:00:00 2001 From: aliang Date: Tue, 31 Dec 2024 14:47:20 +0800 Subject: [PATCH 11/17] Update clients/tabby-agent/src/status.ts Co-authored-by: Zhiming Ma --- clients/tabby-agent/src/status.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 731c27784300..9914c8bc2a4a 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -206,10 +206,10 @@ export class StatusProvider extends EventEmitter implements Feature { case "ready": { const ignored = this.dataStore.data.statusIgnoredIssues ?? []; - if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { - statusInfo = { status: "completionResponseSlow" }; - } else if (this.tabbyApiClient.isRateLimited()) { + if (this.tabbyApiClient.isRateLimited()) { statusInfo = { status: "rateLimited" }; + } else if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { + statusInfo = { status: "completionResponseSlow" }; } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; } else { From 4414dff48537d98420e8de4e9f352fa4f8d9e477 Mon Sep 17 00:00:00 2001 From: aliang Date: Tue, 31 Dec 2024 14:47:28 +0800 Subject: [PATCH 12/17] Update clients/tabby-agent/src/status.ts Co-authored-by: Zhiming Ma --- clients/tabby-agent/src/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 9914c8bc2a4a..51df67b06ddc 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -270,7 +270,7 @@ export class StatusProvider extends EventEmitter implements Feature { statusInfo.tooltip = "Tabby: Slow Completion Response Detected"; break; case "rateLimited": - statusInfo.tooltip = "Tabby: Too many request"; + statusInfo.tooltip = "Tabby: Too Many Requests"; break; default: break; From 11231fec32b25d9cbf2456291f658efc3fd73144 Mon Sep 17 00:00:00 2001 From: aliang Date: Tue, 31 Dec 2024 14:47:45 +0800 Subject: [PATCH 13/17] Update clients/vscode/src/commands/commandPalette.ts Co-authored-by: Zhiming Ma --- clients/vscode/src/commands/commandPalette.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/vscode/src/commands/commandPalette.ts b/clients/vscode/src/commands/commandPalette.ts index 415c201544a9..934e99973bba 100644 --- a/clients/vscode/src/commands/commandPalette.ts +++ b/clients/vscode/src/commands/commandPalette.ts @@ -211,8 +211,8 @@ export class CommandPalette { } case "rateLimited": { return { - label: `${STATUS_PREFIX}Too Many Request`, - description: "Request limit exceeded, please try again later.", + label: `${STATUS_PREFIX}Too Many Requests`, + description: "Request limit exceeded", command: "tabby.outputPanel.focus", }; } From 70660809e9b0f39b8adcc2435c922f523847454f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 06:48:55 +0000 Subject: [PATCH 14/17] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/status.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 51df67b06ddc..27d824f8c959 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -208,7 +208,10 @@ export class StatusProvider extends EventEmitter implements Feature { const ignored = this.dataStore.data.statusIgnoredIssues ?? []; if (this.tabbyApiClient.isRateLimited()) { statusInfo = { status: "rateLimited" }; - } else if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { + } else if ( + this.tabbyApiClient.hasCompletionResponseTimeIssue() && + !ignored.includes("completionResponseSlow") + ) { statusInfo = { status: "completionResponseSlow" }; } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; From f77d2ce88b96df1f117a550762bf51d60033eb59 Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 14:57:38 +0800 Subject: [PATCH 15/17] update --- .../tabby-agent/src/http/tabbyApiClient.ts | 24 +++++++++---------- clients/tabby-agent/src/status.ts | 13 ++++------ clients/vscode/src/StatusBarItem.ts | 2 +- clients/vscode/src/commands/commandPalette.ts | 2 +- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index df064ffbcc34..72797eaa530c 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -49,7 +49,7 @@ export class TabbyApiClient extends EventEmitter { private readonly completionRequestStats = new RequestStats(); private completionResponseIssue: "highTimeoutRate" | "slowResponseTime" | undefined = undefined; - private rateLimited: boolean = false; + private rateLimitExceeded: boolean = false; private connectionErrorMessage: string | undefined = undefined; private serverHealth: TabbyApiComponents["schemas"]["HealthState"] | undefined = undefined; @@ -178,11 +178,11 @@ export class TabbyApiClient extends EventEmitter { } } - private updateIsRateLimited(isRateLimited: boolean) { - if (this.rateLimited != isRateLimited) { - this.logger.debug(`updateIsRateLimited: ${isRateLimited}`); - this.rateLimited = isRateLimited; - this.emit("isRateLimitedUpdated", isRateLimited); + private updateIsRateLimitExceeded(isRateLimitExceeded: boolean) { + if (this.rateLimitExceeded != isRateLimitExceeded) { + this.logger.debug(`updateIsRateLimitExceeded: ${isRateLimitExceeded}`); + this.rateLimitExceeded = isRateLimitExceeded; + this.emit("isRateLimitExceededUpdated", isRateLimitExceeded); } } @@ -224,8 +224,8 @@ export class TabbyApiClient extends EventEmitter { return !!this.completionResponseIssue; } - isRateLimited(): boolean { - return this.rateLimited; + isRateLimitExceeded(): boolean { + return this.rateLimitExceeded; } getServerHealth(): TabbyApiComponents["schemas"]["HealthState"] | undefined { @@ -384,7 +384,7 @@ export class TabbyApiClient extends EventEmitter { } this.logger.trace(`Completion response data: [${requestId}]`, response.data); statsData.latency = performance.now() - requestStartedAt; - this.updateIsRateLimited(false); + this.updateIsRateLimitExceeded(false); return response.data; } catch (error) { this.updateIsFetchingCompletion(false); @@ -397,16 +397,16 @@ export class TabbyApiClient extends EventEmitter { } else if (isUnauthorizedError(error)) { this.logger.debug(`Completion request failed due to unauthorized. [${requestId}]`); statsData.notAvailable = true; - this.updateIsRateLimited(false); + this.updateIsRateLimitExceeded(false); this.connect(); // schedule a reconnection } else if (isRateLimitedError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); statsData.notAvailable = true; - this.updateIsRateLimited(true); + this.updateIsRateLimitExceeded(true); } else { this.logger.error(`Completion request failed. [${requestId}]`, error); statsData.notAvailable = true; - this.updateIsRateLimited(false); + this.updateIsRateLimitExceeded(false); this.connect(); // schedule a reconnection } throw error; // rethrow error diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 27d824f8c959..1be6493bfc0e 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -70,7 +70,7 @@ export class StatusProvider extends EventEmitter implements Feature { this.tabbyApiClient.on("hasCompletionResponseTimeIssueUpdated", async () => { this.notify(); }); - this.tabbyApiClient.on("isRateLimitedUpdated", async () => { + this.tabbyApiClient.on("isRateLimitExceededUpdated", async () => { this.notify(); }); @@ -206,12 +206,9 @@ export class StatusProvider extends EventEmitter implements Feature { case "ready": { const ignored = this.dataStore.data.statusIgnoredIssues ?? []; - if (this.tabbyApiClient.isRateLimited()) { - statusInfo = { status: "rateLimited" }; - } else if ( - this.tabbyApiClient.hasCompletionResponseTimeIssue() && - !ignored.includes("completionResponseSlow") - ) { + if (this.tabbyApiClient.isRateLimitExceeded()) { + statusInfo = { status: "rateLimitExceeded" }; + } else if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { statusInfo = { status: "completionResponseSlow" }; } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; @@ -272,7 +269,7 @@ export class StatusProvider extends EventEmitter implements Feature { case "completionResponseSlow": statusInfo.tooltip = "Tabby: Slow Completion Response Detected"; break; - case "rateLimited": + case "rateLimitExceeded": statusInfo.tooltip = "Tabby: Too Many Requests"; break; default: diff --git a/clients/vscode/src/StatusBarItem.ts b/clients/vscode/src/StatusBarItem.ts index 751df388e942..8a0fc7c98bd0 100644 --- a/clients/vscode/src/StatusBarItem.ts +++ b/clients/vscode/src/StatusBarItem.ts @@ -94,7 +94,7 @@ export class StatusBarItem { break; } case "completionResponseSlow": - case "rateLimited": { + case "rateLimitExceeded": { this.setColorWarning(); this.setIcon(iconWarning); this.setTooltip(statusInfo.tooltip); diff --git a/clients/vscode/src/commands/commandPalette.ts b/clients/vscode/src/commands/commandPalette.ts index 934e99973bba..83f2e7692869 100644 --- a/clients/vscode/src/commands/commandPalette.ts +++ b/clients/vscode/src/commands/commandPalette.ts @@ -209,7 +209,7 @@ export class CommandPalette { }, }; } - case "rateLimited": { + case 'rateLimitExceeded': { return { label: `${STATUS_PREFIX}Too Many Requests`, description: "Request limit exceeded", From 24f716cb86c50756d1291e8d04054448c54ab7fd Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 06:58:54 +0000 Subject: [PATCH 16/17] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/status.ts | 5 ++++- clients/vscode/src/commands/commandPalette.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 1be6493bfc0e..4a2e47320b77 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -208,7 +208,10 @@ export class StatusProvider extends EventEmitter implements Feature { const ignored = this.dataStore.data.statusIgnoredIssues ?? []; if (this.tabbyApiClient.isRateLimitExceeded()) { statusInfo = { status: "rateLimitExceeded" }; - } else if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) { + } else if ( + this.tabbyApiClient.hasCompletionResponseTimeIssue() && + !ignored.includes("completionResponseSlow") + ) { statusInfo = { status: "completionResponseSlow" }; } else if (this.tabbyApiClient.isFetchingCompletion()) { statusInfo = { status: "fetching" }; diff --git a/clients/vscode/src/commands/commandPalette.ts b/clients/vscode/src/commands/commandPalette.ts index 83f2e7692869..5a02c54e5c2d 100644 --- a/clients/vscode/src/commands/commandPalette.ts +++ b/clients/vscode/src/commands/commandPalette.ts @@ -209,7 +209,7 @@ export class CommandPalette { }, }; } - case 'rateLimitExceeded': { + case "rateLimitExceeded": { return { label: `${STATUS_PREFIX}Too Many Requests`, description: "Request limit exceeded", From 93e5b09ae5c62d19b725eb141f1978edfcc8ce4c Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 31 Dec 2024 15:04:01 +0800 Subject: [PATCH 17/17] update --- clients/tabby-agent/src/http/tabbyApiClient.ts | 4 ++-- clients/tabby-agent/src/utils/error.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 72797eaa530c..c6e09ba5deb3 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -26,7 +26,7 @@ import { isUnauthorizedError, isCanceledError, isTimeoutError, - isRateLimitedError, + isRateLimitExceededError, } from "../utils/error"; import { RequestStats } from "./statistics"; @@ -399,7 +399,7 @@ export class TabbyApiClient extends EventEmitter { statsData.notAvailable = true; this.updateIsRateLimitExceeded(false); this.connect(); // schedule a reconnection - } else if (isRateLimitedError(error)) { + } else if (isRateLimitExceededError(error)) { this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`); statsData.notAvailable = true; this.updateIsRateLimitExceeded(true); diff --git a/clients/tabby-agent/src/utils/error.ts b/clients/tabby-agent/src/utils/error.ts index 0df1fd0b4a03..cf963724cff0 100644 --- a/clients/tabby-agent/src/utils/error.ts +++ b/clients/tabby-agent/src/utils/error.ts @@ -35,7 +35,7 @@ export function isUnauthorizedError(error: any) { return error instanceof HttpError && [401, 403].includes(error.status); } -export function isRateLimitedError(error: any) { +export function isRateLimitExceededError(error: any) { return error instanceof HttpError && error.status === 429; }