Repository navigation
[cherry-pick] chat: reduce cloud sandbox discovery load on the task list - #345268
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved merge conflicts, undeclared symbols, and incompatible feed/discovery contracts leave production code and tests uncompilable, while an undefined trigger also breaks refreshes at runtime.
8 open issues
Align discovery tests and calls with the branch API · New Resolve pagination conflicts using the three-argument request API · New Define and pass trigger to stale refresh checks · New Wire refresh handler to the existing feed contract · New Resolve conflicts with branch-compatible reconnect dependencies · New Align the fixture with the production feed contract · New Implement automatic socket disconnects for flapping tests · New Preserve invalid-message failures and cancel setup retries · New
What changed in this PR
This cherry-pick aims to reduce cloud sandbox task-list traffic in VS Code and the Agents Window, addressing discovery and feed-recovery issues from #345234. Redundant per-task reads after reload remain a separate follow-up.
Changes:
- Follow server-provided pagination links with validation and loop detection.
- Replace polling with push updates while connected; otherwise use slower, jittered polling and failure backoff.
- Add feed retry telemetry, regression tests, and updated discovery documentation.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/editorCloudSandboxContribution.test.ts |
Adapts editor tests to polling intervals and telemetry injection. |
src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/cloudSandboxSessionFeed.test.ts |
Adds feed retry, backoff, renewal, and telemetry tests. |
src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/cloudSandboxApiService.test.ts |
Tests cursor pagination, retained filters, and invalid continuations. |
src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxTelemetry.ts |
Defines and reports feed connection and retry events. |
src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionFeed.ts |
Adds transient-failure retries and escalating reconnect delays. |
src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionContribution.ts |
Adjusts polling cadence, connected-feed gating, and timer rearming. |
src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxApiService.ts |
Follows pagination links using the shared parser. |
src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/cloudSandboxAgentHostContribution.test.ts |
Updates discovery tests for polling suppression and idle-account timing. |
src/vs/sessions/contrib/providers/remoteAgentHost/REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md |
Documents the revised polling and feed-recovery behavior. |
Review effort: Balanced
Dmitriy Vasyura (dmitrivMS)
previously approved these changes
Oct 30, 2026
Use incremental inventory catch-up after seamless feed renewal while retaining full recovery for connection gaps and periodic reconciliation. Preserve queued refresh intent and report bounded per-scan cost and outcome telemetry. Co-authored-by: Copilot <[email protected]> (cherry picked from commit a06ebdc)
Reuse the reconnect-delay helper for jittered exponential delays capped at one minute. Reset backoff only after a minute of continuous connection, while retaining the existing stop-after-negotiation-failure behavior. Co-authored-by: Copilot <[email protected]> (cherry picked from commit dc9e435)
* chat: use server-relative session feed renewal Prefer the service's relative renewal and expiry durations to avoid rapid reconnects caused by client clock skew. Preserve timestamp-only compatibility, validate timing bounds, and cover the shared-client and IPC paths. Co-authored-by: Copilot <[email protected]> * test: give feed metadata cases stable names Use explicit case labels instead of payload-derived titles so duration cases remain unique and timestamp-based fixtures have stable names across CI reruns. Co-authored-by: Copilot <[email protected]> * chat: include feed negotiation time in renewal delay Start monotonic timing before awaiting feed negotiation so response delivery and account rechecks count toward renewal. Add an injected stopwatch for deterministic coverage of delayed negotiation and WebSocket setup. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit f327482)
* chat: follow task-list pagination links during sandbox discovery Discovery synthesized page=N for the next request and only checked that a Link header mentioned rel=next, so it could not follow continuation URLs and would re-request the same page indefinitely if the server stopped honoring page numbers. Follow the advertised next link instead, adopting only its query so requests stay on the CORS-enabled endpoint and keep the scope filters a numbered link may omit. A repeated or unparseable continuation fails the scope rather than looping or silently completing a truncated scan. Co-authored-by: Copilot <[email protected]> * chat: poll sandbox discovery every five minutes with jitter Discovery polled the task list every minute whenever the session feed was not connected, which multiplied list requests across windows and lined them up on the same minute grid. Poll on one five-minute interval regardless of feed state, spread each automatic poll with up to a minute of jitter measured from the latest inventory pass, and raise the failure backoff ceiling so unsuccessful scans still slow down. Focus and host-selection refreshes keep bypassing the timer when discovery is stale. Co-authored-by: Copilot <[email protected]> * chat: slow sandbox discovery polling for accounts without sandboxes An account with no known sandbox gains nothing from incremental polls between full reconciliations, so poll it only at the full-scan interval until a sandbox appears through discovery, provisioning, or the session feed. Re-arm the poll timer when an inventory pass settles so a changed interval, from backoff or an idle inventory, takes effect on the next tick instead of one interval late. Co-authored-by: Copilot <[email protected]> * chat: stop polling sandbox discovery while the session feed is connected A connected feed already pushes task changes, and its renewals and reconnects catch up the inventory, so the timer-driven poll only duplicated those reads. Skip it while the feed is connected; the timer keeps ticking so polling resumes within one interval once the feed drops. Focus and host-selection refreshes are unchanged. Co-authored-by: Copilot <[email protected]> * chat: re-arm the sandbox discovery poll when the first sandbox arrives Only inventory scans re-armed the poll timer, so an account whose first sandbox arrived through local provisioning or a feed task read kept the idle fifteen-minute timer until it fired. Re-arm from the shared environment registration on the empty-to-populated transition, without counting it as an inventory pass. Co-authored-by: Copilot <[email protected]> * chat: retry failed session feed negotiations with a slow backoff A window whose first session feed negotiation failed for any reason other than the feed being unavailable for the account, for example a transient HTTP 503, stopped trying for the rest of its lifetime and fell back to discovery polling until the next reload or setting toggle. A failed renewal or reconnect did the same. The feed is the cheapest way for the service to keep a window current, so every window stuck this way was one more window on the polling path. Only an unavailable feed (the service declining it for the account) or an invalid feed message still stop attempts. Every other failed negotiation or handshake is retried on a jittered exponential backoff that starts at about one minute and caps at thirty minutes, and never sooner than a Retry-After. Dropped sockets keep their faster reconnect backoff; both share one consecutive-failure counter that resets after a healthy connection. The first connection after any gap still requests full reconciliation. Feed transitions are reported through a new cloudSandboxSessionFeed telemetry event with a bounded outcome, the consecutive failure count, the scheduled retry delay, and the rejected negotiation status, so windows left on polling can be told apart from windows receiving push updates. Co-authored-by: Copilot <[email protected]> * chat: keep backing off session feed sockets that repeatedly drop A dropped feed socket reconnected on a 1 s to 60 s jittered backoff and stayed at that ceiling for as long as the socket kept dropping, because the failure counter only resets after a connection survives for a minute. A relay that repeatedly accepts and then closes connections therefore cost every window a negotiation request, a socket connect and a telemetry event up to twice a minute, indefinitely. Share the thirty-minute ceiling of the negotiation retry policy instead: the first six drops still reconnect within seconds, after which each further drop keeps doubling the delay (about one, two, four, eight and seventeen minutes, then thirty) until a connection stays healthy for a minute. The dropped-socket test now drives the schedule past the old ceiling with immediately closing sockets, and the flapping bound reflects the lower rate. Co-authored-by: Copilot <[email protected]> * chat: assert which trigger refreshes stale sandbox discovery The stale focus and host selection test waited exactly one poll interval before selecting the host, so the automatic poll fired at the same instant and performed the refresh; the selection found a scan in flight and did nothing. The assertion held, but for the wrong trigger, both before and after the interval change. Give the poll a jitter in this test so that it is due after the inventory goes stale, and record the trigger of every scan so the final refresh is proven to come from the host selection. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit b7eceff)
Osvaldo Ortega (osortega)
force-pushed
the
cherry-pick/345216
branch
from
October 30, 2026 21:13
5f174da to
4d78cff
Compare
Bhavya U (bhavyaus)
approved these changes
Oct 30, 2026
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 30, 2026
Justin Chen (justschen)
approved these changes
Oct 30, 2026
Osvaldo Ortega (osortega)
enabled auto-merge (squash)
October 30, 2026 22:24
Aaron Munger (amunger)
approved these changes
Oct 30, 2026
Signed attestation commit for release/1.144 cherry-pick. Co-authored-by: Copilot <[email protected]>
5 tasks
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.


Cherry-pick of #345216 from
main.The squash commit did not apply to
release/1.144on its own because #345216 builds directly on three session-feed changes that landed onmainafter the branch was cut. This branch backports those first, as exact cherry-picks, and then #345216, so every touched file matchesmain:Validated on this branch:
npm run typecheck-clientpasses; every test file the four commits touch passes (1043 browser tests across the cloud sandbox feed, API service, telemetry, editor and Agents-window contribution and GitHub channel suites, plus 117 node tests for the task-list client); ESLint is clean on the 17 changed TypeScript files.The review comments posted before this push refer to the bot's conflicted version of the branch, which had conflict markers committed, and no longer apply.
What this changes
Part of #345234. Fixes problems 1, 2, 3 and 5 described there; problem 4 (re-reading every sandbox task on reload) stays open as a follow-up.
VS Code's cloud sandbox feature asks the Copilot API for your task list so it knows which cloud sessions to show. Today it asks far more often than it needs to, every open window asks the same way at the same time, and a single bad moment at startup can leave a window on the expensive path for good. This PR changes when and how the client asks, one change per commit, so the service sees a fraction of the traffic and users don't notice a difference.
Problems and fixes
Numbered as in #345234.
1. It turned pages the wrong way
Problem. Long task lists come back in pages, and the server says where the next page is. VS Code ignored that and guessed: "page 2, now page 3…". If the server ever stopped treating those numbers as page numbers, VS Code would ask for the same page over and over until the scan was cancelled.
Fix (
1c1305ea120,cloudSandboxApiService.ts). Follow the server'sLink: rel="next"header, using the parser the rest of VS Code's GitHub integration already uses. Only the query part of the link is adopted, so requests stay on the same API host and keep the filters a link might leave out. A repeated, foreign, or unreadable link ends that scan and reports it as incomplete (keeping the sessions we already had) instead of looping or quietly pretending it finished.2. It asked "anything new?" every minute, even while it was being told
Problem. VS Code learns about changed sessions two ways: a live push connection (the server tells us) or asking on a timer. It asked on the timer regardless — every 5 minutes with the push connection, every 60 seconds without it. Each ask is really four requests (repo vs. no repo, archived vs. not), more if the list spans pages, and every open window asked on the same minute, so the server saw the load in bursts.
Fix (
61e80da2e98andc42273c66ba,cloudSandboxSessionContribution.ts). Don't poll at all while the push connection is working — it already reports changes, and reconnecting after a gap catches up anything missed. The timer keeps running so polling resumes within one interval if the connection drops. Without a push connection, poll every 5 minutes, with each window adding up to a minute of random delay (measured from its own last pass) so windows spread out. If polls keep failing, back off up to 15 minutes. Switching back to VS Code or changing the selected host still refreshes right away if the list is stale.3. Accounts with no sandboxes were polled just as hard
Problem. If you have never created a sandbox, there is nothing for those requests to find — but they ran at the same rate anyway.
Fix (
0dd73e6dd62and0f8bb05e241, same file). Accounts with no known sandbox only check every 15 minutes. The first sandbox to appear — created here, found by a scan, or announced by the push connection — brings back the 5-minute rhythm, and the timer is re-armed immediately so a changed interval takes effect on the next tick rather than one interval late.5. One bad moment knocked a window off the push connection for good
Problem. Setting up the push connection takes one request. If that request failed for any reason other than "not available for this account" — a momentary server error, a network blip, a timeout — VS Code gave up on it for the rest of the window's life and polled instead. A failed renewal of a working connection did the same. A local window log showed exactly this: one transient error at startup, then polling until the next reload. Nothing in telemetry showed it either.
Fix (
633e294aa8dand88dbe05364b,cloudSandboxSessionFeed.tsandcloudSandboxTelemetry.ts). Keep trying, slowly. Only "not available for this account" or a corrupt message from the server stops attempts for good. Anything else retries after about a minute, doubling each time up to 30 minutes, with a random spread so windows don't retry together, and never sooner than the server'sRetry-Afterif it sends one. Polling continues until the connection is back, then stops again. A connection that drops after it was working still reconnects within seconds, but if it keeps dropping before staying up for a minute, each further reconnect waits twice as long, up to the same 30-minute ceiling (88dbe05364b) — previously it stayed at a one-minute ceiling for as long as the dropping lasted, up to twice a minute per window. A newcloudSandboxSessionFeedtelemetry event records each connection, failure, retry delay and give-up, so we can see how many windows are on the push connection versus polling.What changes for users
Supersedes #344841, which also rewrote the shared
Linkparser; that part is dropped here in favor of the unchanged platform parser.How to check
Count
GET /agents/tasks*requests from one focused window (Output → Telemetry channel, or a local proxy):Whether a window is on the push connection or polling is visible in the
[CloudSandboxSessionFeed]lines of the window log and in thecloudSandboxSessionFeedtelemetry event (outcomeisconnected,unavailable,negotiationFailed,socketFailed,disconnected, orinvalidMessage, with the consecutive failure count and the next retry delay).Validation
macOS, Node.js 24.22.1, after
npm run build-fast -- --client-only:npm run test-browser-no-install -- --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/cloudSandboxSessionFeed.test.ts --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/cloudSandboxApiService.test.ts --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/cloudSandboxAgentHostContribution.test.ts --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/editorCloudSandboxContribution.test.ts --browser chromium --reporter dot— passed, 830 tests. These cover the page-following rules (repeated, foreign and unreadable links), the poll gating, jitter, backoff and idle intervals, and the feed retry pacing,Retry-Afterhandling and telemetry, all with virtual time.npm run eslint -- <changed .ts files>— passed.npm run typecheck-client— passed.npm run valid-layers-check— passed.Not run: verification against the live service. The exact
Linkformat the service emits for the next page was not inspected, which is why the client adopts whatever query the server advertises rather than assuming a parameter name.