Skip to content

Commit 2be8763

Browse files
committed
fix: fail repos when all tokens invalid, widen lastUsed to Date | string
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent 93a94da commit 2be8763

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

services/apps/security_best_practices_worker/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export interface ITriggerSecurityInsightsCheckForReposParams {
5252
export interface ITokenInfo {
5353
token: string
5454
inUse: boolean
55-
lastUsed: Date
55+
// Date at initialization time; becomes an ISO string after JSON round-trip through Redis
56+
// and Temporal payloads, so callers must wrap in `new Date()` before comparing.
57+
lastUsed: Date | string
5658
isRateLimited: boolean
5759
rateLimitedAt?: string // ISO timestamp; used to auto-reset after 1 hour
5860
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

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,20 @@ export async function triggerSecurityInsightsCheckForRepos(
182182
if (activeTasks.length > 0) {
183183
await Promise.race(activeTasks)
184184
} else if (queue.length > 0) {
185-
// No active tasks and no free tokens — remaining repos can't be processed this batch.
186-
// Don't add them to failedRepoUrls: they're still obsolete and findObsoleteRepos will
187-
// pick them up on the next batch after rate limits expire.
185+
// No active tasks and no free tokens. If every token is permanently invalid, deferring
186+
// would loop forever across scheduled runs — fail the remaining repos so ops sees the
187+
// problem instead of a silent stall.
188+
const allPermanentlyInvalid = tokenInfos.every((t) => t.isInvalid)
189+
if (allPermanentlyInvalid) {
190+
console.error(
191+
`All tokens permanently invalid; marking ${queue.length} remaining repos as failed`,
192+
)
193+
for (const repo of queue) failedRepoUrls.push(repo.repoUrl)
194+
queue.length = 0
195+
break
196+
}
197+
// Otherwise defer: remaining repos are still obsolete and findObsoleteRepos will pick
198+
// them up on the next batch after rate limits expire.
188199
console.warn(
189200
`No tokens available; deferring ${queue.length} repos to next batch (they will be re-fetched)`,
190201
)

0 commit comments

Comments
 (0)