Skip to content

Commit 333a1aa

Browse files
msukkariclaude
andcommitted
fix(worker): log fail-closed permission cleanup
When the account-driven permission syncer's catch fires (401/403/410/ token-refresh), it silently wipes the account's AccountToRepoPermission rows before re-throwing. Operators can see the upstream error in three sinks already, but there's no signal that the *cleanup* itself ran — forcing a before/after row count to verify behavior. Switch the cleanup to a direct `accountToRepoPermission.deleteMany` so we get the deleted row count, and emit a warn log with the account id, user email, which predicate matched, the count, and the original error message. Behavior is equivalent to the prior `account.update` form (same DELETE WHERE accountId=...). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fd242f7 commit 333a1aa

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

packages/backend/src/ee/accountPermissionSyncer.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,19 @@ export class AccountPermissionSyncer {
195195
// on is gone (e.g. Bitbucket Cloud's CHANGE-2770), clear the
196196
// account's existing permission rows so the read-side filter stops
197197
// matching through them.
198-
if (
199-
isUnauthorized(error) ||
200-
isForbidden(error) ||
201-
isGone(error) ||
202-
error instanceof RefreshTokenError
203-
) {
204-
await this.db.account.update({
205-
where: { id: account.id },
206-
data: {
207-
accessibleRepos: {
208-
deleteMany: {},
209-
},
210-
},
198+
const reason =
199+
error instanceof RefreshTokenError ? 'token refresh failure' :
200+
isUnauthorized(error) ? 'HTTP 401 Unauthorized' :
201+
isForbidden(error) ? 'HTTP 403 Forbidden' :
202+
isGone(error) ? 'HTTP 410 Gone' :
203+
null;
204+
205+
if (reason !== null) {
206+
const { count } = await this.db.accountToRepoPermission.deleteMany({
207+
where: { accountId: account.id },
211208
});
209+
const message = error instanceof Error ? error.message : String(error);
210+
logger.warn(`Cleared ${count} permission row(s) for account ${account.id} (user ${account.user.email ?? 'unknown'}) — fail-closed cleanup triggered by ${reason}: ${message}`);
212211
}
213212
throw error;
214213
}

0 commit comments

Comments
 (0)