diff --git a/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx b/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx index 0de5fd272..0992c3b17 100644 --- a/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx +++ b/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx @@ -131,7 +131,14 @@ export function AgentSessionThreadPanel({ : `Last updated ${new Date(latestActivityAt).toLocaleString()}`; const { fetchOlderArchived, hasOlderArchived } = - useLoadArchivedObserverEvents(isLive, sessionChannelId ?? null); + useLoadArchivedObserverEvents( + // Archive history must load regardless of live status — an idle agent's + // channel should still show its archived observer history. Enable whenever + // there is a resolved sessionChannelId (the hook's owner_p guard handles + // the case where no save subscription exists). + Boolean(sessionChannelId), + sessionChannelId ?? null, + ); useLoadOlderOnScroll({ fetchOlder: fetchOlderArchived, diff --git a/desktop/src/features/channels/ui/useChannelAgentSessions.ts b/desktop/src/features/channels/ui/useChannelAgentSessions.ts index 2f4be2f16..8420c3732 100644 --- a/desktop/src/features/channels/ui/useChannelAgentSessions.ts +++ b/desktop/src/features/channels/ui/useChannelAgentSessions.ts @@ -220,9 +220,14 @@ export function useChannelAgentSessions({ setThreadReplyTargetId(null); setChannelManagementOpen(false); setOpenAgentSessionPubkey(pubkey); - setOpenAgentSessionChannelId(channelId ?? null); + // Fall back to activeChannelId so opening from within a channel always + // scopes the panel to that channel — even when no explicit channelId is + // supplied (e.g. activity-list click). Without this, a null channelId + // bypasses scopeByChannel and lets all channels' live frames through. + setOpenAgentSessionChannelId(channelId ?? activeChannelId ?? null); }, [ + activeChannelId, isAgentSessionOpen, openThreadHeadId, profilePanelPubkey, @@ -260,9 +265,11 @@ export function useChannelAgentSessions({ const selectAgentSession = React.useCallback( (pubkey: string, channelId?: string | null) => { setOpenAgentSessionPubkey(pubkey); - setOpenAgentSessionChannelId(channelId ?? null); + // Same fallback as openAgentSession: use activeChannelId when the caller + // omits channelId, so the panel is always scoped to the current channel. + setOpenAgentSessionChannelId(channelId ?? activeChannelId ?? null); }, - [setOpenAgentSessionChannelId, setOpenAgentSessionPubkey], + [activeChannelId, setOpenAgentSessionChannelId, setOpenAgentSessionPubkey], ); const openThreadAndCloseAgentSession = React.useCallback(