Repository navigation
Renew marketplace resource tokens before expiry - #343688
Michael Cummings (MSFT) (mcumming) wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Transient resource-token lookup failures can retract working marketplace access and stop automatic renewal retries.
1 open issue
What changed in this PR
This PR adds proactive renewal of Microsoft Entra marketplace resource tokens, extending the existing authentication flow so long-lived windows can retain marketplace access.
Changes:
- Schedule renewal using provider-reported token lifetimes, with fallback checks, request coalescing, and stale-result rejection.
- Publish authorization changes to shared and remote processes even when the manifest is unchanged.
- Add deterministic tests for renewal timing, transient recovery, cancellation, and concurrent resolution.
| File | Description |
|---|---|
src/vs/workbench/services/extensionManagement/test/electron-browser/extensionGalleryManifestService.test.ts |
Adds renewal and lifecycle regression tests. |
src/vs/workbench/services/extensionManagement/electron-browser/extensionGalleryManifestService.ts |
Emits updates when authorization changes independently of the manifest. |
src/vs/workbench/services/extensionManagement/electron-browser/extensionGalleryAccountService.ts |
Adds renewal scheduling, request coalescing, and stale-result guards. |
src/vs/workbench/services/extensionManagement/common/extensionGalleryAccount.ts |
Adds optional account refresh timing metadata. |
Review effort: Balanced
|
Karthik Nadig (@karthiknadig) this is ready for your review. Thank you. |
6169719 to
8922cf6
Compare
|
Karthik Nadig (@karthiknadig) this is ready for your review 🙏 |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
Thanks. Renewing before expiry is the right fix, and keeping the manifest during a transient failure is good. Requesting changes for two behavior issues (details inline):
- Every renewal fires
onDidChangeExtensionGalleryManifest, which refreshes the Extensions view and runs a full update check. - Renewal relies only on a timer, which doesn't reliably catch up after sleep, and nothing reacts to a 401 from gallery requests.
This also conflicts with #343687 and #343689 in extensionGalleryAccountService.ts (and with #343686 in the test file), and this branch still contains the sign-in-token fallback that #343689 removes. Please rebase after those land.
Review assisted by Copilot.
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
Robo (@deepak1556)Matched files:
|
01db914 to
f597f66
Compare
|
Karthik Nadig (@karthiknadig) ready for your review again |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
Thanks, this addresses both items from my last review: token-only renewals no longer fire onDidChangeExtensionGalleryManifest, and renewal now also runs on OS resume, on the absolute due time, and after a 401.
Requesting changes for three things:
- The new authorization channel lets the shared process or a remote server force unlimited token refreshes (inline).
- Owner review. This now changes the
microsoft-authenticationextension and adds the workbench-only_workbenchForceRefreshsession option (TylerLeonhardt). It also registers a reverse channel fromsharedProcessMain.tsandserverServices.tsand addsurl/requestHasAuthorizationtoIRequestContextand request IPC (Robo (@deepak1556), Christof Marti (@chrmarti)). Those owners should sign off. - Rebase.
doGetAccountstill falls back to the sign-in token in both places #343689 removes, and the branch conflicts with #343686, #343687, #343689 and #343690. Please rebase after those land so the 401-recovery path is reviewed against the final code.
Review assisted by Copilot.
Use the authentication provider's remaining lifetime to schedule silent resource-token renewal. Coalesce account resolutions, cancel stale generations, retain available manifests during transient failures, and publish rotated process snapshots. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
…lures Distinguish failed renewal of the same account and gallery from initial consent and account switches. Exercise a resource-session failure rather than an identity-session proxy, and ensure a different account cannot keep the previous bearer. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Avoid introducing polling or a second renewal cadence for GitHub and other account providers. Clear retry ownership when the provider or marketplace changes, and exercise both initial failures and provider replacement. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Separate marketplace credential projection from catalog notifications and recover current-bearer failures through one coalesced silent renewal path. Preserve account/cancellation guards and safe request replay. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Share a one-minute completion cooldown across rejection reporters and rotating bearers. Avoid forcing the same rejected current credential twice, retain a server-accepted catalog when renewal returns an unchanged bearer, and preserve genuine authentication failure handling. Cover remote/shared rejection loops, exact cooldown boundaries, slow and failed refreshes, normal expiry renewal, and account/session-change races. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Retain the merge-only regression coverage from df60f49 in the rebased history: same-origin, cross-origin and out-and-back authorization proof, renewable-account 403 handling without forced renewal, and metadata-cache reuse during expiry renewal. Co-authored-by: Copilot App <[email protected]>
df60f49 to
d6fe40a
Compare
|
Karthik Nadig (@karthiknadig) ready for your review again |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
Thanks, the rebase and throttling look good: the sign-in token fallback is gone, a rejected token can trigger at most one renewal per minute (and only for the current or previous token), and token-only renewals no longer fire manifest changes in the workbench, shared process, or remote.
Requesting changes for:
- A transient service-index failure during renewal drops a working session to
AccessDenied(inline). - Owner review is still missing: TylerLeonhardt for the
microsoft-authenticationchanges and_workbenchForceRefresh, and Robo (@deepak1556) / Christof Marti (@chrmarti) for the shared-process and server authorization channel and theIRequestContext/requestIpcfields.
Review assisted by Copilot.
…lures during renewal A token renewal re-fetches the service index. A network error, missing status, 408, 429 or 5xx now raises MarketplaceIndexTransientError. When the account and marketplace URL are unchanged and the renewed token has not been rejected or superseded, the accepted manifest is kept and the renewed token is republished. Account switches and definitive errors still retract access. The next scheduled renewal, or 401 recovery, re-fetches the index. Co-authored-by: Copilot App <[email protected]>
…orkbench sentinel Remove the private _workbenchForceRefresh / WORKBENCH_FORCE_REFRESH option. The microsoft-authentication extension now forces a silent refresh when a cached access token is within five minutes of expiry, keeping the cached unexpired token if that refresh fails. The marketplace account provider no longer passes a sentinel. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Forward trusted WWW-Authenticate feedback through service-index and gallery authorization paths. Bound recovery to one silent resolution and one safe replay, retract rejected cached credentials, and retain legacy no-error behavior. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
|
Karthik Nadig (@karthiknadig) this is ready for your review. Thank you |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
Thanks, the transient service-index fix looks right: a transient failure during renewal keeps the accepted catalog only for the same account and marketplace with a fresh token, first loads and account switches still fail as before, and the tests cover both. Removing _workbenchForceRefresh addresses Tyler's concern about the private contract.
Still requesting changes for:
- Owner sign-off on the new
microsoft-authenticationbehavior (inline), TylerLeonhardt. - The hand-written
WWW-Authenticateparser (inline). - Owner review of the shared-process and server authorization channel and the
IRequestContext/requestIpcfields, Robo (@deepak1556) / Christof Marti (@chrmarti).
Review assisted by Copilot.
| // MSAL renews cached access tokens inside its renewal window, but the native broker can still | ||
| // hand back a cached token that is about to expire. Refresh it here so a caller asking again | ||
| // near the advertised `expiresAfter` receives a fresh token without any extra request option. | ||
| if (result.fromCache && isAccessTokenNearExpiry(result.expiresOn)) { |
There was a problem hiding this comment.
This applies to every acquireTokenSilent caller of the Microsoft provider, not just the marketplace: with the native broker, any cached token within five minutes of expiry now triggers a forced claims refresh. Without the broker it's effectively a no-op, since MSAL already renews inside the same five-minute window. TylerLeonhardt, is this OK for all consumers? If the broker gap is real, it may be better fixed in its own auth-extension PR.
| } | ||
|
|
||
| /** Interpret a single Bearer challenge; malformed, non-Bearer and multiple challenges retain legacy behavior. */ | ||
| export function getExtensionGalleryAuthenticationError(wwwAuthenticate: string | undefined): string | undefined { |
There was a problem hiding this comment.
This re-implements challenge parsing before calling parseWWWAuthenticateHeader. Could it use parseWWWAuthenticateHeader directly and read error from the Bearer challenge? For claims challenges, IAuthenticationService.getSessions already accepts { wwwAuthenticate, fallbackScopes }, and the Microsoft provider implements getSessionsFromChallenges. Since this handling isn't needed for renewing before expiry, it could also move to a follow-up to keep this PR focused.

Related to microsoft/vscode#325412.
Summary
Renew Microsoft Entra marketplace resource credentials through one coalesced account-owned path, including recovery after OS resume. Handle trusted marketplace bearer-rejection challenges without a private workbench/provider refresh contract.
Renewal and recovery
expiresAfterlifetime rather than parsing the resource token. Schedule resolution at 75% of the reported lifetime, bounded between one second and six hours; tokens without usable lifetime metadata are rechecked every five minutes.forceRefreshAPI is planned.Unknownresults after 30 seconds only when this provider/marketplace has an active renewal hint; providers without one are not newly polled.WWW-Authenticate contract
The VSPM server contract is planned separately and is not yet deployed. This PR implements the client side; it does not claim live server interoperability.
Per VSPM, Continuous Access Evaluation (CAE) and claims challenges are non-goals. Revoked-token recovery relies on the server's planned
invalid_tokenresponse and near-expiry renewal of short-lived non-CAE tokens. If silent resolution returns the same rejected token, the client requires sign-in rather than forcing a cache refresh.WWW-Authenticateon both service-index 401s and gallery 401 feedback from the shared process or remote server, only after proving the response is same-origin and the final request carried the bearer.errorparameter, preserve today's acquisition flow: silent resolution and the existing interactive sign-in path when needed.error="invalid_token", silently re-resolve once without bypassing the provider cache. If the provider returns the same rejected token, withdraw the catalog and replicated credential and transition toRequiresSignIn. Renewal events cannot reinstall that rejected credential for the same account and marketplace.error="invalid_token", the client transitions toRequiresSignIn; without it, today's behavior is kept (the current catalog and credential remain until normal renewal). Statistics writes are not replayed.insufficient_scope, surfaces the access error without another token retry.insufficient_claimsis a defensive sign-in fallback only. It does not process a claims challenge or perform automatic CAE recovery; VSPM does not plan to emit this challenge.Process and UI updates
Publish the accepted manifest/token/service-URL snapshot directly to the shared process and remote server, independently of
onDidChangeExtensionGalleryManifest. Compare catalog contents structurally, and emit the public manifest event only for actual content/availability changes. Receivers install token-only updates without emitting redundant manifest/status notifications.Sign-out and access retraction clear replicated credentials and retain their actual availability/status notifications. Token-only renewal does not repeat the Extensions search or automatic update check.
Extension-resource consumers apply genuine catalog changes and retraction rather than retaining their bootstrap resource template.
Validation
The pnpm scripts below were executed through Node 24/Corepack in the isolated Windows worktree.
pnpm run transpile-clientpnpm run typecheck-client$env:VSCODE_SKIP_PRELAUNCH='1'; .\scripts\test.bat --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryAccountService.test.ts --run src\vs\platform\extensionManagement\test\common\extensionGalleryAuthorization.test.ts --reporter dotpnpm run eslint src\vs\platform\extensionManagement\common\extensionGalleryManifest.ts src\vs\platform\extensionManagement\common\extensionGalleryManifestService.ts src\vs\platform\extensionManagement\common\extensionGalleryManifestServiceIpc.ts src\vs\platform\extensionManagement\test\common\extensionGalleryAuthorization.test.ts src\vs\workbench\services\extensionManagement\electron-browser\extensionGalleryManifestService.ts src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.tsFocused regressions cover cached/replacement/rejected replacement credentials, the single-resolution/replay budget, rejection cooldown, account changes, transient index failure, legacy/no-error behavior, malformed/ambiguous challenges, IPC propagation, initial and replay transport proof, 403 handling, and the defensive sign-in fallback for unsupported claims challenges. Gallery recovery tests exercise the request helper through IPC feedback, the manifest/account services, and the resource-session provider fixture with unexpired cached tokens.
Live VSPM responses, Entra/broker behavior, actual OS sleep/resume, remote deployment flows, and full integration/smoke suites were not exercised. This update changes only this PR's head branch; #325815 is unchanged.
Drafted with GitHub Copilot.