Skip to content

[cherry-pick] chat: reduce cloud sandbox discovery load on the task list - #345268

Merged
Osvaldo Ortega (osortega) merged 5 commits into
release/1.144from
cherry-pick/345216
Oct 30, 2026
Merged

Osvaldo Ortega (osortega) merged 5 commits into
release/1.144from
cherry-pick/345216

Conversation

@vs-code-engineering

@vs-code-engineering vs-code-engineering Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Cherry-pick of #345216 from main.

The squash commit did not apply to release/1.144 on its own because #345216 builds directly on three session-feed changes that landed on main after the branch was cut. This branch backports those first, as exact cherry-picks, and then #345216, so every touched file matches main:

Validated on this branch: npm run typecheck-client passes; 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's Link: 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 (61e80da2e98 and c42273c66ba, 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 (0dd73e6dd62 and 0f8bb05e241, 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 (633e294aa8d and 88dbe05364b, cloudSandboxSessionFeed.ts and cloudSandboxTelemetry.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's Retry-After if 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 new cloudSandboxSessionFeed telemetry 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

  • With a working push connection: nothing visible. Changes still arrive as they happen; background list requests go from 4 every 5 minutes to 0.
  • Without one: a sandbox created from another client shows up within about 5–6 minutes instead of 1–2, or within about 15 minutes if the account had no sandboxes before. Background requests go from 4 per minute to 4 per 5 minutes (or 4 per 15 minutes).
  • After a transient error at startup: the window gets back on the push connection within the backoff instead of polling until reload.
  • Sessions created in the window, manual refresh, and push notifications behave as before.

Supersedes #344841, which also rewrote the shared Link parser; 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):

Situation Before After
Push connection working, window in the background 4 requests every 5 min 0
No push connection, account has sandboxes 4 requests every minute 4 every 5 min, plus up to 1 min random delay
No push connection, account has no sandboxes 4 requests every minute 4 every 15 min
Push connection setup fails once (transient server error) polling for the rest of the window's life retries after ~1 min, doubling to 30 min; back on the push connection as soon as one succeeds
Push connection connects but keeps dropping reconnects up to twice a minute, indefinitely first six reconnects within seconds, then doubling (1, 2, 4, 8, 17, 30 min) until a connection stays up for a minute

Whether a window is on the push connection or polling is visible in the [CloudSandboxSessionFeed] lines of the window log and in the cloudSandboxSessionFeed telemetry event (outcome is connected, unavailable, negotiationFailed, socketFailed, disconnected, or invalidMessage, 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-After handling 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 Link format 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.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 20:50
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label Oct 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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
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

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)
Signed attestation commit for release/1.144 cherry-pick.

Co-authored-by: Copilot <[email protected]>
@osortega
Osvaldo Ortega (osortega) merged commit f8850a9 into release/1.144 Oct 30, 2026
44 checks passed
@osortega
Osvaldo Ortega (osortega) deleted the cherry-pick/345216 branch October 30, 2026 23:01
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-artifact Auto-generated cherry-pick PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants