π€― 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(acceptance): move the task along with its acceptance lifecycle (#20441)
Arvin Xudc9cd24864e3
diff --git a/apps/server/src/services/verify/__tests__/acceptanceTaskLifecycle.test.ts b/apps/server/src/services/verify/__tests__/acceptanceTaskLifecycle.test.tsnew file mode 100644index 00000000000..a4da32ec596--- /dev/null+++ b/apps/server/src/services/verify/__tests__/acceptanceTaskLifecycle.test.ts@@ -0,0 +1,302 @@+// @vitest-environment node+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { AcceptanceService } from '../acceptanceService';++/**+ * A task acceptance carries its task through the lifecycle: when the delivery+ * lands (`delivered`) the task completes, and a reject reopens it. Goal graph+ * tasks and recurring tasks are driven elsewhere and stay out of it.+ */+const mocks = vi.hoisted(() => ({+ distilRejections: vi.fn(),+ findById: vi.fn(),+ findPolicyById: vi.fn(),+ findReportByRun: vi.fn(),+ goalFindByGraphTask: vi.fn(),+ listByAcceptance: vi.fn(),+ setDecision: vi.fn(),+ taskFindById: vi.fn(),+ taskResolve: vi.fn(),+ taskServiceUpdateStatus: vi.fn(),+ taskUpdateStatusIfCurrent: vi.fn(),+ updatePolicyStatus: vi.fn(),+ updateStatus: vi.fn(),+}));++vi.mock('@/database/models/acceptance', () => ({+ AcceptanceModel: vi.fn(function () {+ return {+ findById: mocks.findById,+ findPolicyById: mocks.findPolicyById,+ updatePolicyStatus: mocks.updatePolicyStatus,+ updateStatus: mocks.updateStatus,+ };+ }),+}));+vi.mock('@/database/models/verifyRun', () => ({+ VerifyRunModel: vi.fn(function () {+ return { listByAcceptance: mocks.listByAcceptance, setDecision: mocks.setDecision };+ }),+}));+vi.mock('@/database/models/verifyCheckResult', () => ({ VerifyCheckResultModel: vi.fn() }));+vi.mock('@/database/models/verifyEvidence', () => ({ VerifyEvidenceModel: vi.fn() }));+vi.mock('@/database/models/verifyReport', () => ({+ VerifyReportModel: vi.fn(function () {+ return { findByRun: mocks.findReportByRun };+ }),+}));+vi.mock('@/database/models/task', () => ({+ TaskModel: vi.fn(function () {+ return {+ findById: mocks.taskFindById,+ resolve: mocks.taskResolve,+ updateStatusIfCurrent: mocks.taskUpdateStatusIfCurrent,+ };+ }),+}));+vi.mock('@/database/models/goal', () => ({+ GoalModel: vi.fn(function () {+ return { findByGraphTask: mocks.goalFindByGraphTask };+ }),+}));+vi.mock('@/database/models/topic', () => ({ TopicModel: vi.fn() }));+vi.mock('@/database/models/document', () => ({ DocumentModel: vi.fn() }));+vi.mock('@/server/services/task', () => ({+ TaskService: vi.fn(function () {+ return { updateStatus: mocks.taskServiceUpdateStatus };+ }),+}));+vi.mock('@/server/workflows/expertiseRejection', () => ({+ ExpertiseRejectionWorkflow: { trigger: mocks.distilRejections },+}));++const service = () => new AcceptanceService({} as any, 'user-1');++const taskAcceptance = (status: string) => ({+ id: 'acc-1',+ status,+ subjectId: 'task_1',+ subjectType: 'task',+});++describe('AcceptanceService task lifecycle', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mocks.findPolicyById.mockImplementation((...args: unknown[]) => mocks.findById(...args));+ mocks.goalFindByGraphTask.mockResolvedValue(undefined);+ mocks.taskResolve.mockResolvedValue({ automationMode: null, id: 'task_1', status: 'running' });+ // The row read back after the completion write.+ mocks.taskFindById.mockResolvedValue({ id: 'task_1', status: 'completed' });+ });++ describe('delivered β task completed', () => {+ // The stored acceptance row: the rollup writes to it, later reads see it.+ let stored: ReturnType<typeof taskAcceptance>;++ beforeEach(() => {+ stored = taskAcceptance('verifying');+ mocks.findById.mockImplementation(async () => ({ ...stored }));+ mocks.updatePolicyStatus.mockImplementation(async (_id: string, status: string) => {+ stored.status = status;+ });+ // An ingested round: no verify pipeline status, settled by its report.+ mocks.listByAcceptance.mockResolvedValue([{ id: 'run-1', roundIndex: 1, status: null }]);+ mocks.findReportByRun.mockResolvedValue({ id: 'report-1' });+ });++ it('completes the task when an ingested round delivers', async () => {+ await expect(service().recomputeStatus('acc-1')).resolves.toBe('delivered');++ expect(mocks.updatePolicyStatus).toHaveBeenCalledWith('acc-1', 'delivered');+ expect(mocks.taskServiceUpdateStatus).toHaveBeenCalledWith({+ id: 'task_1',+ status: 'completed',+ });+ });++ it('leaves a server-verified round to driveTaskFromVerify', async () => {+ // A failed round may still be auto-repaired; settle drives the task once.+ mocks.listByAcceptance.mockResolvedValue([{ id: 'run-1', roundIndex: 1, status: 'failed' }]);++ await expect(service().recomputeStatus('acc-1')).resolves.toBe('delivered');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('completes the task when an acceptance flow delivers its round', async () => {+ // `AcceptanceFlowModel.complete()` stamps the round `delivered` itself.+ mocks.listByAcceptance.mockResolvedValue([+ { id: 'run-1', roundIndex: 1, status: 'delivered' },+ ]);++ await expect(service().recomputeStatus('acc-1')).resolves.toBe('delivered');+ expect(mocks.taskServiceUpdateStatus).toHaveBeenCalledWith({+ id: 'task_1',+ status: 'completed',+ });+ });++ it('leaves an already completed task alone when the status did not change', async () => {+ stored.status = 'delivered';+ mocks.taskResolve.mockResolvedValue({+ automationMode: null,+ id: 'task_1',+ status: 'completed',+ });++ await service().recomputeStatus('acc-1');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('retries a completion that failed on the delivering recompute', async () => {+ // First recompute delivers, but completing the task fails and it stays open.+ mocks.taskServiceUpdateStatus.mockRejectedValueOnce(new Error('interrupt failed'));+ mocks.taskFindById.mockResolvedValueOnce({ id: 'task_1', status: 'running' });+ await service().recomputeStatus('acc-1');+ expect(stored.status).toBe('delivered');++ // A later recompute (status unchanged) completes it.+ await service().recomputeStatus('acc-1');+ expect(mocks.taskServiceUpdateStatus).toHaveBeenCalledTimes(2);+ expect(mocks.taskServiceUpdateStatus).toHaveBeenLastCalledWith({+ id: 'task_1',+ status: 'completed',+ });+ });++ it('leaves a Goal graph task to its coordinator', async () => {+ mocks.goalFindByGraphTask.mockResolvedValue({ id: 'goal-1' });++ await service().recomputeStatus('acc-1');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('leaves a recurring task on its schedule', async () => {+ mocks.taskResolve.mockResolvedValue({+ automationMode: 'schedule',+ id: 'task_1',+ status: 'scheduled',+ });++ await service().recomputeStatus('acc-1');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('does not touch an already completed task', async () => {+ mocks.taskResolve.mockResolvedValue({+ automationMode: null,+ id: 'task_1',+ status: 'completed',+ });++ await service().recomputeStatus('acc-1');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('still settles the acceptance when completing the task fails', async () => {+ mocks.taskServiceUpdateStatus.mockRejectedValueOnce(new Error('cascade failed'));++ await expect(service().recomputeStatus('acc-1')).resolves.toBe('delivered');+ expect(mocks.updatePolicyStatus).toHaveBeenCalledWith('acc-1', 'delivered');+ });+ });++ describe('a reject racing the completion', () => {+ let stored: ReturnType<typeof taskAcceptance>;++ beforeEach(() => {+ stored = taskAcceptance('delivered');+ mocks.findById.mockImplementation(async () => ({ ...stored }));+ });++ it('leaves the task open when the reject already landed', async () => {+ stored.status = 'rejected';++ await expect(service().completeTaskForDelivery('acc-1', 'task_1')).resolves.toBe('rejected');+ expect(mocks.taskServiceUpdateStatus).not.toHaveBeenCalled();+ });++ it('reopens the task when the reject lands while it is being completed', async () => {+ // The reject saw an unfinished task, so it had nothing to reopen.+ mocks.taskResolve+ .mockResolvedValueOnce({ automationMode: null, id: 'task_1', status: 'running' })+ .mockResolvedValueOnce({ automationMode: null, id: 'task_1', status: 'running' })+ .mockResolvedValue({ automationMode: null, id: 'task_1', status: 'completed' });+ mocks.taskServiceUpdateStatus.mockImplementationOnce(async () => {+ stored.status = 'rejected';+ });++ await expect(service().completeTaskForDelivery('acc-1', 'task_1')).resolves.toBe('rejected');+ expect(mocks.taskUpdateStatusIfCurrent).toHaveBeenCalledWith(+ 'task_1',+ 'completed',+ 'paused',+ { completedAt: null },+ );+ });++ it('reports the completion as skipped when the task could not be completed', async () => {+ // completeTaskSubject swallows the failure; the row still reads running.+ mocks.taskServiceUpdateStatus.mockRejectedValueOnce(new Error('interrupt failed'));+ mocks.taskFindById.mockResolvedValueOnce({ id: 'task_1', status: 'running' });++ await expect(service().completeTaskForDelivery('acc-1', 'task_1')).resolves.toBe('skipped');+ });++ it('completes the task when no reject intervenes', async () => {+ await expect(service().completeTaskForDelivery('acc-1', 'task_1')).resolves.toBe('completed');+ expect(mocks.taskUpdateStatusIfCurrent).not.toHaveBeenCalled();+ });+ });++ describe('rejected β task reopened', () => {+ beforeEach(() => {+ mocks.findById.mockResolvedValue(taskAcceptance('delivered'));+ mocks.listByAcceptance.mockResolvedValue([{ id: 'run-1', roundIndex: 1 }]);+ mocks.taskResolve.mockResolvedValue({+ automationMode: null,+ id: 'task_1',+ status: 'completed',+ });+ });++ it('moves the completed task back to paused', async () => {+ await service().reject('acc-1', 'Fix the header');++ expect(mocks.updateStatus).toHaveBeenCalledWith('acc-1', 'rejected');+ expect(mocks.taskUpdateStatusIfCurrent).toHaveBeenCalledWith(+ 'task_1',+ 'completed',+ 'paused',+ {+ completedAt: null,+ },+ );+ });++ it('keeps a task the user already moved elsewhere', async () => {+ mocks.taskResolve.mockResolvedValue({+ automationMode: null,+ id: 'task_1',+ status: 'running',+ });++ await service().reject('acc-1', 'Fix the header');+ expect(mocks.taskUpdateStatusIfCurrent).not.toHaveBeenCalled();+ });++ it('leaves a Goal graph task to its coordinator', async () => {+ mocks.goalFindByGraphTask.mockResolvedValue({ id: 'goal-1' });++ await service().reject('acc-1', 'Fix the header');+ expect(mocks.taskUpdateStatusIfCurrent).not.toHaveBeenCalled();+ });++ it('ignores non-task subjects', async () => {+ mocks.findById.mockResolvedValue({ ...taskAcceptance('delivered'), subjectType: 'topic' });++ await service().reject('acc-1', 'Fix the header');+ expect(mocks.taskResolve).not.toHaveBeenCalled();+ });+ });+});diff --git a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.tsindex 25b3655a4d1..cd6c6e22a79 100644--- a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts+++ b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts@@ -14,6 +14,12 @@ import { driveTaskFromVerify, finalizeVerifyRun } from '../settle';import { attachTaskRunToAcceptance, resolveTaskAcceptance } from '../taskAcceptance';vi.mock('../goalReview', () => ({ reviewGoalDelivery: vi.fn() }));+const { completeTaskForDelivery } = vi.hoisted(() => ({ completeTaskForDelivery: vi.fn() }));+vi.mock('../acceptanceService', () => ({+ AcceptanceService: vi.fn(function () {+ return { completeTaskForDelivery };+ }),+}));vi.mock('../taskAcceptance', () => ({attachTaskRunToAcceptance: vi.fn(),resolveTaskAcceptance: vi.fn(),@@ -412,6 +418,7 @@ describe('driveTaskFromVerify', () => {.mockImplementation(async (_db, _userId, params) => params.run);vi.mocked(scheduleGoalAdvance).mockClear();goalFindByTask.mockReset();+ completeTaskForDelivery.mockReset().mockResolvedValue('completed');[runClaimTaskDrive,runFindByOperation,@@ -559,6 +566,78 @@ describe('driveTaskFromVerify', () => {expect(deliverMock.mock.calls[0][0]).toMatchObject({ reason: 'error', taskId: 'task-1' });});+ it('failed with an Acceptance β completes the task, since the Acceptance is now delivered', async () => {+ runFindByOperation.mockResolvedValue({+ acceptanceId: 'acceptance-1',+ id: 'run-1',+ metadata: null,+ status: 'failed',+ });+ await driveTaskFromVerify(db, 'u1', 'op-1');+ expect(completeTaskForDelivery).toHaveBeenCalledWith('acceptance-1', 'task-1');+ expect(taskUpdateStatus).not.toHaveBeenCalled();+ // The creator still hears the verdict: the round did not pass.+ expect(deliverMock.mock.calls[0][0]).toMatchObject({ reason: 'error', taskId: 'task-1' });+ });++ it('failed with an Acceptance β pauses when the task could not be completed', async () => {+ runFindByOperation.mockResolvedValue({+ acceptanceId: 'acceptance-1',+ id: 'run-1',+ metadata: null,+ status: 'failed',+ });+ completeTaskForDelivery.mockResolvedValue('skipped');+ await driveTaskFromVerify(db, 'u1', 'op-1');+ expect(taskUpdateStatus).toHaveBeenCalledWith('task-1', 'paused', {+ error: 'Delivery did not pass verification.',+ });+ });++ it('failed with a rejected Acceptance β keeps the task open (paused)', async () => {+ runFindByOperation.mockResolvedValue({+ acceptanceId: 'acceptance-1',+ id: 'run-1',+ metadata: null,+ status: 'failed',+ });+ completeTaskForDelivery.mockResolvedValue('rejected');+ await driveTaskFromVerify(db, 'u1', 'op-1');+ expect(taskUpdateStatus).toHaveBeenCalledWith('task-1', 'paused', {+ error: 'Delivery did not pass verification.',+ });+ });++ it('failed Goal task with an Acceptance β still pauses so the coordinator retries', async () => {+ runFindByOperation.mockResolvedValue({+ acceptanceId: 'acceptance-1',+ id: 'run-1',+ metadata: null,+ status: 'failed',+ });+ goalFindByTask.mockResolvedValue({ id: 'goal-1' });+ await driveTaskFromVerify(db, 'u1', 'op-1');+ expect(completeTaskForDelivery).not.toHaveBeenCalled();+ expect(taskUpdateStatus).toHaveBeenCalledWith('task-1', 'paused', {+ error: 'Delivery did not pass verification.',+ });+ });++ it('failed with an Acceptance β pauses when the Goal lookup fails', async () => {+ runFindByOperation.mockResolvedValue({+ acceptanceId: 'acceptance-1',+ id: 'run-1',+ metadata: null,+ status: 'failed',+ });+ goalFindByTask.mockRejectedValue(new Error('db down'));+ await driveTaskFromVerify(db, 'u1', 'op-1');+ expect(completeTaskForDelivery).not.toHaveBeenCalled();+ expect(taskUpdateStatus).toHaveBeenCalledWith('task-1', 'paused', {+ error: 'Delivery did not pass verification.',+ });+ });+it('errored β pauses without an inbox brief; never claims the delivery "did not pass"', async () => {runFindByOperation.mockResolvedValue({ id: 'run-1', metadata: null, status: 'errored' });await driveTaskFromVerify(db, 'u1', 'op-1');diff --git a/apps/server/src/services/verify/acceptanceService.ts b/apps/server/src/services/verify/acceptanceService.tsindex 4411e5a0de4..99e3e9e52eb 100644--- a/apps/server/src/services/verify/acceptanceService.ts+++ b/apps/server/src/services/verify/acceptanceService.ts@@ -26,6 +26,7 @@ import {} from '@/database/models/acceptance';import { AgentModel } from '@/database/models/agent';import { DocumentModel } from '@/database/models/document';+import { GoalModel } from '@/database/models/goal';import { ProjectModel } from '@/database/models/project';import { TaskModel } from '@/database/models/task';import { TaskTopicModel } from '@/database/models/taskTopic';@@ -878,6 +879,23 @@ export class AcceptanceService {await this.acceptanceModel.updatePolicyStatus(acceptanceId, status);log('acceptance %s β %s (from round %d)', acceptanceId, status, current.roundIndex);}++ // Rounds settled outside the verifier pipeline β an ingested round (no+ // status, settled by its report) or a completed acceptance flow+ // (`delivered`) β have nothing else to drive the task. Rounds the server+ // verifier runs (`passed` / `failed` / `errored`) are driven once, after+ // any auto-repair, by `driveTaskFromVerify`; completing here would race it.+ //+ // Reconciled on every recompute of a delivered aggregate, not only on the+ // transition: a completion that failed once is retried by the next round,+ // report or flow event instead of leaving the task open for good. An+ // already-completed task is a no-op.+ if (+ status === 'delivered' &&+ (!current.status || current.status === 'delivered') &&+ acceptance.subjectType === 'task'+ )+ await this.completeTaskForDelivery(acceptanceId, acceptance.subjectId);return status;};@@ -1019,13 +1037,16 @@ export class AcceptanceService {* decision detail through the prompt builder.*/reject = async (acceptanceId: string, comment?: string): Promise<AcceptanceItem> => {- await this.requireDecidableAcceptance(acceptanceId);+ const acceptance = await this.requireDecidableAcceptance(acceptanceId);const settled = await this.stampDecision(acceptanceId, 'reject', comment);await this.acceptanceModel.updateStatus(acceptanceId, 'rejected');this.distilSettledRound(acceptanceId, settled);+ if (acceptance.subjectType === 'task')+ await this.reopenRejectedTaskSubject(acceptance.subjectId);+return (await this.acceptanceModel.findById(acceptanceId))!;};@@ -1203,9 +1224,10 @@ export class AcceptanceService {};/**- * Accepting a task subject completes the task when verification didn't- * already (e.g. the round failed but the user accepted anyway). Best-effort:- * a task error must not undo the recorded acceptance.+ * Completes a task subject that verification didn't already settle β on+ * accept (e.g. the round failed but the user accepted anyway) and when an+ * ingested round delivers. Best-effort: a task error must not undo the+ * recorded acceptance.*/private completeTaskSubject = async (subjectId: string): Promise<void> => {try {@@ -1222,12 +1244,94 @@ export class AcceptanceService {id: task.id,status: 'completed',});- log('acceptance accepted β task %s completed', task.id);+ log('acceptance β task %s completed', task.id);} catch (error) {log('completeTaskSubject failed (non-fatal): %O', error);}};+ /**+ * The task whose status follows its acceptance's lifecycle: delivered β+ * completed, rejected β reopened. Goal graph tasks are driven by their+ * coordinator (a paused task is its retry signal) and recurring tasks stay+ * on their schedule, so neither follows the acceptance.+ */+ private resolveLifecycleTask = async (subjectId: string) => {+ const task = await new TaskModel(this.db, this.userId, this.workspaceId).resolve(subjectId);+ if (!task || task.automationMode) return null;++ const goal = await new GoalModel(this.db, this.userId, this.workspaceId).findByGraphTask(+ task.id,+ );+ return goal ? null : task;+ };++ /**+ * A delivered acceptance completes its task: the delivery is in, and the+ * user's accept / reject decides from here. Shared by every settlement path.+ *+ * A reject can land at any point around the completion, so the decision is+ * read on both sides of the write: rejected before β the task is left alone;+ * rejected in between β the reject saw an unfinished task and did not reopen+ * it, so it is reopened here. Best-effort β never fails the caller.+ *+ * @returns `completed` when the task now reads completed, `rejected` when a+ * reject won, `skipped` when the task does not follow the acceptance or could+ * not be completed.+ */+ completeTaskForDelivery = async (+ acceptanceId: string,+ subjectId: string,+ ): Promise<'completed' | 'rejected' | 'skipped'> => {+ try {+ const task = await this.resolveLifecycleTask(subjectId);+ if (!task) return 'skipped';++ const before = await this.acceptanceModel.findPolicyById(acceptanceId);+ if (before?.status === 'rejected') return 'rejected';+ if (before?.status !== 'delivered') return 'skipped';++ await this.completeTaskSubject(task.id);+ // `completeTaskSubject` is best-effort and swallows its own failures (e.g. a+ // running operation that could not be interrupted). Only a task that really+ // reads completed counts β anything else lets the caller fall back.+ const written = await new TaskModel(this.db, this.userId, this.workspaceId).findById(task.id);+ if (written?.status !== 'completed') return 'skipped';++ const after = await this.acceptanceModel.findPolicyById(acceptanceId);+ if (after?.status === 'rejected') {+ await this.reopenRejectedTaskSubject(task.id);+ return 'rejected';+ }+ return 'completed';+ } catch (error) {+ log('completeTaskForDelivery failed (non-fatal): %O', error);+ return 'skipped';+ }+ };++ /**+ * Rejecting a delivery reopens the task it completed, so the task is not left+ * reading "done" while its repair is pending. Only a completed task moves β+ * one the user already paused, canceled or restarted keeps its own state.+ */+ private reopenRejectedTaskSubject = async (subjectId: string): Promise<void> => {+ try {+ const task = await this.resolveLifecycleTask(subjectId);+ if (task?.status !== 'completed') return;++ await new TaskModel(this.db, this.userId, this.workspaceId).updateStatusIfCurrent(+ task.id,+ 'completed',+ 'paused',+ { completedAt: null },+ );+ log('acceptance rejected β task %s reopened as paused', task.id);+ } catch (error) {+ log('reopenRejectedTaskSubject failed (non-fatal): %O', error);+ }+ };+/** Best-effort subject header info for the bundle (title may be gone). */resolveSubject = async (acceptance: AcceptanceItem): Promise<AcceptanceSubjectSummary> => {// A user rename wins over the subject's own title β the sidebar entry isdiff --git a/apps/server/src/services/verify/settle.ts b/apps/server/src/services/verify/settle.tsindex 26e603ce235..9b76e399b7f 100644--- a/apps/server/src/services/verify/settle.ts+++ b/apps/server/src/services/verify/settle.ts@@ -17,6 +17,7 @@ import { scheduleGoalAdvance } from '@/server/services/goal/scheduler';import { TaskService } from '@/server/services/task';import { TaskResultBridgeService } from '@/server/services/taskResultBridge';+import { AcceptanceService } from './acceptanceService';import { reviewGoalDelivery } from './goalReview';import { maybeAutoRepair } from './repairService';import { VerifyReporterService } from './reporter';@@ -179,6 +180,17 @@ export const driveTaskFromVerify = async (const task = await taskModel.findById(taskOperation.taskId);if (!task || TERMINAL_TASK_STATUS.has(task.status)) return; // task already settled+ // A Goal graph task is steered by its coordinator, which reads a paused task+ // as "start another attempt". A failed lookup counts as Goal so a failure+ // never silently skips the retry.+ let goal: Awaited<ReturnType<GoalModel['findByGraphTask']>> | 'unknown';+ try {+ goal = await new GoalModel(db, userId, workspaceId).findByGraphTask(taskOperation.taskId);+ } catch (error) {+ log('verify-settle goal lookup failed for task %s: %O', taskOperation.taskId, error);+ goal = 'unknown';+ }+// The review already retries a check whose review could not run. An// `errored` result here is the reviewer's problem, and another builder// attempt would only re-deliver into the same broken review.@@ -252,6 +264,20 @@ export const driveTaskFromVerify = async (: 'verify failed β recurring task %s remains scheduled',taskOperation.taskId,);+ } else if (+ outcome === 'failed' &&+ run.acceptanceId &&+ !goal &&+ // A failed round still delivers the Acceptance β the verdict is advice and+ // the user's accept / reject decides, so the task follows the Acceptance+ // and completes. A reject that already landed (or lands mid-write) keeps+ // the task open instead, falling through to the pause below.+ (await new AcceptanceService(db, userId, workspaceId).completeTaskForDelivery(+ run.acceptanceId,+ taskOperation.taskId,+ )) === 'completed'+ ) {+ log('verify failed β acceptance delivered β task %s completed', taskOperation.taskId);} else {// Verification outcomes belong to the task itself. Do not create an inbox// brief here: a verifier rejection/error is not a separate user todo.@@ -309,10 +335,7 @@ export const driveTaskFromVerify = async (// this is the server-side driver for long-horizon goals, and without it a// goal only progresses while some client keeps ticking it.try {- const goal = await new GoalModel(db, userId, workspaceId).findByGraphTask(- taskOperation.taskId,- );- if (goal) {+ if (goal && goal !== 'unknown') {await scheduleGoalAdvance({ goalId: goal.id, trigger: 'settle', userId, workspaceId });log('verify-settle β queued goal advance for %s', goal.id);}diff --git a/packages/database/src/models/task.ts b/packages/database/src/models/task.tsindex 810499a615c..812521c054f 100644--- a/packages/database/src/models/task.ts+++ b/packages/database/src/models/task.ts@@ -1450,7 +1450,7 @@ export class TaskModel {id: string,currentStatus: string,status: string,- extra?: { completedAt?: Date; error?: string | null; startedAt?: Date },+ extra?: { completedAt?: Date | null; error?: string | null; startedAt?: Date },): Promise<TaskItem | null> {const [task] = await this.db.update(tasks)