Microsoft Authentication loses Settings Sync session after macOS sleep/network interruption; restarting extension host restores valid session
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Summary
On macOS, VS Code Settings Sync periodically shows **Sign in to Sync Settings** after the machine has been asleep on battery with VS Code left running.
The Microsoft Authentication log shows that a silent token acquisition begins while/around the time the Mac is asleep, eventually fails with a transient `network_error`, and the authentication provider then returns `0 session(s)`.
The persisted authentication session appears to remain valid. If I restart the VS Code extension host instead of signing in again, Microsoft Authentication immediately reloads the existing session and returns `1 session(s)` without any interactive authentication.
The problem has not reproduced when:
- VS Code is fully quit before the Mac sleeps.
- VS Code is left running overnight while the Mac is plugged in and able to perform its periodic authentication checks.
This suggests that a transient network failure during macOS sleep causes the Microsoft Authentication provider to enter an incorrect in-memory "no sessions" state and not recover automatically after network connectivity returns.
## Environment
- VS Code: `1.135.0 (Universal)`
- Commit: `08d4889f9ec4a1685d257b9b95de036c8e1ce1e5`
- Build date: `2026-08-25T14:26:52Z`
- Electron: `42.8.1`
- Chromium: `148.0.7778.280`
- Node.js: `24.18.1`
- V8: `14.8.178.38-electron.0`
- GitHub Copilot: `1.0.81-0`
- GitHub Copilot SDK: `1.0.11`
- OS: `Darwin arm64 25.6.0`
- Authentication provider: built-in `vscode.microsoft-authentication`
- Settings Sync account: Microsoft / Entra ID
- `microsoft-authentication.implementation`: `msal`
- Native Broker: unavailable on this Mac
The log confirms:
```text
Native Broker enabled: false
```
I previously tested `msal-no-broker` and observed the same general behavior.
## Reproduction
1. Sign into VS Code Settings Sync using a Microsoft/Entra ID account.
2. Confirm Microsoft Authentication reports `1 session(s)`.
3. Leave VS Code running.
4. Close the MacBook lid while running on battery/unplugged.
5. Leave the machine asleep overnight.
6. Resume the Mac the next day.
7. VS Code shows **Sign in to Sync Settings**.
8. Do **not** authenticate.
9. Run `Developer: Restart Extension Host` / restart extensions.
10. Observe that the existing Microsoft session immediately becomes available again without interactive authentication.
## Actual behavior
Before sleep, authentication is healthy:
```text
2026-09-01 01:18:56.439 [info] [getSessions] [email offline_access openid profile] starting
2026-09-01 01:18:58.151 [info] [getSessions] [email offline_access openid profile] returned 1 session(s)
2026-09-01 01:18:58.158 [info] [getSessions] [499b84ac-1321-427f-aa17-267ca6975798/.default offline_access] starting
2026-09-01 01:18:58.365 [info] [getSessions] [499b84ac-1321-427f-aa17-267ca6975798/.default offline_access] returned 1 session(s)
```
Later, a silent acquisition starts and eventually fails after the machine has been asleep/network unavailable:
```text
2026-09-01 02:26:28.226 [info] [getSessions] [email offline_access openid profile] starting
2026-09-01 02:59:30.960 [info] [getAllSessionsForPca] [email offline_access openid profile] [] failed to acquire token silently, skipping account {"errorCode":"network_error","errorMessage":"Network request failed: fetch failed, additionalErrorInfo: error.name:TypeError, error.message:fetch failed","subError":"","correlationId":"","name":"AuthError"}
2026-09-01 02:59:30.961 [info] [getSessions] [email offline_access openid profile] returned 0 session(s)
```
VS Code then prompts for Settings Sync authentication.
Instead of signing in, I restart the extension host:
```text
2026-09-01 17:30:25.245 [info] Microsoft Authentication is deactivating...
2026-09-01 17:30:28.513 [info] [aebc6443-996d-45c2-90f0-388ff96faa56] Native Broker enabled: false
```
Immediately afterward, the original persisted session works again:
```text
2026-09-01 17:30:28.868 [info] [getSessions] [all] starting
2026-09-01 17:30:28.868 [info] [getSessions] [all] returned 1 session(s)
2026-09-01 17:30:28.869 [info] [getSessions] [email offline_access openid profile] starting
2026-09-01 17:30:31.243 [info] [getSessions] [email offline_access openid profile] returned 1 session(s)
2026-09-01 17:30:31.243 [info] [getSessions] [499b84ac-1321-427f-aa17-267ca6975798/.default offline_access] starting
2026-09-01 17:30:31.341 [info] [getSessions] [499b84ac-1321-427f-aa17-267ca6975798/.default offline_access] returned 1 session(s)
```
No browser login or other interactive authentication occurred between the `0 session(s)` result and restarting the extension host.
## Control test 1: VS Code closed during sleep
I fully quit VS Code, left the Mac asleep over the weekend, and launched VS Code after waking it.
The existing session was recovered normally:
```text
2026-08-31 08:47:08.111 [info] [getSessions] [all] returned 1 session(s)
2026-08-31 08:47:14.579 [info] [getSessions] [email offline_access openid profile] returned 1 session(s)
2026-08-31 08:47:14.737 [info] [getSessions] [499b84ac-1321-427f-aa17-267ca6975798/.default offline_access] returned 1 session(s)
```
No reauthentication was required.
## Control test 2: VS Code running while Mac is plugged in overnight
I left the Mac plugged in overnight with VS Code running.
Microsoft Authentication performed approximately hourly session checks throughout the night. Every check succeeded and continued returning `1 session(s)`:
```text
18:32 → 1 session
19:32 → 1 session
20:32 → 1 session
21:34 → 1 session
22:34 → 1 session
23:36 → 1 session
00:38 → 1 session
01:44 → 1 session
02:45 → 1 session
03:45 → 1 session
04:46 → 1 session
05:49 → 1 session
06:50 → 1 session
```
There were no `network_error` or `0 session(s)` events.
## Additional observations
The failing silent requests show unusually long elapsed times.
Example:
```text
02:26:28 getSessions starting
02:59:30 fetch failed
```
Approximately 33 minutes elapsed.
A previous occurrence showed a similar pattern:
```text
03:16:18 getSessions starting
03:47:24 fetch failed
```
Approximately 31 minutes elapsed.
This appears consistent with a network request being suspended/interrupted around macOS sleep and subsequently failing.
The network failure itself seems reasonable when the machine has lost connectivity. The unexpected behavior is:
```text
network_error
→ account is skipped
→ getSessions returns 0
→ Settings Sync treats the user as signed out
```
The authentication provider does not appear to recover automatically once networking returns.
Restarting the extension host immediately restores the same persisted authentication session without interactive authentication. This suggests that the underlying credential/session has not actually expired or been revoked.
## Expected behavior
A transient `network_error` during silent token acquisition should not permanently remove an otherwise valid authentication session.
After connectivity resumes, Microsoft Authentication should either:
1. Continue exposing the existing session and retry token acquisition when necessary, or
2. Automatically retry/reload the persisted session once networking becomes available.
Interactive sign-in should only be required when authentication actually requires user interaction, rather than as a result of a transient network failure.
The underlying error in this report is specifically a transient `network_error` associated with macOS sleep/network loss rather than a stale or revoked refresh token.
Contributor guide
Assessment
This issue has not been assessed yet.