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(verify): record CLI builder evidence the Acceptance way (#20155)

Arvin Xu80cb913374dc
diff --git a/apps/server/src/services/verify/__tests__/evidenceCoverage.test.ts b/apps/server/src/services/verify/__tests__/evidenceCoverage.test.ts
index 8dc37d6908e..58e2a300e59 100644
--- a/apps/server/src/services/verify/__tests__/evidenceCoverage.test.ts
+++ b/apps/server/src/services/verify/__tests__/evidenceCoverage.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { coverageGaps, readRequiredEvidence } from '../evidenceCoverage';
+import { coverageGaps, readRequiredEvidence, runEvidenceGaps } from '../evidenceCoverage';
describe('readRequiredEvidence', () => {
it('reads a requiredEvidence array off the verifier config', () => {
@@ -16,6 +16,21 @@ describe('readRequiredEvidence', () => {
});
});
+describe('runEvidenceGaps', () => {
+ it('only gates run evidence; deliverable and task artifacts are resolved by the verifier', () => {
+ const config = {
+ requiredEvidence: [
+ { scope: 'deliverable', type: 'text' },
+ { scope: 'task_artifacts', type: 'transcript' },
+ { scope: 'run_evidence', type: 'screenshot' },
+ { type: 'video' },
+ ],
+ };
+ expect(runEvidenceGaps(config, [])).toEqual(['screenshot', 'video']);
+ expect(runEvidenceGaps(config, [{ type: 'screenshot' }, { type: 'video' }])).toEqual([]);
+ });
+});
+
describe('coverageGaps', () => {
it('returns no gaps when the item declares no evidence requirement', () => {
expect(coverageGaps(undefined, [])).toEqual([]);
diff --git a/apps/server/src/services/verify/__tests__/evidenceSubmission.test.ts b/apps/server/src/services/verify/__tests__/evidenceSubmission.test.ts
index 2a97e54cbfb..5b469f844c7 100644
--- a/apps/server/src/services/verify/__tests__/evidenceSubmission.test.ts
+++ b/apps/server/src/services/verify/__tests__/evidenceSubmission.test.ts
@@ -6,10 +6,11 @@ import {
startEvidenceSubmission,
} from '../evidenceSubmission';
-const { createMany, execAgent, findByOperation, upsertByCheckItem } = vi.hoisted(() => ({
+const { createMany, execAgent, findByOperation, listByRun, upsertByCheckItem } = vi.hoisted(() => ({
createMany: vi.fn(),
execAgent: vi.fn(),
findByOperation: vi.fn(),
+ listByRun: vi.fn(),
upsertByCheckItem: vi.fn(),
}));
@@ -25,7 +26,7 @@ vi.mock('@/database/models/verifyCheckResult', () => ({
}));
vi.mock('@/database/models/verifyEvidence', () => ({
VerifyEvidenceModel: vi.fn(function () {
- return { createMany };
+ return { createMany, listByRun };
}),
}));
vi.mock('@/database/models/verifyRun', () => ({
@@ -40,6 +41,7 @@ describe('startEvidenceSubmission', () => {
findByOperation.mockReset().mockResolvedValue({ id: 'run-1' });
upsertByCheckItem.mockReset().mockResolvedValue({ id: 'result-1' });
createMany.mockReset().mockResolvedValue(undefined);
+ listByRun.mockReset().mockResolvedValue([]);
});
it('records the heterogeneous builder deliverable as inline evidence for every criterion', async () => {
@@ -73,6 +75,44 @@ describe('startEvidenceSubmission', () => {
]);
});
+ it('leaves criteria the builder already evidenced untouched', async () => {
+ listByRun.mockResolvedValue([{ checkItemId: 'criterion-1', type: 'transcript' }]);
+
+ await recordHeterogeneousDeliverableEvidence({
+ db: {} as any,
+ deliverable: 'the whole final report',
+ operation: { id: 'work-op' } as any,
+ plan: [
+ {
+ id: 'criterion-1',
+ index: 0,
+ onFail: 'manual',
+ required: true,
+ title: 'Evidenced by the builder',
+ verifierConfig: {},
+ verifierType: 'llm',
+ },
+ {
+ id: 'criterion-2',
+ index: 1,
+ onFail: 'manual',
+ required: true,
+ title: 'Left without evidence',
+ verifierConfig: {},
+ verifierType: 'llm',
+ },
+ ],
+ userId: 'user-1',
+ });
+
+ expect(listByRun).toHaveBeenCalledWith('run-1');
+ expect(upsertByCheckItem).toHaveBeenCalledTimes(1);
+ expect(upsertByCheckItem).toHaveBeenCalledWith(
+ expect.objectContaining({ checkItemId: 'criterion-2' }),
+ );
+ expect(createMany).toHaveBeenCalledTimes(1);
+ });
+
it('continues as the original builder in the same topic with only the evidence tool', async () => {
const operation = {
agentId: 'builder-agent',
diff --git a/apps/server/src/services/verify/__tests__/lifecycleClaim.test.ts b/apps/server/src/services/verify/__tests__/lifecycleClaim.test.ts
index e5c159d4cd7..97424919f78 100644
--- a/apps/server/src/services/verify/__tests__/lifecycleClaim.test.ts
+++ b/apps/server/src/services/verify/__tests__/lifecycleClaim.test.ts
@@ -184,6 +184,47 @@ describe('runVerifyOnCompletion β€” verification claim', () => {
expect(startEvidenceSubmission).toHaveBeenCalledTimes(1);
});
+ /**
+ * Regression (T-545): a CLI builder evidenced every criterion with
+ * `result submit`, but the plan also named `deliverable`-scoped text it never
+ * uploads. The handoff counted those as missing, so the builder's final
+ * report was pasted into every check even though the structural gate ignores
+ * that scope.
+ */
+ it('treats deliverable-scoped requirements as covered, like the structural gate', async () => {
+ findByOperation.mockResolvedValue({
+ ...confirmedRun,
+ plan: [
+ {
+ id: 'c1',
+ required: true,
+ verifierConfig: {
+ requiredEvidence: [
+ { scope: 'deliverable', type: 'text' },
+ { scope: 'deliverable', type: 'transcript' },
+ ],
+ },
+ },
+ ],
+ });
+ operationFindById.mockResolvedValue({
+ agentId: 'builder',
+ id: 'op-1',
+ model: null,
+ provider: 'claude-code',
+ taskId: 'task-1',
+ topicId: 'topic-1',
+ });
+ evidenceListByRun.mockResolvedValue([{ checkItemId: 'c1', type: 'transcript' }]);
+ claimEvidenceCollection.mockResolvedValue(true);
+
+ await runVerifyOnCompletion(db, 'u1', params);
+
+ expect(recordHeterogeneousDeliverableEvidence).not.toHaveBeenCalled();
+ expect(startEvidenceSubmission).not.toHaveBeenCalled();
+ expect(execute).toHaveBeenCalledTimes(1);
+ });
+
/**
* Regression: attaching onto an acceptance whose newest round is still a draft
* folds this run into it and deletes the source row, moving the operation id
diff --git a/apps/server/src/services/verify/evidenceCoverage.ts b/apps/server/src/services/verify/evidenceCoverage.ts
index 987e72fe226..1195880ca68 100644
--- a/apps/server/src/services/verify/evidenceCoverage.ts
+++ b/apps/server/src/services/verify/evidenceCoverage.ts
@@ -25,3 +25,20 @@ export const coverageGaps = (
const present = new Set(evidence.map((e) => e.type));
return [...new Set(required.map((r) => r.type))].filter((t) => !present.has(t));
};
+
+/**
+ * Run-evidence types a criterion still misses. `deliverable` / `task_artifacts`
+ * requirements are resolved by the verifier from the operation's documents and
+ * files, so only `run_evidence` must exist as verify_evidence rows. This is the
+ * one coverage rule shared by the builder handoff and the structural gate:
+ * when they disagree, a builder that already evidenced a criterion is treated
+ * as missing evidence and gets its final report pasted into every check.
+ */
+export const runEvidenceGaps = (
+ config: Record<string, unknown> | undefined | null,
+ evidence: { type: VerifyEvidenceType }[],
+): VerifyEvidenceType[] =>
+ coverageGaps(
+ readRequiredEvidence(config)?.filter((spec) => !spec.scope || spec.scope === 'run_evidence'),
+ evidence,
+ );
diff --git a/apps/server/src/services/verify/evidenceSubmission.ts b/apps/server/src/services/verify/evidenceSubmission.ts
index 6a8cf6c9b5d..e283f269cf3 100644
--- a/apps/server/src/services/verify/evidenceSubmission.ts
+++ b/apps/server/src/services/verify/evidenceSubmission.ts
@@ -21,6 +21,12 @@ Call submitEvidence once for each criterion. This is evidence collection only: d
* External CLI agents cannot call server builtin tools. Preserve their final
* handoff as inline evidence instead of starting an evidence-only hetero turn
* that can never reach `submitEvidence`.
+ *
+ * Only criteria the builder left without any evidence get the handoff. A
+ * criterion it already evidenced through `lh acceptance run result submit`
+ * keeps exactly what it submitted, as an Acceptance round does: the final
+ * report is not evidence for a specific check and is already handed to the
+ * verifier as the deliverable.
*/
export const recordHeterogeneousDeliverableEvidence = async (params: {
db: LobeChatDatabase;
@@ -34,7 +40,15 @@ export const recordHeterogeneousDeliverableEvidence = async (params: {
const run = await new VerifyRunModel(db, userId, workspaceId).findByOperation(operation.id);
if (!run) throw new Error('Verification run is missing for heterogeneous evidence');
+ const evidenced = new Set(
+ (await new VerifyEvidenceModel(db, userId, workspaceId).listByRun(run.id)).map(
+ (row) => row.checkItemId,
+ ),
+ );
+
for (const item of plan) {
+ if (evidenced.has(item.id)) continue;
+
const result = await new VerifyCheckResultModel(db, userId, workspaceId).upsertByCheckItem({
checkItemId: item.id,
checkItemIndex: item.index,
diff --git a/apps/server/src/services/verify/executor.ts b/apps/server/src/services/verify/executor.ts
index 6f09cfa2227..a9fde2620c6 100644
--- a/apps/server/src/services/verify/executor.ts
+++ b/apps/server/src/services/verify/executor.ts
@@ -29,7 +29,7 @@ import type { LobeChatDatabase } from '@/database/type';
import { AiGenerationService } from '@/server/services/aiGeneration';
import { FileService } from '@/server/services/file';
-import { coverageGaps, readRequiredEvidence } from './evidenceCoverage';
+import { runEvidenceGaps } from './evidenceCoverage';
import { planEvidenceVerification } from './evidencePlanner';
import { resolveModelReadableFrameUrl } from './modelFrames';
import { planItemToPendingResult } from './resultSnapshot';
@@ -266,13 +266,7 @@ export class VerifyExecutorService {
): Promise<Set<string>> {
const gapIds = new Set<string>();
for (const item of items) {
- // Deliverable/task-artifact evidence is resolved by the verifier agent
- // from the operation's associated documents/files. Only run evidence is
- // expected to have been explicitly captured into verify_evidence rows.
- const required = readRequiredEvidence(item.verifierConfig)?.filter(
- (spec) => !spec.scope || spec.scope === 'run_evidence',
- );
- const gaps = coverageGaps(required, evidenceByItem.get(item.id) ?? []);
+ const gaps = runEvidenceGaps(item.verifierConfig, evidenceByItem.get(item.id) ?? []);
if (gaps.length === 0) continue;
gapIds.add(item.id);
diff --git a/apps/server/src/services/verify/lifecycle.ts b/apps/server/src/services/verify/lifecycle.ts
index 64ed9e36222..7a596aafaae 100644
--- a/apps/server/src/services/verify/lifecycle.ts
+++ b/apps/server/src/services/verify/lifecycle.ts
@@ -1,4 +1,5 @@
import { isHeterogeneousAgentModelId } from '@lobechat/const';
+import type { VerifyEvidenceType } from '@lobechat/types';
import debug from 'debug';
import { AgentOperationModel } from '@/database/models/agentOperation';
@@ -9,6 +10,7 @@ import { VerifyRunModel } from '@/database/models/verifyRun';
import type { LobeChatDatabase } from '@/database/type';
import { createVerifierAgentRunner } from './agentVerifier';
+import { runEvidenceGaps } from './evidenceCoverage';
import {
recordHeterogeneousDeliverableEvidence,
startEvidenceSubmission,
@@ -143,25 +145,21 @@ const executeVerifyLifecycle = async (
const inRunEvidence = await new VerifyEvidenceModel(db, userId, workspaceId).listByRun(
run.id,
);
- const byCheckItem = new Map<string, Set<string>>();
+ const byCheckItem = new Map<string, { type: VerifyEvidenceType }[]>();
for (const row of inRunEvidence) {
- const types = byCheckItem.get(row.checkItemId) ?? new Set<string>();
- types.add(row.type);
- byCheckItem.set(row.checkItemId, types);
+ const rows = byCheckItem.get(row.checkItemId) ?? [];
+ rows.push(row);
+ byCheckItem.set(row.checkItemId, rows);
}
+ // A criterion that names the artifacts it needs is only covered once each
+ // declared run-evidence type is present β€” the same rule the structural
+ // gate applies, so the handoff never asks for what the gate ignores.
const uncovered = plan.filter((item) => {
if (item.required === false) return false;
const captured = byCheckItem.get(item.id);
- if (!captured?.size) return true;
-
- // A criterion that names the artifacts it needs is only covered once
- // each declared type is present.
- const declared = (item.verifierConfig as { requiredEvidence?: { type: string }[] })
- ?.requiredEvidence;
- return Array.isArray(declared)
- ? declared.some((required) => !captured.has(required.type))
- : false;
+ if (!captured?.length) return true;
+ return runEvidenceGaps(item.verifierConfig, captured).length > 0;
});
if (inRunEvidence.length > 0 && uncovered.length === 0) {
diff --git a/packages/prompts/src/prompts/task/index.ts b/packages/prompts/src/prompts/task/index.ts
index ef94c097165..164a233e3dc 100644
--- a/packages/prompts/src/prompts/task/index.ts
+++ b/packages/prompts/src/prompts/task/index.ts
@@ -794,6 +794,9 @@ export const buildTaskRunPrompt = (input: TaskRunPromptInput, now?: Date): strin
taskLines.push(
' A criterion with a visible surface is proved by a screenshot or recording, and `screenshot`/`video` evidence must reference a real artifact by fileId. Never label prose as a visual artifact: if you could not capture one, say what you observed as `text` and name the blocker.',
);
+ taskLines.push(
+ ' Caption each artifact in the language this Task is written in, in 1–3 short sentences saying what it shows for that criterion. Never paste your final report into a criterion: it already reaches the verifier as the deliverable.',
+ );
taskLines.push(
' Produce concrete evidence while you work, and include artifact paths, commands, and observed results in your final response.',
);