🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(brief): keep recurring tasks active when resolving their result briefs (#14348)
Arvin Xub0315133218a
diff --git a/locales/en-US/home.json b/locales/en-US/home.jsonindex 7228409fd50..2f6ad9fb0cb 100644--- a/locales/en-US/home.json+++ b/locales/en-US/home.json@@ -5,6 +5,7 @@"agentSelection.search": "No matching agents found","brief.action.acknowledge": "Acknowledge","brief.action.approve": "Approve",+ "brief.action.confirm": "Confirm","brief.action.confirmDone": "Confirm complete","brief.action.feedback": "Feedback","brief.action.retry": "Retry",diff --git a/locales/zh-CN/home.json b/locales/zh-CN/home.jsonindex 01d7a511edf..40f3b94378c 100644--- a/locales/zh-CN/home.json+++ b/locales/zh-CN/home.json@@ -5,6 +5,7 @@"agentSelection.search": "未找到匹配的助理","brief.action.acknowledge": "确认","brief.action.approve": "批准",+ "brief.action.confirm": "确认","brief.action.confirmDone": "确认完成","brief.action.feedback": "反馈","brief.action.retry": "重试",diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskBriefCard.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskBriefCard.tsxindex ef7a1e51ce8..3393ff37862 100644--- a/src/features/AgentTasks/AgentTaskDetail/TaskBriefCard.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TaskBriefCard.tsx@@ -109,6 +109,7 @@ const TaskBriefCard = memo<TaskBriefCardProps>(briefType={brief.type}resolvedAction={brief.resolvedAction}taskId={brief.taskId}+ taskStatus={brief.taskStatus}topicId={brief.topicId}onAfterAddComment={onAfterAddComment}onAfterResolve={onAfterResolve}diff --git a/src/features/DailyBrief/BriefCard.tsx b/src/features/DailyBrief/BriefCard.tsxindex 80abcf5a1a4..1fb4740dda4 100644--- a/src/features/DailyBrief/BriefCard.tsx+++ b/src/features/DailyBrief/BriefCard.tsx@@ -117,6 +117,7 @@ const BriefCard = memo<BriefCardProps>(briefType={brief.type}resolvedAction={brief.resolvedAction}taskId={brief.taskId}+ taskStatus={brief.taskStatus}topicId={brief.topicId}onAfterAddComment={onAfterAddComment}onAfterResolve={onAfterResolve}diff --git a/src/features/DailyBrief/BriefCardActions.tsx b/src/features/DailyBrief/BriefCardActions.tsxindex 23fe7669def..54b1ca341d6 100644--- a/src/features/DailyBrief/BriefCardActions.tsx+++ b/src/features/DailyBrief/BriefCardActions.tsx@@ -1,4 +1,4 @@-import { type BriefAction, DEFAULT_BRIEF_ACTIONS } from '@lobechat/types';+import { type BriefAction, DEFAULT_BRIEF_ACTIONS, type TaskStatus } from '@lobechat/types';import { Button, Flexbox, Icon, Text, Tooltip } from '@lobehub/ui';import { cssVar } from 'antd-style';import { Check, SquarePen, Workflow } from 'lucide-react';@@ -23,6 +23,8 @@ export interface BriefCardActionsProps {onAfterResolve?: () => void | Promise<void>;resolvedAction?: string | null;taskId?: string | null;+ /** Parent task's runtime status — `scheduled` flips the result action to a plain "Confirm" since approving must NOT terminate a task parked between automated runs. */+ taskStatus?: TaskStatus | null;/** When set together with taskId, renders a "View run" shortcut to the topic drawer. */topicId?: string | null;}@@ -45,6 +47,7 @@ const BriefCardActions = memo<BriefCardActionsProps>(onAfterResolve,resolvedAction,taskId,+ taskStatus,topicId,}) => {const { t } = useTranslation('home');@@ -83,19 +86,26 @@ const BriefCardActions = memo<BriefCardActionsProps>() : null;const isResult = briefType === 'result';+ // A result brief on a task parked at status='scheduled' is one occurrence+ // of a recurring run — approving must NOT mark the task as completed+ // (server-side guard mirrors this). Use a plain "Confirm" so the label+ // reflects the dismiss-only behavior; otherwise "Confirm complete" signals+ // the terminal transition.+ const resultLabelKey =+ taskStatus === 'scheduled' ? 'brief.action.confirm' : 'brief.action.confirmDone';const actions: BriefAction[] = isResult- ? [{ key: 'approve', label: t('brief.action.confirmDone'), type: 'resolve' }]+ ? [{ key: 'approve', label: t(resultLabelKey), type: 'resolve' }]: (actionsProp ?? DEFAULT_BRIEF_ACTIONS[briefType] ?? []);const getActionLabel = useCallback((action: BriefAction) => {- if (isResult && action.key === 'approve') return t('brief.action.confirmDone');+ if (isResult && action.key === 'approve') return t(resultLabelKey);const i18nKey = `brief.action.${action.key}`;const translated = t(i18nKey, { defaultValue: '' });return !translated || translated === i18nKey ? action.label : translated;},- [isResult, t],+ [isResult, resultLabelKey, t],);const handleResolve = useCallback(diff --git a/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx b/src/features/DailyBrief/__tests__/BriefCardActions.test.tsxindex 261fd423219..6ca80345bf7 100644--- a/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx+++ b/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx@@ -19,6 +19,7 @@ vi.mock('react-i18next', () => ({'cancel': 'Cancel','brief.commentPlaceholder': 'Share your feedback...','brief.commentSubmit': 'Submit feedback',+ 'brief.action.confirm': 'Confirm','brief.action.confirmDone': 'Confirm complete','brief.editResult': 'Edit','brief.viewRun': 'View run',@@ -171,4 +172,32 @@ describe('BriefCardActions', () => {);expect(screen.queryByText('View run')).not.toBeInTheDocument();});++ it('should label the result action "Confirm complete" when the parent task is not parked at scheduled', () => {+ renderWithRouter(+ <BriefCardActions+ actions={[{ key: 'approve', label: 'X', type: 'resolve' }]}+ briefId="brief-7"+ briefType="result"+ taskId="task-7"+ taskStatus={'paused'}+ />,+ );+ expect(screen.getByText('Confirm complete')).toBeInTheDocument();+ expect(screen.queryByText('Confirm', { exact: true })).not.toBeInTheDocument();+ });++ it('should label the result action "Confirm" when the parent task is parked at status="scheduled"', () => {+ renderWithRouter(+ <BriefCardActions+ actions={[{ key: 'approve', label: 'X', type: 'resolve' }]}+ briefId="brief-8"+ briefType="result"+ taskId="task-8"+ taskStatus={'scheduled'}+ />,+ );+ expect(screen.getByText('Confirm')).toBeInTheDocument();+ expect(screen.queryByText('Confirm complete')).not.toBeInTheDocument();+ });});diff --git a/src/locales/default/home.ts b/src/locales/default/home.tsindex 4ac77447c12..e33104bd343 100644--- a/src/locales/default/home.ts+++ b/src/locales/default/home.ts@@ -6,8 +6,9 @@ export default {'brief.addFeedback': 'Share feedback','brief.action.acknowledge': 'Acknowledge','brief.action.approve': 'Approve',- 'brief.action.feedback': 'Feedback',+ 'brief.action.confirm': 'Confirm','brief.action.confirmDone': 'Confirm complete',+ 'brief.action.feedback': 'Feedback','brief.action.retry': 'Retry','brief.collapse': 'Show less','brief.commentPlaceholder': 'Share your feedback...',diff --git a/src/server/services/brief/index.test.ts b/src/server/services/brief/index.test.tsindex 961a3010b7a..f17713bf598 100644--- a/src/server/services/brief/index.test.ts+++ b/src/server/services/brief/index.test.ts@@ -35,6 +35,8 @@ describe('BriefService', () => {};const mockTaskModel = {+ findById: vi.fn(),+ findByIds: vi.fn(),getTreeAgentIdsForTaskIds: vi.fn(),updateStatus: vi.fn(),};@@ -47,6 +49,10 @@ describe('BriefService', () => {});describe('enrichBriefsWithAgents', () => {+ beforeEach(() => {+ mockTaskModel.findByIds.mockResolvedValue([]);+ });+it('should return briefs with empty agents when no taskIds', async () => {const service = new BriefService(db, userId);@@ -59,11 +65,14 @@ describe('BriefService', () => {expect(result).toHaveLength(2);expect(result[0].agents).toEqual([]);+ expect(result[0].taskStatus).toBeNull();expect(result[1].agents).toEqual([]);+ expect(result[1].taskStatus).toBeNull();expect(mockTaskModel.getTreeAgentIdsForTaskIds).not.toHaveBeenCalled();+ expect(mockTaskModel.findByIds).not.toHaveBeenCalled();});- it('should enrich briefs with agent data from task trees', async () => {+ it('should enrich briefs with agent data and taskStatus from the parent task', async () => {const service = new BriefService(db, userId);const briefs = [@@ -75,6 +84,10 @@ describe('BriefService', () => {'task-1': ['agent-a', 'agent-b'],'task-2': ['agent-b', 'agent-c'],});+ mockTaskModel.findByIds.mockResolvedValue([+ { id: 'task-1', status: 'scheduled' },+ { id: 'task-2', status: 'paused' },+ ]);mockAgentModel.getAgentAvatarsByIds.mockResolvedValue([{ avatar: '🤖', backgroundColor: null, id: 'agent-a', title: 'Agent A' },@@ -85,14 +98,12 @@ describe('BriefService', () => {const result = await service.enrichBriefsWithAgents(briefs);expect(result[0].agents).toHaveLength(2);- expect(result[0].agents[0].id).toBe('agent-a');- expect(result[0].agents[1].id).toBe('agent-b');-+ expect(result[0].taskStatus).toBe('scheduled');expect(result[1].agents).toHaveLength(2);- expect(result[1].agents[0].id).toBe('agent-b');- expect(result[1].agents[1].id).toBe('agent-c');+ expect(result[1].taskStatus).toBe('paused');expect(mockTaskModel.getTreeAgentIdsForTaskIds).toHaveBeenCalledWith(['task-1', 'task-2']);+ expect(mockTaskModel.findByIds).toHaveBeenCalledWith(['task-1', 'task-2']);expect(mockAgentModel.getAgentAvatarsByIds).toHaveBeenCalledWith(expect.arrayContaining(['agent-a', 'agent-b', 'agent-c']),);@@ -109,6 +120,7 @@ describe('BriefService', () => {mockTaskModel.getTreeAgentIdsForTaskIds.mockResolvedValue({'task-1': ['agent-a'],});+ mockTaskModel.findByIds.mockResolvedValue([{ id: 'task-1', status: 'scheduled' }]);mockAgentModel.getAgentAvatarsByIds.mockResolvedValue([{ avatar: '🤖', backgroundColor: null, id: 'agent-a', title: 'Agent A' },@@ -117,7 +129,9 @@ describe('BriefService', () => {const result = await service.enrichBriefsWithAgents(briefs);expect(result[0].agents).toHaveLength(1);+ expect(result[0].taskStatus).toBe('scheduled');expect(result[1].agents).toEqual([]);+ expect(result[1].taskStatus).toBeNull();});it('should handle task with no agents in tree', async () => {@@ -126,10 +140,12 @@ describe('BriefService', () => {const briefs = [{ id: 'b1', taskId: 'task-1', title: 'Brief' }] as any[];mockTaskModel.getTreeAgentIdsForTaskIds.mockResolvedValue({});+ mockTaskModel.findByIds.mockResolvedValue([{ id: 'task-1', status: 'paused' }]);const result = await service.enrichBriefsWithAgents(briefs);expect(result[0].agents).toEqual([]);+ expect(result[0].taskStatus).toBe('paused');expect(mockAgentModel.getAgentAvatarsByIds).not.toHaveBeenCalled();});});@@ -169,13 +185,14 @@ describe('BriefService', () => {});describe('resolve', () => {- it('should complete the task when approving a result brief', async () => {+ it('should complete the task when approving a result brief on a non-scheduled task', async () => {const service = new BriefService(db, userId);mockBriefModel.resolve.mockResolvedValue({id: 'b1',taskId: 'task-1',type: 'result',});+ mockTaskModel.findById.mockResolvedValue({ id: 'task-1', status: 'paused' });const brief = await service.resolve('b1', { action: 'approve' });@@ -199,6 +216,7 @@ describe('BriefService', () => {// decision briefs are non-terminal checkpoints — approving must not complete// the task or resume/continue flows break.expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ expect(mockTaskModel.findById).not.toHaveBeenCalled();});it('should not change task status for non-approve actions', async () => {@@ -249,5 +267,37 @@ describe('BriefService', () => {expect(result).toBeNull();expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();});++ it('should NOT complete a task parked at status="scheduled" when approving its result brief', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b6',+ taskId: 'task-6',+ type: 'result',+ });+ mockTaskModel.findById.mockResolvedValue({ id: 'task-6', status: 'scheduled' });++ await service.resolve('b6', { action: 'approve' });++ // status='scheduled' means the task is parked between automated runs+ // (heartbeat or schedule). Approving one occurrence is a UI dismissal —+ // the next tick must still surface, so don't flip the task to completed.+ expect(mockTaskModel.findById).toHaveBeenCalledWith('task-6');+ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });++ it('should not complete the task if it has been deleted between resolving and updating', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b7',+ taskId: 'task-gone',+ type: 'result',+ });+ mockTaskModel.findById.mockResolvedValue(null);++ await service.resolve('b7', { action: 'approve' });++ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });});});diff --git a/src/server/services/brief/index.ts b/src/server/services/brief/index.tsindex 0d73c346d37..4ce368eba9c 100644--- a/src/server/services/brief/index.ts+++ b/src/server/services/brief/index.ts@@ -1,3 +1,5 @@+import type { TaskStatus } from '@lobechat/types';+import { AgentModel } from '@/database/models/agent';import { BriefModel } from '@/database/models/brief';import { TaskModel } from '@/database/models/task';@@ -11,7 +13,11 @@ export interface AgentAvatarInfo {title: string | null;}-export type BriefWithAgents = BriefItem & { agents: AgentAvatarInfo[] };+export type BriefWithAgents = BriefItem & {+ agents: AgentAvatarInfo[];+ /** Parent task's runtime status — `scheduled` marks a task parked between automated runs. */+ taskStatus: TaskStatus | null;+};export class BriefService {private agentModel: AgentModel;@@ -28,10 +34,16 @@ export class BriefService {const taskIds = briefs.map((b) => b.taskId).filter((id): id is string => id !== null);if (taskIds.length === 0) {- return briefs.map((brief) => ({ ...brief, agents: [] }));+ return briefs.map((brief) => ({ ...brief, agents: [], taskStatus: null }));}- const taskAgentIdsMap = await this.taskModel.getTreeAgentIdsForTaskIds(taskIds);+ const [taskAgentIdsMap, taskRows] = await Promise.all([+ this.taskModel.getTreeAgentIdsForTaskIds(taskIds),+ this.taskModel.findByIds(taskIds),+ ]);+ const taskStatusMap = Object.fromEntries(+ taskRows.map((t) => [t.id, (t.status as TaskStatus) ?? null]),+ );const allAgentIds = [...new Set(Object.values(taskAgentIdsMap).flat())];let agentMap: Record<string, AgentAvatarInfo> = {};@@ -46,6 +58,7 @@ export class BriefService {agents: (brief.taskId ? taskAgentIdsMap[brief.taskId] || [] : []).map((id) => agentMap[id]).filter(Boolean),+ taskStatus: brief.taskId ? (taskStatusMap[brief.taskId] ?? null) : null,}));}@@ -74,6 +87,14 @@ export class BriefService {* `completed`, otherwise resume/continue flows break. Other actions* (feedback / retry / acknowledge) likewise do not transition task status* here; retry triggers re-execution via a separate flow.+ *+ * Tasks parked at `status === 'scheduled'` are also exempt: that status means+ * the task is between automated runs (heartbeat or schedule), so approving+ * one occurrence's `result` brief is a UI dismissal, not a lifecycle+ * terminal — the next tick must still surface. Discriminating on the runtime+ * `status` (rather than `automationMode`) also means a manual run of a+ * recurring task — which leaves the task in `scheduled` between runs — is+ * handled the same way.*/async resolve(id: string,@@ -83,7 +104,10 @@ export class BriefService {if (!brief) return null;if (options?.action === 'approve' && brief.taskId && brief.type === 'result') {- await this.taskModel.updateStatus(brief.taskId, 'completed', { error: null });+ const task = await this.taskModel.findById(brief.taskId);+ if (task && task.status !== 'scheduled') {+ await this.taskModel.updateStatus(brief.taskId, 'completed', { error: null });+ }}return brief;diff --git a/src/store/brief/types.ts b/src/store/brief/types.tsindex 00809926be8..3d16bfad31d 100644--- a/src/store/brief/types.ts+++ b/src/store/brief/types.ts@@ -1,4 +1,9 @@-import { type BriefAction, type BriefArtifacts, type BriefType } from '@lobechat/types';+import {+ type BriefAction,+ type BriefArtifacts,+ type BriefType,+ type TaskStatus,+} from '@lobechat/types';export interface AgentAvatarInfo {avatar: string | null;@@ -22,6 +27,8 @@ export interface BriefItem {resolvedComment: string | null;summary: string;taskId: string | null;+ /** Parent task's runtime status — `scheduled` means the task is parked between automated runs and approving the brief should NOT complete it. Populated by server enrichment; optional on locally-constructed BriefItems (e.g. from activity rows). */+ taskStatus?: TaskStatus | null;title: string;topicId: string | null;type: BriefType;