π€― 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
β»οΈ refactor(tasks): default to await-review on topic done, drive completion via accept signals (#14167)
Arvin Xu774e29e400b2
diff --git a/src/server/routers/lambda/brief.ts b/src/server/routers/lambda/brief.tsindex ab70f536cac..1b00e7c5c53 100644--- a/src/server/routers/lambda/brief.ts+++ b/src/server/routers/lambda/brief.ts@@ -166,8 +166,8 @@ export const briefRouter = router({).mutation(async ({ input, ctx }) => {try {- const model = new BriefModel(ctx.serverDB, ctx.userId);- const brief = await model.resolve(input.id, {+ const service = new BriefService(ctx.serverDB, ctx.userId);+ const brief = await service.resolve(input.id, {action: input.action,comment: input.comment,});diff --git a/src/server/services/brief/index.test.ts b/src/server/services/brief/index.test.tsindex 13c76da03a2..75ac42c441c 100644--- a/src/server/services/brief/index.test.ts+++ b/src/server/services/brief/index.test.ts@@ -31,10 +31,12 @@ describe('BriefService', () => {const mockBriefModel = {list: vi.fn(),listUnresolved: vi.fn(),+ resolve: vi.fn(),};const mockTaskModel = {getTreeAgentIdsForTaskIds: vi.fn(),+ updateStatus: vi.fn(),};beforeEach(() => {@@ -165,4 +167,87 @@ describe('BriefService', () => {expect(mockBriefModel.listUnresolved).toHaveBeenCalled();});});++ describe('resolve', () => {+ it('should complete the task when approving a result brief', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b1',+ taskId: 'task-1',+ type: 'result',+ });++ const brief = await service.resolve('b1', { action: 'approve' });++ expect(brief).toEqual({ id: 'b1', taskId: 'task-1', type: 'result' });+ expect(mockBriefModel.resolve).toHaveBeenCalledWith('b1', { action: 'approve' });+ expect(mockTaskModel.updateStatus).toHaveBeenCalledWith('task-1', 'completed', {+ error: null,+ });+ });++ it('should complete the task when force-approving a decision brief', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b2',+ taskId: 'task-2',+ type: 'decision',+ });++ await service.resolve('b2', { action: 'approve' });++ expect(mockTaskModel.updateStatus).toHaveBeenCalledWith('task-2', 'completed', {+ error: null,+ });+ });++ it('should not change task status for non-approve actions', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b3',+ taskId: 'task-3',+ type: 'result',+ });++ await service.resolve('b3', { action: 'feedback', comment: 'tweak the tone' });++ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });++ it('should not change task status when approving a non-result/decision brief', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b4',+ taskId: 'task-4',+ type: 'insight',+ });++ await service.resolve('b4', { action: 'approve' });++ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });++ it('should not change task status when brief has no taskId', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue({+ id: 'b5',+ taskId: null,+ type: 'result',+ });++ await service.resolve('b5', { action: 'approve' });++ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });++ it('should return null and skip task update when brief is not found', async () => {+ const service = new BriefService(db, userId);+ mockBriefModel.resolve.mockResolvedValue(null);++ const result = await service.resolve('missing', { action: 'approve' });++ expect(result).toBeNull();+ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();+ });+ });});diff --git a/src/server/services/brief/index.ts b/src/server/services/brief/index.tsindex ca2c9c9e436..f66862ec3ec 100644--- a/src/server/services/brief/index.ts+++ b/src/server/services/brief/index.ts@@ -59,4 +59,31 @@ export class BriefService {const items = await this.briefModel.listUnresolved();return this.enrichBriefsWithAgents(items);}++ /**+ * Resolve a brief and propagate accept signals to the task lifecycle.+ *+ * 'approve' on a `result` brief is the user-issued accept signal that completes+ * the task (the agent's result brief alone is only a *proposal* of completion).+ * 'approve' on a `decision` brief (review max-iterations force-pass) carries the+ * same semantics. Other actions (feedback / retry / acknowledge) do not transition+ * task status here β retry triggers re-execution via a separate flow.+ */+ async resolve(+ id: string,+ options?: { action?: string; comment?: string },+ ): Promise<BriefItem | null> {+ const brief = await this.briefModel.resolve(id, options);+ if (!brief) return null;++ if (+ options?.action === 'approve' &&+ brief.taskId &&+ (brief.type === 'result' || brief.type === 'decision')+ ) {+ await this.taskModel.updateStatus(brief.taskId, 'completed', { error: null });+ }++ return brief;+ }}diff --git a/src/server/services/taskLifecycle/index.ts b/src/server/services/taskLifecycle/index.tsindex d11349494a1..3d0e0698e45 100644--- a/src/server/services/taskLifecycle/index.ts+++ b/src/server/services/taskLifecycle/index.ts@@ -75,30 +75,26 @@ export class TaskLifecycleService {);}- // 3. Auto-review (if configured)- if (currentTask && topicId && lastAssistantContent) {- await this.runAutoReview(- taskId,- taskIdentifier,- topicId,- lastAssistantContent,- currentTask,- );- }-- // 4. Check if agent delivered a result brief β auto-complete- // If the latest brief is type 'result' and no review is configured, complete the task- const reviewConfig = currentTask ? this.taskModel.getReviewConfig(currentTask) : null;- if (!reviewConfig?.enabled) {- const briefs = await this.briefModel.findByTaskId(taskId);- const latestBrief = briefs[0]; // sorted by createdAt desc- if (latestBrief?.type === 'result') {- await this.taskModel.updateStatus(taskId, 'completed', { error: null });- return;- }- }-- // 5. Checkpoint β pause for user review+ // 3. Auto-review (if configured) β Judge is the trusted accept signal:+ // when review passes, runAutoReview itself transitions the task to 'completed'.+ // Returns true if it terminated the task (completed/paused for retry/etc.).+ const reviewTerminated =+ currentTask && topicId && lastAssistantContent+ ? await this.runAutoReview(+ taskId,+ taskIdentifier,+ topicId,+ lastAssistantContent,+ currentTask,+ )+ : false;++ if (reviewTerminated) return;++ // 4. Default: pause for user review.+ // A 'result' brief from the agent is a *proposal* of completion β the user+ // must explicitly approve via the brief action to transition to 'completed'.+ // Auto-complete only happens via the Judge path above.if (currentTask && this.taskModel.shouldPauseOnTopicComplete(currentTask)) {await this.taskModel.updateStatus(taskId, 'paused', { error: null });}@@ -176,7 +172,13 @@ export class TaskLifecycleService {/*** Run auto-review if configured.- * @returns true if auto-retry is in progress (caller should skip pause)+ *+ * Acts as a "Judge" accept signal: when review passes the task transitions to+ * `completed` here; when it fails, the task is paused for retry or human action.+ *+ * @returns true if this method terminated the task lifecycle (caller should not+ * additionally pause/transition); false if review wasn't configured or+ * a non-terminal path was taken.*/private async runAutoReview(taskId: string,@@ -184,9 +186,9 @@ export class TaskLifecycleService {topicId: string,content: string,currentTask: any,- ): Promise<void> {+ ): Promise<boolean> {const reviewConfig = this.taskModel.getReviewConfig(currentTask);- if (!reviewConfig?.enabled || !reviewConfig.rubrics?.length) return;+ if (!reviewConfig?.enabled || !reviewConfig.rubrics?.length) return false;try {const topicLinks = await this.taskTopicModel.findByTaskId(taskId);@@ -227,7 +229,9 @@ export class TaskLifecycleService {title: `${taskIdentifier} review passed`,type: 'result',});- return;+ // Judge is a trusted accept signal β complete the task directly.+ await this.taskModel.updateStatus(taskId, 'completed', { error: null });+ return true;}if (reviewConfig.autoRetry && iteration < reviewConfig.maxIterations) {@@ -241,7 +245,7 @@ export class TaskLifecycleService {// Pause so the webhook / polling loop can pick up and re-runawait this.taskModel.updateStatus(taskId, 'paused', { error: null });- return;+ return true;}// Max iterations reached@@ -257,8 +261,11 @@ export class TaskLifecycleService {title: `${taskIdentifier} review failed β needs attention`,type: 'decision',});+ await this.taskModel.updateStatus(taskId, 'paused', { error: null });+ return true;} catch (e) {console.warn('[TaskLifecycle] auto-review failed:', e);+ return false;}}}