Skip to content

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

fix: address Greptile review - register cache key in KeyStorePrefixes, add identity context to error logs, document intentional catch fall-through

Devin AI909af55eeb0b
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 6d4e76475b..a5e780d960 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -99,7 +99,9 @@ export const KeyStorePrefixes = {
ProjectSSEConnection: (projectId: string, connectionId: string) =>
`project-sse-conn:${projectId}:${connectionId}` as const,
- ProjectDeleteLock: (projectId: string) => `project-delete-lock-${projectId}` as const
+ ProjectDeleteLock: (projectId: string) => `project-delete-lock-${projectId}` as const,
+
+ TelemetryIdentifyIdentity: (dedupKey: string) => `telemetry-identify-identity:${dedupKey}` as const
};
export const KeyStoreTtls = {
@@ -110,7 +112,8 @@ export const KeyStoreTtls = {
ProjectPermissionDalVersionTtl: "15m", // Project permission DAL version TTL
MfaSessionInSeconds: 300, // 5 minutes
WebAuthnChallengeInSeconds: 300, // 5 minutes
- ProjectSSEConnectionTtlSeconds: 180 // Must be > heartbeat interval (60s) * 2
+ ProjectSSEConnectionTtlSeconds: 180, // Must be > heartbeat interval (60s) * 2
+ TelemetryIdentifyIdentityInSeconds: 600 // 10 minutes
};
type TDeleteItems = {
diff --git a/backend/src/server/plugins/auth/inject-identity.ts b/backend/src/server/plugins/auth/inject-identity.ts
index 895a2d75f9..69f3b953d6 100644
--- a/backend/src/server/plugins/auth/inject-identity.ts
+++ b/backend/src/server/plugins/auth/inject-identity.ts
@@ -249,7 +249,7 @@ export const injectIdentity = fp(
authMethod: identity.authMethod
})
.catch((error) => {
- req.log.error(error, "Failed to enrich PostHog identity");
+ req.log.error(error, `Failed to enrich PostHog identity [identityId=${identity.identityId}]`);
});
break;
diff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.ts
index 5be1b110db..788cb6a47a 100644
--- a/backend/src/services/telemetry/telemetry-service.ts
+++ b/backend/src/services/telemetry/telemetry-service.ts
@@ -3,7 +3,7 @@ import { PostHog } from "posthog-node";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { InstanceType } from "@app/ee/services/license/license-types";
-import { TKeyStoreFactory } from "@app/keystore/keystore";
+import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto/cryptography";
@@ -391,9 +391,6 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme
}
};
- const IDENTITY_IDENTIFY_CACHE_KEY_PREFIX = "telemetry-identify-identity";
- const IDENTITY_IDENTIFY_CACHE_TTL = 600; // 10 minutes in seconds
-
// In-memory fallback dedup set to limit blast radius during Redis outages
const inMemoryIdentityDedup = new Set<string>();
@@ -409,17 +406,25 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme
if (instanceType === InstanceType.Cloud) {
const dedupKey = `${identityId}-${properties.authMethod ?? ""}`;
try {
- const cacheKey = `${IDENTITY_IDENTIFY_CACHE_KEY_PREFIX}:${dedupKey}`;
+ const cacheKey = KeyStorePrefixes.TelemetryIdentifyIdentity(dedupKey);
// Atomic SET NX + EX: only the first caller within the TTL window proceeds
- const wasSet = await keyStore.setItemWithExpiryNX(cacheKey, IDENTITY_IDENTIFY_CACHE_TTL, "1");
+ const wasSet = await keyStore.setItemWithExpiryNX(
+ cacheKey,
+ KeyStoreTtls.TelemetryIdentifyIdentityInSeconds,
+ "1"
+ );
if (!wasSet) return;
} catch (error) {
logger.error(error, `Failed to check PostHog identity dedup cache [identityId=${identityId}]`);
// In-memory fallback to limit blast radius during Redis outage
if (inMemoryIdentityDedup.has(dedupKey)) return;
inMemoryIdentityDedup.add(dedupKey);
- const timer = setTimeout(() => inMemoryIdentityDedup.delete(dedupKey), IDENTITY_IDENTIFY_CACHE_TTL * 1000);
+ const timer = setTimeout(
+ () => inMemoryIdentityDedup.delete(dedupKey),
+ KeyStoreTtls.TelemetryIdentifyIdentityInSeconds * 1000
+ );
timer.unref();
+ // falls through intentionally: first caller during Redis outage still identifies
}
const distinctId = `identity-${identityId}`;