Skip to content

Cache and coalesce marketplace protected resource discovery - #343687

Merged
Karthik Nadig (karthiknadig) merged 5 commits into
microsoft:mainfrom
mcumming:dev/mcumming/marketplace-metadata-cache
Nov 4, 2026
Merged

Karthik Nadig (karthiknadig) merged 5 commits into
microsoft:mainfrom
mcumming:dev/mcumming/marketplace-metadata-cache

Conversation

@mcumming

@mcumming Michael Cummings (MSFT) (mcumming) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Related to microsoft/vscode#325412.

Discovery cache

Cache and coalesce Microsoft marketplace protected-resource discovery in the provider, retaining only the active full service URL, including its path.

  • Validated metadata is cached for five minutes after discovery completes; reads do not extend expiry. Concurrent account resolution and interactive consent share the in-flight lookup.
  • Confirmed absence is cached for 30 seconds only when at least one endpoint was attempted and every actual discovery attempt completed with 404 or 410. The provider's existing custom fetcher records those outcomes; the shared OAuth API is unchanged.
  • Network/cancellation failures, malformed metadata, 401/403, 429, 5xx, and mixed absence/error outcomes remain uncached. A 404 followed by a timeout is not classified as absence.
  • Explicit sign-in bypasses a negative entry so discovery can immediately observe corrected configuration without evicting valid positive metadata.

Validation and lifecycle boundaries

Validate authorization-server URL shape and scope-token syntax before positive caching. Authorization servers must be absolute HTTPS identifiers without credentials, query, fragment, raw whitespace, or backslashes. Scope entries must be nonempty RFC 6749 scope-token strings. A provider-private invalid-scope reason is retained without caching malformed data; syntax-valid scope lists remain intact. The cache does not replace credential-acquisition policy; the scoped-token prerequisite supplies the resource-usability guards.

Provider replacement and service-URL changes invalidate reuse. Consent ignores obsolete discovery/session results after cache replacement, expiry, URL changes, or disposal. The cache stores discovery metadata, not bearer credentials; resource-session lookup and token lifetime remain independent.

This is a provider-local cache with no new setting, public event, shared discovery contract, or general-purpose caching layer.

Validation

Command Result
npm run typecheck-client Passed on the local implementation.
node build\next\build-fast.ts --client-only Passed.
$env:VSCODE_SKIP_PRELAUNCH = '1'; .\scripts\test.bat --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryAccountService.test.ts --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts --reporter dot Passed: 170 tests.

Exercise fixed positive/negative expiries, concurrent reuse, every absence/error classification, explicit-sign-in bypass, metadata correction, full-URL/provider invalidation, and stale discovery/consent races. Verify resource tokens are acquired independently of cached metadata.

No live private-marketplace or interactive identity-provider flow was exercised.

Drafted with GitHub Copilot.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 03:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed discovery metadata can remain cached for five minutes, preventing immediate recovery after the endpoint is corrected.

1 open issue
What changed in this PR

This PR adds bounded caching to Microsoft marketplace protected-resource discovery, reducing repeated requests while preserving per-lookup token acquisition.

Changes:

  • Cache successful discovery for five minutes and coalesce concurrent requests.
  • Guard interactive consent against stale metadata and provider lifecycle changes.
  • Add deterministic tests for expiration, retries, URL changes, and consent races.
File Description
src/​vs/​workbench/​services/​extensionManagement/​test/​electron-browser/​extensionGalleryAccountService.test.ts Adds cache lifecycle and stale-consent regression tests.
src/​vs/​workbench/​services/​extensionManagement/​electron-browser/​extensionGalleryAccountService.ts Implements discovery caching, request coalescing, and consent guards.

Review effort: Balanced

@mariaghiondea

Copy link
Copy Markdown

Karthik Nadig (@karthiknadig) this is ready for your review. Thank you.

@mcumming
Michael Cummings (MSFT) (mcumming) force-pushed the dev/mcumming/marketplace-metadata-cache branch from d6f7bf7 to 895f5d7 Compare October 26, 2026 19:00
@mariaghiondea

Copy link
Copy Markdown

Karthik Nadig (@karthiknadig) this is ready for your review 🙏

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Only successful, validated discovery is cached, keyed by the full service URL, and concurrent lookups share one request. One optional nit inline.

This conflicts with #343689 in extensionGalleryAccountService.ts, so it will need a rebase after that lands.


Review assisted by Copilot.

Coalesce concurrent discovery and reuse successful metadata for five minutes per active service URL. Reject stale consent work after marketplace or metadata changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 33fab878-5295-4cc5-9011-f5bbdb034eec
Assert accessToken rather than the entire extensible account result in reuse, coalescing, and retry tests. Production metadata cache behavior is unchanged.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 33fab878-5295-4cc5-9011-f5bbdb034eec
Reject malformed authorization server lists and unusable issuer URLs, and validate supported scope tokens before returning cacheable metadata. Keep corrected discovery immediately retryable and preserve valid Entra authorities and default scopes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 33fab878-5295-4cc5-9011-f5bbdb034eec
Check metadata caching for omitted and empty scopes through repeated passive account resolution. Retain exact interactive consent assertions for explicit resource scopes without depending on identity-scope fallback.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 33fab878-5295-4cc5-9011-f5bbdb034eec
Cache confirmed all-404/410 protected-resource discovery absence for thirty seconds and bypass only negative entries during explicit sign-in. Preserve uncached invalid-scope diagnostics without resource acquisition, and retain positive-cache validation and lifecycle guards.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 33fab878-5295-4cc5-9011-f5bbdb034eec
@mcumming
Michael Cummings (MSFT) (mcumming) force-pushed the dev/mcumming/marketplace-metadata-cache branch from f1e8bd6 to 7ef36b8 Compare November 2, 2026 19:58
@mariaghiondea

Copy link
Copy Markdown

Karthik Nadig (@karthiknadig) do you approve this one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The negative cache only applies when every discovery probe returns 404 or 410, lasts 30 seconds, and is bypassed on explicit sign-in, which covers my earlier nit.

One thing for the rebase onto #343689, since the two conflict in doGetAccount: the new invalidScopes path returns session.accessToken. Please make sure it resolves to return {} there, like the other sign-in-token fallbacks #343689 removes.


Review assisted by Copilot.

@karthiknadig
Karthik Nadig (karthiknadig) merged commit 5cd53ea into microsoft:main Nov 4, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants