Skip to content

chat (sessions): fix forking AHP chats so the new session opens with a "Forked: " title#319064

Merged
connor4312 merged 1 commit into
mainfrom
connor4312/317839
May 29, 2026
Merged

chat (sessions): fix forking AHP chats so the new session opens with a "Forked: " title#319064
connor4312 merged 1 commit into
mainfrom
connor4312/317839

Conversation

@connor4312

Copy link
Copy Markdown
Member

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: " 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)

…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)
Copilot AI review requested due to automatic review settings May 29, 2026 21:45
@connor4312 connor4312 enabled auto-merge (squash) May 29, 2026 21:45

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.

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

@connor4312 connor4312 merged commit 0d42e11 into main May 29, 2026
26 checks passed
@connor4312 connor4312 deleted the connor4312/317839 branch May 29, 2026 22:43
@vs-code-engineering vs-code-engineering Bot added this to the 1.123.0 milestone May 29, 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.

creating a fork of an AHP chat will create duplicate session, and none get the forked: prefix

3 participants