Skip to content

Canvases: restore canvases after idle session release - #345740

Merged
Joaquín Ruales (jruales) merged 5 commits into
mainfrom
jruales-canvas-idle-restoration
Nov 5, 2026
Merged

Joaquín Ruales (jruales) merged 5 commits into
mainfrom
jruales-canvas-idle-restoration

Conversation

@jruales

@jruales Joaquín Ruales (jruales) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes microsoft/vscode-internalbacklog#10570

Summary

When Agent Host residency released an inactive Copilot chat, session.detach intentionally tore down the runtime's canvas and extension services, and VS Code published empty canvas membership. Returning to the chat restored its transcript but not its canvases; sending a new message happened to resume the runtime and made canvases return on new channels.

This change keeps a bounded, source-less canvas handoff across an idle release for the Agent Host process lifetime. When a client observes the chat and contributes to it again, the Copilot provider resumes the runtime without a model turn, from that client's current customizations. The runtime rehydrates its own durable canvas instances and input, and VS Code republishes their fresh sources on the original canvas channels. VS Code does not replay the input or issue a second canvas.open.

Restoration waits for the client's contribution instead of retaining plugin roots or a custom-agent definition. A plugin disabled or removed while the chat was released is therefore not relaunched, standalone customization directories never reach SDK plugin directories, and repeated release/restore cycles behave like the first.

It also:

  • latches residency release vetoes and passes providers the release reason, so continuity is kept only across idle releases;
  • removes a closed released canvas from membership immediately and applies the close when the runtime next resumes; a failing provider close is retried after the handoff is adopted instead of failing the resume;
  • lets a fixed-ID reopen supersede an earlier close, and keeps stale provider URLs, source-less republishing, and delayed close events from affecting other or reopened canvases;
  • bounds retained continuity to 32 chats without evicting the continuity it just retained;
  • invalidates continuity on archive (including unloaded sessions, saved continuations, archive changes imported from older builds, and cross-provider peer chats), delete, backing replacement, owner change, and terminal restore failures.

Process-restart restoration remains separate in #345872. The Agent Host sessions specification documents idle-release continuity separately from configuration refreshes and ordinary cold starts.

Commits

The history is organized for review, and each commit builds and passes the affected suites on its own:

  1. agentHost: tell providers why and whether a chat release may continue: residency release veto latch and release reason.
  2. agentHost: carry deferred canvas closes across Copilot runtime handoffs: session-level handoff mechanics for deferred closes, discard, and republishing.
  3. agentHost: restore Copilot canvases after an idle residency release: provider continuity, client-driven restore, the host canvas watch, and the specification.
  4. agentHost: clear canvas continuity when chats or sessions are archived: archive invalidation.

Validation

Command Result
fnm exec --using=24.22.1 pnpm run typecheck-client Passed at each of the four commits
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/agentSessionResidency.test.ts --run src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.ts --run src/vs/platform/agentHost/test/node/chatContributions.test.ts Passed at each commit; 4,352 passing, 17 pending at the tip
fnm exec --using=24.22.1 pnpm run eslint <changed TypeScript files> Passed
git diff --check Passed

An earlier revision of this branch was verified live in an isolated authenticated Agents window with VSCODE_AGENT_HOST_SESSION_RESIDENCY_LIMIT=1 and a minimal canvas-only SDK plugin. On main, returning to an idly evicted chat restored its transcript without its canvas pill or tab. On the branch, returning without sending a message restored the existing pill, tab, and content on a fresh source. Grove's agent was discovered, but its extension encountered an unrelated extension-permission-access handshake failure, so the minimal plugin was used to isolate the lifecycle under test.

Not run: full integration or smoke suites, pnpm run valid-layers-check for this revision, and a live re-verification of this revision, which now starts restoration once the observing client contributes (including two consecutive release/restore cycles and a plugin disabled while the chat is released).

🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales) and Ulugbek Abdullaev (@ulugbekna).

Copilot AI balanced review requested due to automatic review settings November 3, 2026 08:07

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

Unresolved canvas lifecycle issues can lose continuity or pending close intent, leave closed canvases visible, remove reopened canvases, and delay dismissal until runtime restoration completes.

5 open issues
What changed in this PR

This PR restores Agent Host canvas continuity after idle Copilot chat release, allowing users to recover canvases by reopening a chat without sending another message.

Changes:

  • Retains source-less canvas handoffs and restores fresh sources on existing channels when a chat is observed.
  • Adds release vetoes, deferred closes, and continuity invalidation for lifecycle changes.
  • Adds focused regression tests and documents idle-release behavior separately from configuration refreshes and process restarts.
File Description
src/​vs/​sessions/​contrib/​providers/​agentHost/​AGENT_HOST_SESSIONS_PROVIDER.md Documents canvas continuity and close semantics.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests handoff publication, invalidation, and deferred closes.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Tests observation restore, scoped credentials, cancellation, and retention.
src/​vs/​platform/​agentHost/​test/​node/​chatContributions.test.ts Tests continuity invalidation when archiving chats.
src/​vs/​platform/​agentHost/​test/​node/​agentSessionResidency.test.ts Tests latched release vetoes.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests hydrated canvas watches and execution context.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Reconciles handoffs, republishes state, and applies deferred closes.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Manages retained continuity and observation-triggered restoration.
src/​vs/​platform/​agentHost/​node/​chatContributions/​sessionFlags/​sessionFlagsContribution.ts Invalidates continuity on session archive.
src/​vs/​platform/​agentHost/​node/​chatContributions/​chatArchive/​chatArchiveContribution.ts Invalidates continuity on chat archive.
src/​vs/​platform/​agentHost/​node/​agentSessionResidency.ts Latches vetoes during asynchronous release.
src/​vs/​platform/​agentHost/​node/​agentService.ts Connects canvas watches, credentials, and release reasons.
src/​vs/​platform/​agentHost/​common/​agent.ts Defines provider contracts for release options and canvas continuity.

Review effort: Balanced

@jruales Joaquín Ruales (jruales) changed the title Agent Host: restore canvases after idle session release Canvases + Agent Host: restore canvases after idle session release Nov 3, 2026
@jruales Joaquín Ruales (jruales) changed the title Canvases + Agent Host: restore canvases after idle session release Canvases / Agent Host: restore canvases after idle session release Nov 3, 2026
@jruales Joaquín Ruales (jruales) changed the title Canvases / Agent Host: restore canvases after idle session release Canvases: restore canvases after idle session release Nov 3, 2026
@jruales
Joaquín Ruales (jruales) force-pushed the jruales-canvas-idle-restoration branch from a3ed0f5 to 740e41a Compare November 3, 2026 08:58
@jruales
Joaquín Ruales (jruales) force-pushed the jruales-canvas-idle-restoration branch from 740e41a to bb08f54 Compare November 3, 2026 18:08
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Base: 52b3cc7c Current: 19d6b985

No screenshot changes.

Ulugbek Abdullaev (ulugbekna) added a commit that referenced this pull request Nov 3, 2026
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]>
@jruales
Joaquín Ruales (jruales) force-pushed the jruales-canvas-idle-restoration branch from bb08f54 to b7071d6 Compare November 4, 2026 06:54
Residency now latches a release veto: once the session stops being
eligible during a release, it stays vetoed for the rest of that release
instead of becoming eligible again before eviction. Providers receive the
live `canContinue` check and a lazily computed release reason (`idle`,
`archived`, or `other`), so they can stop releasing chats once the session
becomes ineligible and later keep state only across idle releases.

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

A replacement can also discard a handoff that is no longer current, and
hosts can republish its projected canvas states before membership once the
chat is registered.

Co-authored-by: ulugbekna <[email protected]>
Co-authored-by: Copilot <[email protected]>
An idle residency release used to tear down a chat's canvas providers and
publish empty canvas membership; returning to the chat restored only its
transcript until a new turn resumed the runtime.

The Copilot provider now keeps a bounded, source-less canvas handoff for
each idly released chat for the Agent Host process lifetime. Once a client
observes the chat and contributes to it again, the provider resumes the
runtime without a model turn, from that client's current customizations:
a plugin disabled or removed while the chat was released is not
relaunched. The runtime rehydrates its durable canvas instances and input,
and VS Code republishes their fresh sources on the original canvas
channels instead of reopening them.

Closing a released canvas removes it from membership immediately and is
applied when the runtime next resumes. Continuity is invalidated on chat
deletion, backing replacement, owner change, a terminal restore failure,
and eviction from the bounded cache, which never evicts the continuity it
just retained.

Co-authored-by: ulugbekna <[email protected]>
Co-authored-by: Copilot <[email protected]>
Archiving a chat or session clears the owning provider's retained idle
canvas continuity, so an archived chat never restores its canvases. This
covers chat and session archive actions, saved continuations, sessions and
peer chats that are not loaded, and archive changes imported from older
builds, and clears cross-provider peer chats through their own provider.

Co-authored-by: Copilot <[email protected]>
@jruales
Joaquín Ruales (jruales) force-pushed the jruales-canvas-idle-restoration branch from e730e14 to 10d912e Compare November 5, 2026 06:36
@jruales
Joaquín Ruales (jruales) marked this pull request as draft November 5, 2026 06:56
@jruales
Joaquín Ruales (jruales) marked this pull request as ready for review November 5, 2026 08:05
@jruales
Joaquín Ruales (jruales) merged commit ccf7045 into main Nov 5, 2026
59 checks passed
@jruales
Joaquín Ruales (jruales) deleted the jruales-canvas-idle-restoration branch November 5, 2026 08:14
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 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