fix(github): restore the recovery path for revoked user OAuth tokens - #10995
Merged
ArtyomSavchenko merged 3 commits intoJul 26, 2026
Merged
Conversation
`checkRefreshToken` accepts a `force` parameter but never reads it, so the only caller that passes `force = true` (worker.ts, when re-syncing a user) behaves exactly like the non-forced call and skips the refresh entirely. Gate the refresh on `force || expired` instead of on expiry alone. As a side effect a record with a `refreshToken` but a null `expiresIn` is now validated when forced, instead of being reported as valid unchecked. Signed-off-by: koreanjoker <namug014@gmail.com>
When `checkRefreshToken` reports failure, `getOctokit` cleared `record.octokit` and then fell straight through to constructing a new Octokit from the very token that was just rejected. The method therefore never returned `undefined` for a revoked user, so the `(await getOctokit(...)) ?? container.container.octokit` installation-token fallback that the sync code already writes at 13 call sites was unreachable. Return `undefined` after clearing the client so the existing fallback can take effect. Signed-off-by: koreanjoker <namug014@gmail.com>
`updateUser` serialises the whole `GithubUserRecord` — `accounts`
included — into the integration secret, but `secretToUserRecord` placed a
literal `accounts: {}` after the spread of the parsed payload, discarding
whatever was stored.
Every consumer of a record loaded through `getAccount` therefore saw an
empty map. `revokeUserAuth` iterates `Object.entries(record.accounts)`, so
its body never ran and the re-authorisation notice was never written to
any workspace.
Read `accounts` back from the parsed payload, keeping `{}` as the fallback
for records written before the field existed.
Signed-off-by: koreanjoker <namug014@gmail.com>
kimnamwook1
force-pushed
the
fix-github-dead-user-token-recovery
branch
from
July 26, 2026 04:41
c5a1634 to
fb8104b
Compare
ArtyomSavchenko
approved these changes
Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10994.
Three small fixes in
services/github/pod-githubthat together restore the recovery path for a GitHub user whose OAuth token has been revoked or has expired past refresh.Why these three belong in one PR
The three defects sit on a single chain, and each one disables a different recovery mechanism that is already written in the codebase:
checkRefreshTokenignoresforce— the validation is skipped, so a dead token is never detected.getOctokitkeeps going after a failed check — a client is built from the dead token anyway, so the installation-token fallback the callers already wrote can never fire.secretToUserRecorddropsaccounts— even when revocation is detected, the notification loop has nothing to iterate, so the user is never told to re-authorise.Fixing only one of them leaves the chain broken. Each fix is independent and reviewable on its own (one commit each), but the user-visible symptom only clears with all three.
1.
platform.ts—forcewas never readcheckRefreshTokendeclaresforcebut the body never references it:The only caller that passes
trueis the user re-sync path:so that call is indistinguishable from the unforced one and returns
truewithout contacting GitHub.Change:
This also narrows a second gap: a record with a
refreshTokenbutexpiresIn == nullcurrently returnstrueunvalidated.platform.ts:481can write exactly that (expiresIn: resultJson.expires_in != null ? … : null). After the change, the forced call validates it.Behaviour for the unforced call is unchanged:
forceisfalse, so the condition reduces torefreshToken != null && expired, which is the original predicate.2.
worker.ts— a failed check did not stop client creationClearing
record.octokitand then falling through means the next statement rebuilds a client fromrecord.token— the token that was just rejected.getOctokitconsequently never returnsundefinedfor a revoked user.That matters because the callers already handle
undefined, at 13 sites:(also
issues.ts:803,issueBase.ts:343,comments.ts:156,365,441,reviews.ts:154,439,reviewComments.ts:159,442,520,reviewThreads.ts:383,461)The
?? container.container.octokitbranch is dead code today. Change:On whether enabling this fallback is intended — this is the one change here that widens existing behaviour, so it deserves the scrutiny. I read the
??operators at those 13 sites as intended design rather than defensive noise, for three reasons: the right-hand side is the installation token, which is the natural degraded mode when a user token is gone; the expression is meaningless if the left side can never beundefined; and the helper those calls feed into declares theundefinedcase in its own signature and documents the fallback:(same shape in
ensureRESTOctokit,utils.ts:57-62). Both takeOctokit | undefinedand both fall back to the installation client — parameters that, before this change, could only ever receive a defined value.If the intent was instead to fail the sync outright when a user token dies, the fix should be a thrown error and those 13
??clauses plus the| undefinedparameters should go — happy to redo it that way.3.
users.ts—accountswas discarded on readThe literal
accounts: {}sits after the spread, so it overwrites whatever was parsed.accountsis genuinely persisted —updateUserstringifies the entire record:and it is populated on the authorisation path at
platform.ts:488andplatform.ts:495:So the write path stores it and the read path throws it away. The consequence is in
revokeUserAuth:For any record loaded via
getAccount,record.accountsis{}, the loop body never executes, and no workspace ever learns that the user must re-authorise.Change:
?? {}keeps the old value for secrets written before the field existed.accountand_idstill deliberately override the parsed payload, as before.Verification — what I actually ran
Please read this section literally; I have not claimed anything I did not execute.
Ran, passed:
_phase:formatpipeline (prettier3.6.2 →eslint8.54.0 withstandard-with-typescript40 and the three rig rule overrides, perplatform-rig/profiles/default/eslint.config.json) in a standalone directory over the three files.c36dd74:prettier --write+eslint --fixreproduced them byte for byte (diffexit 0 on all three), so the harness matches what CI expects.prettier --write+eslint --fixagain left all three files byte for byte unchanged (diffexit 0). The formatting step should be a no-op on this branch.--fix: the unmodified files report 28 errors (all inworker.ts, all pre-existingstrict-boolean-expressions/return-await;users.tsandplatform.tsreport zero). The modified files report the same 28 errors — same rules, same order, same counts. The three errors before the insertion point (lines 202, 242, 278) are unshifted; every error from line 735 onward shifted by exactly +1, accounted for by the single line added ingetOctokit. No new lint findings, none removed.Did not run, and why:
rush install, norush build, norushx test.@hcengineering/pod-githubdeclares ~100workspace:dependencies; compiling it means building a large portion of the monorepo, which I could not justify setting up for a 6-line change. The repository's ownAGENTS.mdalso asks not to run build commands for verification.any. That is exactly why the 28strict-boolean-expressionserrors appear on the unmodified files too. The differential is still meaningful (identical degradation on both sides), but it is not a substitute fortsc. Please let CI type-check this.Type-level reasoning I did check by hand (not machine-verified):
getOctokitis declaredPromise<Octokit | undefined>(worker.ts:621), soreturn undefinedis within the signature.forceandexpiredare bothboolean, soforce || expiredisboolean.GithubUserRecord.accountsisRecord<WorkspaceUuid, PersonId>and non-optional (types.ts:226);parsed.accounts ?? {}satisfies it.Scope
Three files, +6 −3, all under
services/github/pod-github/src/. No other files touched, no dependency or config changes.