Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/web-ui/src/flow_chat/services/FlowChatManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ describe('FlowChatManager initialization', () => {
projectWorkspaceId: workspaceFixture('/project', 'ssh-user@server', 'server').id,
workspaceHostname: 'server',
});
// Legacy record: it predates execution-workspace stamping, so it has no
// session workspace ID and is attributed through its project scope only.
session.workspaceId = undefined;
delete (session as { config?: Record<string, unknown> }).config.workspaceId;
storeMocks.store = {
registerPersistUnreadCompletionCallback: vi.fn(),
getSurfaceGeneration: vi.fn(() => 0),
Expand Down
16 changes: 16 additions & 0 deletions src/web-ui/src/flow_chat/utils/sessionOrdering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ describe('sessionOrdering', () => {
expect(sessionBelongsToWorkspaceNavRow({ workspaceId: 'host-b-project' }, 'host-a-project')).toBe(false);
});

it('does not show a worktree session under its main project group', () => {
const worktreeSession = {
workspaceId: 'worktree-cli',
projectWorkspaceId: 'main-project',
};
expect(sessionBelongsToWorkspaceNavRow(worktreeSession, 'worktree-cli')).toBe(true);
expect(sessionBelongsToWorkspaceNavRow(worktreeSession, 'main-project')).toBe(false);
expect(sessionBelongsToWorkspaceNavRow(worktreeSession, 'sibling-worktree')).toBe(false);
});

it('still attributes a legacy record that only carries the project ID', () => {
const legacySession = { projectWorkspaceId: 'main-project' };
expect(sessionBelongsToWorkspaceNavRow(legacySession, 'main-project')).toBe(true);
expect(sessionBelongsToWorkspaceNavRow(legacySession, 'other-project')).toBe(false);
});

it('does not guess membership from a missing or stale ID', () => {
expect(sessionBelongsToWorkspaceNavRow({}, 'known')).toBe(false);
expect(sessionBelongsToWorkspaceNavRow({ workspaceId: 'stale' }, 'known')).toBe(false);
Expand Down
11 changes: 9 additions & 2 deletions src/web-ui/src/flow_chat/utils/sessionOrdering.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import type { Session } from '../types/flow-chat';
import type { SessionMetadata } from '@/shared/types/session-history';
/** Session list membership is the owning host's workspace ID, never a path. */
/**
* Session list membership is the owning execution workspace ID (`workspaceId`),
* never a path. `projectWorkspaceId` is only the persistence owner (the main
* project for linked worktrees) and a legacy fallback for records created
* before execution-workspace stamping; it must never widen membership to
* sibling worktrees of the same project.
*/
export function sessionBelongsToWorkspaceNavRow(
session: Pick<Session, 'workspaceId' | 'projectWorkspaceId'>,
workspaceId?: string,
): boolean {
return Boolean(workspaceId && (session.workspaceId === workspaceId || session.projectWorkspaceId === workspaceId));
if (!workspaceId) return false;
return (session.workspaceId ?? session.projectWorkspaceId) === workspaceId;
}

export function getSessionSortTimestamp(session: Pick<Session, 'createdAt' | 'lastFinishedAt'>): number {
Expand Down
Loading