sessions: recover empty Agent Host session list after a failed initial refresh#319216
Merged
Conversation
…l refresh The Agents-app local session list could stay empty on launch and only populate after the user started a new session. The provider's session cache is one-shot: `_refreshSessions()` ran once, but its blanket catch could not tell "listSessions() threw" (e.g. the agent throws AHP_AUTH_REQUIRED before its token is effective server-side, or a transient offline error) from "listSessions() returned []" (a genuinely empty, valid result). Both collapsed to an empty cache marked initialized, and nothing retried until an unrelated AHP event (SessionTurnComplete / sessionAdded) forced a re- which is whyfetch starting a new session "unstuck" the list. `_refreshSessions` now owns `_cacheInitialized` and sets it only on a successful list. On a thrown failure it logs and arms a capped exponential-backoff retry (1s -> 30s, reset on success), so a transient startup failure self-heals on its own. An empty successful list is still treated as a valid result that marks the cache initialized and arms no retry. Listing sessions still never pops a sign-in dialog; AHP_AUTH_REQUIRED is retried silently in the background. The local provider's auth autorun and the remote provider's setConnection no longer pre-set `_cacheInitialized`; clearConnection cancels any pending retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Agent Host session cache refresh behavior so a failed initial listSessions() call does not permanently leave the Agents app session list empty.
Changes:
- Moves
_cacheInitializedownership into successful_refreshSessions()completion. - Adds silent retry with exponential backoff for failed session list refreshes.
- Updates local/remote providers and adds tests for retry and empty-list behavior.
Show a summary per file
| File | Description |
|---|---|
src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts |
Adds retry/backoff handling and successful-list cache initialization semantics. |
src/vs/sessions/contrib/providers/agentHost/browser/localAgentHostSessionsProvider.ts |
Stops pre-marking the cache initialized before eager local refresh. |
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts |
Lets refresh own cache initialization and cancels pending retry on connection clear. |
src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts |
Adds mock failure injection and tests around failed initial refresh recovery. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 3
The static SESSION_REFRESH_RETRY_MIN_MS was referenced by the _sessionRefreshRetryDelay instance field initializer but declared after it, causing a 'used before its initialization' compile error under the full tsc build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
With _cacheInitialized now staying false until a successful listSessions, every synchronous getSessions()/getSessionByResource() during the failure window would call _ensureSessionCache() and launch a fresh listSessions(), bypassing the backoff and repeatedly hitting the agent/auth path. Add an in-flight flag and skip _ensureSessionCache when a refresh is already running or a backoff retry is already scheduled, so recovery only happens via the backoff timer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bhavyaus
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the Agents app, the local Agent Host session list could stay empty on the list just stayed blank. Starting a new local session would "unstick" it and make all the existing sessions appear.launch
Root cause
The provider's session cache is one-shot.
BaseAgentHostSessionsProvider._refreshSessions()ran once (guarded by_cacheInitialized), but its blanketcatch {}could not distinguish two very different outcomes:listSessions()** e.g. the agent throwsAHP_AUTH_REQUIREDbefore its token is effective server-side, or a transient offline/network error.threw**listSessions()** a genuinely empty, valid result.returned[]**Both collapsed to an empty cache marked initialized, and nothing retried until an unrelated AHP event (
SessionTurnComplete/notify/sessionAdded) forced a re-fetch. That's exactly why starting a new whose turn completes and firesmade the whole list suddenly populate.SessionTurnCompletesessionFix
_refreshSessionsnow owns_cacheInitializedand sets ittrueonly on a successful list.30s, reset on success), so a transient startup failure self-heals on its own without any user action.
AHP_AUTH_REQUIREDis retried silently in the background.dialogsetConnectionno longer pre-set_cacheInitialized;clearConnectioncancels any pending retry.Tests
Three new tests in
localAgentHostSessionsProvider.test.ts(via alistSessionsfailure-injection hook on the mock):listSessionsfails, without needing a new sessionlistSessionsarms no retrylistSessionssucceedsVerified: browser unit suite 78 passing (incl. the 3 new tests), full
test-node10640 passing, eslint + hygiene clean.(Written by Copilot)