Skip to content

agentHost: keep open canvases across session configuration refreshes - #341518

Merged
Ulugbek Abdullaev (ulugbekna) merged 3 commits into
mainfrom
ulugbekna/agents/open-canvas-session-issue
Oct 14, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 3 commits into
mainfrom
ulugbekna/agents/open-canvas-session-issue

Conversation

@ulugbekna

Copy link
Copy Markdown
Contributor

Fixes #340508

When a send refreshes a chat's session configuration (for example after its customizations change), the Agent Host destroys the chat's SDK session and resumes a replacement. Destroying the session cleared its canvas projection and published an empty canvas list, so the Agents window closed every open canvas, and the replacement then ignored the canvases the runtime restored.

The refresh now hands the projected canvases to the replacement:

  • CopilotAgentSession.takeCanvasProjection() releases the old session's canvases and republishes them without a source, so they keep their resources (and their tabs) and show as temporarily unavailable.
  • CopilotAgent holds the handoff per chat while the refresh runs. The replacement is created with it, keeps those canvases instead of ignoring them on resume, accepts the runtime's rehydration events, and reconciles them with rpc.canvas.listOpen once its extensions settle.
  • Membership changes stay unpublished until the refresh adopts the replacement that survives restore retries. If the refresh fails, the canvases close as before.
  • Canvas projection state is now one phase (starting, live, released) plus a per-canvas hand-over mark, replacing two flags and a parallel set.

The canvas contract in AGENT_HOST_SESSIONS_PROVIDER.md now describes the refresh handoff.

How to test

  1. Enable chat.canvases.enabled. In the Agents window, start a local Copilot session in a folder.
  2. Ask the agent to open a canvas.
  3. Add a file such as .github/instructions/test.instructions.md to the folder, then send another message.

The canvas tab stays open, is briefly unavailable, and then reloads from the new runtime. Before this change, the tab closed.

Validation

  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --grep "canvas|config-driven session refresh": 29 passing.
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts: 1,731 passing, 14 failing locally. The failures are in tests unrelated to canvases and refreshes that depend on machine state, such as existing ~/.copilot/session-state entries or a /home/test home directory.
  • ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/copilotSdkCanvas.integrationTest.ts: passed, including the new test that keeps an open canvas across a resume on the real Copilot runtime.
  • npm run typecheck-client: passed.
  • npm run eslint -- <changed .ts files>: no problems.
  • Manual, in a Code - OSS Agents window before rebasing onto current main: two consecutive refreshes, with one and then two canvases open. Every tab stayed open and reloaded from the new runtime, and the host published no empty chat/canvasesChanged. A canvas opened after the first refresh got its own tab.

A send that refreshes a chat's session configuration destroys its SDK
session and resumes a replacement. Destroying the session cleared its
canvas projection and published an empty canvas list, so the Agents
window closed every open canvas, and the replacement then ignored the
canvases the runtime restored.

The refresh now hands the projected canvases to the replacement. They
keep their resources, so their tabs stay open, and they show as
temporarily unavailable until the new runtime serves them again. The
replacement reconciles them with the canvases the runtime reports open.
Membership changes stay unpublished until the refresh adopts the
replacement that survives restore retries; if the refresh fails, the
canvases close as before.

Fixes #340508

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:47

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

Failed listOpen reconciliation can leave stale unavailable canvas membership indefinitely.

1 open finding
What changed in this PR

Preserves canvas tabs while Agent Host refreshes a Copilot session’s configuration.

Changes:

  • Transfers canvas projections between SDK sessions.
  • Reconciles restored canvases and preserves stable resources.
  • Adds unit, integration, and contract coverage.
File Description
AGENT_HOST_SESSIONS_PROVIDER.md Documents refresh handoff behavior.
copilotSdkCanvas.integrationTest.ts Tests runtime canvas restoration.
copilotAgentSession.test.ts Covers handoff lifecycle and reconciliation.
copilotAgent.test.ts Covers refresh orchestration and failure paths.
copilotAgentSession.ts Implements projection transfer and reconciliation.
copilotAgent.ts Coordinates handoff across session refreshes.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

If the replacement runtime could not report its open canvases, the
refresh still adopted every handed-over canvas, so canvases the runtime
had not restored stayed open as unavailable tabs. A timed-out request
also left the session marked for resync while the send used it.

Let the failure fail initialization instead, as a failed canvas
registry listing already does. The refresh then discards the session
and closes the handed-over canvases.

Co-authored-by: Copilot <[email protected]>
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Base: 0feedbf3 Current: 9b88dadb

No screenshot changes.

…cile"

This reverts commit e2c03bf.

Failing the replacement session turned a failed or slow open-canvas
listing into a failed send, and closed every canvas, including the ones
the runtime had restored. A canvas the runtime did not restore staying
as an unavailable tab until a later refresh reconciles it is the
smaller problem.

Co-authored-by: Copilot <[email protected]>
@ulugbekna
Ulugbek Abdullaev (ulugbekna) merged commit 85f9801 into main Oct 14, 2026
35 checks passed
@ulugbekna
Ulugbek Abdullaev (ulugbekna) deleted the ulugbekna/agents/open-canvas-session-issue branch October 14, 2026 13:07
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone Oct 14, 2026
@rwoll

Copy link
Copy Markdown
Member

Heads-up Ulugbek Abdullaev (@ulugbekna): the unchanged Copilot SDK - canvas lifecycle / keeps an open canvas across a resume on the same client test failed in macOS Electron integration on #342184. Immediately after resume, openCanvases lacked the instance (restoredOnResume: false); after extensions settled, canvas.listOpen() included it (listedOnceExtensionsSettle: true).

Log: https://github.com/microsoft/vscode/actions/runs/38977911553/job/117231763554

Both canvas lifecycle tests passed in 40 local repetitions with the same bundled SDK/runtime. No root cause established, and no canvas code or assertions changed. Flagging the intermittent resume-snapshot result rather than weakening the test. No CI rerun was triggered.

🤖 Authored with GitHub Copilot on behalf of Ross Wollman (@rwoll).

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.

Agent Host: open canvases close when a send triggers a session configuration refresh

4 participants