sessions: recover empty Agent Host session list after a failed initial refresh (#319216)
* sessions: recover empty Agent Host session list after a failed initial 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> * fix compile error: declare retry backoff statics before instance field 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> * address review: guard _ensureSessionCache against redundant refreshes 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> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
R
Rob Lourens committed
4918ed64f11c8fb78f89b7c40805c1ddab82790b
Parent: 83b7ce6
Committed by GitHub <noreply@github.com>
on 6/1/2026, 12:03:09 AM