chat (sessions): fix forking AHP chats so the new session opens with a "Forked: " title#319064
Merged
Conversation
…a "Forked: " title Fixes two user-facing bugs when forking an agent-host (AHP) chat from the Agents window, and one underlying turn-id mismatch that made forks target the wrong SDK event boundary on restored sessions: - agentService: stamp "Forked: <source title>" onto the forked session's SessionSummary at create time so the sidebar (which renders from SessionSummary.title via sessionAdded / sessionSummaryChanged) shows the prefix instead of the auto-generated summary inherited from the source. Idempotent so re-forking an already-forked session does not double-prefix. - agentHostSessionHandler: read the forked title back from the freshly hydrated session state for the returned IChatSessionItem and drop the client-side SessionTitleChanged dispatch. - chatForkActions: route the contributed-session fork path through ForkConversationAction._openForkedSession so the Agents-window override applies; inlines the helper to avoid a callback hop. - localChatSessions.contribution: in the Agents-window override, wait for the forked resource to appear and then open it via sessionsManagementService.openSession for every session type (not just the local VS Code chat type) -- the previous fallback called chatWidgetService.openSession, which is a no-op in the Agents window because there is no ChatViewPane. - mapSessionEvents: when restoring a session from disk, seed the protocol turn id from the SDK envelope id (the same value setTurnEventId persists to turns.event_id). This makes the restored state.turns[].id round-trip back to the SDK boundary id that the sessions.fork / history.truncate RPCs operate on. - sessionDatabase: getNextTurnEventId now resolves the source row by either turns.id (live request_xxx) OR turns.event_id (SDK envelope id), so fork works for both freshly-dispatched and restored turn ids. Fixes #317839 (Commit message generated by Copilot)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes AHP chat forking in the Agents window so forked sessions open correctly, carry a visible "Forked: " title, and use restored turn IDs that align with SDK event boundaries.
Changes:
- Moves forked-session title stamping into Agent Host session creation and reads it back when returning forked chat items.
- Routes contributed chat forks through the overridable open path so the Agents window can open forked sessions via
ISessionsManagementService. - Aligns restored turn IDs with SDK envelope event IDs and adds database/test coverage for next-turn event lookup by either turn ID or event ID.
Show a summary per file
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts |
Uses hydrated forked session summary title for the returned forked chat item label. |
src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts |
Routes contributed-session forks through _openForkedSession so subclass overrides apply. |
src/vs/sessions/contrib/providers/localChatSessions/browser/localChatSessions.contribution.ts |
Opens forked sessions in the Agents window through session management for local and AHP sessions. |
src/vs/platform/agentHost/test/node/sessionDatabase.test.ts |
Adds tests for resolving next turn event IDs by both stored turn IDs and SDK event IDs. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Updates and adds replay tests for SDK envelope IDs as restored turn IDs. |
src/vs/platform/agentHost/node/sessionDatabase.ts |
Allows getNextTurnEventId to resolve source turns by turns.id or turns.event_id. |
src/vs/platform/agentHost/node/copilot/mapSessionEvents.ts |
Seeds restored turn IDs from SDK envelope event IDs when available. |
src/vs/platform/agentHost/node/agentService.ts |
Prefixes forked AHP session summaries with "Forked: " at creation time, idempotently. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 0
pwang347
approved these changes
May 29, 2026
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 two user-facing bugs when forking an agent-host (AHP) chat from the Agents
window, and one underlying turn-id mismatch that made forks target the wrong
SDK event boundary on restored sessions:
SessionSummary at create time so the sidebar (which renders from
SessionSummary.title via sessionAdded / sessionSummaryChanged) shows the
prefix instead of the auto-generated summary inherited from the source.
Idempotent so re-forking an already-forked session does not double-prefix.
hydrated session state for the returned IChatSessionItem and drop the
client-side SessionTitleChanged dispatch.
ForkConversationAction._openForkedSession so the Agents-window override
applies; inlines the helper to avoid a callback hop.
the forked resource to appear and then open it via
sessionsManagementService.openSession for every session type (not just
the local VS Code chat type) -- the previous fallback called
chatWidgetService.openSession, which is a no-op in the Agents window
because there is no ChatViewPane.
protocol turn id from the SDK envelope id (the same value
setTurnEventId persists to turns.event_id). This makes the restored
state.turns[].id round-trip back to the SDK boundary id that the
sessions.fork / history.truncate RPCs operate on.
either turns.id (live request_xxx) OR turns.event_id (SDK envelope id),
so fork works for both freshly-dispatched and restored turn ids.
Fixes #317839
(Commit message generated by Copilot)