Skip to content

Cloud agents: preserve archive state across v1↔v2 backend flip#317860

Merged
osortega merged 2 commits into
mainfrom
cloud-agent/pr-uri-shim
May 22, 2026
Merged

Cloud agents: preserve archive state across v1↔v2 backend flip#317860
osortega merged 2 commits into
mainfrom
cloud-agent/pr-uri-shim

Conversation

@osortega
Copy link
Copy Markdown
Contributor

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

  • Always emit /<prNumber> URIs when a PR is resolvable, regardless of which backend produced the entry.
  • PR-less tasks (Task API) keep their /task/<id> URIs — there's no PR number to migrate to.
  • Newly-created tasks still start as /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 to provideTaskChatSessionContent(taskId).
  • openSessionInBrowser → uses task.html_url.
  • handleFollowUp → routes to handleTaskFollowUp(taskId).

Reverse resolution hits a per-provider _taskIdByPrNumber cache populated at list time, falling back to a targeted listTasksForRepo({ artifact_type: 'pull', artifact_id }) lookup on cold URIs.

Files

  • extensions/copilot/src/extension/chatSessions/vscode/cloudAgentBackend.ts — new findTaskIdForPullRequest on TaskCloudAgentBackend.
  • extensions/copilot/src/extension/chatSessions/vscode-node/taskApiBackend.ts — implementation via existing listTasksForRepo.
  • 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 createChatSessionItemController migration) is planned as a follow-up. This PR is the bridge that prevents user-visible regression while that lands.

Verification

  • Compile clean across the three modified files.
  • No host-side changes.

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.
Copilot AI review requested due to automatic review settings May 21, 2026 21:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.
@osortega osortega marked this pull request as ready for review May 21, 2026 23:58
@osortega osortega enabled auto-merge (squash) May 21, 2026 23:58
@osortega osortega merged commit 3645d2e into main May 22, 2026
25 checks passed
@osortega osortega deleted the cloud-agent/pr-uri-shim branch May 22, 2026 00:26
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants