@@ -14,6 +14,7 @@ import { SWR_KEYS } from "@/lib/swr-keys";
1414import { MinimalAgent } from "@/lib/agents/types" ;
1515import useAppFocus from "./useAppFocus" ;
1616import { useAgents } from "@/lib/agents/hooks" ;
17+ import { useActiveProject } from "@/lib/projects/hooks" ;
1718import { DEFAULT_AGENT_ID } from "@/lib/constants" ;
1819
1920const PAGE_SIZE = 50 ;
@@ -175,6 +176,7 @@ export default function useChatSessions(): UseChatSessionsOutput {
175176 ) ;
176177
177178 const appFocus = useAppFocus ( ) ;
179+ const activeProject = useActiveProject ( ) ;
178180 const pendingSessions = usePendingSessions ( ) ;
179181
180182 // Flatten all pages into a single session list
@@ -241,10 +243,23 @@ export default function useChatSessions(): UseChatSessionsOutput {
241243 } , [ allFetchedSessions , pendingSessions ] ) ;
242244
243245 const currentChatSessionId = appFocus . isChat ( ) ? appFocus . getId ( ) : null ;
244- const currentChatSession =
245- chatSessions . find (
246- ( chatSession ) => chatSession . id === currentChatSessionId
247- ) ?? null ;
246+
247+ // `chatSessions` is the Recents feed, which excludes project chats on purpose
248+ // (`only_non_project_chats` defaults to true on the server). Fall back to the
249+ // owning project's session list so a project chat still resolves — otherwise
250+ // the header actions, document title, and agent lookup all see `null`.
251+ const currentChatSession = useMemo ( ( ) => {
252+ if ( ! currentChatSessionId ) return null ;
253+ return (
254+ chatSessions . find (
255+ ( chatSession ) => chatSession . id === currentChatSessionId
256+ ) ??
257+ activeProject ?. chat_sessions . find (
258+ ( chatSession ) => chatSession . id === currentChatSessionId
259+ ) ??
260+ null
261+ ) ;
262+ } , [ chatSessions , activeProject , currentChatSessionId ] ) ;
248263
249264 const agentForCurrentChatSession =
250265 useFindAgentForCurrentChatSession ( currentChatSession ) ;
0 commit comments