Skip to content

Enhancement: opening the same agent-session in a different workspace should reuse the shared AgentChat instance rather than creating a new one #303

Description

@JoshuaRowePhantom

Current behaviour

\AgentSessionWorkspaceTabViewModel\ uses the agent-session entity id as its \WorkspaceTabViewModel.Id. \MainWindowViewModel.OpenTabAsync\ deduplicates tabs by this id within a single workspace, so opening the same session a second time in the same workspace correctly focuses the existing tab.

However, each open (including opening in a second workspace window) creates a brand-new \AgentChat\ instance. Two workspace windows opening the same session therefore each have a separate, independent chat — messages in one are not visible in the other, and state is not shared.

Additionally, separate windows maintain their own per-window persistence-store caches, so they can diverge even when pointing at the same persisted \�gent-session-id.

Desired behaviour

  1. Within a single workspace: opening the same session focuses the existing tab (current behaviour — correct, keep as-is).
  2. Across separate workspaces: opening the same session in a second workspace opens a new tab in that workspace, but both tabs bind to the same running \AgentChat\ instance (shared live state).
  3. Closing one workspace's tab releases its view; the shared chat stays alive until the last view across all workspaces is closed.

Design

A process-wide \RunningAgentChatTable\ (see #304) should be used to look up or create the shared \AgentChat\ keyed by agent-session id, and return a reference-counted lease. Tab deduplication within a workspace continues to use the entity id as before. \DisposeAsync\ on the tab view model should release the lease rather than dispose the chat directly.

Files

  • \Phantom.Workspaces/ViewModels/OpenAgentSessionShortcutHandler.cs\ — \Handle\ / \CreateAgentSessionTab\
  • \Phantom.Workspaces/ViewModels/AgentSessionWorkspaceTabViewModel.cs\ — \DisposeAsync\
  • \Phantom.Workspaces/ViewModels/AgentSessionShortcutContext.cs\ — shared persistence cache

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions