Skip to content

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

define the decision requested at as null on the last attempt

adilsonebcb27098c4e
diff --git a/CLAUDE.md b/CLAUDE.md
index fdb3b8f032..2bf4239fa8 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -209,17 +209,18 @@ refusal (no row for the record id, bad or missing token, request not `waiting_ap
gets one neutral 403 while the reason goes to the log. An accepted callback only emits an outbox event, and
only when it wins `claimDecisionRead`: a conditional update of `decisionReadRequestedAt`, in the emit's
transaction, that one of any number of concurrent callbacks wins. A repeat while a read-back is still in
-flight gets the same 200, emits nothing and is not counted; a claim older than `DELEGATED_APPROVAL_DECISION_READ_CLAIM_TTL_MS`
-(70 minutes, past the outbox's last retry) has expired, so a fresh notification after an earlier read-back
-ran out of retries still starts one. `eventType` is the
+flight gets the same 200, emits nothing and is not counted. The last read-back attempt clears
+`decisionReadRequestedAt`, so a callback after the outbox gives up claims immediately. A claim whose worker
+died before that write stays until it is older than `DELEGATED_APPROVAL_DECISION_READ_CLAIM_TTL_MS`
+(70 minutes), which is what lets a fresh notification start one then. `eventType` is the
body's event and `idempotencyKey` is the delegated request id plus the attempt count. The
`delegated-approval-decision` consumer (`backend/src/services/delegated-approval-decision/`, a thin outbox
adapter over `delegatedApprovalDecisionService.applyDecision` that, like dispatch, reads up to 10 different
requests at once and one request's events serially) then reads the decision back through the
policy's app connection: `TDelegatedApprovalProvider.fetchDecision` returns `pending` or a decision with
the permissions the provider holds, and the consumer answers `Retry` for `pending` (on the last attempt, `Failed`
-with the request left open and a `statusReason` saying Infisical stopped checking and the callback has to be
-sent again, which the claim TTL lets start a new read-back), compares the approved
+with the request left open, `decisionReadRequestedAt` cleared, and a `statusReason` saying Infisical stopped
+checking and the callback has to be sent again), compares the approved
permissions with the ones it dispatched after both go through `normalizeDelegatedApprovalPermissions` (set
comparison: padding, order, duplicates and case never count as a change), and finalizes in one transaction
that locks the approval request, moves the delegated row `waiting_approval` → `approved` / `rejected`, and
diff --git a/backend/src/services/delegated-approval-decision/delegated-approval-decision-consumer.test.ts b/backend/src/services/delegated-approval-decision/delegated-approval-decision-consumer.test.ts
index 09eebc1f25..ea05536c65 100644
--- a/backend/src/services/delegated-approval-decision/delegated-approval-decision-consumer.test.ts
+++ b/backend/src/services/delegated-approval-decision/delegated-approval-decision-consumer.test.ts
@@ -62,6 +62,7 @@ const APPROVAL_REQUEST_ID = "33333333-3333-3333-3333-333333333333";
const ORG_ID = "22222222-2222-2222-2222-222222222222";
const EXTERNAL_ID = "snow-1";
const POLICY_NAME = "Production secrets";
+const DECISION_READ_REQUESTED_AT = new Date("2026-10-27T15:00:00.000Z");
const TX = { tx: true } as never;
const PRIMARY = { primary: true } as never;
const SERVICENOW_RECORD = { type: DelegatedApprovalPolicyType.ServiceNow, recordNumber: "INFAR1000000" };
@@ -70,7 +71,8 @@ const waitingDelegatedRequest = {
requestId: APPROVAL_REQUEST_ID,
status: DelegatedApprovalRequestStatus.WaitingApproval,
details: { statusReason: null, provider: SERVICENOW_RECORD } as TDelegatedApprovalRequestDetails,
- providerRequestId: EXTERNAL_ID as string | null
+ providerRequestId: EXTERNAL_ID as string | null,
+ decisionReadRequestedAt: DECISION_READ_REQUESTED_AT as Date | null
};
type TDelegatedRow = typeof waitingDelegatedRequest;
@@ -362,6 +364,7 @@ describe("delegatedApprovalDecisionConsumer", () => {
}
});
expect(approval()?.status).toBe(ApprovalRequestStatus.Pending);
+ expect(row()?.decisionReadRequestedAt).toEqual(DECISION_READ_REQUESTED_AT);
expect(createAuditLog).not.toHaveBeenCalled();
});
@@ -518,6 +521,7 @@ describe("delegatedApprovalDecisionConsumer", () => {
}
});
expect(approval()?.status).toBe(ApprovalRequestStatus.Pending);
+ expect(row()?.decisionReadRequestedAt).toBeNull();
expect(createAuditLog).not.toHaveBeenCalled();
});
@@ -532,6 +536,7 @@ describe("delegatedApprovalDecisionConsumer", () => {
expect(row()?.details.statusReason).toBe(
`ServiceNow could not be reached. ${DELEGATED_APPROVAL_DECISION_STOPPED_HINT}`
);
+ expect(row()?.decisionReadRequestedAt).toBeNull();
expect(approval()?.status).toBe(ApprovalRequestStatus.Pending);
});
@@ -554,6 +559,7 @@ describe("delegatedApprovalDecisionConsumer", () => {
expect(result).toEqual({ id: "1", status, error: "The grant could not be written." });
expect(row()?.status).toBe(DelegatedApprovalRequestStatus.WaitingApproval);
expect(row()?.details.statusReason).toBe(statusReason);
+ expect(row()?.decisionReadRequestedAt).toEqual(isFinalAttempt ? null : DECISION_READ_REQUESTED_AT);
expect(approval()?.status).toBe(ApprovalRequestStatus.Pending);
expect(createAuditLog).not.toHaveBeenCalled();
}
diff --git a/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts b/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
index 0a73787822..85e3169c08 100644
--- a/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
+++ b/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
@@ -114,7 +114,10 @@ export const delegatedApprovalDecisionServiceFactory = ({
try {
await delegatedApprovalRequestDAL.updateWithDetails(
{ id: delegatedRequestId, status: DelegatedApprovalRequestStatus.WaitingApproval },
- { details: { statusReason: toDelegatedApprovalStatusReason(`${reason} ${hint}`) } }
+ {
+ ...(isFinalAttempt ? { decisionReadRequestedAt: null } : {}),
+ details: { statusReason: toDelegatedApprovalStatusReason(`${reason} ${hint}`) }
+ }
);
} catch (error) {
logger.error(