Skip to content

Commit f5cc244

Browse files
feedback
1 parent a6e39a7 commit f5cc244

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Fixed issue where repo permissions could go stale when authentication or token refresh related errors occured. [#1215](https://github.com/sourcebot-dev/sourcebot/pull/1215)
12+
1013
## [4.17.2] - 2026-05-16
1114

1215
### Added

packages/backend/src/ee/accountPermissionSyncer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const POLLING_INTERVAL_MS = 1000;
2929
type AccountPermissionSyncJob = {
3030
jobId: string;
3131
}
32+
3233
class RefreshTokenError extends Error {
3334
constructor(message: string) {
3435
super(message);
@@ -192,7 +193,7 @@ export class AccountPermissionSyncer {
192193
// account is permanently unauthorized (token revoked, user
193194
// deprovisioned, OAuth grant dead), clear the account's existing
194195
// permission rows so the read-side filter stops matching through
195-
// them. Re-throw so the job is marked FAILED via onJobFailed.
196+
// them.
196197
if (
197198
isUnauthorized(error) ||
198199
isForbidden(error) ||
@@ -220,6 +221,14 @@ export class AccountPermissionSyncer {
220221
logger.debug(`Syncing permissions for ${account.provider} account (id: ${account.id}) for user ${account.user.email}...`);
221222

222223
// Ensure the OAuth token is fresh, refreshing it if it is expired or near expiry.
224+
//
225+
// @note(SOU-1177) re-throwing as a RefreshTokenError here is required to flag to the caller
226+
// (runJob) that the account's permissions should be cleared. The side-effect with this
227+
// approach is that permissions will be cleared for any error thrown in the
228+
// ensureFreshAccountToken path. A better approach would be to look at the response
229+
// from the oauth call and determining if the host returned a invalid_grant.
230+
//
231+
// @see: https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
223232
let accessToken;
224233
try {
225234
accessToken = await ensureFreshAccountToken(account, this.db);

0 commit comments

Comments
 (0)