Skip to content

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

fix retry on the UI so it does not run indefinetly

adilson7189f90c3401
diff --git a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts
index 1bd5828c15..e6c4ecd618 100644
--- a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts
+++ b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts
@@ -894,8 +894,8 @@ export const secretAccessApprovalGlobalRequestBridgeServiceFactory = ({
);
}
- const { delegatedPolicy } = await delegatedApprovalService.retryDispatch({ approvalRequest: request });
const auditDetails = await $describeRequestForAudit(request);
+ const { delegatedPolicy } = await delegatedApprovalService.retryDispatch({ approvalRequest: request });
return {
request: { ...toLegacyAccessApprovalRequest(request), policyId: delegatedPolicy.policyId },
@@ -937,6 +937,7 @@ export const secretAccessApprovalGlobalRequestBridgeServiceFactory = ({
});
}
+ const auditDetails = await $describeRequestForAudit(request);
const policyId = await approvalRequestDAL.transaction(async (tx) => {
const locked = await approvalRequestDAL.findByIdForUpdate(requestId, tx);
if (!locked || locked.status !== ApprovalRequestStatus.Pending || !locked.policyId) {
@@ -946,11 +947,8 @@ export const secretAccessApprovalGlobalRequestBridgeServiceFactory = ({
return locked.policyId;
});
- const cancelled = await $findRequestByIdFromPrimary(requestId);
- const auditDetails = await $describeRequestForAudit(cancelled);
-
return {
- request: { ...toLegacyAccessApprovalRequest(cancelled), policyId },
+ request: { ...toLegacyAccessApprovalRequest(request), policyId },
projectId: request.projectId,
...auditDetails
};
diff --git a/frontend/src/hooks/api/accessApproval/queries.tsx b/frontend/src/hooks/api/accessApproval/queries.tsx
index 757c50da5a..c24d900e0d 100644
--- a/frontend/src/hooks/api/accessApproval/queries.tsx
+++ b/frontend/src/hooks/api/accessApproval/queries.tsx
@@ -6,7 +6,7 @@ import { TReactQueryOptions } from "@app/types/reactQuery";
import { DelegatedApprovalRequestStatus } from "../delegatedApprovals/enums";
import { TProjectPermission } from "../roles/types";
-import { hasDelegatedDispatchRetries } from "./retrying-delegated-dispatch";
+import { isDelegatedDispatchRetrying } from "./retrying-delegated-dispatch";
import {
TAccessApprovalPolicy,
TAccessApprovalRequest,
@@ -142,9 +142,9 @@ export const useGetAccessApprovalRequests = ({
refetchInterval:
options?.refetchInterval ??
((query) =>
- hasDelegatedDispatchRetries() ||
query.state.data?.some(
(request) =>
+ isDelegatedDispatchRetrying(request.id) ||
request.delegatedApproval?.status === DelegatedApprovalRequestStatus.PendingDispatch
)
? DELEGATED_DISPATCH_POLL_MS
diff --git a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts
index a0e78d89c3..64e49aba1a 100644
--- a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts
+++ b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts
@@ -3,7 +3,6 @@ import { afterEach, beforeEach, describe, it, vi } from "vitest";
import { DelegatedApprovalRequestStatus } from "../delegatedApprovals/enums";
import {
- hasDelegatedDispatchRetries,
isDelegatedDispatchRetrying,
markDelegatedDispatchRetry,
noteDelegatedDispatchRetryStatuses
@@ -45,7 +44,6 @@ describe("delegated dispatch retry store", () => {
note("missed-pending", DelegatedApprovalRequestStatus.FailedDispatch);
assert.equal(isDelegatedDispatchRetrying("missed-pending"), false);
- assert.equal(hasDelegatedDispatchRetries(), false);
});
it("clears the retry once a dispatch it saw start has failed", () => {
@@ -71,4 +69,20 @@ describe("delegated dispatch retry store", () => {
assert.equal(isDelegatedDispatchRetrying("delivered"), false);
});
+
+ it("keeps a retry another list does not include until it expires", () => {
+ mark("other-env");
+ vi.advanceTimersByTime(10_000);
+ note("unrelated", DelegatedApprovalRequestStatus.WaitingApproval);
+
+ assert.equal(isDelegatedDispatchRetrying("other-env"), true);
+ });
+
+ it("drops a retry whose request never shows up again", () => {
+ mark("left-the-list");
+ vi.advanceTimersByTime(120_000);
+ note("unrelated", DelegatedApprovalRequestStatus.WaitingApproval);
+
+ assert.equal(isDelegatedDispatchRetrying("left-the-list"), false);
+ });
});
diff --git a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
index 40d0dec51b..bd07178faa 100644
--- a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
+++ b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
@@ -5,6 +5,7 @@ import { DelegatedApprovalRequestStatus } from "../delegatedApprovals/enums";
type RetryPhase = "awaiting-dispatch" | "dispatching";
const DISPATCH_PICKUP_WINDOW_MS = 30_000;
+const RETRY_TRACKING_TTL_MS = 120_000;
const retries = new Map<string, { phase: RetryPhase; markedAt: number }>();
const listeners = new Set<() => void>();
@@ -29,15 +30,20 @@ export const markDelegatedDispatchRetry = (requestId: string) => {
export const isDelegatedDispatchRetrying = (requestId: string) => retries.has(requestId);
-export const hasDelegatedDispatchRetries = () => retries.size > 0;
-
// A refetch can still return failed_dispatch until the consumer starts. That row is the
// failure the user just retried, so it must not clear the in-flight label.
export const noteDelegatedDispatchRetryStatuses = (
requests: { id: string; status?: DelegatedApprovalRequestStatus | null }[]
) => {
+ const now = Date.now();
let changed = false;
+ retries.forEach((retry, id) => {
+ if (now - retry.markedAt < RETRY_TRACKING_TTL_MS) return;
+ retries.delete(id);
+ changed = true;
+ });
+
requests.forEach(({ id, status }) => {
const retry = retries.get(id);
if (!retry) return;
@@ -53,7 +59,7 @@ export const noteDelegatedDispatchRetryStatuses = (
retries.set(id, { ...retry, phase: "dispatching" });
return;
}
- const isAwaitingPickup = Date.now() - retry.markedAt < DISPATCH_PICKUP_WINDOW_MS;
+ const isAwaitingPickup = now - retry.markedAt < DISPATCH_PICKUP_WINDOW_MS;
if (status === DelegatedApprovalRequestStatus.FailedDispatch && isAwaitingPickup) return;
retries.delete(id);