Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

order by expire At

Thiago Araujo da Silvac81e39fad2c8
diff --git a/backend/src/services/alert/alert-types.ts b/backend/src/services/alert/alert-types.ts
index a8c1bac20c..8d62e78f7f 100644
--- a/backend/src/services/alert/alert-types.ts
+++ b/backend/src/services/alert/alert-types.ts
@@ -74,6 +74,9 @@ export interface IResourceAlertProvider<TTarget = unknown> {
// Resources currently due to alert for this alert's scope + condition. The engine handles dedup
// afterwards, so this returns all current matches in the window (not minus already-alerted).
+ // Must be ordered most-urgent-first (soonest expiry): the engine's per-channel maxTargetsPerRun cap
+ // keeps the head of this list and defers the tail, so urgency ordering ensures the targets closest
+ // to expiry are never the ones dropped.
findDueTargets(input: TFindDueTargetsInput): Promise<TTarget[]>;
// Deep link to the alert's resource, honouring its scope (org- vs project-scoped). Resolved once
diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.ts
index 40b44b98fe..08a47e2b49 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-dal.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.ts
@@ -54,7 +54,8 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {
.where(`${TableName.IdentityUaClientSecret}.isClientSecretRevoked`, false)
.where(`${TableName.IdentityUaClientSecret}.clientSecretTTL`, ">", 0)
.whereRaw(`${expiresAtSql} > ?`, [asOf])
- .whereRaw(`${expiresAtSql} <= ? + ?::interval + ?::interval`, [asOf, alertBeforeInterval, leadInterval]);
+ .whereRaw(`${expiresAtSql} <= ? + ?::interval + ?::interval`, [asOf, alertBeforeInterval, leadInterval])
+ .orderByRaw(`${expiresAtSql} asc`);
if (projectId) {
void query