Skip to content

Commit 4177f00

Browse files
committed
fix: use scoped ID for sidebarThread map to avoid cross-environment collisions
The sidebarThreadById map was keyed by raw thread.id, which could collide when threads from different environments share the same ThreadId. Renamed to sidebarThreadByScopedId and keyed by the environment-scoped ID (via getThreadScopedId) for consistency with other scoped maps in the sidebar. Updated handleMultiSelectContextMenu to search by raw ID through the map values since the selection store still uses raw ThreadIds.
1 parent bd017a0 commit 4177f00

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import { isElectron } from "../env";
5858
import { APP_STAGE_LABEL, APP_VERSION } from "../branding";
5959
import { isTerminalFocused } from "../lib/terminalFocus";
6060
import { isLinuxPlatform, isMacPlatform, newCommandId, newProjectId } from "../lib/utils";
61-
import { getProjectScopedId, useStore } from "../store";
61+
import { getProjectScopedId, getThreadScopedId, useStore } from "../store";
6262
import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";
6363
import { useUiStateStore } from "../uiStateStore";
6464
import {
@@ -785,8 +785,14 @@ export default function Sidebar() {
785785
.filter((thread): thread is NonNullable<typeof thread> => thread !== undefined),
786786
[sidebarThreadsByScopedId, threadScopedIdsByProjectScopedId],
787787
);
788-
const sidebarThreadById = useMemo(
789-
() => new Map(sidebarThreads.map((thread) => [thread.id, thread] as const)),
788+
const sidebarThreadByScopedId = useMemo(
789+
() =>
790+
new Map(
791+
sidebarThreads.map((thread) => [
792+
getThreadScopedId({ environmentId: thread.environmentId, id: thread.id }),
793+
thread,
794+
]),
795+
),
790796
[sidebarThreads],
791797
);
792798
const routeTerminalOpen = routeThreadId
@@ -1138,7 +1144,13 @@ export default function Sidebar() {
11381144

11391145
if (clicked === "mark-unread") {
11401146
for (const id of ids) {
1141-
const thread = sidebarThreadById.get(id);
1147+
let thread: SidebarThreadSummary | undefined;
1148+
for (const t of sidebarThreadByScopedId.values()) {
1149+
if (t.id === id) {
1150+
thread = t;
1151+
break;
1152+
}
1153+
}
11421154
markThreadUnread(id, thread?.latestTurn?.completedAt);
11431155
}
11441156
clearSelection();
@@ -1169,7 +1181,7 @@ export default function Sidebar() {
11691181
deleteThread,
11701182
markThreadUnread,
11711183
removeFromSelection,
1172-
sidebarThreadById,
1184+
sidebarThreadByScopedId,
11731185
selectedThreadIds,
11741186
],
11751187
);

0 commit comments

Comments
 (0)