Skip to content

Commit a8f4886

Browse files
committed
fix(webapp): resolve idempotency-reset residency only when the org is loaded on the env
Guards against a missing environment.organization so the reset no longer crashes, falling back to the two-store reset in that case. The authenticated API path always loads the org, so behavior is unchanged in production.
1 parent 54e7a09 commit a8f4886

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

apps/webapp/app/v3/services/resetIdempotencyKey.server.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ export class ResetIdempotencyKeyService extends BaseService {
1111
authenticatedEnv: AuthenticatedEnvironment
1212
): Promise<{ id: string }> {
1313
// The predicate has no run id to route by. When the env mints run-ops ids its runs live on NEW,
14-
// so pin the reset to NEW and skip the wrong-DB (0-row) write to the draining legacy DB.
15-
const mintKind = await resolveRunIdMintKind({
16-
organizationId: authenticatedEnv.organizationId,
17-
id: authenticatedEnv.id,
18-
orgFeatureFlags: authenticatedEnv.organization.featureFlags,
19-
});
20-
const residency = mintKind === "runOpsId" ? "NEW" : "LEGACY";
14+
// so pin the reset to NEW and skip the wrong-DB (0-row) write to the draining legacy DB. Resolve
15+
// this only when the org (and its flags) is loaded on the env — which the authenticated API path
16+
// always provides; otherwise fall back to the two-store reset (correct, just not optimized).
17+
let residency: "NEW" | "LEGACY" = "LEGACY";
18+
if (authenticatedEnv.organization) {
19+
const mintKind = await resolveRunIdMintKind({
20+
organizationId: authenticatedEnv.organizationId,
21+
id: authenticatedEnv.id,
22+
orgFeatureFlags: authenticatedEnv.organization.featureFlags,
23+
});
24+
residency = mintKind === "runOpsId" ? "NEW" : "LEGACY";
25+
}
2126

2227
const { count: pgCount } = await this.runStore.clearIdempotencyKey(
2328
{

0 commit comments

Comments
 (0)