Skip to content

managed settings: fix stale cache case when moving to unavailable - #330896

Merged
joshspicer merged 1 commit into
mainfrom
joshspicer/cache-bug
Aug 18, 2026
Merged

joshspicer merged 1 commit into
mainfrom
joshspicer/cache-bug

Conversation

@joshspicer

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings August 14, 2026 16:44
@joshspicer
joshspicer enabled auto-merge (squash) August 14, 2026 16: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.

Pull request overview

Fixes managed-settings cache expiration when remote settings become unavailable.

Changes:

  • Preserves the cached response timestamp after failed refreshes.
  • Drops stale managed settings instead of renewing them.
  • Adds regression coverage for repeated unavailable responses.
Show a summary per file
File Description
defaultAccount.ts Corrects unavailable-response cache handling.
defaultAccount.test.ts Tests cache aging and expiration.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@joshspicer
joshspicer disabled auto-merge August 14, 2026 16:51
@joshspicer
joshspicer merged commit b019241 into main Aug 18, 2026
28 checks passed
@joshspicer
joshspicer deleted the joshspicer/cache-bug branch August 18, 2026 22:08
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 18, 2026
Ross Wollman (rwoll) added a commit that referenced this pull request Sep 23, 2026
Drop the 24-hour retention bound. Failed refreshes, including 401/403 responses that a token refresh or SSO sign-in may resolve, keep the last successful response without renewing its timestamp; only a service answer, sign-out, or account or scope change clears it. This matches the retention before #330896 while keeping its fix that a failure never renews the cache.

Co-authored-by: Copilot <[email protected]>
Ross Wollman (rwoll) added a commit that referenced this pull request Sep 24, 2026
…7583)

Copilot's OTel reload notification (reworked in #336701) exposed a managed-settings refresh regression from #330896. Enterprise users see "Copilot OTel endpoint will change to http://localhost:4318 after reload." every few hours, especially after idle, and reloading clears chat.

## Cause

Since #330896, a cached server-managed-settings response expires one hour after the last successful fetch. If a refresh fails after that (no response, 401/403, 429, 5xx, malformed), the policy is dropped rather than kept. A policy-backed OTel endpoint then reverts to its default and the notification appears. The next successful fetch restores the policy, so it keeps switching back and forth. Every other server-managed control switches back and forth in the same way, so for the length of the gap their restrictions are silently lifted.

## Change

Keep the policy unless the service answers affirmatively that it should change. A failed refresh without `forceRemoteSettingsRefresh` now keeps the last successful response, however old, with its original timestamp. The failure therefore doesn't count as a refresh, and the next poll or focus retries. A 401/403 is treated as a failure because it can be temporary, for example while a token refreshes.

This keeps #330896's fix that a failure never renews the cache timestamp, and reverts only its dropping of stale policy. Before #330896, failures also kept the previous policy, but they renewed the timestamp.

These still behave as before:
- A 200 replaces the policy; a 404 or 466 clears it.
- Sign-out, or an account or scope change, clears or stops reusing the policy.
- `forceRemoteSettingsRefresh` still fails closed.

## Follow-up

- A thrown session lookup error still makes `getDefaultAccountForAuthenticationProvider` return `null`, so `setDefaultAccount(null)` clears the policy without applying this retention. This path predates #330896 and changes account availability, so it needs a separate PR.
- `managedSettingsActive` (set when the server returns settings that no VS Code policy uses) is never cleared once set. This bug existed before this PR and will be fixed separately.

## Validation

- `defaultAccount.test.ts`: 49 passing. The updated test fails without this change.
- Account and policy suites: 250 passing.
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants