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: reset client-mode topic status out of running when viewing (#17372)

Arvin Xu1afd7d091a05
diff --git a/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
index 3d4ba5e4d58..c6a4de32482 100644
--- a/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
+++ b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
@@ -63,6 +63,7 @@ const makeStore = (afterCompletionCallbacks?: Array<() => void>) => {
summaryTopicTitle: vi.fn(),
// topicDataMap / messagesMap reads default to empty (no topic, no messages).
topicDataMap: {},
+ updateTopicStatus: vi.fn(async () => {}),
};
return { get: (() => store) as unknown as () => ChatStore, store };
};
@@ -166,6 +167,89 @@ describe('buildRunLifecycle.completeRun β€” transport-driven disposition', () =>
});
});
+// The client transport persists `status: 'running'` at run start; without a
+// terminal reset for the topic the user is viewing, both the sidebar spinner and
+// the home "running" card would stay stuck after the reply finished (the
+// `markTopicUnread` reset early-returns on the active topic). Mirrors gateway's
+// onSessionComplete `viewing || !succeeded β†’ 'active'` rule.
+describe('buildRunLifecycle.completeRun β€” client resets a viewed topic out of `running`', () => {
+ it('client success while VIEWING the topic force-resets its status to `active`', async () => {
+ const { get, store } = makeStore(); // activeTopicId === 't1' (viewing)
+ await lifecycle('client', get).completeRun(completeEvent('client', { runtimeStatus: 'done' }));
+
+ expect(store.updateTopicStatus).toHaveBeenCalledWith(
+ expect.objectContaining({ agentId: 'a1', status: 'active', topicId: 't1' }),
+ );
+ });
+
+ it('client success on a VIEWED group topic routes the reset to the group bucket (scope: group)', async () => {
+ // A group run's start-write passes scope: 'group'; the reset must too, or the
+ // optimistic patch derives `group_agent` and misses the visible group row.
+ const { get, store } = makeStore();
+ const groupContext = {
+ agentId: 'a1',
+ groupId: 'g1',
+ scope: 'group',
+ topicId: 't1',
+ } as ConversationContext;
+ await buildRunLifecycle(get, {
+ context: groupContext,
+ parentMessageId: 'u1',
+ parentMessageType: 'user',
+ runId: OP,
+ runScope: 'top_level',
+ runtimeType: 'client',
+ }).completeRun({
+ context: groupContext,
+ operationId: OP,
+ runId: OP,
+ runScope: 'top_level',
+ runtimeStatus: 'done',
+ runtimeType: 'client',
+ });
+
+ expect(store.updateTopicStatus).toHaveBeenCalledWith(
+ expect.objectContaining({ scope: 'group', status: 'active', topicId: 't1' }),
+ );
+ });
+
+ it('client success while NOT viewing leaves the reset to markTopicUnread (no `active` write)', async () => {
+ const { get, store } = makeStore();
+ store.activeTopicId = 'other-topic';
+ await lifecycle('client', get).completeRun(completeEvent('client', { runtimeStatus: 'done' }));
+
+ expect(store.markTopicUnread).toHaveBeenCalled();
+ expect(store.updateTopicStatus).not.toHaveBeenCalled();
+ });
+
+ it('client failure resets the topic to `active` even when not viewing (error is never left `running`)', async () => {
+ const { get, store } = makeStore();
+ store.activeTopicId = 'other-topic';
+ await lifecycle('client', get).completeRun(completeEvent('client', { runtimeStatus: 'error' }));
+
+ expect(store.failOperation).toHaveBeenCalled();
+ expect(store.updateTopicStatus).toHaveBeenCalledWith(
+ expect.objectContaining({ status: 'active', topicId: 't1' }),
+ );
+ });
+
+ it('gateway success while viewing does NOT reset via the shared lifecycle (gateway owns its own reset)', async () => {
+ const { get, store } = makeStore();
+ await lifecycle('gateway', get).completeRun(completeEvent('gateway', { status: 'completed' }));
+
+ expect(store.updateTopicStatus).not.toHaveBeenCalled();
+ });
+
+ it('a client sub_agent success does NOT reset the shared topic (sub-agents never wrote `running`)', async () => {
+ const { get, store } = makeStore();
+ await lifecycle('client', get, 'sub_agent').completeRun(
+ completeEvent('client', { runScope: 'sub_agent', runtimeStatus: 'done' }),
+ );
+
+ expect(store.updateTopicStatus).not.toHaveBeenCalled();
+ });
+});
+
describe('buildRunLifecycle β€” sub-agent runs skip top-level effects', () => {
it('a sub_agent success completes the op but does NOT drain the parent input queue', async () => {
const { get, store } = makeStore();
diff --git a/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
index 943fd91728c..fcd685d7136 100644
--- a/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
+++ b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
@@ -323,6 +323,39 @@ export const buildRunLifecycle = (
}
};
+ // The client transport persists `status: 'running'` at run start
+ // (streamingExecutor) but, unlike gateway (see gateway.ts onSessionComplete),
+ // had no terminal write that flips it back for the topic the user is
+ // watching β€” `markTopicUnread` early-returns on the active topic, so the
+ // persisted status stayed `running` forever and stuck both the sidebar
+ // spinner and the home "δ»»εŠ‘ζ­£εœ¨ζ‰§θ‘Œ" card. Mirror gateway's rule here: a
+ // clean completion the user isn't watching is owned by `markTopicUnread`
+ // (status: 'unread'); every OTHER case (viewing, error, abort) force-resets
+ // to 'active'. Client + top-level + real topic only β€” sub-agents never wrote
+ // 'running', and gateway/hetero own their own reset.
+ const resetActiveTopicRunningStatus = () => {
+ if (adapter.runtimeType !== 'client') return;
+ if (adapter.runScope === 'sub_agent') return;
+ if (!topicId) return;
+ const viewing = get().activeTopicId === topicId;
+ // Not-viewing clean success is owned by `markTopicUnread` (β†’ 'unread');
+ // skip so the two never race over the status field.
+ if (!viewing && disposition === 'success') return;
+ // Carry the group scope through, exactly like the start-write does. Without
+ // it `updateTopicStatus` auto-derives `group_agent` from agentId+groupId and
+ // the optimistic in-memory patch lands in the wrong bucket, leaving the
+ // VISIBLE group topic's sidebar spinner stuck until the next refetch.
+ void get().updateTopicStatus?.({
+ agentId,
+ groupId,
+ ...(context.scope === 'group' || context.scope === 'group_agent'
+ ? { scope: context.scope }
+ : {}),
+ status: 'active',
+ topicId,
+ });
+ };
+
// 1. afterCompletion callbacks β€” fire on ALL terminal states (tools that
// registered post-run actions: speak / broadcast / delegate).
const operation = get().operations[operationId];
@@ -411,6 +444,10 @@ export const buildRunLifecycle = (
// `onRunParked`.
}
+ // Runs past the requeue early-return, so a run that continues into a queued
+ // follow-up (which writes 'running' again) is never reset mid-flight.
+ resetActiveTopicRunningStatus();
+
emitComplete(operationId, runtimeStatus);
return { requeued: false };