Repository navigation
Canvases: restore canvases from a persisted record after idle release or Agent Host restart - #346111
Draft
Ulugbek Abdullaev (ulugbekna) wants to merge 4 commits into
Draft
Ulugbek Abdullaev (ulugbekna) wants to merge 4 commits into
Ulugbek Abdullaev (ulugbekna) wants to merge 4 commits into
Conversation
A canvas handoff can now carry close intent recorded while no runtime projected the canvas. A replacement session applies those closes when it reconciles the handoff with the canvases its runtime restored, keeps the closed instances unprojected, and retries closes that fail after it adopts the handoff, so a failing provider close never fails the resume. A fixed-ID reopen supersedes an earlier close, including one still being flushed, and late closed events cannot remove a reopened canvas. Hosts can also republish a live session's projected canvas states before membership once its chat is registered. Co-authored-by: ulugbekna <[email protected]> Co-authored-by: Copilot <[email protected]>
A Copilot session can now report its projected canvases, without their sources, together with the closes it still owes its runtime, whenever it publishes canvas state or membership while its runtime is live. Teardown and pending handoffs never report, so the last report describes what the chat showed before its runtime went away. Co-authored-by: Copilot <[email protected]>
An idle residency release or an Agent Host restart tore down a chat's canvas providers, and returning to the chat restored only its transcript until a new turn resumed the runtime. While a chat's runtime is live, the Copilot provider now persists the canvases it reports, without their sources, in the chat's own storage, tied to its SDK session. When the runtime is gone: - observing the chat shows those canvases as unavailable on their original channels and, once a client contributes to the chat, resumes the runtime without a model turn from that client's current customizations, so a plugin disabled or removed meanwhile is not relaunched; - any resume seeds the runtime with the record, so the runtime's rehydrated canvases get fresh sources on the same channels; - closing a canvas records the close for the next runtime to apply. Releasing a runtime writes nothing, so the record outlives both idle release and process restarts with one mechanism. Archived chats are not restored, and a record left by an earlier SDK session is discarded when read, instead of being cleared on every archive or backing change. Co-authored-by: Copilot <[email protected]>
The host drops canvas state and membership published for a chat whose state has not loaded yet, which happens when a client reconnects to a restarted Agent Host and a restored chat resumes before its history loads. Restored canvases then stayed unavailable until something else re-subscribed to the chat. The host now registers a subscribed chat's watches once its state loads, and tells the canvas watch when that happens, so the provider republishes the chat's canvases into the loaded state. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved lifecycle and restoration issues can lose canvas updates, reopen archived canvases, or destroy runtimes that still have active canvas subscriptions.
4 open issues
What changed in this PR
This PR unifies canvas restoration after idle runtime release and Agent Host restart for local Copilot chats, using persisted records to preserve canvas channels without storing stale URLs.
Changes:
- Persists canvas projections and deferred closes, then reconciles them when the runtime resumes.
- Adds chat canvas observation and republishes restored canvases after chat state loads.
- Adds lifecycle regression tests and updates the provider contract.
| File | Description |
|---|---|
src/vs/sessions/contrib/providers/agentHost/AGENT_HOST_SESSIONS_PROVIDER.md |
Documents persisted restoration and deferred-close behavior. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests handoffs, deferred closes, reopening, and continuity reporting. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests persistence, idle release, restart, archive handling, and cold closes. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Tests canvas-watch lifecycle and host context. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Reports source-less continuity and reconciles deferred closes. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Stores, restores, adopts, and observes persisted canvases. |
src/vs/platform/agentHost/node/agentService.ts |
Connects canvas watches to subscriptions and state loading. |
src/vs/platform/agentHost/common/agent.ts |
Defines the optional canvas-watch provider contract. |
Review effort: Balanced
Comment on lines
+8030
to
+8032
| if (!this._canvasWatches.has(chat)) { | ||
| // Nobody observes the chat anymore, and residency may have released its session while it resumed. | ||
| await this._releaseChat(chat, operationContext); |
Comment on lines
+8096
to
+8098
| private async _claimPersistedCanvases(chat: URI, storage: URI, sdkSessionId: string): Promise<void> { | ||
| if (!this._canvasesEnabled() || this._canvasHandoffs.has(chat)) { | ||
| return; |
Comment on lines
+8115
to
+8117
| if (handoff) { | ||
| this._resumingCanvasHandoffs.delete(chat); | ||
| replacement?.adoptCanvasHandoff(handoff); |
Comment on lines
+8125
to
+8127
| void this._canvasContinuityIO.queue(chat.toString(), async () => { | ||
| if (!this._isShuttingDown && this._findChatByUri(chat) === session) { | ||
| await this._writeCanvasContinuity(chat, session.resourceUri, value); |
This branch has not been deployed
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.

Fixes microsoft/vscode-internalbacklog#10570
Fixes #344999
An alternative to #345740 (idle release) and #345872 (Agent Host restart). It covers both cases in one mechanism.
Summary
When the Agent Host releases an idle Copilot runtime, or the Agent Host restarts, returning to a chat brings back its transcript but not its canvases. They only came back, on new channels, after the next message.
This change stores each chat's open canvases, without their URLs, in the chat's own storage, as a
copilot.canvasContinuitymetadata record tied to the chat's SDK session. Whenever the chat's runtime resumes, the Copilot provider reads the record. It republishes the canvases on their original channels, unavailable at first, and they become live when the runtime reports them open again. The runtime rehydrates each canvas's input itself; VS Code doesn't replay input or issue a secondcanvas.open.Because the record lives in storage, idle release and process restart take the same path. Compared with #345740 + #345872:
Commits
The history is layered for review:
agentHost: carry deferred canvas closes across Copilot runtime handoffs(from Canvases: restore canvases after idle session release #345740): when a canvas is closed while no runtime is running, the next runtime applies the close when it adopts the handoff. A failing close is retried and doesn't fail the resume.agentHost: report Copilot canvas continuity while the runtime is live: the session reports which canvases it shows, plus closes it still owes the runtime, through a newonDidChangeCanvasContinuityoption. It reports only while its runtime is live; handoffs and teardown never report.agentHost: restore Copilot canvases from their persisted record:IAgent.watchChatCanvasesshows a cold, observed chat's canvases as unavailable;AGENT_HOST_SESSIONS_PROVIDER.md.agentHost: republish restored canvases once a chat's state loads: after an Agent Host restart, the window can resubscribe before the host has loaded the chat's state, and restored canvases published in that window were dropped. The host now reports when a watched chat's state loads (IAgentChatCanvasWatchHost.onDidLoadState), and the provider republishes.Known limitations
openCanvasesresume option.How to test
chat.canvases.enabled. In the Agents window, open a canvas in a local Copilot chat, for example from a project extension in.github/extensions/.VSCODE_AGENT_HOST_SESSION_RESIDENCY_LIMIT=1. Send a message in another session so the first one is released, then go back to the first one without sending anything. The canvas shows as unavailable, then live again on the same tab with the same input.Recordings
The test canvas shows its input and a "provider generation" ID that changes whenever a new provider process serves it. In both recordings, the tab and input stay the same while the generation changes, and no message is sent. The chat footer and model picker are blurred.
Idle release: switch to another session so this one is released, then return.
▶ Watch the idle release recording (MP4)
Agent Host restart: run Developer: Restart Local Agent Host while the chat is open.
▶ Watch the Agent Host restart recording (MP4)
Validation
pnpm run typecheck-client./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.tspnpm run eslint <changed .ts files>git diff --check origin/main...HEADThe manual run was done before rebasing onto current
main. The rebase only resolved an import conflict.