Skip to content

agentHost: keep lazily activated canvases open across runtime refreshes - #347946

Merged
Ulugbek Abdullaev (ulugbekna) merged 1 commit into
mainfrom
ulugbekna/agents/dormant-canvas-preservation-fix
Nov 12, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 1 commit into
mainfrom
ulugbekna/agents/dormant-canvas-preservation-fix

Conversation

@ulugbekna

Copy link
Copy Markdown
Contributor

Follow-up to #347629.

The Copilot runtime can start an extension lazily (github/copilot-agent-runtime#28873). An extension that declares its canvases in an extension.json sidecar with "initialization": "module" starts on first use.

The Agent Host sometimes replaces a chat's runtime session in place: after a configuration refresh, after telemetry is revoked, or when an idle chat is released and later resumed. It hands the chat's open canvases to the replacement, then keeps the ones the resumed runtime lists as open. On resume, the runtime keeps a restored canvas of a lazily activated extension out of canvas.listOpen until a host opens the same instance again. The Agent Host removed those canvases, so the user's canvas tab closed on the next refresh.

Changes

  • Each projected canvas privately keeps the input it was opened with, and the handoff carries it. The input isn't part of the published CanvasState.
  • When a handed-over canvas is missing from the resumed runtime's open canvases, the Agent Host checks canvas.list:
    • A canvas the runtime no longer declares is removed, as before.
    • Otherwise the canvas stays in the chat as unavailable, and the Agent Host reopens it in the background with canvas.open, using the same instance ID and input. The runtime treats this as a reopen: it starts the extension, publishes the canvas with a new URL, and records no new first open, so first-open telemetry is unaffected.
  • The reopen doesn't delay the resume or the turn that triggered it. Its wait is bounded. A timeout keeps the canvas unavailable without marking the session desynchronized, which would force another runtime restart on the next message. A late reopen still arrives as an opened event.
  • A reopen result is applied only if the canvas hasn't changed meanwhile, so a close during the reopen wins. If the reopen fails, the tab shows that the canvas provider is unavailable, and the next handoff tries again.
  • Unchanged:
    • Canvases of eagerly started extensions, which the runtime rehydrates itself. If one is still rehydrating when the Agent Host checks, the reopen joins that rehydration.
    • Cold resumes, where restored canvases stay hidden until they are opened explicitly.

How to test

  1. Set COPILOT_HOME to an empty folder and add the dormant-demo extension from agentHost: treat dormant canvas extensions as enabled and settled #347629 to extensions/dormant-demo/ inside it.
  2. Launch Code - OSS with that environment and enable chat.canvases.enabled. Start a Copilot chat on a folder in the Agents window, and open Dormant Demo.
  3. Force a runtime refresh: add a custom agent file, such as .github/agents/probe.agent.md, to the folder and send a message. The Agent Host log shows Session configuration changed, refreshing session with reason=clientPluginsChanged.
  4. Before this change, the canvas tab closes. With it, the tab stays and the page shows a new extension process ID. The message is answered without waiting for the extension to start.
  5. Optionally, repeat with an extension that has no extension.json. Its canvas also stays open.

Demo, recorded in a dev build of the Agents window: first without this change (the Dormant Demo tab closes), then with it (both a lazily activated and an eagerly started canvas stay open and come back from new extension processes with their input). https://raw.githubusercontent.com/ulugbekna/screenshots/main/attachments/2026/11/12/dormant-canvas-runtime-refresh.mp4

Validation

  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts: passed (2784 passing, 1 existing pending). With the source change reverted, 5 of the 6 new tests fail. The sixth, a close during the reopen, passes either way.
  • ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/copilotSdkCanvas.integrationTest.ts: passed (4 passing). The new test records the runtime behavior against the bundled runtime. After a resume on the same client, a lazily activated extension stays dormant, and its canvas is missing from openCanvases and listOpen. Opening the same instance ID again brings the canvas back with its input and records no new first open. The test doesn't run the Agent Host, so it passes without this change.
  • pnpm run typecheck-client: passed.
  • pnpm run oxlint <changed files>: passed.
  • Manual check in a dev build of the Agents window, as in the demo:
    • With a lazily activated and an eagerly started canvas open, both tabs stayed open after each refresh. They showed content again from new extension processes, with their original input.
    • The refresh took under a second from detection to the message being sent.
    • Without this change, the lazily activated canvas's tab closed on the first refresh.
    • The manual check ran before the branch was updated to current main, which didn't change these files.

Notes

  • The runtime currently ignores an openCanvases list passed to session.resume when it decides which restored canvases to rehydrate. If it starts honoring that list, or offers a rehydrate call that reuses the stored input, this reopen could become simpler.
  • If the Agent Host stops waiting for a reopen and the user then closes the tab, a late reopen could show the canvas again. The user's own canvas open has the same gap today.

The Agent Host disconnects and resumes a chat's Copilot runtime session in place after a configuration refresh, a telemetry revocation, or an idle release. It hands the chat's open canvases to the replacement and keeps those the resumed runtime lists as open. The runtime can now start an extension lazily, and on resume it keeps a restored canvas of such an extension hidden from `canvas.listOpen` until a host opens the same instance again. The Agent Host removed those canvases, which closed the user's canvas tabs.

Keep each canvas's open input privately in the projection and carry it in the handoff. When a handed-over canvas is missing from the resumed runtime's open canvases but still declared, keep it projected as unavailable and reopen it in the background with its instance ID and input. The runtime treats this as a reopen, so it starts the extension without recording a new first open. The reopen doesn't delay the resume or the turn, and its timeout leaves the canvas unavailable without desynchronizing the session; a late reopen still arrives as an opened event.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 17:21

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.

🔵 Needs a closer look

Only local validation is reported for the bundled-runtime lazy-extension lifecycle test; required packaged Electron integration runs on Windows, Linux, and macOS, including repeated lifecycle runs, still need confirmation before merging.

No open issues 🎉

What changed in this PR

Preserves open canvases from lazily activated extensions when the Agent Host replaces a Copilot runtime session, extending the earlier dormant-extension support.

Changes:

  • Retains canvas input privately across runtime handoffs without exposing it in published state.
  • Reopens still-declared canvases in the background, keeping tabs unavailable until recovery completes without delaying resume or desynchronizing the session on timeout.
  • Adds unit and SDK integration coverage for recovery, failures, close races, input preservation, and first-open telemetry.
File Description
src/​vs/​platform/​agentHost/​test/​node/​copilotSdkCanvas.integrationTest.ts Adds a lazy-provider fixture and verifies same-client resume and reopen behavior.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests handoff recovery, timeouts, failures, close races, and private input retention.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Preserves input and performs bounded background recovery of handed-over canvases.

Review effort: Balanced

@ulugbekna
Ulugbek Abdullaev (ulugbekna) merged commit 876c7ff into main Nov 12, 2026
53 of 54 checks passed
@ulugbekna
Ulugbek Abdullaev (ulugbekna) deleted the ulugbekna/agents/dormant-canvas-preservation-fix branch November 12, 2026 17:32
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 12, 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