Skip to content

Commit 93a94da

Browse files
committed
fix: monotonic release timestamp for LRU rotation, clarify isInvalid TTL
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent 24d0730 commit 93a94da

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

services/apps/security_best_practices_worker/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ export interface ITokenInfo {
5555
lastUsed: Date
5656
isRateLimited: boolean
5757
rateLimitedAt?: string // ISO timestamp; used to auto-reset after 1 hour
58-
isInvalid?: boolean // permanent auth failure — never auto-resets
58+
isInvalid?: boolean // 401 auth failure; persists until the Redis token cache expires (24h TTL) — after a full idle day the token re-enters the pool fresh, giving re-provisioned PATs a natural recovery path
5959
}

services/apps/security_best_practices_worker/src/workflows/triggerSecurityInsightsCheckForRepos.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const { findObsoleteRepos, initializeTokenInfos, updateTokenInfos, getCurrentTim
2121

2222
const ONE_HOUR_MS = 60 * 60 * 1000
2323

24+
// Monotonic offset added to nowMs on each releaseToken so lastUsed is strictly increasing
25+
// per release even when currentTimeMs hasn't refreshed. Without this, sequential releases in
26+
// the same iteration all share currentTimeMs, the stable sort in getNextToken falls back to
27+
// env order, and the first PAT gets re-selected repeatedly instead of rotating LRU.
28+
let releaseCounter = 0
29+
2430
export async function triggerSecurityInsightsCheckForRepos(
2531
args: ITriggerSecurityInsightsCheckForReposParams,
2632
): Promise<void> {
@@ -254,7 +260,7 @@ async function releaseToken(tokenInfos: ITokenInfo[], token: string, nowMs: numb
254260
const tokenInfo = tokenInfos.find((tokenInfo) => tokenInfo.token === token)
255261
if (tokenInfo) {
256262
tokenInfo.inUse = false
257-
tokenInfo.lastUsed = new Date(nowMs)
263+
tokenInfo.lastUsed = new Date(nowMs + releaseCounter++)
258264
}
259265
}
260266

0 commit comments

Comments
 (0)