Skip to content

Canvases: restore canvases after an Agent Host restart - #345872

Closed
Ulugbek Abdullaev (ulugbekna) wants to merge 3 commits into
mainfrom
ulugbekna/agents/canvas-restart-continuity
Closed

Ulugbek Abdullaev (ulugbekna) wants to merge 3 commits into
mainfrom
ulugbekna/agents/canvas-restart-continuity

Conversation

@ulugbekna

@ulugbekna Ulugbek Abdullaev (ulugbekna) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #344999

Stacked on #345740: this PR's base is that PR's branch (jruales-canvas-idle-restoration), so the diff shows only this change. It builds on the idle-release continuity there, not on the alternative in #345767.

Summary

#345740 keeps a chat's canvases, without their URLs, in memory when an idle Copilot runtime is released, and restores them when the chat is opened again. A process restart, such as an Insiders update, still loses them. This change stores that record in the chat's storage, so the chat's canvases come back after the Agent Host restarts, without a model turn.

Changes

  • Session reports its canvases: CopilotAgentSession reports which canvases it shows (no URLs), plus closes it still owes the runtime, through a new onDidChangeCanvasContinuity option. It reports whenever it publishes canvas state or membership while its runtime is live; handoffs and teardown never report.
  • Agent stores the record: CopilotAgent saves it as copilot.canvasContinuity metadata in the chat's own storage. The record is tied to the chat and its SDK session, not to its owner, since chats can move between sessions.
    • Writes are serialized per chat and dropped once the chat's continuity has been invalidated, so a late update from a running runtime can't undo an archive or delete.
    • Shutdown keeps the record.
  • Cold chats load it: opening a cold chat (watchChatCanvases) or resuming it (default and peer chats) loads a matching record before the resume claims Canvases: restore canvases after idle session release #345740's continuity. The canvases are then republished on their original channels and reconciled with what the runtime still has open.
  • Stale or archived records are discarded: a record for a different SDK session is deleted. A cold archived chat discards its record instead of resuming, via a new optional IAgentChatCanvasWatchHost.isArchived. This covers archiving while the session isn't loaded, which never reaches the provider.
  • Fix for a Canvases: restore canvases after idle session release #345740 edge case: a close the runtime had already applied was carried into the next handoff even after the same instance was reopened, so the reopened canvas was dropped on the next restore. The editor + → Canvas menu always reuses the same instance IDs, so this is easy to hit.
  • Docs: updated the canvas paragraph in AGENT_HOST_SESSIONS_PROVIDER.md.

Known limitations

  • Closed tabs come back: closing a canvas tab doesn't close the canvas in the runtime, so its tab reopens after a restart. That matches what the first message after a restart does today. Fixing it means persisting tab dismissals on the client, which is now possible because canvas channels stay the same across restarts.
  • Startup cost: opening a chat that had canvases starts its runtime and extension processes without a message, as Canvases: restore canvases after idle session release #345740 already does after an idle release.
  • Canvases setting: turning canvases off leaves the record, so it can restore again after they are turned back on.
  • Local only: local Copilot chats only; remote agent hosts are unchanged.

How to test

  1. Enable chat.canvases.enabled. In the Agents window, open a canvas in a local Copilot chat.
  2. Quit and relaunch VS Code.
  3. Open the chat without sending a message. The canvas shows as unavailable, then live again on the same tab.
  4. Close the canvas from its canvas pill, restart, and open the chat. It does not come back.

Validation

Command Result
fnm exec --using=24.22.1 pnpm run build-fast --client-only Passed
fnm exec --using=24.22.1 ./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/agentSessionResidency.test.ts --run src/vs/platform/agentHost/test/node/chatContributions.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.ts Passed on the current base (bb08f54ac40): 4044 passing, 17 pending. On the previous base, 4 consecutive runs passed. One earlier run reported 1 failure that was not captured and did not reproduce.
fnm exec --using=24.22.1 ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --grep "persisted by an earlier host process|archiving a chat removes its persisted|discards instead of restoring|reports source-less continuity|applied close into the next handoff" Passed: the 7 new tests
The reopen test, with the edge-case fix temporarily reverted Failed, as expected: it catches the bug
fnm exec --using=24.22.1 node_modules/.bin/tsc --project ./src/tsconfig.json --noEmit --skipLibCheck (same as pnpm run typecheck-client) Passed
fnm exec --using=24.22.1 pnpm run eslint <6 changed TypeScript files> Passed
git diff --check HEAD~1 HEAD Passed

Not run: pnpm run valid-layers-check, the integration and smoke suites, and the manual steps above in a Code OSS build.

Retain source-less canvas continuity across idle session residency release and restore it when the chat is observed again, without requiring a model turn.

Co-authored-by: Copilot App <[email protected]>
Apply review feedback for close intent during restore, source-less membership publication, continuity retention after navigation, pending-close-only handoffs, and delayed close events.

Co-authored-by: Copilot App <[email protected]>
Builds on the idle-release canvas continuity in #345740 so a chat's canvases
also come back after the Agent Host process restarts (for example, after an
update), without a model turn.

- A live Copilot runtime reports its source-less canvas continuity (projections
  plus closes it still owes the runtime) whenever it publishes canvas state or
  membership; teardown and handoffs never report.
- The agent persists it as `copilot.canvasContinuity` in the chat's storage,
  keyed to the chat and its SDK backing, sequenced per chat and bound to the
  continuity generation so archive and delete cannot be overwritten.
- Observing or resuming a cold chat loads a matching record into the existing
  released continuity, so the canvases are republished on their original
  channels and reconciled with the runtime. Observing an archived chat discards
  it instead. Shutdown keeps the record.
- A reopened instance no longer carries its earlier applied close into the next
  handoff, which dropped the canvas on the next restore.

Co-authored-by: Copilot <[email protected]>
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.

Agents window: canvases don't come back after the agent host process restarts

2 participants