Skip to content

Commit 20366fb

Browse files
t3dotggclaude
andcommitted
perf(web): hidden terminal drawers no longer keep full thread history in memory
Each thread with an open terminal keeps a drawer mounted while hidden (up to 10 threads). The drawer used useThread, which holds a live thread detail subscription, so every hidden thread kept its full message and activity history in memory and kept growing while its agent ran. The drawer only reads environmentId, projectId and worktreePath, which are all on the thread shell. It now uses useThreadShell, so hidden threads drop their detail after the normal idle TTL. Draft threads still fall back to the draft record. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 2598ce7 commit 20366fb

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,11 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
917917
const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
918918
const closeTerminalMutation = useAtomCommand(terminalEnvironment.close, "terminal close");
919919
const draftThread = useComposerDraftStore((store) => store.getDraftThreadByRef(threadRef));
920-
const serverThread = useThread(threadRef, { waitForShell: draftThread !== null });
921-
const projectRef = serverThread
922-
? scopeProjectRef(serverThread.environmentId, serverThread.projectId)
920+
// Shell only: hidden drawers stay mounted (see MAX_HIDDEN_MOUNTED_TERMINAL_THREADS),
921+
// and a detail subscription would keep each thread's full, growing history in memory.
922+
const serverThreadShell = useThreadShell(threadRef);
923+
const projectRef = serverThreadShell
924+
? scopeProjectRef(serverThreadShell.environmentId, serverThreadShell.projectId)
923925
: draftThread
924926
? scopeProjectRef(draftThread.environmentId, draftThread.projectId)
925927
: null;
@@ -1030,7 +1032,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
10301032
reconcileTerminalIds(threadRef, serverOrderedTerminalIds);
10311033
}, [reconcileTerminalIds, serverOrderedTerminalIds, terminalUiState.terminalIds, threadRef]);
10321034
const [localFocusRequestId, setLocalFocusRequestId] = useState(0);
1033-
const worktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
1035+
const worktreePath = serverThreadShell?.worktreePath ?? draftThread?.worktreePath ?? null;
10341036
const effectiveWorktreePath = useMemo(() => {
10351037
if (launchContext !== null) {
10361038
return launchContext.worktreePath;

0 commit comments

Comments
 (0)