Skip to content

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

address ui problem

adilson5695262ffe8a
diff --git a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts
new file mode 100644
index 0000000000..a0e78d89c3
--- /dev/null
+++ b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.test.ts
@@ -0,0 +1,74 @@
+import assert from "node:assert/strict";
+import { afterEach, beforeEach, describe, it, vi } from "vitest";
+
+import { DelegatedApprovalRequestStatus } from "../delegatedApprovals/enums";
+import {
+ hasDelegatedDispatchRetries,
+ isDelegatedDispatchRetrying,
+ markDelegatedDispatchRetry,
+ noteDelegatedDispatchRetryStatuses
+} from "./retrying-delegated-dispatch";
+
+const markedIds = new Set<string>();
+
+const mark = (id: string) => {
+ markedIds.add(id);
+ markDelegatedDispatchRetry(id);
+};
+
+const note = (id: string, status: DelegatedApprovalRequestStatus | null) =>
+ noteDelegatedDispatchRetryStatuses([{ id, status }]);
+
+describe("delegated dispatch retry store", () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ });
+
+ afterEach(() => {
+ noteDelegatedDispatchRetryStatuses([...markedIds].map((id) => ({ id, status: null })));
+ markedIds.clear();
+ vi.useRealTimers();
+ });
+
+ it("keeps the retry while the outbox has not picked up the resend", () => {
+ mark("before-pickup");
+ vi.advanceTimersByTime(10_000);
+ note("before-pickup", DelegatedApprovalRequestStatus.FailedDispatch);
+
+ assert.equal(isDelegatedDispatchRetrying("before-pickup"), true);
+ });
+
+ it("clears the retry when the resend failed between two polls", () => {
+ mark("missed-pending");
+ note("missed-pending", DelegatedApprovalRequestStatus.FailedDispatch);
+ vi.advanceTimersByTime(30_000);
+ 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", () => {
+ mark("seen-pending");
+ note("seen-pending", DelegatedApprovalRequestStatus.PendingDispatch);
+ note("seen-pending", DelegatedApprovalRequestStatus.FailedDispatch);
+
+ assert.equal(isDelegatedDispatchRetrying("seen-pending"), false);
+ });
+
+ it("keeps the retry while the dispatch is running past the pickup window", () => {
+ mark("long-dispatch");
+ note("long-dispatch", DelegatedApprovalRequestStatus.PendingDispatch);
+ vi.advanceTimersByTime(60_000);
+ note("long-dispatch", DelegatedApprovalRequestStatus.PendingDispatch);
+
+ assert.equal(isDelegatedDispatchRetrying("long-dispatch"), true);
+ });
+
+ it("clears the retry as soon as the request reaches the delegated system", () => {
+ mark("delivered");
+ note("delivered", DelegatedApprovalRequestStatus.WaitingApproval);
+
+ assert.equal(isDelegatedDispatchRetrying("delivered"), false);
+ });
+});
diff --git a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
index 8595b6f318..40d0dec51b 100644
--- a/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
+++ b/frontend/src/hooks/api/accessApproval/retrying-delegated-dispatch.ts
@@ -4,7 +4,9 @@ import { DelegatedApprovalRequestStatus } from "../delegatedApprovals/enums";
type RetryPhase = "awaiting-dispatch" | "dispatching";
-const retries = new Map<string, RetryPhase>();
+const DISPATCH_PICKUP_WINDOW_MS = 30_000;
+
+const retries = new Map<string, { phase: RetryPhase; markedAt: number }>();
const listeners = new Set<() => void>();
let version = 0;
@@ -21,7 +23,7 @@ const subscribe = (listener: () => void) => {
};
export const markDelegatedDispatchRetry = (requestId: string) => {
- retries.set(requestId, "awaiting-dispatch");
+ retries.set(requestId, { phase: "awaiting-dispatch", markedAt: Date.now() });
emit();
};
@@ -37,8 +39,8 @@ export const noteDelegatedDispatchRetryStatuses = (
let changed = false;
requests.forEach(({ id, status }) => {
- const phase = retries.get(id);
- if (!phase) return;
+ const retry = retries.get(id);
+ if (!retry) return;
if (!status) {
retries.delete(id);
@@ -46,12 +48,13 @@ export const noteDelegatedDispatchRetryStatuses = (
return;
}
- if (phase === "awaiting-dispatch") {
+ if (retry.phase === "awaiting-dispatch") {
if (status === DelegatedApprovalRequestStatus.PendingDispatch) {
- retries.set(id, "dispatching");
+ retries.set(id, { ...retry, phase: "dispatching" });
return;
}
- if (status === DelegatedApprovalRequestStatus.FailedDispatch) return;
+ const isAwaitingPickup = Date.now() - retry.markedAt < DISPATCH_PICKUP_WINDOW_MS;
+ if (status === DelegatedApprovalRequestStatus.FailedDispatch && isAwaitingPickup) return;
retries.delete(id);
changed = true;