🤯 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(verify): tell the dispatching agent which checks failed and why (#20058)
Arvin Xu1784cec821c2
diff --git a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.tsindex 47f6ccb118c..25b3655a4d1 100644--- a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts+++ b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts@@ -71,6 +71,14 @@ vi.mock('@/database/models/verifyRun', () => ({};}),}));+const { checkResultsListByRun } = vi.hoisted(() => ({+ checkResultsListByRun: vi.fn().mockResolvedValue([]),+}));+vi.mock('@/database/models/verifyCheckResult', () => ({+ VerifyCheckResultModel: vi.fn(function () {+ return { listByRun: checkResultsListByRun };+ }),+}));vi.mock('@/database/models/agentOperation', () => ({AgentOperationModel: vi.fn(function () {return { findById: opFindById };@@ -152,6 +160,117 @@ describe('driveTaskFromVerify', () => {* the attempt budget ran out. This string has no recovery branch, so the Goal* stops on a person instead.*/+ /**+ * Regression: a rejected delivery reached the dispatching agent as the bare+ * "Delivery did not pass verification.", so it could not tell a real+ * shortfall from a gate misfire and re-verified by hand.+ */+ it('tells the dispatcher which checks failed and why', async () => {+ runFindByOperation.mockResolvedValue({ id: 'run-1', status: 'failed' });+ checkResultsListByRun.mockResolvedValueOnce([+ {+ checkItemTitle: 'Optional style polish',+ required: false,+ status: 'failed',+ suggestion: 'Tighten the intro.',+ toulmin: null,+ verdict: 'failed',+ },+ {+ checkItemTitle: 'Each chapter has at least 2500 characters',+ required: true,+ status: 'failed',+ suggestion: null,+ toulmin: { reasoning: 'Chapters 1-5 are 2030-2353 characters, all below 2500.' },+ verdict: 'failed',+ },+ {+ checkItemTitle: 'Report is in Markdown',+ required: true,+ status: 'passed',+ suggestion: null,+ toulmin: { reasoning: 'It is.' },+ verdict: 'passed',+ },+ {+ checkItemTitle: 'Sources are cited',+ required: true,+ status: 'errored',+ suggestion: null,+ toulmin: null,+ verdict: null,+ },+ ]);++ await driveTaskFromVerify(db, 'u1', 'op-1');++ expect(checkResultsListByRun).toHaveBeenCalledWith('run-1');+ expect(deliverMock.mock.calls[0][0].errorMessage).toBe(+ [+ 'Delivery did not pass verification.',+ 'Failed checks:',+ '- Each chapter has at least 2500 characters: Chapters 1-5 are 2030-2353 characters, all below 2500.',+ ].join('\n'),+ );+ });++ it('explains a failure from stored evidence when the verifier gave no reasoning', async () => {+ runFindByOperation.mockResolvedValue({ id: 'run-1', status: 'failed' });+ checkResultsListByRun.mockResolvedValueOnce([+ {+ checkItemTitle: 'Screenshot shows the saved report',+ required: true,+ status: 'failed',+ suggestion: null,+ toulmin: { evidence: 'The screenshot shows an empty editor.' },+ verdict: 'failed',+ },+ ]);++ await driveTaskFromVerify(db, 'u1', 'op-1');++ expect(deliverMock.mock.calls[0][0].errorMessage).toContain(+ '- Screenshot shows the saved report: The screenshot shows an empty editor.',+ );+ });++ it('lists no optional checks when the Acceptance review is what rejected the delivery', async () => {+ runFindByOperation.mockResolvedValue({ acceptanceId: 'a-1', id: 'run-1', status: 'passed' });+ vi.mocked(reviewGoalDelivery).mockResolvedValueOnce({+ feedback: 'The table is missing the totals row.',+ predictionIds: [],+ status: 'rejected',+ });+ checkResultsListByRun.mockResolvedValueOnce([+ {+ checkItemTitle: 'Optional style polish',+ required: false,+ status: 'failed',+ suggestion: 'Tighten the intro.',+ toulmin: null,+ verdict: 'failed',+ },+ ]);++ await driveTaskFromVerify(db, 'u1', 'op-1');++ expect(deliverMock.mock.calls[0][0].errorMessage).toBe(+ [+ 'Delivery did not pass verification.',+ 'Acceptance review: The table is missing the totals row.',+ ].join('\n'),+ );+ });++ it('still sends the bare verdict when the failure details cannot be read', async () => {+ runFindByOperation.mockResolvedValue({ id: 'run-1', status: 'failed' });+ checkResultsListByRun.mockRejectedValueOnce(new Error('connection reset'));++ await driveTaskFromVerify(db, 'u1', 'op-1');++ expect(deliverMock.mock.calls[0][0].errorMessage).toBe('Delivery did not pass verification.');+ });+it('parks an undecidable Goal delivery on a person instead of another attempt', async () => {runFindByOperation.mockResolvedValue({id: 'run-1',diff --git a/apps/server/src/services/verify/settle.ts b/apps/server/src/services/verify/settle.tsindex 1a985397a37..26e603ce235 100644--- a/apps/server/src/services/verify/settle.ts+++ b/apps/server/src/services/verify/settle.ts@@ -9,7 +9,9 @@ import debug from 'debug';import { AgentOperationModel } from '@/database/models/agentOperation';import { GoalModel } from '@/database/models/goal';import { TaskModel } from '@/database/models/task';+import { VerifyCheckResultModel } from '@/database/models/verifyCheckResult';import { VerifyRunModel } from '@/database/models/verifyRun';+import type { VerifyCheckResultItem } from '@/database/schemas/verify';import type { LobeChatDatabase } from '@/database/type';import { scheduleGoalAdvance } from '@/server/services/goal/scheduler';import { TaskService } from '@/server/services/task';@@ -64,6 +66,56 @@ export const recomputeRepairAncestors = async (}};+const MAX_REPORTED_FAILURES = 5;+const MAX_REASON_CHARS = 300;++/**+ * Turn a failed run's check results into the rejection the dispatching agent+ * reads. The bare "did not pass" left it unable to tell a real shortfall from+ * a gate misfire, so it re-verified by hand or overrode the verdict.+ */+export const describeVerifyFailure = (+ results: Pick<+ VerifyCheckResultItem,+ 'checkItemTitle' | 'required' | 'status' | 'suggestion' | 'toulmin' | 'verdict'+ >[],+ reviewFeedback?: string,+): string => {+ const failed = results.filter(+ (r) =>+ r.status !== 'errored' &&+ (r.status === 'failed' || r.verdict === 'failed' || r.verdict === 'uncertain'),+ );+ // Only required checks gate the run. Optional failures stay out entirely —+ // when the Acceptance review is what rejected a passing run, its feedback is+ // the reason, not unrelated optional rows.+ const reasons = failed+ .filter((r) => r.required)+ .map((r) => {+ // Verifier agents may submit a verdict with only evidence or a limitation.+ const why = (+ r.toulmin?.reasoning ||+ r.suggestion ||+ r.toulmin?.limitation ||+ r.toulmin?.evidence ||+ ''+ )+ .replaceAll(/\s+/g, ' ')+ .trim();+ const clipped = why.length > MAX_REASON_CHARS ? `${why.slice(0, MAX_REASON_CHARS)}…` : why;+ return `- ${r.checkItemTitle || 'Untitled check'}${clipped ? `: ${clipped}` : ''}`;+ });++ const lines = ['Delivery did not pass verification.'];+ if (reviewFeedback?.trim()) lines.push(`Acceptance review: ${reviewFeedback.trim()}`);+ if (reasons.length > 0) {+ lines.push('Failed checks:', ...reasons.slice(0, MAX_REPORTED_FAILURES));+ if (reasons.length > MAX_REPORTED_FAILURES)+ lines.push(`- …and ${reasons.length - MAX_REPORTED_FAILURES} more`);+ }+ return lines.join('\n');+};+interface ReportContext {deliverable: string;goal: string;@@ -219,7 +271,17 @@ export const driveTaskFromVerify = async (try {const errorMessage =outcome === 'failed'- ? 'Delivery did not pass verification.'+ ? describeVerifyFailure(+ // The run is already claimed, so a failed lookup must not cost the+ // creator its callback — fall back to the bare verdict.+ await new VerifyCheckResultModel(db, userId, workspaceId)+ .listByRun(run.id)+ .catch((error) => {+ log('verify-settle failure details unavailable for %s: %O', run.id, error);+ return [];+ }),+ goalReview?.status === 'rejected' ? goalReview.feedback : undefined,+ ): outcome === 'errored' || outcome === 'review_errored'? 'Verification could not be completed due to an internal error; the delivery was not evaluated. Please retry or review it manually.': outcome === 'unjudgeable'