diff --git a/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts b/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts index 984f1a85..cadafd87 100644 --- a/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts +++ b/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts @@ -82,7 +82,10 @@ export class FreebitOperationsService { ); // If all timestamps are stale (or entry is empty), mark for removal - if (timestamps.length === 0 || timestamps.every(t => t < staleThreshold)) { + // EXCEPT: Never clean up entries with a cancellation - cancellation blocks plan changes permanently + // until the account is actually cancelled or the cancellation is reverted externally + const hasCancellation = typeof entry.cancellation === "number"; + if (!hasCancellation && (timestamps.length === 0 || timestamps.every(t => t < staleThreshold))) { accountsToRemove.push(account); } } @@ -210,8 +213,11 @@ export class FreebitOperationsService { } catch (err: unknown) { lastError = err; if (getErrorMessage(err).includes("HTTP 404")) { - continue; // try next endpoint + continue; // try next endpoint for 404 (endpoint not found) } + // For non-404 errors (auth failures, rate limits, 500s, etc.), fail fast + // instead of wasting resources retrying fundamentally broken requests + break; } }