Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/sse/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,29 @@ export async function getProviderCredentials(
return null;
}

// Auto-decay backoffLevel for accounts whose rateLimitedUntil has passed.
// Without this, high backoffLevel permanently deprioritizes accounts even
// after the rate limit window expires, creating a deadlock where the account
// needs a successful request to reset but never gets selected.
for (const c of connections) {
if (
c.backoffLevel > 0 &&
!isTerminalConnectionStatus(c) &&
!isAccountUnavailable(c.rateLimitedUntil)
) {
c.backoffLevel = 0;
updateProviderConnection(c.id, {
backoffLevel: 0,
testStatus: "active",
lastError: null,
lastErrorAt: null,
lastErrorType: null,
lastErrorSource: null,
errorCode: null,
}).catch(() => {});
Comment on lines +382 to +390

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This update object is very similar to the one used in clearAccountError (lines 859-868), creating code duplication. This could become a maintenance concern if new error-related fields are added in the future. It would be beneficial to refactor this to a shared helper or constant.

I have a couple of suggestions for this block:

  1. For consistency with clearAccountError, consider adding rateLimitedUntil: null to the update payload, since the rate limit has passed.
  2. Swallowing errors with an empty .catch(() => {}) can hide underlying problems. While this is a fire-and-forget operation, logging the error would be valuable for debugging without blocking the request.
        updateProviderConnection(c.id, {
          backoffLevel: 0,
          testStatus: "active",
          lastError: null,
          lastErrorAt: null,
          lastErrorType: null,
          lastErrorSource: null,
          errorCode: null,
          rateLimitedUntil: null,
        }).catch((err) =>
          log.warn("AUTH", `Failed to auto-decay backoffLevel for ${c.id.slice(0, 8)}`, err)
        );

}
}

// Filter out unavailable accounts and excluded connection
const availableConnections = connections.filter((c) => {
if (excludeConnectionId && c.id === excludeConnectionId) return false;
Expand Down
Loading