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(tasks): scope task completion to terminal result briefs only (#14168)

Arvin Xu84fd8da4a3b6
diff --git a/src/server/services/brief/index.test.ts b/src/server/services/brief/index.test.ts
index 75ac42c441c..961a3010b7a 100644
--- a/src/server/services/brief/index.test.ts
+++ b/src/server/services/brief/index.test.ts
@@ -186,7 +186,7 @@ describe('BriefService', () => {
});
});
- it('should complete the task when force-approving a decision brief', async () => {
+ it('should NOT complete the task when approving a decision brief (mid-execution checkpoint)', async () => {
const service = new BriefService(db, userId);
mockBriefModel.resolve.mockResolvedValue({
id: 'b2',
@@ -196,9 +196,9 @@ describe('BriefService', () => {
await service.resolve('b2', { action: 'approve' });
- expect(mockTaskModel.updateStatus).toHaveBeenCalledWith('task-2', 'completed', {
- error: null,
- });
+ // decision briefs are non-terminal checkpoints β€” approving must not complete
+ // the task or resume/continue flows break.
+ expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();
});
it('should not change task status for non-approve actions', async () => {
@@ -214,7 +214,7 @@ describe('BriefService', () => {
expect(mockTaskModel.updateStatus).not.toHaveBeenCalled();
});
- it('should not change task status when approving a non-result/decision brief', async () => {
+ it('should not change task status when approving a non-result brief', async () => {
const service = new BriefService(db, userId);
mockBriefModel.resolve.mockResolvedValue({
id: 'b4',
diff --git a/src/server/services/brief/index.ts b/src/server/services/brief/index.ts
index f66862ec3ec..0d73c346d37 100644
--- a/src/server/services/brief/index.ts
+++ b/src/server/services/brief/index.ts
@@ -63,11 +63,17 @@ export class BriefService {
/**
* 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.
+ * Terminal accept rule: `approve` on a `result` brief completes the task. The
+ * `result` type is the only brief that carries terminal-deliverable semantics
+ * β€” the agent's `result` brief is a *proposal* of completion that the user
+ * accepts here (and the review max-iterations force-pass also surfaces a
+ * `result` brief for the same reason).
+ *
+ * `decision` briefs are non-terminal checkpoints (mid-execution approvals
+ * like "should I proceed with X?") β€” approving them must NOT move the task to
+ * `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.
*/
async resolve(
id: string,
@@ -76,11 +82,7 @@ export class BriefService {
const brief = await this.briefModel.resolve(id, options);
if (!brief) return null;
- if (
- options?.action === 'approve' &&
- brief.taskId &&
- (brief.type === 'result' || brief.type === 'decision')
- ) {
+ if (options?.action === 'approve' && brief.taskId && brief.type === 'result') {
await this.taskModel.updateStatus(brief.taskId, 'completed', { error: null });
}
diff --git a/src/server/services/taskLifecycle/index.ts b/src/server/services/taskLifecycle/index.ts
index 3d0e0698e45..22a9a9f3049 100644
--- a/src/server/services/taskLifecycle/index.ts
+++ b/src/server/services/taskLifecycle/index.ts
@@ -222,14 +222,19 @@ export class TaskLifecycleService {
});
if (reviewResult.passed) {
+ // Judge is a trusted accept signal β€” the brief is created already-resolved
+ // (no actionable buttons in the UI) and the task transitions to 'completed'.
+ const now = new Date();
await this.briefModel.create({
priority: 'info',
+ resolvedAction: 'auto-judge-pass',
+ resolvedAt: now,
+ readAt: now,
summary: `Review passed (score: ${reviewResult.overallScore}%, iteration: ${iteration}). ${content.slice(0, 150)}`,
taskId,
title: `${taskIdentifier} review passed`,
type: 'result',
});
- // Judge is a trusted accept signal β€” complete the task directly.
await this.taskModel.updateStatus(taskId, 'completed', { error: null });
return true;
}
@@ -248,7 +253,9 @@ export class TaskLifecycleService {
return true;
}
- // Max iterations reached
+ // Max iterations reached β€” surface the (failed) result for human accept/retry.
+ // Type is `result` so the user's `approve` action is treated as a terminal
+ // accept signal (force-pass) by BriefService.resolve.
await this.briefModel.create({
actions: [
{ key: 'retry', label: 'πŸ”„ 重试', type: 'resolve' as const },
@@ -259,7 +266,7 @@ export class TaskLifecycleService {
summary: `Review failed after ${iteration} iteration(s) (score: ${reviewResult.overallScore}%). Suggestions: ${reviewResult.suggestions?.join('; ') || 'none'}`,
taskId,
title: `${taskIdentifier} review failed β€” needs attention`,
- type: 'decision',
+ type: 'result',
});
await this.taskModel.updateStatus(taskId, 'paused', { error: null });
return true;