Repository navigation
feat(auth): report sign-in, refresh, stored-session and token outcomes #2010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b0c408
97d95ef
a53ca1d
b3437a1
515b9f8
f61e035
3c60527
efe4c57
923fbe6
def5a41
a2a9212
b869fdb
2994475
cdc55fa
eb5127d
70b19b4
a6f4a24
77acce7
1a3bad9
30ffc8c
27a936b
b14a446
62fa90c
642e9a9
2151ecd
f13b8a6
ddc1544
6ec9e41
0c693ff
57123ae
9b43ff5
5378739
fedf100
b586ad2
9e18e3c
7bfc295
44ef7df
d9424e8
4098de9
c64c3fd
5d639ea
bcc8cb6
30c0a7c
4cf376f
2738055
c32e255
45b36d7
8036529
1b187e4
1882926
48452b5
7180ad5
4718e70
9f520cc
de31b8f
eaf58c9
5a46f08
94204fe
d42a61f
84cf227
9494b02
3c5a188
0c71d16
83b8a91
8b608d9
76c352e
483cc0f
19b0872
97c765e
b27f32f
1832e53
272947e
13fe2d1
c8e3e0e
fb46c20
88a15a4
1006a9e
bd0eb97
79ba148
0c627d4
4daa5bc
dc25010
1563bd2
0a04c74
320e160
7ea45ce
ab4c97e
184836b
177f2ed
66a3445
7cda12d
4b4a231
17ad3c8
2d05a98
d45bb57
ca9cfc5
32e5302
638a4fd
ac8a4ec
d53a433
3b3a3e2
296ab54
351b430
cf3ba73
3334d80
1870bd6
ff17458
750dbbd
68f4af6
31c19cb
47eacc4
7dedcb7
ac7f8d3
289159c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| import * as mainTelemetry from '../lib/telemetry' | ||
| import { CLOUD_REFRESH_TOKEN_LIFETIME_MS, revokeUrlOf } from './config' | ||
| import { revoke } from './oauth' | ||
| import type { RevokeResult } from './oauth' | ||
| import { addPendingRevocation, loadPendingRevocations, removePendingRevocation } from './tokenStore' | ||
| import type { PendingRevocation } from './tokenStore' | ||
|
|
||
| export const GRANT_REVOCATION_EVENT = 'comfy.desktop.auth.grant_revocation' | ||
|
|
||
| const FIRST_RETRY_MS = 5_000 | ||
| const MAX_RETRY_MS = 15 * 60_000 | ||
|
|
||
|
|
@@ -12,9 +16,11 @@ export class Revocations { | |
| private failures = 0 | ||
| private retryTimer: ReturnType<typeof setTimeout> | null = null | ||
| private readonly settledButSaved = new Set<string>() | ||
| private readonly reportedWaiting = new Set<string>() | ||
|
|
||
| add(revocation: Omit<PendingRevocation, 'queuedAt'>): void { | ||
| addPendingRevocation({ ...revocation, queuedAt: Date.now() }) | ||
| const saved = addPendingRevocation({ ...revocation, queuedAt: Date.now() }) | ||
| if (!saved) mainTelemetry.emit(GRANT_REVOCATION_EVENT, { outcome: 'not_saved' }) | ||
| if (this.draining) this.drainAgain = true | ||
| else void this.drain() | ||
| } | ||
|
|
@@ -49,17 +55,28 @@ export class Revocations { | |
| return | ||
| } | ||
| const expired = next.queuedAt + CLOUD_REFRESH_TOKEN_LIFETIME_MS <= Date.now() | ||
| if ( | ||
| !expired && | ||
| (await revoke(next.refreshToken, next.clientId, revokeUrlOf(next.issuer))) === 'retry' | ||
| ) { | ||
| const outcome = expired | ||
| ? 'expired' | ||
| : await revoke(next.refreshToken, next.clientId, revokeUrlOf(next.issuer)) | ||
| this.report(next.refreshToken, outcome) | ||
| if (outcome === 'retry') { | ||
| failed.add(next.refreshToken) | ||
| } else if (!removePendingRevocation(next.refreshToken)) { | ||
| this.settledButSaved.add(next.refreshToken) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private report(refreshToken: string, outcome: RevokeResult | 'expired'): void { | ||
| if (outcome === 'retry') { | ||
| if (this.reportedWaiting.has(refreshToken)) return | ||
| this.reportedWaiting.add(refreshToken) | ||
| } else { | ||
| this.reportedWaiting.delete(refreshToken) | ||
| } | ||
| mainTelemetry.emit(GRANT_REVOCATION_EVENT, { outcome }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve startup revocation outcomes for the Datadog relay. On startup,
|
||
| } | ||
|
|
||
| private scheduleRetry(): void { | ||
| const delay = Math.min(FIRST_RETRY_MS * 2 ** this.failures, MAX_RETRY_MS) | ||
| this.failures += 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not mark a retry as reported when consent blocks it.
If the first
retryoccurs while consent is undecided,mainTelemetry.emitdrops it, butreportedWaitingretains the refresh token. If the person then grants consent while Cloud remains unavailable, later retries return at Line 72. No retry outcome is reported until the revocation reaches a different outcome. Only deduplicate an admitted report, or leave the token eligible for reporting after consent changes. (raw.githubusercontent.com)