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(task): topic activity keeps the agent that ran it, not the task's current assignee (#16315)

Arvin Xu1ac620acba89
diff --git a/apps/server/src/services/task/index.ts b/apps/server/src/services/task/index.ts
index 2853a7cccff..03cb4094011 100644
--- a/apps/server/src/services/task/index.ts
+++ b/apps/server/src/services/task/index.ts
@@ -564,8 +564,13 @@ export class TaskService {
const agentIds = new Set<string>();
const userIds = new Set<string>();
- // Topics are created by the task's assignee agent
- if (task.assigneeAgentId && topics.length > 0) agentIds.add(task.assigneeAgentId);
+ // Each topic keeps the agent that actually ran it (topics.agentId), so an
+ // earlier run's avatar stays correct after the task is reassigned. Fall back
+ // to the current assignee only when a topic has no recorded agent.
+ for (const t of topics) {
+ const topicAgentId = t.agentId ?? task.assigneeAgentId;
+ if (topicAgentId) agentIds.add(topicAgentId);
+ }
// Briefs may have an agentId
for (const b of briefs) {
if (b.agentId) agentIds.add(b.agentId);
@@ -600,8 +605,9 @@ export class TaskService {
...(createdActivity ? [createdActivity] : []),
...topics.map((t) => {
const handoff = t.handoff as TaskTopicHandoff | null;
+ const topicAgentId = t.agentId ?? task.assigneeAgentId;
return {
- author: task.assigneeAgentId ? authorMap.get(task.assigneeAgentId) : undefined,
+ author: topicAgentId ? authorMap.get(topicAgentId) : undefined,
completedAt: toISO(t.completedAt),
id: t.topicId ?? undefined,
operationId: t.operationId ?? null,
diff --git a/packages/database/src/models/taskTopic.ts b/packages/database/src/models/taskTopic.ts
index b4f1f7221ac..062a8c7b084 100644
--- a/packages/database/src/models/taskTopic.ts
+++ b/packages/database/src/models/taskTopic.ts
@@ -222,6 +222,10 @@ export class TaskTopicModel {
async findWithHandoff(taskId: string, limit: number) {
return this.db
.select({
+ // The agent that actually ran this topic — used so each activity row
+ // keeps its own avatar instead of inheriting the task's *current*
+ // assignee (which changes when the task is reassigned).
+ agentId: topics.agentId,
completedAt: topics.completedAt,
createdAt: taskTopics.createdAt,
handoff: taskTopics.handoff,