Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

šŸ› fix(goal): keep the supervision panel on its bound record (#23011)

Rdmclin2408c7d60438d
diff --git a/src/features/AgentGoals/GoalChat/GoalChatProvider.test.tsx b/src/features/AgentGoals/GoalChat/GoalChatProvider.test.tsx
index 46a65f62c75..e79146bcbad 100644
--- a/src/features/AgentGoals/GoalChat/GoalChatProvider.test.tsx
+++ b/src/features/AgentGoals/GoalChat/GoalChatProvider.test.tsx
@@ -21,8 +21,19 @@ vi.mock('@/hooks/useGatewayReconnect', () => ({ useGatewayReconnect: hooks.useGa
vi.mock('@/hooks/useTopicRunEvents', () => ({ useTopicRunEvents: hooks.useTopicRunEvents }));
vi.mock('@/hooks/useOperationState', () => ({ useOperationState: () => ({}) }));
+const conversation = vi.hoisted(() => ({ contexts: [] as { topicId?: string | null }[] }));
+
vi.mock('@/features/Conversation', () => ({
- ConversationProvider: ({ children }: { children: unknown }) => children,
+ ConversationProvider: ({
+ children,
+ context,
+ }: {
+ children: unknown;
+ context: { topicId?: string | null };
+ }) => {
+ conversation.contexts.push(context);
+ return children;
+ },
}));
vi.mock('@/store/agent', () => {
@@ -60,6 +71,7 @@ vi.mock('@/store/chat/selectors', () => ({
beforeEach(() => {
hooks.useGatewayReconnect.mockReset();
hooks.useTopicRunEvents.mockReset();
+ conversation.contexts = [];
chat.state = {
activeAgentId: 'agt_goal',
activeTopicId: 'tpc_goal',
@@ -101,7 +113,7 @@ describe('GoalChatProvider', () => {
chat.state.activeTopicId = 'tpc_other';
render(
- <GoalChatProvider pinned agentId="agt_goal" goalId="goal_1" initialTopicId="tpc_goal">
+ <GoalChatProvider agentId="agt_goal" goalId="goal_1" initialTopicId="tpc_goal">
<div />
</GoalChatProvider>,
);
@@ -109,4 +121,30 @@ describe('GoalChatProvider', () => {
for (const [topicId] of hooks.useGatewayReconnect.mock.calls) expect(topicId).toBeUndefined();
for (const [topicId] of hooks.useTopicRunEvents.mock.calls) expect(topicId).toBeUndefined();
});
+
+ // ROOT CAUSE (T-14085):
+ //
+ // The supervision panel read the store's `activeTopicId`, which other hosts
+ // on the page also write. On the agent-less `/goal/:goalId` route the task
+ // manager panel stays mounted while folded; when its built-in agent finished
+ // loading after the panel opened, it switched the store to a blank topic, so
+ // the panel fetched no messages and showed "Waiting for the first run" over
+ // a record that has turns — only on some loads, depending on which came last.
+ //
+ // Before: context topic = store's active topic. After: the bound record.
+ it('keeps reading its bound record when another host moves the active topic', () => {
+ chat.state.activeAgentId = 'agt_task';
+ chat.state.activeTopicId = null as unknown as string;
+
+ render(
+ <GoalChatProvider pinned agentId="agt_goal" goalId="goal_1" initialTopicId="tpc_goal">
+ <div />
+ </GoalChatProvider>,
+ );
+
+ expect(conversation.contexts.length).toBeGreaterThan(0);
+ for (const context of conversation.contexts) expect(context.topicId).toBe('tpc_goal');
+ expect(hooks.useGatewayReconnect).toHaveBeenLastCalledWith('tpc_goal', marker, 'agt_goal');
+ expect(hooks.useTopicRunEvents).toHaveBeenLastCalledWith('tpc_goal', 'agt_goal');
+ });
});
diff --git a/src/features/AgentGoals/GoalChat/GoalChatProvider.tsx b/src/features/AgentGoals/GoalChat/GoalChatProvider.tsx
index 21b750f36f3..6423c16e72a 100644
--- a/src/features/AgentGoals/GoalChat/GoalChatProvider.tsx
+++ b/src/features/AgentGoals/GoalChat/GoalChatProvider.tsx
@@ -60,13 +60,21 @@ export const GoalChatProvider = memo<GoalChatProviderProps>(
setInitialized(true);
}, [agentId, initialTopicId, setActiveAgentId]);
+ // A pinned panel reads its own record, not the store's active topic: other
+ // hosts on the page write that too. On the agent-less `/goal/:goalId` route
+ // the task manager panel stays mounted while folded, and its agent loading
+ // late switches the store to a blank topic, which left this panel on
+ // "Waiting for the first run" over a record that has turns.
+ const boundTopicId = pinned ? initialTopicId : undefined;
+ const topicId = boundTopicId ?? activeTopicId;
+
const context = useMemo<ConversationContext>(
() => ({
agentId,
- topicId: activeTopicId,
+ topicId,
viewedGoal: { goalId },
}),
- [activeTopicId, agentId, goalId],
+ [agentId, goalId, topicId],
);
const operationState = useOperationState(context);
@@ -77,13 +85,14 @@ export const GoalChatProvider = memo<GoalChatProviderProps>(
// starts a second run that discards the live one (and kills its CLI).
// Only once the store points at this panel's conversation: until the
// switch above lands, `activeTopicId` is whatever was open before, and its
- // run would be followed under this panel's agent.
- const followedTopicId =
- initialized &&
- activeChatAgentId === agentId &&
- (!initialTopicId || activeTopicId === initialTopicId)
- ? activeTopicId
- : undefined;
+ // run would be followed under this panel's agent. A pinned panel already
+ // knows its topic.
+ const followedTopicId = !initialized
+ ? undefined
+ : (boundTopicId ??
+ (activeChatAgentId === agentId && (!initialTopicId || activeTopicId === initialTopicId)
+ ? activeTopicId
+ : undefined));
const runningOperation = useChatStore((s) =>
followedTopicId
? topicSelectors.getTopicById(followedTopicId)(s)?.metadata?.runningOperation
diff --git a/src/features/AgentGoals/GoalChat/Toolbar.tsx b/src/features/AgentGoals/GoalChat/Toolbar.tsx
index 239a472dfd8..94d3f2f4e34 100644
--- a/src/features/AgentGoals/GoalChat/Toolbar.tsx
+++ b/src/features/AgentGoals/GoalChat/Toolbar.tsx
@@ -12,6 +12,7 @@ import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/slices/topic/selectors';
import TopicActions from './TopicActions';
+import { useConversationTopic } from './useConversationTopic';
interface ToolbarProps {
/** Shown while the open conversation has no titled topic. @default the side chat's title */
@@ -42,7 +43,7 @@ const Toolbar = memo<ToolbarProps>(({ fallbackTitle, onCollapse, topicLocked })
s.switchTopic,
topicSelectors.currentTopics(s),
]);
- const currentTopic = useChatStore(topicSelectors.currentActiveTopic);
+ const currentTopic = useConversationTopic();
const isLoadingTopics = topics === undefined;
const topicTitle = currentTopic?.title || fallbackTitle || t('goalChat.title');
diff --git a/src/features/AgentGoals/GoalChat/useConversationTopic.test.ts b/src/features/AgentGoals/GoalChat/useConversationTopic.test.ts
new file mode 100644
index 00000000000..2b3de7255cb
--- /dev/null
+++ b/src/features/AgentGoals/GoalChat/useConversationTopic.test.ts
@@ -0,0 +1,58 @@
+import { renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useConversationTopic } from './useConversationTopic';
+
+const conversation = vi.hoisted(() => ({ context: { topicId: 'tpc_goal' as string | null } }));
+
+const chat = vi.hoisted(() => ({
+ state: {} as {
+ activeTopicId: string | null;
+ topics: { id: string; title: string }[];
+ },
+}));
+
+vi.mock('@/features/Conversation', () => ({
+ conversationSelectors: { topicId: (s: typeof conversation) => s.context.topicId },
+ useConversationStore: (selector: (s: typeof conversation) => unknown) => selector(conversation),
+}));
+
+vi.mock('@/store/chat', () => ({
+ useChatStore: (selector: (s: typeof chat.state) => unknown) => selector(chat.state),
+}));
+
+vi.mock('@/store/chat/slices/topic/selectors', () => ({
+ topicSelectors: {
+ getTopicById: (id: string) => (s: typeof chat.state) => s.topics.find((t) => t.id === id),
+ },
+}));
+
+beforeEach(() => {
+ conversation.context = { topicId: 'tpc_goal' };
+ chat.state = {
+ activeTopicId: 'tpc_goal',
+ topics: [
+ { id: 'tpc_goal', title: 'Supervision record' },
+ { id: 'tpc_task', title: 'Task manager chat' },
+ ],
+ };
+});
+
+describe('useConversationTopic', () => {
+ // ROOT CAUSE (T-14085): the goal panel header read the store's active topic.
+ // On the agent-less goal route the task manager panel can move that topic
+ // after the supervision record opened, so the header lost the record's title
+ // and topic menu. The header now follows its own conversation's topic.
+ it('keeps the conversation’s own topic when the store’s active topic moved', () => {
+ chat.state.activeTopicId = null;
+ expect(renderHook(() => useConversationTopic()).result.current?.id).toBe('tpc_goal');
+
+ chat.state.activeTopicId = 'tpc_task';
+ expect(renderHook(() => useConversationTopic()).result.current?.id).toBe('tpc_goal');
+ });
+
+ it('has no topic while the conversation has none', () => {
+ conversation.context.topicId = null;
+ expect(renderHook(() => useConversationTopic()).result.current).toBeUndefined();
+ });
+});
diff --git a/src/features/AgentGoals/GoalChat/useConversationTopic.ts b/src/features/AgentGoals/GoalChat/useConversationTopic.ts
new file mode 100644
index 00000000000..7fd64640fb3
--- /dev/null
+++ b/src/features/AgentGoals/GoalChat/useConversationTopic.ts
@@ -0,0 +1,14 @@
+import { conversationSelectors, useConversationStore } from '@/features/Conversation';
+import { useChatStore } from '@/store/chat';
+import { topicSelectors } from '@/store/chat/slices/topic/selectors';
+
+/**
+ * The topic this panel's conversation is on — read from its own context, not
+ * the store's active topic. Other hosts on the goal page (the task manager
+ * panel) move that one, and a pinned supervision record must keep its title
+ * and topic menu when they do.
+ */
+export const useConversationTopic = () => {
+ const topicId = useConversationStore(conversationSelectors.topicId);
+ return useChatStore((s) => (topicId ? topicSelectors.getTopicById(topicId)(s) : undefined));
+};