Skip to content

sessions: recover empty Agent Host session list after a failed initial refresh#319216

Merged
roblourens merged 3 commits into
mainfrom
roblou/agents/fix-empty-session-list
Jun 1, 2026
Merged

sessions: recover empty Agent Host session list after a failed initial refresh#319216
roblourens merged 3 commits into
mainfrom
roblou/agents/fix-empty-session-list

Conversation

@roblourens
Copy link
Copy Markdown
Member

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 blanket catch {} could not distinguish two very different outcomes:

  • listSessions() ** e.g. the agent throws AHP_AUTH_REQUIRED before 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 fires made the whole list suddenly populate.SessionTurnComplete session

Fix

  • _refreshSessions now owns _cacheInitialized and sets it true only on a successful list.
    30s, reset on success), so a transient startup failure self-heals on its own without any user action.
  • An empty successful list is still treated as a valid result: it marks the cache initialized and arms no retry.
  • Listing sessions still never pops a sign-in AHP_AUTH_REQUIRED is retried silently in the background.dialog
  • The local provider's auth autorun and the remote provider's setConnection no longer pre-set _cacheInitialized; clearConnection cancels any pending retry.

Tests

Three new tests in localAgentHostSessionsProvider.test.ts (via a listSessions failure-injection hook on the mock):

  • recovers an empty list when the initial listSessions fails, without needing a new session
  • a successful empty listSessions arms no retry
  • retries with backoff until listSessions succeeds

Verified: browser unit suite 78 passing (incl. the 3 new tests), full test-node 10640 passing, eslint + hygiene clean.

(Written by Copilot)

…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>
Copilot AI review requested due to automatic review settings May 31, 2026 20:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 _cacheInitialized ownership 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

roblourens and others added 2 commits May 31, 2026 13:53
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>
@roblourens roblourens marked this pull request as ready for review May 31, 2026 21:12
@roblourens roblourens enabled auto-merge (squash) May 31, 2026 21:12
@roblourens roblourens merged commit 4918ed6 into main Jun 1, 2026
25 checks passed
@roblourens roblourens deleted the roblou/agents/fix-empty-session-list branch June 1, 2026 00:03
@vs-code-engineering vs-code-engineering Bot added this to the 1.123.0 milestone Jun 1, 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.

3 participants