Cloud agents: preserve archive state across v1↔v2 backend flip#317860
Merged
Conversation
Always emit `/<prNumber>` URIs when a PR is resolvable, regardless of backend. Adds reverse PR→task lookup so PR-shaped URIs on the Task API (v2) route content, follow-up, and openInBrowser through task endpoints.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Copilot Cloud Sessions provider to keep PR-backed session URIs stable (/<prNumber>) across the Jobs API (v1) ↔ Task API (v2) backend flip, so archived/pinned state (keyed by URI) is preserved even when the underlying backend representation changes.
Changes:
- Adds a Task-backend reverse-lookup API (
findTaskIdForPullRequest) to map PR numbers back to task IDs on v2. - Updates the sessions provider to always emit PR-number URIs when a PR is resolvable, and to reverse-resolve PR URIs to tasks for content rendering, browser opening, and follow-ups on v2.
- Introduces an in-memory PR→taskId cache populated during listing to avoid extra network lookups.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/vscode/cloudAgentBackend.ts | Extends the Task backend interface with a PR→task reverse-lookup method. |
| extensions/copilot/src/extension/chatSessions/vscode-node/taskApiBackend.ts | Implements PR→task lookup using Task API list filtering. |
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts | Emits stable PR URIs on v2 when PRs resolve; adds PR→task cache and v2 routing for content/open/follow-up. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 5
- findTaskIdForPullRequest now sorts by created_at desc to actually return the most recent task. - openSessionInBrowser and handleFollowUp v2 reverse-resolution accept both '/<n>' and legacy '/pull-session-by-index-<n>-<idx>' URI shapes by trying SessionIdForPr.parse() first. - Finish the truncated TODO docstring on resolveTaskIdForPrNumber.
dmitrivMS
approved these changes
May 22, 2026
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.
Why
When the cloud-agent backend flips from Jobs API (v1) to Task API (v2), the same PR-backed session would change URI shape from
/<prNumber>to/task/<id>. The VS Code chat sessions host stores archive (and pin) state keyed by resource URI, so a flip silently un-archives every previously archived item — surfacing dozens of stale closed/merged PR sessions in users' sidebars.This change keeps the URI stable across the flip.
What
/<prNumber>URIs when a PR is resolvable, regardless of which backend produced the entry./task/<id>URIs — there's no PR number to migrate to./task/<id>(the PR doesn't exist at creation time); the first list refresh after the PR materializes upgrades the URI to/<prNumber>for subsequent renders.To keep this safe, PR-shaped URIs on the v2 backend now reverse-resolve to the underlying task before dispatching:
provideChatSessionContent→ routes toprovideTaskChatSessionContent(taskId).openSessionInBrowser→ usestask.html_url.handleFollowUp→ routes tohandleTaskFollowUp(taskId).Reverse resolution hits a per-provider
_taskIdByPrNumbercache populated at list time, falling back to a targetedlistTasksForRepo({ artifact_type: 'pull', artifact_id })lookup on cold URIs.Files
extensions/copilot/src/extension/chatSessions/vscode/cloudAgentBackend.ts— newfindTaskIdForPullRequestonTaskCloudAgentBackend.extensions/copilot/src/extension/chatSessions/vscode-node/taskApiBackend.ts— implementation via existinglistTasksForRepo.extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts— cache, helper, URI emission change, and three consumer-site dispatches.Out of scope (follow-up)
A durable fix that decouples archive state from URI shape entirely (provider-managed archive store keyed by stable id, layered on the
createChatSessionItemControllermigration) is planned as a follow-up. This PR is the bridge that prevents user-visible regression while that lands.Verification