Skip to content

sessions: let remote message recipients reply to the exact sender - #350508

Draft
Dmitriy Vasyura (dmitrivMS) wants to merge 6 commits into
mainfrom
agents/vscode-issue-349566-investigation
Draft

Dmitriy Vasyura (dmitrivMS) wants to merge 6 commits into
mainfrom
agents/vscode-issue-349566-investigation

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #349566

When a chat receives a message through send_remote_message, it had no way to reply to the exact chat that sent it. get_current_session and get_session_context did not show a sender, and session: "origin" only addresses the chat that created the session. Messages already carry the sender in their delegation metadata (vscode.chat.delegation), so this change exposes it without changing the host protocol.

Changes

  • send_remote_message accepts session: "sender". It replies to the chat whose message started the calling chat's current turn. The address is read from that turn's message, so a later message from another chat cannot redirect the reply. A sender on the same host is mapped to its host-qualified session. If the current turn was not started by another chat, the call fails with an error.
  • get_session_context reports from: { chat, replyWith } for each agent-sent turn. chat is an exact reference to the sending chat, including nested chats. replyWith names the tool that accepts it: send_message for a sender on the same host, send_remote_message otherwise. Because the sender is reported per turn, a later turn can still reply to an earlier sender, as in the A → B → C → B → A chain.
  • readAgentMessageSender only reads agent- or tool-authored messages, and reuses the address validation that origin already uses. It does not use prompt text or other _meta fields.
  • The sender reference is only an address. Replies still go through the existing resolution, approval and workspace-trust checks, and origin behaves as before.
  • Updated the model-facing tool descriptions and the Remote delegation section of src/vs/sessions/SESSIONS.md.

send_remote_message accepts session "sender", resolved from the delegation metadata of the message that started the calling chat's current turn. get_session_context reports each agent-sent turn's sender as `from` with the tool that replies to it. Both reuse the existing delegation metadata and origin validation; approval, trust and origin semantics are unchanged.

Fixes #349566

Co-authored-by: Copilot <[email protected]>
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added agents-window agent-host Issues for the agent-host implementation (not the protocol) remote-session-tools Issues related to Agents Window tools for managing sessions on remote Agent Hosts labels Nov 26, 2026
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:45
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as draft November 26, 2026 07:47
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added this to the 1.149.0 milestone Nov 26, 2026

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

Active sender-identity and chat-resolution defects can misroute replies when short IDs collide and reject valid sender URIs or recorded default chats.

3 open issues
What changed in this PR

Extends Agent Host messaging in the Agents Window so recipients can reply to the exact sending chat, rather than only the session’s creator, without changing the host protocol.

Changes:

  • Adds session: "sender" resolution using the message that started the current turn.
  • Exposes per-turn from.chat and replyWith fields through get_session_context.
  • Adds reply-chain and sender-validation tests, and updates tool guidance and documentation.
File Description
src/​vs/​sessions/​SESSIONS.md Documents turn-bound sender replies and existing permission checks.
src/​vs/​sessions/​contrib/​remoteSessions/​test/​browser/​remoteSessionMessageRouter.test.ts Tests nested reply chains, missing senders, and same-host routing.
src/​vs/​sessions/​contrib/​remoteSessions/​browser/​sendRemoteMessageTool.ts Documents the sender alias and earlier-turn reply references.
src/​vs/​sessions/​contrib/​remoteSessions/​browser/​remoteSessionMessageRouter.ts Resolves the current turn’s sender for reply routing.
src/​vs/​platform/​agentHost/​test/​node/​sessionServerTools.test.ts Tests per-turn sender references and reply-tool selection.
src/​vs/​platform/​agentHost/​node/​shared/​sessionServerTools.ts Adds sender details to serialized session context.
src/​vs/​platform/​agentHost/​common/​meta/​vscode/​agentRemoteSessionMeta.ts Reads sender delegation metadata and constructs reply references.
src/​vs/​platform/​agentHost/​common/​meta/​agentRemoteSessionMeta.ts Exports the sender type and helpers.

Review effort: Balanced

Sender references now carry the complete recorded chat resource in an open link, so replies reach the recorded chat even when short chat ids collide and session URIs have an authority, query or fragment. Host-qualified senders are recognized by scheme alone. send_message accepts an exact match to the recorded default chat before searching a possibly stale listing.

Co-authored-by: Copilot <[email protected]>

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

Reply routing still fails for cloud-task sender aliases, recorded default chats with stale catalog entries, and nested-chat calls rendered in a parent, requiring targeted fixes and round-trip tests.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Recognize cloud-task senders as window-qualified addresses

src/​vs/​platform/​agentHost/​common/​meta/​vscode/​agentRemoteSessionMeta.ts:80

Messages from connected Cloud tasks record a cloud-sandbox-task:/… sender, but this classifies that frontend alias as same-host. As a result, get_session_context recommends send_message with an unresolvable native session, and session: "sender" looks up the alias on the recipient's host and fails. Recognize CLOUD_SANDBOX_TASK_SCHEME as a window-qualified sender address without relaxing creator-origin validation, and add a cloud-task reply round-trip test.

Medium severity Use the originating chat for nested remote replies

src/​vs/​sessions/​contrib/​remoteSessions/​browser/​remoteSessionMessageRouter.ts:245

When a nested chat's tool call is rendered in its parent, SendRemoteMessageTool passes the rendering chat to the router, so this reads the parent's turn. session: "sender" then fails for a user-started parent turn or replies to the parent's sender instead of the nested chat's sender. Use the dispatcher's originatingChatResource for source selection in both preparation and invocation, retain the rendering context for approval, and cover a parent-rendered child call.

3 resolved since last review

Review effort: Balanced

getSessionChatResource now accepts an exact match to the recorded default chat, so remote resolution and admission reach a sender whose default chat was recreated while its catalog entry is stale. A missing peer chat still fails without falling back. Update the Copilot prompt snapshots for the get_session_context description.

Co-authored-by: Copilot <[email protected]>

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

Registered Cloud-task senders are misclassified as same-host, breaking session: "sender" resolution and causing get_session_context to recommend the wrong reply tool.

1 open issue
1 resolved since last review

Review effort: Balanced

A Cloud task records its window alias as the sending session, so it is now a window-qualified sender that send_remote_message resolves, rather than a same-host session. The creator-origin validator is unchanged. send_remote_message now takes its calling chat from the dispatcher's originating chat, so a nested chat's call rendered in its parent records and replies to the nested chat's sender.

Co-authored-by: Copilot <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: c17d657e Current: 07cf9750

Changed (1)

chat/agent-lifecycle/chatAgentLifecycle/CompletedThinkingAfterSubagents/Light
Before After
before after

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

agent-host Issues for the agent-host implementation (not the protocol) agents-window remote-session-tools Issues related to Agents Window tools for managing sessions on remote Agent Hosts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent Host: let a send_remote_message recipient reply to the exact sending chat

2 participants