Repository navigation
Description
What's happening
VS Code's cloud sandbox feature needs to know which cloud sessions you have so it can show them in the Agent Sessions view and in the Agents window. To find out, it asks the Copilot API for your list of tasks, then asks for details about each sandbox task one at a time.
The way it does this today asks far more often, and for far more, than it needs to. The extra load adds up across every open VS Code window and grows with how many tasks an account has ever created.
Why this matters
- It hurts everyone, not just VS Code. This endpoint is shared by every client of the cloud agent experience. Bursts from many VS Code windows cause throttling and intermittent failures across the board.
- It's what's holding back the rollout. The cloud sandbox feature is being turned on for VS Code users gradually. Request volume is the main reason it can't be turned on for everyone yet.
- Users feel it. Throttled or failed requests show up as sessions missing from the list, stale entries that don't go away, and slower startup.
Problems and fixes
Problems 1, 2, 3 and 5 are fixed in #345216 (which replaces #344841); the fix is on main and shipped to 1.144 via #345268. Problem 4 is still open; see the follow-ups below.
1. It turned pages the wrong way
Problem. When the task list is long, the server returns it in pages and tells us where the next page is. Instead of going where the server points, VS Code was guessing: "give me 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. Follow the server's directions for the next page. If the directions are missing, repeated, or point somewhere unexpected, stop that scan and report it as incomplete rather than looping or quietly pretending it finished.
2. It asked "anything new?" every minute, even when it was already being told
Problem. There are two ways VS Code learns a session changed: a live push connection (the server tells us) or asking on a timer. VS Code asked on the timer regardless, every 5 minutes with the push connection and every 60 seconds without it. Each ask is actually four requests (repo vs. no-repo, archived vs. not), plus more if the list spans several pages. Every open window did this on the same minute, so the server saw the load arrive in bursts.
Fix. Don't poll at all while the push connection is working — it already tells us about changes, and reconnecting after a gap catches up anything missed. Without it, poll every 5 minutes, with each window adding a random delay of up to a minute so they don't all hit the server at once. If polls keep failing, back off up to 15 minutes. Switching back to VS Code after a while away 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. Accounts with no known sandboxes only check every 15 minutes. As soon as the first sandbox shows up — created here, found by a scan, or announced by the push connection — the normal 5-minute rhythm resumes.
4. Every window reload re-reads every sandbox task individually
Problem. Startup makes two kinds of requests. First the list: a few pages that return every task with its name, last-updated time, and archive state. That part is necessary — it is how we learn what exists and what changed, and it costs a few dozen requests at most. Then, for each sandbox task on the list, a separate detail request for the one thing the list leaves out: which environment and session the task is bound to. That binding is set when the task is created and never changes, and VS Code already saves it on disk for every session it has shown before. But the check that decides "do I still need the detail?" only looks at what was learned since the window opened, so after a reload it asks for every task again. For an account with a thousand or more tasks, that is a thousand or more detail requests in the first few minutes, and a noticeable share of them get throttled and retried.
Fix. Not yet — this is the first follow-up below. The list requests stay; the per-task detail requests become "only the tasks whose last-updated time changed since the last run," which for most people is a handful instead of hundreds.
5. One bad moment knocked a window off the push connection for good
Problem. The push connection is the cheap path: while it is working, the server tells VS Code what changed and VS Code makes no list requests at all (problem 2). But setting it up takes one request, and if that request failed for any reason other than "this account doesn't have the push connection" — a momentary server error, a network blip, a timeout — VS Code gave up on it for the rest of the window's life and fell back to polling. The same happened if the periodic renewal of a working connection failed. We saw exactly this in a local window log: a single transient error during startup, and the window polled from then on. Every window in that state is one more window on the expensive path, and nothing in telemetry showed it.
Fix. 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, then doubles the wait each time up to 30 minutes, with a random spread so windows don't all retry together, and never sooner than the server's Retry-After if it sends one. Polling continues until the connection is back, at which point it stops again. 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.
Follow-ups
Most impactful first:
- Stop re-reading every task on reload (fixes problem 4). Load the saved session details from disk into the discovery cache at startup. The existing "did this task change?" check then does the rest: the list is still read in full, but the per-task detail request only happens for tasks whose last-updated time differs from what was saved.
- Use the shared task client that the rest of VS Code's GitHub integration already uses. It handles paging, caching with revalidation ("has this changed since I last asked?"), and rate limiting, so the hand-written request loop in the sandbox code can be removed.
- Only load archived sessions when the user asks to see them. Today half of every poll is spent on archived tasks that most people have hidden. Needs a shared signal for "archived sessions are visible" and care not to throw away hidden sessions between scans.
- Ask the service to include the session binding in the list itself. That would remove the one-request-per-task step for every client, not just VS Code. Tracked separately with the service team.
- Treat an unreadable push message the same before and after the handshake (Cloud sandbox session feed: an unreadable message before the handshake is retried, after it stops the feed #345282). Today a corrupt message that arrives before the handshake is retried slowly, while one that arrives after it stops the push connection for the rest of the window's life. Small, but the two paths should agree.
How to check
Count GET /agents/tasks* requests from one focused window (Output → Telemetry channel, or a local proxy):
| Situation | Before | After #345216 | Goal after follow-ups |
|---|---|---|---|
| Push connection working, in the background | 4 requests every 5 min | 0 | 0 |
| No push connection, has sandboxes | 4 requests every minute | 4 every 5 min (+ random delay) | 2 every 5 min |
| No push connection, no sandboxes | 4 requests every minute | 4 every 15 min | 2 every 15 min |
| Window reload with N sandbox tasks | list pages + N detail requests | unchanged | list pages + detail requests only for changed tasks |
| Push connection setup fails once (e.g. a 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 | same |
Whether a window is on the push connection or polling is visible in the cloudSandboxSessionFeed telemetry event (outcome is connected, unavailable, negotiationFailed, socketFailed, disconnected, or invalidMessage, with the failure count and the next retry delay) and in the [CloudSandboxSessionFeed] lines of the window log.
For reference, the code lives in src/vs/workbench/contrib/chat/browser/remoteAgentHost/ — cloudSandboxApiService.ts (the requests), cloudSandboxSessionContribution.ts (when to make them), and cloudSandboxSessionFeed.ts (the push connection).
Activity
chat: avoid redundant editor cloud sandbox discovery (#345710)
chat: preserve errors from coalesced session refreshes (#345717)
chat: skip focus discovery on connected feeds (Written by Copilot)
[Perf] chat: avoid cloud discovery on focus with a connected feed (#3…
[Perf] sessions: defer cloud task resolution (Written by Copilot)
chat: batch targeted cloud sandbox discovery
github: migrate cloud sandbox API operations to shared GitHub clients (…