Skip to content

[cherry-pick] managed settings: keep policy through transient refresh failures - #337739

Merged
Ross Wollman (rwoll) merged 1 commit into
release/1.139from
cherry-pick/337583
Sep 24, 2026
Merged

Ross Wollman (rwoll) merged 1 commit into
release/1.139from
cherry-pick/337583

Conversation

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Cherry-pick of #337583 from main.

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 managed settings: fix stale cache case when moving to unavailable #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.

Copilot AI balanced review requested due to automatic review settings September 24, 2026 16:13
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label Sep 24, 2026

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.

Copilot review overview

🟢 Approval recommended

The retention behavior is correctly implemented and tested; only a non-blocking comment-style cleanup remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Retains cached server-managed policy through transient refresh failures without renewing its timestamp.

Changes:

  • Preserve stale managed settings after network, authentication, rate-limit, server, or malformed-response failures.
  • Update regression coverage for stale-cache retention across no-response, 401, and 403 failures.
File Description
defaultAccount.ts Retains the last scoped policy after transient failures.
defaultAccount.test.ts Verifies retained policy and unchanged timestamps.

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

Comment on lines +1231 to +1233
// A failed fetch (including a 401/403, which may be transient) is not evidence that policy was withdrawn:
// keep the last successful response even once stale, with its original timestamp so the failure does not
// count as a refresh and it is still refetched.
@rwoll
Ross Wollman (rwoll) merged commit d8b49dc into release/1.139 Sep 24, 2026
34 checks passed
@rwoll
Ross Wollman (rwoll) deleted the cherry-pick/337583 branch September 24, 2026 20:12
@vs-code-engineering vs-code-engineering Bot added this to the 1.139.0 milestone Sep 24, 2026
@chrmarti Christof Marti (chrmarti) added the candidate Issue identified as probable candidate for fixing in the next release label Sep 25, 2026
@Mgsfmd

Mgsfmd commented Sep 29, 2026

Copy link
Copy Markdown

Ghazanfar Shahzad 00923007410070 // 00923158281285 //Gujranwala make roud Asad kalone St no 2 ho no 1 Punjab Pakistan //

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

candidate Issue identified as probable candidate for fixing in the next release cherry-pick-artifact Auto-generated cherry-pick PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed settings are dropped after transient refresh failures

6 participants