Skip to content

canvas: add chat-scoped discovery and URI-addressed lifecycle - #528

Open
Joaquín Ruales (jruales) wants to merge 16 commits into
mainfrom
jruales/ahp-canvas-inventory
Open

Joaquín Ruales (jruales) wants to merge 16 commits into
mainfrom
jruales/ahp-canvas-inventory

Conversation

@jruales

@jruales Joaquín Ruales (jruales) commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

AHP already projects live Canvas instances through ChatState.canvases and experimental ahp-canvas: channels, but clients also need an authoritative way to discover the Canvas types available to one exact chat and manage a selected Canvas resource.

This PR models discovery as chat state and uses the Canvas channel URI as the resource identity:

  • ChatState.canvasRegistry is the authoritative exact-chat Canvas type registry.
  • chat/canvasRegistryChanged replaces or clears that registry when live provider registration changes.
  • Client-dispatchable chat/canvasRegistryRequested explicitly requests potentially effectful materialization for a persisted cold chat.
  • openCanvas uses a client-chosen ahp-canvas: URI and separately identifies the owning chat and declaration.
  • disposeCanvas closes that URI-addressed Canvas resource.
  • Extension metadata is normalized once per CanvasExtensionDeclaration; nested CanvasTypeDeclaration entries use title and contain only type-local metadata.
  • Extension IDs are opaque. The protocol does not expose VS Code/Copilot-specific extension-source taxonomy.
  • The registry field and actions remain Stability 1 — Experimental and are capability-gated by AgentCapabilities.canvases.

Protocol behavior

Live registry state

For a live chat, the host keeps canvasRegistry synchronized with provider registration and emits chat/canvasRegistryChanged only when the authoritative registry changes. Clients do not poll and do not treat changes to the open-instance list as registry invalidation.

The registry distinguishes three states:

  • absent: not materialized or currently unavailable;
  • { extensions: [] }: materialized, with no available Canvas types;
  • populated: declarations keyed by (extensionId, canvasId).

requiresInput remains so clients can exclude declarations whose input flow they do not support. Speculative action metadata is not part of the registry.

Cold materialization

When a persisted chat is cold, a client may dispatch chat/canvasRegistryRequested. The reducer intentionally leaves optimistic state unchanged while the host may resume the backing runtime, discover extensions, and execute extension startup code. The host then publishes the complete result through chat/canvasRegistryChanged.

Materialization must not create a backing for a brand-new chat, send a user message, or invoke a model.

URI-addressed lifecycle

openCanvas.channel is the client-chosen ahp-canvas: resource URI. Reusing that URI for the same chat and declaration focuses or refreshes the logical instance; reusing it for a different chat, extension, or Canvas type must fail with Conflict.

disposeCanvas.channel identifies the same resource for disposal. CanvasState.instanceId remains provider-facing correlation metadata; the Canvas URI is the AHP resource identity.

sequenceDiagram
    participant C as Client
    participant H as Agent Host

    C->>H: subscribe(chat)
    H-->>C: ChatState snapshot

    opt Registry absent and chat persisted
        C->>H: dispatchAction(chat, canvasRegistryRequested)
        H->>H: Resume runtime and discover providers
        H-->>C: action(chat, canvasRegistryChanged)
    end

    C->>H: openCanvas(canvas, chat, extensionId, canvasId)
    H-->>C: action(chat, canvasesChanged)
    C->>H: subscribe(canvas)
    H-->>C: CanvasState snapshot
    C->>H: disposeCanvas(canvas)
    H-->>C: action(chat, canvasesChanged)
Loading

Compatibility and generated surfaces

  • The change is additive and capability-gated; hosts that omit AgentCapabilities.canvases remain unsupported without probing.
  • The registry actions are introduced in protocol 1.1.0; this PR does not bump the protocol version.
  • Existing server-published Canvas references and channels remain the live-instance mechanism.
  • Canonical TypeScript definitions generate schemas, reference documentation, action-origin metadata, and wire types and command helpers for each language client; native reducers remain hand-written ports validated by shared fixtures.
  • Swift and Kotlin include typed openCanvas / disposeCanvas command helpers, and Swift dispatchability matches the client-dispatchable registry request.
  • Shared reducer and round-trip fixtures cover registry updates, lifecycle commands, and Canvas capability presence across clients.
  • This PR does not define host/runtime implementation, client UI, extension installation or enablement, input-bearing Canvas flows, or pre-session catalogue probing.

Validation

Check Result
npm test Passed: 623 tests; 100% reducer coverage; generated output verified
npm run docs:build Passed
TypeScript npm run typecheck && npm test && npm run build Passed: 77 tests
Rust cargo fmt --all -- --check, cargo clippy --workspace -- -D warnings, cargo test --workspace Passed, including workspace and doc tests
Go go build ./..., gofmt -l, go vet ./..., go test ./... Passed
swift build && swift test Passed: 96 tests
Kotlin ./gradlew build --stacktrace on JDK 17 Passed
.NET interop typecheck, restore, format, Release build, and tests Passed: 688 tests

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

Comment thread types/channels-canvas/commands.ts Resolved
Comment thread types/channels-canvas/commands.ts Resolved
Comment thread types/channels-canvas/commands.ts Resolved
Comment thread types/channels-canvas/state.ts Resolved
Comment thread types/channels-canvas/state.ts Resolved
@jruales Joaquín Ruales (jruales) changed the title canvas: add discovery and open commands canvas: expose registry state and URI-addressed open Oct 15, 2026
@jruales Joaquín Ruales (jruales) changed the title canvas: expose registry state and URI-addressed open canvas: add chat-scoped discovery and URI-addressed lifecycle Nov 3, 2026
@jruales
Joaquín Ruales (jruales) marked this pull request as ready for review November 3, 2026 08:49
Add capability-gated exact-chat listCanvasTypes and openCanvas commands, including owning extension metadata, and regenerate all protocol clients and schemas.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Replace snapshot-only Canvas listing with an authoritative exact-chat registry, explicit cold materialization action, and URI-addressed Canvas opening. Normalize provider metadata and update every generated client, reducer, fixture, and specification.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread types/channels-canvas/commands.ts Resolved
/** Stable identifier of the extension that declares the canvas. */
extensionId: string;
/** Provider-local canvas type identifier. */
canvasId: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canvasId was initially proposed in a PR before, but we removed it since the canvas channel: URI is already unique, so there was no need for another unique canvasId. Can we retain that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here canvasId selects the registered Canvas type to open (CanvasType.id), not the instance. It has the same meaning as the existing CanvasState.canvasId; multiple canvas instances can share it while having different channel URIs. The new, client-chosen URI alone doesn’t tell the host which type to create.

We could keep canvasId consistently and clarify the docs, or rename both fields to canvasTypeId to make that distinction explicit—though renaming CanvasState.canvasId would change an existing wire-format field.

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

Auto-replied by the GitHub Copilot app

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is canvasTypeId; not canvasId -- that should be renamed

Comment thread types/channels-canvas/state.ts Resolved
Comment thread types/channels-canvas/state.ts Resolved
Comment thread types/channels-canvas/state.ts Resolved
Comment thread types/channels-canvas/state.ts Resolved
* URI. They MUST NOT treat this provider identifier as a second resource
* identity.
*/
instanceId: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the ID/URI note -- I don't see this used/passed around anywhere else in the protocol. How does a client use it / can it be removed?

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceId predates this PR and supports sidebar-pin restoration and matching agent open requests to canvases. URI-only identity is a possibility, but replacing those uses requires a broader migration. I propose retaining it here and exploring that in a follow-up. I’ve clarified the docstring locally to distinguish correlation from protocol addressing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would favor getting rid of it. It's never used outside of this one field, there's no reason to have it in the protocol when we already have a unique identifier (the URI)

/** Human-readable canvas type title. */
title: string;
/** Description of what the canvas type does. */
description: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be StringOrMarkdown?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the current runtime and Copilot app implementations. The runtime declares this as a plain String and defines it as a short, single-sentence catalog description. The app preserves and validates it as a string, uses it as plain search/accessibility text, and renders it directly in Canvas pickers and Customize. Keeping string here matches both source and consumer behavior; StringOrMarkdown would introduce rendering and sanitization semantics that neither currently supports.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not necessarily asking what the runtime does, I'm asking what should it do. If we make this a string and only a string, changing it in the future is a breaking change.

Comment thread types/channels-canvas/state.ts Outdated
* Declaring namespaces. `extensionId` MUST be unique within this
* array. An empty array is an authoritative loaded registry with no types.
*/
extensions: CanvasExtensionDeclaration[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be among the SessionState.customizations?: Customization[] instead of on its own over here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this in the new Canvas collection rather than SessionState.customizations: it describes types currently available in one exact chat, whereas customizations describe session-scoped sources and enablement. Runtime registrations can also exist without a corresponding source customization. A provenance link could connect the two later without making customizations a second registry.

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

Auto-replied by the GitHub Copilot app

Comment thread types/channels-chat/actions.ts Outdated
* @stability 1.0
* @clientDispatchable
*/
export interface ChatCanvasRegistryRequestedAction {

@connor4312 Connor Peet (connor4312) Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative design:

  • Remove canvasRegistry and canvases from the ChatState
  • Intead advertise a canvasesUri?: URI in the ChatState that would be a new CanvasesState
  • Have that state expose the registry and canvases state. Subscribing to that would trigger enumeration of canvas registries as this action does today.

I like this because:

  • It segments off canvas capability so that hosts/clients/implementors who don't support them don't have the code or mental overhead of dealing with canvas concepts mixed into general Chat state which everyone cares about
  • It composes well as we start thinking about cross-session/app-level canvases -- the canvases URIs would just be given out additionally by the root state or whatever we want to do there, but after that point operate the exact same way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 2309426, with the VS Code consumer in microsoft/vscode#345703. ChatState.canvasesUri now points to a CanvasesState containing the registry and live references; openCanvas stays instance-addressed and names the collection as its owner.

Two deliberate differences: collection subscriptions enumerate already-live runtimes, but cold resume/extension startup still requires canvases/registryRequested, so passive membership and pin observers don't start runtimes. Also, the shipped ChatState.canvases field/action remain deprecated projections of the same membership for compatibility. Registry loading/errors and explicit retry are represented in state. Ownership remains chat-scoped in this PR.

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

Auto-replied by the GitHub Copilot app

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to remove ChatState.canvases and chat/canvasesChanged outright, or deprecate them? They predate this PR, are present in the AHP 1.0.0 release, and have a consumer in released VS Code 1.141.0, although the Canvas feature is experimental/default-off.

The pushed change moves discovery and live membership into CanvasesState, advertised through ChatState.canvasesUri. For now, I've deprecated the old field/action and kept them as a compatibility projection of the collection's authoritative membership—not a separate inventory. Are you okay with removing that projection outright instead?

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

Auto-replied by the GitHub Copilot app

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Separate passive collection observation from explicit runtime activation, preserve legacy chat membership, and carry full input schemas through generated clients.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve Canvas collection registry and membership alongside upstream snapshot decoding, action origin generation, and rejected-envelope handling.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines +136 to +137
* back to those references when this pointer is absent. Advertising the URI
* does not require materializing backing or starting extensions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* back to those references when this pointer is absent. Advertising the URI
* does not require materializing backing or starting extensions.
* back to those references when this pointer is absent.

*/
backgroundWork?: BackgroundWork[];
/**
* Advertised `ahp-canvases:` collection owned by this exact chat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Advertised `ahp-canvases:` collection owned by this exact chat.
* Advertised `ahp-canvases:` collection owned by this chat.

* @category Canvases State
* @nonexhaustive
*/
export enum CanvasRegistryStatus {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export enum CanvasRegistryStatus {
export const enum CanvasRegistryStatus {

Comment on lines +75 to +80
* Advertising and subscribing are observation only: hosts MUST NOT create
* backing, resume a cold runtime, or start extensions to serve a subscription.
* Hosts MAY enumerate or refresh an already-live runtime. Collection ownership
* is established by the host, not inferred from URI grammar. Other ownership
* scopes are not currently defined.
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is up to the implementation, doesn't matter for the protocol.

Suggested change
* Advertising and subscribing are observation only: hosts MUST NOT create
* backing, resume a cold runtime, or start extensions to serve a subscription.
* Hosts MAY enumerate or refresh an already-live runtime. Collection ownership
* is established by the host, not inferred from URI grammar. Other ownership
* scopes are not currently defined.
*

/** Stable identifier of the extension that declares the canvas. */
extensionId: string;
/** Provider-local canvas type identifier. */
canvasId: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is canvasTypeId; not canvasId -- that should be renamed

Comment on lines +56 to +57
* within this array. An empty array is an authoritative loaded registry with
* no types.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* within this array. An empty array is an authoritative loaded registry with
* no types.
* within this array.

export interface CanvasReference {
/** Canvas channel URI. Subscribe to this resource for the full state. */
/**
* Canvas channel URI. Subscribe to this resource for the full state.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should note the scheme

* URI. They MUST NOT treat this provider identifier as a second resource
* identity.
*/
instanceId: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would favor getting rid of it. It's never used outside of this one field, there's no reason to have it in the protocol when we already have a unique identifier (the URI)

Comment on lines +95 to +97
/** Owning declaration namespace. */
extensionId: string;
/** Owning extension display name, when available. */
/** Owning namespace title, when available. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does a namespace mean here? This is a new concept.

* @stability 1.0
* @clientDispatchable
*/
export interface CanvasesRegistryRequestedAction {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case I would subscribe to ahp-canvases but not want to dispatch this action to materialize?

This branch has not been deployed

No deployments
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.

2 participants